/* The Reaction Atlas — Vol. III of the Learning Library.
   Identity: the lab notebook. Same petrol/brass/paper family as the
   library shelf, but the working surface is a quad-ruled notebook page
   with a red margin rule and handwritten annotations. */

:root {
    color-scheme: only light;

    /* family palette (matches the library landing page) */
    --cover: #1c3138;
    --cover-deep: #13242a;
    --brass: #c09a55;
    --brass-bright: #d6b471;
    --brass-deep: #9a7a3e;
    --brass-soft: rgba(192, 154, 85, 0.55);

    /* the notebook page */
    --paper: #f8f3e2;
    --paper-bright: #fffdf3;
    --grid-ink: rgba(94, 130, 148, 0.16);
    --margin-red: rgba(184, 84, 74, 0.5);
    --ink: #253c46;
    --ink-soft: #5d7078;
    --pencil: #7d8a90;

    /* marking pens */
    --correct-ink: #2e7d4f;
    --correct-soft: rgba(46, 125, 79, 0.12);
    --wrong-ink: #b0504a;
    --wrong-soft: rgba(176, 80, 74, 0.12);
    --trap-ink: #9a6b1f;
    --trap-soft: rgba(154, 107, 31, 0.14);

    --font-display: 'Besley', 'Iowan Old Style', Georgia, serif;
    --font-ui: 'Archivo', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    --font-hand: 'Caveat', 'Bradley Hand', cursive;
    --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-ui);
    color: var(--ink);
    min-height: 100svh;
    background-color: var(--cover);
    background-image:
        radial-gradient(ellipse 120% 90% at 50% -10%, rgba(214, 180, 113, 0.07), transparent 60%),
        linear-gradient(var(--cover-deep), var(--cover) 30%, var(--cover) 70%, var(--cover-deep));
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 28px 16px;
}

.screen { width: min(1150px, 100%); }
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

.btn {
    border: 1.5px solid var(--ink);
    border-radius: 7px;
    background: var(--paper-bright);
    color: var(--ink);
    font-size: 14.5px;
    font-weight: 600;
    padding: 10px 18px;
    box-shadow: 0 2px 0 rgba(19, 36, 42, 0.35);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 0 rgba(19, 36, 42, 0.35); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(19, 36, 42, 0.35); }
.btn.primary {
    background: linear-gradient(var(--brass-bright), var(--brass));
    border-color: var(--brass-deep);
    color: #2a2010;
    letter-spacing: 0.02em;
}
.btn.ghost { background: transparent; border-color: rgba(37, 60, 70, 0.45); box-shadow: none; }
.btn.ghost:hover { background: rgba(37, 60, 70, 0.06); }
.btn.small { padding: 8px 14px; font-size: 13.5px; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ============================== start screen ============================== */

#startScreen { display: flex; justify-content: center; padding-top: 6svh; }

.cover-card {
    width: min(680px, 100%);
    background: var(--paper);
    border: 1px solid rgba(19, 36, 42, 0.6);
    border-radius: 4px;
    padding: 44px 46px 38px;
    box-shadow:
        inset 0 0 0 1px rgba(37, 60, 70, 0.12),
        inset 0 0 0 6px var(--paper),
        inset 0 0 0 7px rgba(37, 60, 70, 0.28),
        0 16px 40px rgba(0, 0, 0, 0.4);
}

.eyebrow {
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--brass-deep);
    text-align: center;
    margin-bottom: 14px;
}

.cover-card h1 {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(34px, 5.5vw, 46px);
    text-align: center;
    line-height: 1.08;
}

.cover-rule {
    display: flex; align-items: center; gap: 12px;
    width: min(300px, 70%);
    margin: 18px auto 14px;
    color: var(--brass-deep); font-size: 9px;
}
.cover-rule::before, .cover-rule::after { content: ''; flex: 1; height: 1px; background: var(--brass-soft); }

.subtitle { text-align: center; color: var(--ink-soft); font-size: 15px; margin-bottom: 32px; }

.setup-row { display: flex; gap: 16px; margin-bottom: 16px; align-items: flex-end; flex-wrap: wrap; }
.field { flex: 1; min-width: 200px; }

