/* ═════════════════════════════════════════════════════════════════════════ */
/* LogYield — Log Board-Foot Yield, Sawing Plan & Scale Overrun               */
/* Theme: mill yard — bark shadow, fresh-sawn face, moss on the log deck      */
/* ═════════════════════════════════════════════════════════════════════════ */

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

    /* Surfaces — bark shadow through weathered deck timber */
    --bg-primary: #101410;
    --bg-surface: #1a1f19;
    --bg-card: #1a1f19;
    --bg-hover: #252b23;
    --bg-input: #1e241d;
    --bg-sunken: #0b0e0b;

    /* Type — sawdust on dark timber */
    --text-primary: #f0f3ea;
    --text-secondary: #c6cdbc;
    --text-muted: #949c8a;

    /* Structure */
    --border: #2c3329;
    --border-hover: #4a5443;

    /* Action — fresh moss lime. Nothing else on the site sits at this hue,
       which matters because eight tools already own the amber band and two
       woodworking neighbours own the orange one. */
    --accent: #a3d94a;
    --accent-hover: #bce56b;
    --accent-glow: rgba(163, 217, 74, 0.16);
    --on-accent: #131a06;

    /* Semantic — success is pushed to a bluer, deeper green so it stays
       separable from the lime accent at a glance and to a colour-blind reader. */
    --success: #3fa96b;
    --warning: #e0b23f;
    --error: #e46a5c;

    /* Domain state — what a piece of the log turns into */
    --state-board: #d9a441;          /* a keeper board: fresh-sawn amber */
    --state-board-fill: rgba(217, 164, 65, 0.62);
    --state-drop: #6f7768;           /* below minimum width — greyed out */
    --state-drop-fill: rgba(111, 119, 104, 0.55);
    --state-kerf: #e0574a;           /* sawdust: the kerf the blade eats */
    --state-kerf-fill: rgba(224, 87, 74, 0.45);
    --state-wane: rgba(148, 156, 138, 0.55);
    --state-slab: rgba(90, 74, 52, 0.45);

    /* The log itself */
    --log-bark: #5a4a34;
    --log-wood: #2a2c1f;
    --log-pith: #949c8a;
    --grid-line: #232a20;
    --axis-line: #f0f3ea;

    /* The four scale rules, held apart in hue so the bar chart reads without
       its legend. */
    --rule-doyle: #e0574a;
    --rule-scribner: #d9a441;
    --rule-intl: #5a9bd6;
    --rule-actual: #a3d94a;

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

/* ── Light theme — same hues, lightness remapped. ── */
[data-theme="light"] {
    --bg-primary: #f5f7f2;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #e9ede3;
    --bg-input: #fbfcf9;
    --bg-sunken: #eef1e9;

    --text-primary: #141a12;
    --text-secondary: #363f31;
    --text-muted: #5c6553;

    --border: #d5dbcc;
    --border-hover: #a8b19c;

    --accent: #4f7211;
    --accent-hover: #3d5a08;
    --accent-glow: rgba(79, 114, 17, 0.12);
    --on-accent: #ffffff;

    --success: #24704a;
    --warning: #8a6206;
    --error: #b23a2c;

    --state-board: #8a6206;
    --state-board-fill: rgba(217, 164, 65, 0.55);
    --state-drop: #5c6553;
    --state-drop-fill: rgba(111, 119, 104, 0.40);
    --state-kerf: #b23a2c;
    --state-kerf-fill: rgba(178, 58, 44, 0.38);
    --state-wane: rgba(92, 101, 83, 0.45);
    --state-slab: rgba(120, 100, 70, 0.30);

    --log-bark: #8a7250;
    --log-wood: #e6e3cf;
    --log-pith: #5c6553;
    --grid-line: #e3e8dc;
    --axis-line: #141a12;

    --rule-doyle: #b23a2c;
    --rule-scribner: #8a6206;
    --rule-intl: #2a63ad;
    --rule-actual: #4f7211;

    --shadow-subtle: 0 4px 22px rgba(20, 26, 18, 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: 820px; 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.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    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; }

/* 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. With
   no explicit width the flex base size resolves to max-content, so the widest
   descendant (the 940px mill canvas, the Scribner reference grid) drags the
   whole page wider than the viewport and the inner scroll wrappers never act. */
.app-main {
    width: 100%;
    max-width: 1140px;
    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-size: 0.8rem;
    text-align: center;
    padding: 0.75rem;
    margin-bottom: 1.25rem;
}

.answer-block {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.75rem;
    color: var(--text-secondary);
}

.answer-block strong { color: var(--text-primary); }

/* ── Cards ───────────────────────────────────────────────────────────────── */

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

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

.card-head h2 { margin: 0; }

/* ── Verdict pill ────────────────────────────────────────────────────────── */

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

.verdict-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex: 0 0 auto; }
.verdict-good { color: var(--success); border-color: var(--success); }
.verdict-good .verdict-dot { background: var(--success); }
.verdict-warn { color: var(--warning); border-color: var(--warning); }
.verdict-warn .verdict-dot { background: var(--warning); }
.verdict-bad  { color: var(--error); border-color: var(--error); }
.verdict-bad  .verdict-dot { background: var(--error); }

