/* ═════════════════════════════════════════════════════════════════════════ */
/* CarbonBalance — Compost Feedstock C:N Ratio & Moisture Calculator          */
/* Theme: humus brown, damp leaf litter, fresh-cut green                      */
/* ═════════════════════════════════════════════════════════════════════════ */

:root {
    --sil-light-ready: 1;

    /* Surfaces — deep humus through to turned bedding */
    --bg-primary: #14100b;
    --bg-surface: #1f1810;
    --bg-card: #1f1810;
    --bg-hover: #2b2117;
    --bg-input: #271e14;
    --bg-sunken: #191309;

    /* Type */
    --text-primary: #f7f1e4;
    --text-secondary: #dcc9a8;
    --text-muted: #b39a75;

    /* Structure */
    --border: #3d3020;
    --border-hover: #58452c;

    /* Action — fresh clipping green */
    --accent: #9dc93f;
    --accent-hover: #b2dc55;
    --accent-glow: rgba(157, 201, 63, 0.22);
    --on-accent: #16200a;

    /* Semantic */
    --success: #7cc45a;
    --warning: #e0a33a;
    --error: #e2694f;

    /* Domain state — the two recommended windows from Rynk Table 3.1 */
    --state-preferred: #7cc45a;
    --state-reasonable: #6a6034;
    --gauge-track: #2e2417;

    /* Feedstock layer ramp — carbon-brown through nitrogen-green, chosen to
       stay mutually distinguishable in both themes rather than inverted. */
    --layer-1: #8fbf3c;
    --layer-2: #c99a3c;
    --layer-3: #6ba4a0;
    --layer-4: #b4694a;
    --layer-5: #9a86c4;
    --layer-6: #d0b45f;
    --on-layer: #14100b;

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --shadow-subtle: 0 4px 22px rgba(0, 0, 0, 0.42);
}

/* ── Light theme — same hues, lightness remapped. ── */
[data-theme="light"] {
    --bg-primary: #f8f4ea;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #efe7d6;
    --bg-input: #fbf8f1;
    --bg-sunken: #f2ecdf;

    --text-primary: #1e1710;
    --text-secondary: #4b3c27;
    --text-muted: #6b5735;

    --border: #ddd0b6;
    --border-hover: #bda87f;

    --accent: #4c7a15;
    --accent-hover: #3c6210;
    --accent-glow: rgba(76, 122, 21, 0.14);
    --on-accent: #ffffff;

    --success: #3f7d29;
    --warning: #96620a;
    --error: #b8371f;

    --state-preferred: #3f7d29;
    --state-reasonable: #c2b477;
    --gauge-track: #e6dec9;

    --layer-1: #4f7a12;
    --layer-2: #9a6a10;
    --layer-3: #216f6a;
    --layer-4: #9c3f22;
    --layer-5: #5b4a9c;
    --layer-6: #8a6f14;
    --on-layer: #ffffff;

    --shadow-subtle: 0 4px 22px rgba(30, 23, 16, 0.10);
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    margin: 0;
    padding: 0;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
    font-family: 'Outfit', system-ui, sans-serif;
    color: var(--text-primary);
    margin: 0 0 0.6rem;
}

h1 { font-size: 2.5rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
h3 { font-size: 1.35rem; font-weight: 700; line-height: 1.3; }
h4 { font-size: 1.15rem; font-weight: 600; line-height: 1.4; }

p { margin: 0 0 1rem; }
a { color: var(--accent); }

/* ── Header ──────────────────────────────────────────────────────────────── */

.app-header {
    background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border);
    padding: 2.5rem 1rem 2rem;
    text-align: center;
}

.header-container { max-width: 900px; margin: 0 auto; }

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--accent-glow);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.badge-icon { font-size: 1rem; }

.app-header p {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin: 0;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

/* width:100% is load-bearing, not cosmetic. shared/global-ui.css makes <body> a
   column flex container and gives main `flex: 1 0 auto` — flex-shrink 0. Without
   an explicit width the flex base size resolves to max-content, so the widest
   descendant (the 620px reference table, the 760px canvas) drags the whole page
   wider than the viewport and the body scrolls sideways on a phone. Pinning the
   width to the container makes the inner overflow-x containers do their job. */
.app-main {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 1.75rem 1rem 3rem;
}

.ad-placeholder {
    background: var(--bg-sunken);
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1rem auto 1.5rem;
}

.ad-desktop { width: 728px; height: 90px; max-width: 100%; }
.ad-mobile { display: none; width: 320px; height: 50px; }

@media (max-width: 767px) {
    .ad-desktop { display: none; }
    .ad-mobile { display: flex; }
}

.calculator-card,
.content-section,
.reference-section,
.seo-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-subtle);
    padding: 1.5rem;
    margin-bottom: 1.75rem;
}

