:root {
    color-scheme: light;
    --bg: #f5f3ee;
    --fg: #191918;
    --muted: #666863;
    --rule: #cbc8bf;
    --rule-strong: #8d8b84;
    --link: #1558c0;
    --link-visited: #65469a;
    --focus: #8a4f00;
    --positive: #26734d;
    --caution: #8a4f00;
    --negative: #b4232f;
    --maxw: 40rem;
    --gutter: 1rem;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --radius: 2px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #111210;
        --fg: #e9e7e1;
        --muted: #aaa9a3;
        --rule: #373833;
        --rule-strong: #70716b;
        --link: #8ab4f8;
        --link-visited: #c7a7ff;
        --focus: #ffbf47;
        --positive: #67c795;
        --caution: #ffbf47;
        --negative: #ff7b86;
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    width: min(100%, calc(var(--maxw) + 2 * var(--gutter)));
    min-height: 100vh;
    margin: 0 auto;
    padding: clamp(2rem, 8vh, 5rem) var(--gutter) calc(3rem + env(safe-area-inset-bottom));
    background: var(--bg);
    color: var(--fg);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: clamp(0.95rem, 0.92rem + 0.15vw, 1rem);
    line-height: 1.6;
}

button,
input {
    font: inherit;
}

button {
    touch-action: manipulation;
}

.hidden,
[hidden] {
    display: none !important;
}

a {
    color: var(--link);
    font-weight: 650;
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.2em;
}

a:visited {
    color: var(--link-visited);
}

a:hover {
    text-decoration-thickness: 0.14em;
}

:where(a, button, input, [tabindex]:not([tabindex="-1"])):focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
    border-radius: var(--radius);
}

.site-header {
    padding-bottom: var(--space-5);
    border-bottom: 2px solid var(--fg);
}

.site-kicker {
    margin: 0 0 var(--space-2);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.site-title {
    margin: 0;
    font-size: clamp(1.75rem, 1.45rem + 1.5vw, 2.35rem);
    font-weight: 700;
    letter-spacing: -0.045em;
    line-height: 1.1;
}

.site-subtitle {
    margin: var(--space-3) 0 0;
    color: var(--muted);
}

.site-section {
    padding: var(--space-6) 0;
    border-bottom: 1px solid var(--rule);
}

.section-heading {
    margin: 0 0 var(--space-4);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.3;
    text-transform: uppercase;
}

.section-intro {
    max-width: 36rem;
    margin: 0 0 var(--space-5);
    color: var(--muted);
}

.form-wrapper,
#product-form {
    margin: 0;
}

label {
    display: inline-block;
    margin-bottom: var(--space-2);
    font-weight: 700;
}

#product-input,
.text-answer-input {
    width: 100%;
    min-height: 2.75rem;
    padding: var(--space-3);
    border: 1px solid var(--fg);
    border-radius: 0;
    background: var(--bg);
    color: var(--fg);
    appearance: none;
}

#product-input::placeholder,
.text-answer-input::placeholder {
    color: var(--muted);
    opacity: 1;
}

.char-counter {
    margin: var(--space-1) 0 var(--space-4);
    color: var(--muted);
    font-size: 0.78rem;
    text-align: right;
}

.char-counter.warning {
    color: var(--negative);
    font-weight: 700;
}

button {
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--fg);
    border-radius: 0;
    background: transparent;
    color: var(--fg);
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--fg);
    color: var(--bg);
}

button:disabled,
.disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

#product-form > button,
#final-assessment-btn,
#reset-btn {
    width: 100%;
}

.spinner {
    min-height: 1.5em;
    margin: var(--space-5) 0 var(--space-1);
    color: var(--muted);
    font-size: 0.78rem;
}

.spinner::before {
    content: "[ processing / ]";
    animation: status-step 800ms steps(1, end) infinite;
}

.loading-message {
    min-height: 1.6em;
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

@keyframes status-step {
    25% { content: "[ processing — ]"; }
    50% { content: "[ processing \\ ]"; }
    75% { content: "[ processing | ]"; }
}

.questions-container {
    margin-top: var(--space-5);
    border-top: 1px solid var(--rule);
    counter-reset: question;
}

.question-block {
    position: relative;
    padding: var(--space-5) 0 var(--space-5) 2.75rem;
    border-bottom: 1px solid var(--rule);
    counter-increment: question;
}

.question-block::before {
    content: counter(question, decimal-leading-zero);
    position: absolute;
    top: var(--space-5);
    left: 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.question-block p {
    margin: 0 0 var(--space-4);
    font-weight: 700;
}

.answer-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.answer-buttons button {
    min-width: 5.5rem;
}

.answer-buttons button.selected {
    background: var(--fg);
    color: var(--bg);
}

.text-answer-input {
    margin: 0;
}

#final-assessment-btn {
    margin-top: var(--space-5);
}

.stock-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--rule);
}

.stock-title,
.stock-price-info {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3);
}

#stock-symbol,
#stock-price {
    font-size: 1.15rem;
    font-weight: 700;
}

#stock-price {
    color: var(--fg);
}

.yahoo-link {
    font-size: 0.78rem;
}

.skeleton {
    display: inline-block;
    min-width: 4rem;
    min-height: 1.2em;
    background: var(--rule);
    color: transparent !important;
    animation: skeleton-loading 1.2s ease-in-out infinite alternate;
}

.skeleton-chart {
    background: color-mix(in srgb, var(--rule) 45%, var(--bg));
    animation: skeleton-loading 1.2s ease-in-out infinite alternate;
}

@keyframes skeleton-loading {
    from { opacity: 0.45; }
    to { opacity: 0.9; }
}