/* ── Controls ────────────────────────────────────────────────────────────── */

.mode-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    padding-bottom: 1.1rem;
    margin-bottom: 1.1rem;
    border-bottom: 1px solid var(--border);
}

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

.control-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

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

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

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

.control-select,
.field-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    padding: 0.55rem 0.7rem;
    min-height: 42px;
    width: 100%;
    min-width: 0;
}

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

.field-input.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem 1rem;
    margin-bottom: 1.1rem;
}

.field-grid > * { min-width: 0; }

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.field > label,
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
.field-hint { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; }

.field-row { display: flex; gap: 0.5rem; align-items: center; min-width: 0; }
.field-row .field-input { flex: 1 1 auto; }

.range-input {
    width: 100%;
    min-width: 0;
    accent-color: var(--accent);
    min-height: 30px;
}

.range-value {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
}

.subsection {
    border-top: 1px solid var(--border);
    padding-top: 1.1rem;
    margin-top: 1.1rem;
}

.subsection h3 { font-size: 1.1rem; margin-bottom: 0.2rem; }
.subsection-lead { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.9rem; }

.row-tools { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.1rem; }

.action-btn {
    appearance: none;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    padding: 0.6rem 1.1rem;
    min-height: 44px;
}

.action-btn:hover { border-color: var(--border-hover); background: var(--bg-surface); }
.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); }

.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    color: var(--text-secondary);
    min-height: 38px;
}

.check-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

/* ── Warnings ────────────────────────────────────────────────────────────── */

.input-warnings {
    background: var(--bg-sunken);
    border: 1px solid var(--warning);
    border-left: 4px solid var(--warning);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    margin-bottom: 1.1rem;
    font-size: 0.9rem;
}

.input-warnings ul { margin: 0; padding-left: 1.1rem; }
.input-warnings li + li { margin-top: 0.35rem; }

/* ── Results ─────────────────────────────────────────────────────────────── */

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

.results-grid > * { min-width: 0; }

.stat-card {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    min-width: 0;
}

.stat-card.is-good  { border-color: var(--success); }
.stat-card.is-warn  { border-color: var(--warning); }
.stat-card.is-alert { border-color: var(--error); }
.stat-card.is-hero  { border-color: var(--accent); background: var(--accent-glow); }

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

.stat-value {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.stat-note { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; line-height: 1.35; }

/* ── The mill canvas ─────────────────────────────────────────────────────── */

.visual-section { margin-bottom: 1.4rem; }
.visual-head h3 { margin-bottom: 0.3rem; }
.visual-head p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.8rem; }

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

#millCanvas {
    display: block;
    width: 940px;
    max-width: 100%;
    height: auto;
}

.canvas-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    margin-top: 0.7rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid var(--border);
    flex: 0 0 auto;
}

.swatch-board { background: var(--state-board-fill); border-color: var(--state-board); }
.swatch-drop  { background: var(--state-drop-fill);  border-color: var(--state-drop); }
.swatch-kerf  { background: var(--state-kerf-fill);  border-color: var(--state-kerf); }
.swatch-wane  { background: var(--state-wane); }
.swatch-slab  { background: var(--state-slab); }

/* ── The board tally ─────────────────────────────────────────────────────── */

.tally-list { display: flex; flex-direction: column; gap: 0.4rem; }

.tally-row {
    display: grid;
    grid-template-columns: 82px 1fr auto;
    gap: 0.75rem;
    align-items: center;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.55rem 0.85rem;
    min-width: 0;
}

.tally-row.is-drop { opacity: 0.62; }

.tally-width {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.98rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
}

.tally-bar-track {
    background: var(--bg-hover);
    border-radius: 999px;
    height: 12px;
    min-width: 0;
    overflow: hidden;
}

.tally-bar {
    height: 100%;
    border-radius: 999px;
    background: var(--state-board);
}

.tally-row.is-drop .tally-bar { background: var(--state-drop); }