.field label {
    display: block;
    font-family: var(--font-mono);
    font-size: 10.5px; font-weight: 600;
    letter-spacing: 0.22em; text-transform: uppercase;
    color: var(--ink-soft);
    margin-bottom: 7px;
}

.field select {
    width: 100%;
    font-family: inherit; font-size: 14.5px;
    color: var(--ink);
    padding: 10px 12px;
    border: 1.5px solid rgba(37, 60, 70, 0.5);
    border-radius: 7px;
    background: var(--paper-bright);
}

#startBtn { flex: 1; min-width: 200px; padding: 12px 18px; font-size: 15.5px; }

.drill-blurb {
    font-family: var(--font-hand);
    font-size: 19px;
    color: var(--ink-soft);
    text-align: center;
    min-height: 26px;
    transform: rotate(-0.6deg);
}

.dayone-btn {
    width: 100%;
    margin-top: 14px;
    font-family: var(--font-hand);
    font-size: 19px;
    color: var(--brass-deep);
    border-style: dashed;
}

.intro-lines {
    font-family: var(--font-hand);
    font-size: 19px;
    color: var(--ink-soft);
    margin-bottom: 24px;
}
.intro-lines p { margin-bottom: 10px; transform: rotate(-0.4deg); }

/* ============================== the notebook page ============================== */

.page {
    background:
        linear-gradient(90deg, transparent 54px, var(--margin-red) 54px, var(--margin-red) 56px, transparent 56px),
        repeating-linear-gradient(transparent 0 23px, var(--grid-ink) 23px 24px),
        repeating-linear-gradient(90deg, transparent 0 23px, var(--grid-ink) 23px 24px),
        var(--paper);
    border: 1px solid rgba(19, 36, 42, 0.6);
    border-radius: 4px;
    box-shadow:
        inset 0 0 0 1px rgba(37, 60, 70, 0.1),
        0 16px 40px rgba(0, 0, 0, 0.4);
    padding: 20px 26px 16px 74px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    border-bottom: 1.5px solid rgba(37, 60, 70, 0.3);
    padding-bottom: 10px;
}

.prompt-eyebrow {
    font-family: var(--font-mono);
    font-size: 10.5px; font-weight: 600;
    letter-spacing: 0.22em; text-transform: uppercase;
    color: var(--brass-deep);
    margin-bottom: 3px;
}

.prompt-main {
    font-family: var(--font-hand);
    font-size: clamp(24px, 3.4vw, 32px);
    font-weight: 600;
    line-height: 1.1;
    color: var(--ink);
    transform: rotate(-0.4deg);
}

.prompt-tag {
    font-family: var(--font-hand);
    font-size: 18px;
    color: var(--ink-soft);
    transform: rotate(-0.4deg);
}

.stats-block {
    display: flex; gap: 16px; flex-wrap: wrap;
    justify-content: flex-end;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--ink-soft);
    padding-top: 6px;
    white-space: nowrap;
}
.stat b { color: var(--ink); font-weight: 700; }

.feedback-line {
    font-family: var(--font-hand);
    font-size: 20px;
    min-height: 30px;
    padding: 3px 2px 0;
    transform: rotate(-0.3deg);
    transition: color 0.15s ease;
}
.feedback-line.correct { color: var(--correct-ink); }
.feedback-line.incorrect { color: var(--wrong-ink); }
.feedback-line.trap { color: var(--trap-ink); font-size: 18px; }

.answer-bar { display: flex; gap: 10px; margin: 4px 0 8px; }

.answer-bar input {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 15.5px;
    color: var(--ink);
    background: var(--paper-bright);
    border: 1.5px solid rgba(37, 60, 70, 0.5);
    border-radius: 7px;
    padding: 10px 13px;
}
.answer-bar input::placeholder { color: var(--pencil); }
.answer-bar input.shake { animation: shake 0.35s; border-color: var(--wrong-ink); }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}

/* gazetteer checklist chips */
.gaz-checklist { display: flex; flex-wrap: wrap; gap: 7px; margin: 2px 0 8px; }

