@layer base, layout, components, responsive, print;

@layer base {
    :root {
        color-scheme: light;
        --paper: #f7f3e8;
        --surface: #fffcf5;
        --ink: #22392e;
        --secondary: #526558;
        --forest: #245744;
        --forest-dark: #183d30;
        --seed: #936126;
        --clay: #a04632;
        --leaf: #dde9d9;
        --straw: #f1e2bc;
        --frost: #496a83;
        --rule: #d5d1c0;
        --error: #9c3829;
        --serif: Georgia, 'Times New Roman', serif;
        --content: 75rem;
        --gutter: clamp(1rem, 4vw, 2.5rem);
    }
    *, *::before, *::after { box-sizing: border-box; }
    html { color: var(--ink); background: var(--paper); font: 100%/1.58 system-ui, sans-serif; }
    body { margin: 0; }
    [hidden] { display: none !important; }
    h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.16; margin: 0 0 .65em; font-weight: 600; }
    h1 { font-size: clamp(2.15rem, 4.5vw, 3.5rem); letter-spacing: -.035em; }
    h2 { font-size: clamp(1.55rem, 3vw, 2.05rem); letter-spacing: -.018em; }
    h3 { font-size: 1.34rem; }
    h4 { font-size: 1.1rem; }
    p { margin: 0 0 1em; max-width: 70ch; }
    a { color: var(--forest); text-underline-offset: .19em; text-decoration-thickness: .085em; }
    a:hover { color: var(--forest-dark); }
    img { display: block; max-width: 100%; height: auto; }
    button, input, select { font: inherit; }
    :focus-visible { outline: 3px solid var(--clay); outline-offset: 4px; }
    .skip { position: absolute; inset: .5rem auto auto 1rem; z-index: 2; transform: translateY(-180%); background: var(--surface); padding: .65rem .85rem; }
    .skip:focus { transform: none; }
}

@layer layout {
    main, .site-header, .site-footer { max-width: calc(var(--content) + 2 * var(--gutter)); padding-inline: var(--gutter); margin-inline: auto; }
    main { min-height: 65vh; padding-block: 1.75rem 3rem; }
    .header-wrap { border-bottom: 1px solid var(--rule); }
    .site-header, .site-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .35rem 1rem; padding-block: .6rem; }
    .site-header nav, .site-footer nav { display: flex; flex-wrap: wrap; column-gap: clamp(.75rem, 2vw, 1.55rem); }
    .site-header nav a, .site-footer a { display: inline-flex; align-items: center; min-height: 44px; font-size: .9rem; }
    nav a, .site-footer a, .section-title > a, .tool-guide > a { text-decoration: none; }
    nav a:is(:hover, :focus-visible, [aria-current="page"]),
    .site-footer a:is(:hover, :focus-visible),
    .section-title > a:is(:hover, :focus-visible),
    .tool-guide > a:is(:hover, :focus-visible) { text-decoration-line: underline; }
    .wordmark { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
    .footer-wrap { color: var(--surface); background: var(--forest-dark); }
    .site-footer { padding-block: 1.2rem; }
    .site-footer a { color: var(--surface); }
    .site-footer a:hover { color: var(--straw); }
    .site-footer a:focus-visible { outline-color: var(--straw); }

    .hero { display: grid; gap: 1rem; align-items: center; }
    .hero h1 { font-size: clamp(2.15rem, 4.75vw, 4.2rem); line-height: 1.07; }
    .hero-copy p { font-size: clamp(1rem, 2vw, 1.18rem); color: var(--secondary); max-width: 45ch; }
    .hero-art { overflow: hidden; border-radius: 8px; }
    .hero-art img { width: 100%; max-height: 7.5rem; object-fit: cover; object-position: center 56%; }
    .hero-actions, .form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
    .quick-start { margin-top: 1.65rem; padding: 1rem 0 1.4rem; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
    .quick-start h2 { font-size: 1.5rem; margin-bottom: .65rem; }
    .quick-start form { display: grid; gap: .65rem; align-items: end; }
    .quick-start button { justify-self: start; }
    .crop-section, .season-tasks { padding-block: 2rem 0; }
    .section-title { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0 1rem; }
    .section-title > a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 630; }
    .crop-grid { margin: .5rem 0 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .85rem; }
    .crop-grid a { display: block; height: 100%; padding: .45rem .45rem .6rem; border: 1px solid var(--rule); text-decoration: none; background: var(--surface); border-radius: 7px; }
    .crop-grid a:hover { border-color: var(--forest); }
    .crop-grid a img { width: 100%; border-radius: 3px; }
    .crop-grid strong, .crop-grid span { display: block; margin-inline: .2rem; }
    .crop-grid strong { margin-top: .45rem; font-family: var(--serif); font-size: 1.19rem; }
    .crop-grid span { color: var(--secondary); font-family: var(--serif); font-style: italic; font-size: .84rem; }
    .task-links { display: grid; margin-bottom: 1.15rem; }
    .task-links a {
        position: relative; display: flex; flex-direction: column; padding: .85rem 1.5rem .85rem 0;
        border-top: 1px solid var(--rule); text-decoration: none;
    }
    .task-links a::after {
        content: ''; position: absolute; inset: 1.35rem .35rem auto auto; width: .42rem; height: .42rem;
        border: solid currentColor; border-width: 1.5px 1.5px 0 0; transform: rotate(45deg);
    }
    .task-links a:is(:hover, :focus-visible) { border-color: var(--forest); }
    .task-links a:is(:hover, :focus-visible) strong, .crop-grid a:is(:hover, :focus-visible) strong { text-decoration-line: underline; }
    .task-links span { color: var(--secondary); font-size: .9rem; }
}