.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.card-head h2 { margin: 0; }

/* ── Verdict badge ───────────────────────────────────────────────────────── */

.verdict {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.verdict-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-muted);
    flex: 0 0 auto;
}

.verdict-ok .verdict-dot { background: var(--success); }
.verdict-warn .verdict-dot { background: var(--warning); }
.verdict-bad .verdict-dot { background: var(--error); }
.verdict-ok { border-color: var(--success); }
.verdict-warn { border-color: var(--warning); }
.verdict-bad { border-color: var(--error); }

/* ── Control bar ─────────────────────────────────────────────────────────── */

.control-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    align-items: flex-end;
    padding: 0.9rem 1rem;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.control-select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    padding: 0.5rem 0.65rem;
    min-height: 44px;
    min-width: 190px;
}

.control-select:focus-visible,
.fs-input:focus-visible,
.fs-select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.toggle-group {
    display: inline-flex;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 3px;
}

.toggle-btn {
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.85rem;
    min-height: 40px;
}

.toggle-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.toggle-btn.active { background: var(--accent); color: var(--on-accent); }

/* ── Feedstock rows ──────────────────────────────────────────────────────── */

.row-list { display: flex; flex-direction: column; gap: 0.85rem; }

.fs-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-hover);
    padding: 0.9rem 1rem;
}

.fs-row.is-solving {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-glow);
}

.fs-row-main {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) auto;
    gap: 0.75rem 1rem;
    align-items: end;
}

.fs-row-sub {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem 1rem;
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px dashed var(--border);
}

.fs-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }

.fs-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.fs-select,
.fs-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    padding: 0.5rem 0.6rem;
    min-height: 44px;
    width: 100%;
}

.fs-input { font-family: 'JetBrains Mono', Consolas, monospace; }
.fs-input:disabled { color: var(--text-muted); background: var(--bg-sunken); }

.fs-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', Consolas, monospace;
}

.fs-readout-val {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.95rem;
    color: var(--text-primary);
    padding: 0.55rem 0;
}

.fs-row-actions { display: flex; gap: 0.5rem; }

.fs-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.5rem 0.8rem;
    min-height: 44px;
}

.fs-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.fs-solve.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.fs-remove:hover { border-color: var(--error); color: var(--error); }

.row-tools { display: flex; flex-wrap: wrap; gap: 0.65rem; margin: 1rem 0 0.25rem; }

.action-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.6rem 1.1rem;
    min-height: 44px;
}

.action-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.action-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.action-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.input-warnings {
    margin-top: 1rem;
    border: 1px solid var(--warning);
    border-radius: var(--radius-md);
    background: var(--bg-sunken);
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.input-warnings p { margin: 0 0 0.4rem; }
.input-warnings p:last-child { margin-bottom: 0; }

/* ── Targets ─────────────────────────────────────────────────────────────── */

.target-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    margin-top: 1.5rem;
    padding: 1.1rem 1rem;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.target-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.target-head label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.target-out {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-primary);
}

.target-item input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    min-height: 44px;
}

.target-scale {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', Consolas, monospace;
}

.target-solve { display: flex; flex-direction: column; gap: 0.4rem; }
.target-help { font-size: 0.8rem; color: var(--text-muted); margin: 0.2rem 0 0; }

.solve-result {
    margin-top: 1.25rem;
    border: 1px solid var(--accent);
    border-left-width: 4px;
    border-radius: var(--radius-md);
    background: var(--accent-glow);
    padding: 0.9rem 1.1rem;
    color: var(--text-secondary);
}

.solve-result strong { color: var(--text-primary); }
.solve-result.solve-impossible { border-color: var(--warning); background: var(--bg-sunken); }

/* ── Stat cards ──────────────────────────────────────────────────────────── */

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 0.85rem;
    margin-top: 1.5rem;
}

.stat-card {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    animation: statIn 0.35s ease both;
}