.gaz-chip {
    font-family: var(--font-mono);
    font-size: 12px;
    border: 1.2px dashed rgba(37, 60, 70, 0.45);
    border-radius: 6px;
    color: var(--pencil);
    padding: 5px 10px;
    background: rgba(255, 253, 243, 0.6);
}
.gaz-chip.found {
    border-style: solid;
    border-color: var(--correct-ink);
    color: var(--correct-ink);
    background: var(--correct-soft);
}
.gaz-chip.revealed {
    border-style: solid;
    border-color: var(--wrong-ink);
    color: var(--wrong-ink);
    background: var(--wrong-soft);
}

/* ============================== the map ============================== */

.map-container { width: 100%; }
.map-container svg { display: block; width: 100%; height: auto; }

/* nodes */
.node rect {
    fill: var(--paper-bright);
    stroke: var(--ink);
    stroke-width: 1.6;
    transition: fill 0.15s ease, stroke 0.15s ease, stroke-width 0.15s ease;
}
.node .label {
    font-family: var(--font-ui);
    font-size: 15.5px; font-weight: 600;
    fill: var(--ink);
    text-anchor: middle;
    pointer-events: none;
}
.node .sublabel {
    font-family: var(--font-ui);
    font-size: 11.5px; font-weight: 500;
    fill: var(--ink-soft);
    text-anchor: middle;
    pointer-events: none;
}
.node.hub rect { fill: var(--cover); stroke: var(--brass-deep); stroke-width: 2; }
.node.hub .label { fill: var(--brass-bright); font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }

/* edges */
.edge .line { fill: none; stroke: var(--pencil); stroke-width: 1.8; transition: stroke 0.15s ease, stroke-width 0.15s ease, opacity 0.15s ease; }
.edge .head { fill: var(--pencil); transition: fill 0.15s ease, opacity 0.15s ease; }
.edge .hit { fill: none; stroke: transparent; stroke-width: 22; }

/* question focus: brass marching ants on the asked edge, everything else recedes */
.mode-recall .edge:not(.target) .line,
.mode-recall .edge:not(.target) .head { opacity: 0.3; }
.mode-recall .node:not(.hub) rect { fill: var(--paper); }

.edge.target .line {
    stroke: var(--brass-deep);
    stroke-width: 3.2;
    stroke-dasharray: 9 5;
    animation: march 1.1s linear infinite;
}
.edge.target .head { fill: var(--brass-deep); }

@keyframes march { to { stroke-dashoffset: -14; } }

.edge.target-node-src rect, .edge.target-node-dst rect { stroke-width: 2.4; }

/* answered states */
.edge.correct .line { stroke: var(--correct-ink); stroke-width: 3; stroke-dasharray: none; animation: none; }
.edge.correct .head { fill: var(--correct-ink); }
.edge.found .line { stroke: var(--correct-ink); stroke-width: 2.6; opacity: 1; }
.edge.found .head { fill: var(--correct-ink); opacity: 1; }
.edge.revealed .line { stroke: var(--wrong-ink); stroke-width: 2.6; opacity: 1; stroke-dasharray: none; animation: none; }
.edge.revealed .head { fill: var(--wrong-ink); opacity: 1; }

.node.flash-correct rect { fill: var(--correct-soft); stroke: var(--correct-ink); stroke-width: 2.6; }
.node.flash-wrong rect { fill: var(--wrong-soft); stroke: var(--wrong-ink); stroke-width: 2.6; }
.node.flash-trap rect { fill: var(--trap-soft); stroke: var(--trap-ink); stroke-width: 2.6; }
.node.highlight rect { stroke: var(--brass-deep); stroke-width: 2.6; }

/* synthesis pathfinding */
.node.syn-current rect {
    fill: #f0e0b8;
    stroke: var(--brass-deep);
    stroke-width: 3;
}
.node.syn-target rect {
    stroke: var(--brass-deep);
    stroke-width: 3;
    stroke-dasharray: 8 5;
    animation: march 1.1s linear infinite;
}

/* click mode */
.mode-click .node { cursor: pointer; }
@media (hover: hover) and (pointer: fine) {
    .mode-click .node:hover rect { stroke-width: 2.6; fill: var(--paper-bright); }
    .mode-click .node.hub:hover rect { fill: var(--cover); }
}
.mode-click .edge .hit { pointer-events: none; }