.tally-count {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.88rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── The scale-rule comparison ───────────────────────────────────────────── */

.rule-list { display: flex; flex-direction: column; gap: 0.55rem; }

.rule-row {
    display: grid;
    grid-template-columns: 122px 1fr;
    gap: 0.75rem 0.9rem;
    align-items: center;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.7rem 0.9rem;
    min-width: 0;
}

.rule-row.is-actual { border-color: var(--accent); background: var(--accent-glow); }

.rule-name { font-weight: 600; color: var(--text-primary); font-size: 0.92rem; }
.rule-name small { display: block; font-weight: 400; color: var(--text-muted); font-size: 0.76rem; }

.rule-meter { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }

.rule-bar-track {
    flex: 1 1 auto;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    height: 20px;
    min-width: 0;
    overflow: hidden;
}

.rule-bar { height: 100%; border-radius: var(--radius-sm); background: var(--text-muted); }
.rule-bar.bar-doyle    { background: var(--rule-doyle); }
.rule-bar.bar-scribner { background: var(--rule-scribner); }
.rule-bar.bar-intl     { background: var(--rule-intl); }
.rule-bar.bar-actual   { background: var(--rule-actual); }

.rule-figure {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    text-align: right;
    min-width: 92px;
}

.rule-figure small { display: block; font-size: 0.75rem; color: var(--text-muted); }
.rule-figure .over  { color: var(--success); }
.rule-figure .under { color: var(--error); }

/* ── The opening-face scan ───────────────────────────────────────────────── */

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

#scanCanvas {
    display: block;
    width: 620px;
    max-width: 100%;
    height: auto;
}

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

.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: 560px;
}

.data-table th,
.data-table td {
    padding: 0.55rem 0.7rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table th {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.82rem;
    background: var(--bg-hover);
    position: sticky;
    top: 0;
}

.data-table td { color: var(--text-secondary); }
.data-table td.num,
.data-table th.num { text-align: right; font-family: 'JetBrains Mono', ui-monospace, monospace; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table .row-name { color: var(--text-primary); font-weight: 500; white-space: normal; min-width: 120px; }
.data-table tr.is-current td { background: var(--accent-glow); }
.data-table td.is-drop { color: var(--text-muted); }

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

/* ── Prose ───────────────────────────────────────────────────────────────── */

.content-section h2 { margin-top: 0; }
.content-section h3 { margin-top: 1.6rem; }
.content-section p { color: var(--text-secondary); }
.content-section strong { color: var(--text-primary); }
.content-section ul { color: var(--text-secondary); padding-left: 1.2rem; }
.content-section li { margin-bottom: 0.4rem; }

.equation-block {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
    margin: 1rem 0 1.2rem;
    overflow-x: auto;
}

.equation-title {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}

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

.equation:last-child { margin-bottom: 0; }

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

.callout {
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-left: 4px solid var(--warning);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
    margin: 1.2rem 0;
}

.callout h4 { margin-bottom: 0.5rem; }
.callout p:last-child { margin-bottom: 0; }
.callout-note  { border-left-color: var(--accent); }
.callout-fence { border-left-color: var(--error); }

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

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

.ref-head h2 { margin-bottom: 0.3rem; }
.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.7rem; }
.ref-controls .control-group { min-width: 170px; }
.ref-count { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 0.6rem; }
.source-note { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.9rem; line-height: 1.5; }
.source-note strong { color: var(--text-secondary); }

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

.faq-section details {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-sunken);
    padding: 0.85rem 1rem;
    margin-bottom: 0.7rem;
}

.faq-section summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    min-height: 30px;
}

.faq-section details p { margin: 0.7rem 0 0; color: var(--text-secondary); font-size: 0.94rem; }

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

@media (max-width: 640px) {
    h1 { font-size: 2rem; }
    h2 { font-size: 1.45rem; }
    .app-header { padding: 2rem 1rem 1.5rem; }
    .app-main { padding: 1.25rem 0.75rem 2.5rem; }
    .calculator-card,
    .content-section,
    .reference-section,
    .seo-content { padding: 1.1rem; }
    .mode-bar { flex-direction: column; align-items: stretch; }
    .toggle-group { flex-wrap: wrap; }
    .field-grid { grid-template-columns: 1fr; }
    .tally-row { grid-template-columns: 76px 1fr auto; gap: 0.5rem; }
    .rule-row { grid-template-columns: 1fr; gap: 0.45rem; }
    .rule-figure { text-align: left; min-width: 0; }
    .equation { white-space: normal; }
    .ref-controls { width: 100%; }
    .ref-controls .control-group { min-width: 0; flex: 1 1 140px; }
    .stat-value { font-size: 1.3rem; }
}