@layer components {
    .button, button {
        display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .55rem .9rem;
        border: 1px solid var(--forest); border-radius: 6px; font-weight: 680; line-height: 1.3;
        background: var(--forest); color: var(--surface); text-decoration: none; text-align: center; cursor: pointer;
    }
    .button:hover, button:hover { background: var(--forest-dark); color: var(--surface); }
    .button-secondary, .link-button { background: transparent; color: var(--forest); }
    .link-button { border-color: transparent; text-decoration: underline; }

    .tool-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin-top: 1rem; align-items: start; }
    .tool-panel, .result-panel, .tool-guide { min-width: 0; padding: clamp(.85rem, 3vw, 1.35rem); border: 1px solid var(--rule); border-radius: 8px; }
    .tool-panel, .result-panel { background: var(--surface); }
    .tool-guide { background: var(--leaf); }
    .tool-guide > a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 630; }
    .tool-guide figure { margin: 0 0 .8rem; }
    .tool-guide img { width: 100%; border-radius: 4px; }
    .tool-guide figcaption { margin-top: .55rem; font-size: .9rem; max-width: 58ch; }
    .control-section { min-inline-size: 0; margin: 0 0 1.2rem; padding: .55rem 0 0; border: 0; border-top: 1px solid var(--rule); }
    .control-section legend { max-width: 100%; padding: 0 .45rem 0 0; font: 600 1.3rem/1.3 var(--serif); }
    .field-grid, .observation-grid { display: grid; gap: .75rem; }
    .field { min-width: 0; }
    .field > label { display: block; margin: 0 0 .19rem; font-size: .93rem; font-weight: 640; }
    .field input, .field select {
        display: block; width: 100%; min-height: 44px; min-width: 0; padding: .45rem .58rem;
        border: 1px solid var(--secondary); border-radius: 6px; background: var(--surface); color: var(--ink);
    }
    .field input[type="date"], .field input[type="number"] { font-variant-numeric: tabular-nums; }
    .field select {
        appearance: none; padding-right: 1.85rem;
        background-image: url('/art/chevron.svg'); background-position: right .58rem center;
        background-size: .8rem; background-repeat: no-repeat;
    }
    .field [aria-invalid="true"] { border: 2px solid var(--error); }
    .field-note { margin: .48rem 0 .3rem; font-size: .88rem; color: var(--secondary); }
    .field-note:empty, .form-status:empty, #tool-outcome:empty { display: none; }
    [data-profile-note]:empty + .field-grid { margin-top: .75rem; }
    .form-details { margin-top: .62rem; padding-bottom: .5rem; }
    .form-details .field-grid { margin-top: .22rem; }
    .simulator-detail { margin-bottom: .75rem; }
    summary { min-height: 44px; padding-block: .62rem; font-weight: 630; cursor: pointer; }
    .form-status { margin: .6rem 0 0; color: var(--secondary); font-size: .9rem; }
    .result-panel { margin-bottom: 1rem; }
    .result-panel:last-child { margin-bottom: 0; }
    .result-panel .field-note { margin-bottom: .75rem; }
    .error-panel { border-color: var(--error); }
    .error-panel h2 { color: var(--error); }
    .plan { border-top: 1px solid var(--rule); padding-block: 1rem .55rem; }
    .plan h3 { margin-bottom: .55rem; }
    .plan p, .plan-warnings { margin-block: 0 .53rem; }
    .plan-warnings { padding-left: 1.2rem; }
    .comparison { width: 100%; margin-bottom: 1rem; border-collapse: collapse; table-layout: fixed; font-size: .87rem; }
    .comparison :is(th, td) { padding: .5rem .33rem; vertical-align: top; border-bottom: 1px solid var(--rule); text-align: left; overflow-wrap: anywhere; }
    .comparison caption { text-align: left; color: var(--secondary); }
    .comparison th:first-child { width: 42%; }
    .comparison th span { display: block; font-weight: 400; }
    .result-state {
        display: inline-flex; align-items: center; gap: .42rem; padding: .2rem .56rem; margin-bottom: .65rem;
        border-radius: 5px; background: var(--paper); color: var(--ink); font-size: .86rem; font-weight: 720; line-height: 1.4;
    }
    .result-state::before { content: ''; width: .57rem; height: .57rem; border: 1.5px solid currentColor; border-radius: 50%; }
    .result-state:is([data-state="fits"],[data-state="likely_ready"]) { background: var(--leaf); }
    .result-state:is([data-state="fits"],[data-state="likely_ready"])::before { background: var(--forest); }
    .result-state:is([data-state="borderline"],[data-state="wait"],[data-state="provisional"],[data-state="past_preferred_stage"]) { background: var(--straw); }
    .result-state:is([data-state="concern"],[data-state="blocked"],[data-state="late"]) { color: var(--error); background: #faeee7; }
    .result-state:is([data-state="concern"],[data-state="blocked"],[data-state="late"])::before { border-radius: 0; transform: rotate(45deg); }
    .result-actions { margin-top: .65rem; }
    .timeline { list-style: none; padding: 0; margin: .5rem 0 .8rem .28rem; border-left: 2px solid var(--rule); }
    .timeline li { position: relative; display: flex; flex-direction: column; padding: .24rem .55rem .52rem 1rem; }
    .timeline li::before { content: ''; position: absolute; width: .57rem; height: .57rem; border-radius: 50%; background: var(--forest); top: .64rem; left: -.35rem; }
    .timeline li:first-child::before { background: var(--seed); }
    .timeline li:last-child::before { border-radius: 0; background: var(--clay); }
    .timeline span { color: var(--secondary); font-size: .88rem; font-variant-numeric: tabular-nums; }
    .season-key { list-style: none; margin: 1rem 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .45rem; }
    .season-key li { padding: .2rem 0; border-top: 4px solid var(--forest); font-size: .87rem; }
    .season-key .seed { border-top-style: dotted; border-color: var(--seed); }
    .season-key .growth { border-top-style: double; }
    .season-key .harvest { border-color: var(--clay); }
    .season-key .frost { border-top-style: dashed; border-color: var(--frost); }
    .ribbon { display: none; }
    .target-window { margin: .58rem 0; padding: .6rem; border: 1px solid var(--rule); border-radius: 5px; }
    .source-list { margin: .6rem 0; }
    .source-list ul { margin-top: 0; padding-left: 1.15rem; }
    .prose { max-width: 70ch; }
    .page-intro { color: var(--secondary); font-size: clamp(1rem, 1.7vw, 1.15rem); }
    .breadcrumbs { margin-bottom: .8rem; color: var(--secondary); font-size: .86rem; }
    .breadcrumbs ol { display: flex; flex-wrap: wrap; gap: 0 .42rem; margin: 0; padding: 0; list-style: none; }
    .breadcrumbs li + li::before { content: '/'; margin-right: .42rem; }
    .life-links { display: flex; flex-wrap: wrap; gap: .2rem .9rem; margin-bottom: .55rem; }
    .life-links a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 630; }
    .crop-feature { display: grid; align-items: start; gap: 1rem; margin-block: 1.2rem; }
    .crop-feature figure { margin: 0; }
    .crop-feature img { width: 100%; border-radius: 6px; }
    .crop-feature figcaption { margin-top: .42rem; }
    .editorial { margin-top: 1.65rem; }
    .editorial section { margin-bottom: 1.45rem; }
    .editorial details p { padding-left: 1rem; }
    .registry dd { margin: .12rem 0 1rem; color: var(--secondary); }
}