/* ============================== molecule drills ============================== */

.molecule-stage {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 22px;
    padding: 12px 0 16px;
    flex-wrap: wrap;
}

.molecule-card {
    background: var(--paper-bright);
    border: 1.5px solid rgba(37, 60, 70, 0.5);
    border-radius: 10px;
    padding: 10px 14px 6px;
    max-width: 560px;
    flex: 1 1 340px;
    margin: 0;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.molecule-card svg { width: 100%; height: auto; display: block; }
.molecule-card figcaption {
    font-family: var(--font-hand);
    font-size: 19px;
    text-align: center;
    color: var(--ink-soft);
    padding: 2px 0 6px;
}

.mode-pick .molecule-card { cursor: pointer; }
/* hover affordances only on devices that truly hover — iOS lets :hover
   stick to whatever lands under the last tap point after a re-render */
@media (hover: hover) and (pointer: fine) {
    .mode-pick .molecule-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12);
        border-color: var(--brass-deep);
    }
}
.molecule-card.card-correct { border-color: var(--correct-ink); box-shadow: 0 0 0 3px var(--correct-soft); }
.molecule-card.card-wrong { border-color: var(--wrong-ink); box-shadow: 0 0 0 3px var(--wrong-soft); animation: shake 0.35s; }

/* functional-group hit circles (injected by tools/make_molecules.py) */
.fg-hit circle { fill: rgba(0, 0, 0, 0); stroke: none; pointer-events: all; }
.mode-spot .fg-hit { cursor: pointer; }
@media (hover: hover) and (pointer: fine) {
    .mode-spot .fg-hit:hover circle {
        stroke: rgba(192, 154, 85, 0.55);
        stroke-width: 2.5;
        stroke-dasharray: 5 4;
    }
}
.fg-hit.hit-correct circle { stroke: var(--correct-ink); stroke-width: 3; fill: var(--correct-soft); }
.fg-hit.hit-wrong circle { stroke: var(--wrong-ink); stroke-width: 3; fill: var(--wrong-soft); }
.fg-hit.hit-reveal circle {
    stroke: var(--brass-deep);
    stroke-width: 3;
    stroke-dasharray: 9 5;
    fill: var(--trap-soft);
    animation: march 1.1s linear infinite;
}

/* ============================== controls & hints ============================== */

.page-controls {
    display: flex; gap: 10px; justify-content: center;
    border-top: 1.5px solid rgba(37, 60, 70, 0.3);
    padding-top: 12px; margin-top: 6px;
}

.hint-line {
    font-family: var(--font-hand);
    font-size: 19px;
    color: var(--trap-ink);
    padding: 0 2px 6px;
    transform: rotate(-0.3deg);
}

/* ============================== completion overlay ============================== */

.overlay {
    position: fixed; inset: 0;
    background: rgba(19, 36, 42, 0.72);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    z-index: 10;
}

.report-card {
    width: min(440px, 100%);
    background: var(--paper);
    border: 1px solid rgba(19, 36, 42, 0.6);
    border-radius: 4px;
    padding: 34px 36px 30px;
    text-align: center;
    box-shadow:
        inset 0 0 0 1px rgba(37, 60, 70, 0.12),
        inset 0 0 0 6px var(--paper),
        inset 0 0 0 7px rgba(37, 60, 70, 0.28),
        0 20px 48px rgba(0, 0, 0, 0.5);
}

.report-card h2 {
    font-family: var(--font-display);
    font-size: 30px; font-weight: 800;
    margin-bottom: 18px;
}

.report-stats {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--ink-soft);
    display: grid; gap: 8px;
    margin-bottom: 26px;
}
.report-stats b { color: var(--ink); }

.report-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ============================== small screens ============================== */

@media (max-width: 640px) {
    body { padding: 12px 8px; }
    .page { padding: 14px 14px 12px 46px; }
    .page-header { flex-direction: column; gap: 6px; }
    .stats-block { justify-content: flex-start; }
    .cover-card { padding: 30px 24px 26px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
    .edge.target .line { animation: none; stroke-dasharray: none; }
}