#stock-change {
    padding-left: var(--space-2);
    border-left: 1px solid var(--rule);
}

#stock-change.positive {
    color: var(--positive);
}

#stock-change.negative {
    color: var(--negative);
}

#stock-chart {
    display: block;
    width: 100%;
    height: auto;
    margin: var(--space-5) 0;
    border-bottom: 1px solid var(--rule);
}

.stock-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin: 0;
}

.stock-info-item {
    min-width: 0;
    padding: 0 var(--space-4);
    border-left: 1px solid var(--rule);
}

.stock-info-item:first-child {
    padding-left: 0;
    border-left: 0;
}

.info-label,
.info-value {
    margin: 0;
}

.info-label {
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.info-value {
    margin-top: var(--space-1);
    font-weight: 700;
}

#score-display {
    margin: 0 0 var(--space-5);
}

.score-circle {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    color: var(--score-color, var(--caution));
}

#score-value {
    font-size: clamp(2.5rem, 2rem + 3vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.07em;
    line-height: 1;
}

.score-denominator {
    color: var(--muted);
}

#score-label {
    margin-top: var(--space-2);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#result-text {
    padding: var(--space-4) 0 var(--space-5) var(--space-4);
    border-left: 2px solid var(--score-color, var(--caution));
}

.md-content > :first-child {
    margin-top: 0;
}

.md-content > :last-child {
    margin-bottom: 0;
}

.md-content p,
.md-content ul,
.md-content ol,
.md-content blockquote {
    margin-top: 0;
    margin-bottom: var(--space-3);
}

.md-content ul,
.md-content ol {
    padding-left: var(--space-5);
}

.md-content li {
    margin: var(--space-1) 0;
}

.md-content strong {
    color: var(--fg);
}

.md-content em {
    color: var(--muted);
}

.md-content code {
    padding: 0.08rem var(--space-1);
    border: 1px solid var(--rule);
    background: var(--bg);
    font-size: 0.9em;
}

.md-content blockquote {
    padding-left: var(--space-3);
    border-left: 1px solid var(--rule-strong);
    color: var(--muted);
}

#bull-bear-cases {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: var(--space-6) 0;
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
}

.case-section {
    min-width: 0;
    padding: var(--space-4);
}

.case-section + .case-section {
    border-left: 1px solid var(--rule);
}

.case-section h3,
.legal-content h3 {
    margin: 0 0 var(--space-3);
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.bull-case h3 {
    color: var(--positive);
}

.bear-case h3 {
    color: var(--negative);
}

#history-list {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: history;
}

#history-list li {
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr) auto;
    gap: var(--space-3);
    align-items: baseline;
    padding: var(--space-4) 0;
    border-top: 1px solid var(--rule);
    counter-increment: history;
}

#history-list li::before {
    content: counter(history, decimal-leading-zero);
    color: var(--muted);
    font-size: 0.78rem;
}

.history-product {
    min-width: 0;
    overflow-wrap: anywhere;
}

.history-score {
    font-weight: 700;
}

.score--positive {
    color: var(--positive);
}

.score--caution {
    color: var(--caution);
}

.score--negative {
    color: var(--negative);
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-3);
    padding-top: var(--space-4);
    color: var(--muted);
    font-size: 0.82rem;
}

.site-footer p {
    margin: 0;
}

.site-footer a {
    font-weight: 600;
}

.legal-content p,
.legal-content ul {
    margin-top: 0;
    margin-bottom: var(--space-4);
}

.legal-content h3:not(:first-child) {
    margin-top: var(--space-6);
}

.legal-content ul {
    padding-left: var(--space-5);
}

.legal-content li {
    margin-bottom: var(--space-2);
}

.legal-updated {
    color: var(--muted);
    font-size: 0.82rem;
}

@media (max-width: 40rem) {
    body {
        padding-top: clamp(1.75rem, 7vw, 2.5rem);
    }

    .site-section {
        padding: var(--space-5) 0;
    }

    .stock-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .stock-price-info {
        width: 100%;
        justify-content: space-between;
    }

    #bull-bear-cases {
        grid-template-columns: 1fr;
    }

    .case-section + .case-section {
        border-top: 1px solid var(--rule);
        border-left: 0;
    }
}

@media (max-width: 23rem) {
    .question-block {
        padding-left: 2rem;
    }

    .answer-buttons {
        display: grid;
        grid-template-columns: 1fr;
    }

    .answer-buttons button {
        min-width: 0;
        width: 100%;
    }

    .stock-info {
        grid-template-columns: 1fr;
    }

    .stock-info-item,
    .stock-info-item:first-child {
        padding: var(--space-3) 0;
        border-top: 1px solid var(--rule);
        border-left: 0;
    }

    .stock-info-item:first-child {
        border-top: 0;
    }

    #history-list li {
        grid-template-columns: 1.75rem minmax(0, 1fr) auto;
        gap: var(--space-2);
    }
}

@media (prefers-reduced-motion: reduce) {
    .spinner::before,
    .skeleton,
    .skeleton-chart {
        animation: none;
    }

    .spinner::before {
        content: "[ processing ]";
    }
}

@media print {
    :root {
        --bg: #ffffff;
        --fg: #000000;
        --muted: #333333;
        --rule: #999999;
        --rule-strong: #000000;
        --link: #000000;
        --link-visited: #000000;
    }

    body {
        width: auto;
        max-width: none;
        margin: 0;
        padding: 0;
        font-size: 12pt;
    }

    a::after {
        content: " (" attr(href) ")";
        font-weight: normal;
    }

    button,
    .spinner,
    .loading-message,
    #stock-chart {
        display: none !important;
    }
}