@layer responsive {
    @media (width < 44rem) {
        .menu-toggle {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: .5rem;
            min-height: 44px;
            padding-inline: .75rem;
            border: 1px solid var(--forest);
            border-radius: 5px;
            background: var(--surface);
            color: var(--forest-dark);
            font-size: .9rem;
            cursor: pointer;
        }
        .menu-icon {
            width: 1rem;
            height: .75rem;
            border-block: 2px solid currentColor;
            background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat;
        }
        .menu-toggle[aria-expanded="true"] { background: var(--leaf); }
        .site-header nav {
            flex-basis: 100%;
            flex-direction: column;
            border-top: 1px solid var(--rule);
        }
        .menu-toggle:not([hidden])[aria-expanded="false"] + nav { display: none; }
    }
    @media (min-width: 34rem) {
        .quick-start form { grid-template-columns: minmax(9rem, .65fr) minmax(13rem, 1fr) auto; }
        .season-key { grid-template-columns: repeat(4, 1fr); }
    }
    @media (min-width: 44rem) {
        .menu-toggle { display: none; }
        main { padding-top: 2.1rem; }
        .hero { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: clamp(1.25rem, 4vw, 3.5rem); }
        .hero-art img { max-height: none; }
        .crop-grid { grid-template-columns: repeat(5,minmax(0,1fr)); gap: clamp(.6rem, 1.4vw, 1rem); }
        .task-links { grid-template-columns: repeat(3,1fr); gap: 1rem; }
        .field-grid, .observation-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
        :is(.field-grid, .observation-grid) > .field { display: flex; flex-direction: column; }
        :is(.field-grid, .observation-grid) > .field > label { flex-grow: 1; }
        .crop-feature { grid-template-columns: minmax(0, 24rem) minmax(0, 22rem); }
        .ribbon { display: block; margin: .62rem 0 .8rem; padding: .5rem; border: 1px solid var(--rule); border-radius: 5px; }
        .ribbon-heading, .ribbon-row { display: grid; grid-template-columns: minmax(6.5rem, .55fr) minmax(12rem, 1.45fr); align-items: center; gap: .45rem; }
        .ribbon-row > span { font-size: .76rem; line-height: 1.16; }
        .ribbon-months, .ribbon-track { display: grid; grid-template-columns: repeat(12,minmax(0,1fr)); text-align: center; }
        .ribbon-months span { color: var(--secondary); font-size: .62rem; }
        .ribbon-track { min-height: 1.15rem; padding-block: .19rem; }
        .ribbon-track span { border-right: 1px solid var(--rule); background: var(--paper); }
        .ribbon-track .seed { border-block: 2px dotted var(--seed); background: var(--straw); }
        .ribbon-track .growth { border-block: 3px double var(--forest); background: var(--leaf); }
        .ribbon-track .harvest { background: var(--clay); }
        .ribbon-track .frost { border-right: 2px dashed var(--frost); background: #dce7ee; }
    }
    @media (min-width: 60rem) {
        .tool-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); column-gap: 1.25rem; align-items: start; }
        .tool-panel { grid-column: 1; grid-row: 1 / span 2; }
        #tool-outcome, .tool-guide { grid-column: 2; }
        #tool-outcome { grid-row: 1; }
        .tool-guide { grid-row: 2; }
        .tool-layout:has(#tool-outcome:empty) .tool-guide { grid-row: 1; }
    }
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after { scroll-behavior: auto !important; }
    }
}

@layer print {
    @media print {
        :root { --paper: white; --surface: white; --ink: black; --secondary: #222; --rule: #aaa; }
        main { display: block; padding: 0; min-height: 0; }
        .header-wrap, .footer-wrap, .skip, .breadcrumbs, .tool-panel, .tool-guide, .result-actions, .ribbon { display: none !important; }
        .tool-layout, #tool-outcome { display: block; }
        .result-panel { padding: 0; border: 0; }
        .plan { break-inside: avoid-page; }
        .timeline li { display: flex; flex-direction: row; justify-content: space-between; gap: .5rem; }
    }
}