@keyframes statIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.stat-card:nth-child(2) { animation-delay: 0.04s; }
.stat-card:nth-child(3) { animation-delay: 0.08s; }
.stat-card:nth-child(4) { animation-delay: 0.12s; }
.stat-card:nth-child(5) { animation-delay: 0.16s; }
.stat-card:nth-child(6) { animation-delay: 0.20s; }

@media (prefers-reduced-motion: reduce) {
    .stat-card { animation: none; }
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.stat-value {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 1.6rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.15;
    transition: color 0.2s ease;
}

.stat-note {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
    line-height: 1.4;
}

.band-preferred { color: var(--success); }
.band-reasonable { color: var(--warning); }
.band-outside { color: var(--error); }
.band-none { color: var(--text-muted); }

/* ── Canvas ──────────────────────────────────────────────────────────────── */

.visual-section { margin-top: 1.75rem; }

.visual-head h3 { margin-bottom: 0.35rem; }
.visual-head p { color: var(--text-muted); font-size: 0.9rem; max-width: 68ch; }

.canvas-wrap {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    overflow-x: auto;
}

#pileCanvas {
    display: block;
    width: 760px;
    max-width: 100%;
    height: auto;
    aspect-ratio: 760 / 430;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */

.scenario-section { margin-top: 1.75rem; }
.scenario-lead { color: var(--text-secondary); font-size: 0.95rem; }

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-sunken);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 620px;
}

.data-table th,
.data-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table thead th {
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    position: sticky;
    top: 0;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-hover); }

.data-table .num {
    text-align: right;
    font-family: 'JetBrains Mono', Consolas, monospace;
    white-space: nowrap;
}

.data-table td.num { color: var(--text-primary); }
.data-table .row-na td { color: var(--text-muted); font-style: italic; }
.data-table sup { color: var(--warning); font-weight: 700; }

.table-note { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.6rem; }

/* ── Long-form content ───────────────────────────────────────────────────── */

.content-section p { color: var(--text-secondary); max-width: 76ch; }
.content-section h3 { margin-top: 1.75rem; }
.content-section strong { color: var(--text-primary); }
.content-section em { color: var(--text-primary); font-style: normal; font-weight: 600; }

.equation-block {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 1rem 1.15rem;
    margin: 1.25rem 0;
    overflow-x: auto;
}

.equation-title {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.equation-title + .equation + .equation-title { margin-top: 1.1rem; }

.equation {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
}

.caveat {
    border-left: 3px solid var(--warning);
    padding-left: 0.9rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.callout {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    margin-top: 1.75rem;
}

.callout-note { border-left: 4px solid var(--warning); }
.callout h4 { margin-bottom: 0.6rem; }
.callout p:last-child { margin-bottom: 0; }

/* ── Reference section ───────────────────────────────────────────────────── */

.ref-head {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.ref-head p { color: var(--text-muted); font-size: 0.9rem; margin: 0; max-width: 60ch; }
.ref-controls { display: flex; flex-wrap: wrap; gap: 0.85rem; }
.ref-count { font-size: 0.78rem; color: var(--text-muted); font-family: 'JetBrains Mono', Consolas, monospace; margin: 0 0 0.5rem; }

.omitted-block { margin-top: 1.5rem; }
.omitted-block p { color: var(--text-secondary); font-size: 0.92rem; max-width: 76ch; }

.omitted-list {
    margin: 0;
    padding-left: 1.1rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.omitted-list li { margin-bottom: 0.4rem; }
.omitted-list strong { color: var(--text-secondary); }

/* ── FAQ ─────────────────────────────────────────────────────────────────── */

.seo-content h2 { margin-bottom: 1rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 860px) {
    .fs-row-main { grid-template-columns: 1fr; }
    .fs-row-actions { justify-content: flex-start; }
    .fs-row-sub { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
    h1 { font-size: 2rem; }
    h2 { font-size: 1.45rem; }
    .app-main { padding: 1.25rem 0.75rem 2.5rem; }
    .calculator-card,
    .content-section,
    .reference-section,
    .seo-content { padding: 1.1rem; }
    .fs-row-sub { grid-template-columns: 1fr; }
    .control-select { min-width: 0; width: 100%; }
    .control-bar { flex-direction: column; align-items: stretch; }
    .toggle-group { flex-wrap: wrap; }
    .equation { white-space: normal; }
}

/* Inputs at 16px or larger stop iOS Safari zooming the viewport on focus. */
@media (max-width: 767px) {
    .fs-input,
    .fs-select,
    .control-select { font-size: 16px; }
}
