/* Watcher — borrowed verbatim from the agency design system to keep it
   a sibling of bluff/plume. The lab-specific bit is the notebook panel. */
:root {
    --bg: #f5f0e8;
    --bg-alt: #ffffff;
    --ink: #1a1a1a;
    --ink-light: #6b6560;
    --cream: #f5f0e8;
    --card-bg: #ffffff;
    --card-border: rgba(26,26,26,.08);
    --nav-bg: rgba(245,240,232,.85);
    --nav-border: rgba(26,26,26,.06);
    --orange: #e8572a;
    --orange-light: #ff7a52;
    --teal: #1a8a7d;
    --teal-light: #2bc4b0;
    --lemon: #e8d44a;
    --blue: #3d5afe;
    --shadow-color: rgba(26,26,26,.08);
    --shadow-strong: rgba(26,26,26,.14);
    --pill-bg: rgba(26,26,26,.05);
    --tag-bg: rgba(26,26,26,.06);
    --logo-border: rgba(26,26,26,.08);
    --font-display: 'Instrument Serif', Georgia, serif;
    --font-body: 'Outfit', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;

    /* Tile palette — agency colours, not the standard Wordle green/yellow. */
    --tile-correct: var(--orange);
    --tile-present: var(--lemon);
    --tile-absent:  #b6ada4;
    --tile-empty-border: rgba(26,26,26,.18);
    --tile-filled-border: rgba(26,26,26,.55);

    /* Notebook — paper-like with a hint of warmth */
    --paper: #fbf6ec;
    --paper-line: rgba(26,26,26,.08);
    --paper-margin: rgba(232,87,42,.35);
}

[data-theme="dark"] {
    --bg: #121214;
    --bg-alt: #1a1a1e;
    --ink: #e8e4dc;
    --ink-light: #9a958f;
    --cream: #e8e4dc;
    --card-bg: #1e1e22;
    --card-border: rgba(255,255,255,.07);
    --nav-bg: rgba(18,18,20,.88);
    --nav-border: rgba(255,255,255,.06);
    --shadow-color: rgba(0,0,0,.35);
    --shadow-strong: rgba(0,0,0,.5);
    --pill-bg: rgba(255,255,255,.06);
    --tag-bg: rgba(255,255,255,.06);
    --logo-border: rgba(255,255,255,.1);

    --tile-absent:  #4a4641;
    --tile-empty-border: rgba(255,255,255,.18);
    --tile-filled-border: rgba(255,255,255,.55);

    --paper: #1c1c20;
    --paper-line: rgba(255,255,255,.06);
    --paper-margin: rgba(232,87,42,.35);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
::selection { background: var(--orange); color: #fff; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--ink);
    overflow-x: hidden;
    min-height: 100vh;
    transition: background .4s, color .4s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; }
button { font-family: inherit; }

/* ---------- Nav ---------- */
nav {
    position: sticky;
    top: 0;
    z-index: 99;
    padding: 1rem 2.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1.5px solid var(--nav-border);
    transition: background .4s, border-color .4s;
}
.nav-logo {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    text-decoration: none;
    color: var(--ink);
    user-select: none;
    transition: transform .2s;
}
.nav-logo:active { transform: scale(.96); }

.logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1.5px solid var(--logo-border);
    background: var(--card-bg);
    color: var(--orange);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1), border-color .3s;
}
.logo-mark svg { width: 19px; height: 19px; }
.nav-logo:hover .logo-mark {
    transform: rotate(-6deg) scale(1.05);
    border-color: var(--orange);
}

.nav-name {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.45rem;
    letter-spacing: -.5px;
}

.nav-right { display: flex; align-items: center; gap: 1rem; }
.nav-back {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .82rem;
    font-weight: 500;
    color: var(--ink-light);
    text-decoration: none;
    padding: .5rem .9rem;
    border-radius: 100px;
    transition: color .2s, background .2s;
}
.nav-back:hover { color: var(--ink); background: var(--pill-bg); }
.nav-back svg { transition: transform .2s; }
.nav-back:hover svg { transform: translateX(-3px); }

.icon-btn, .theme-toggle {
    background: none;
    border: 1.5px solid var(--card-border);
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ink);
    transition: all .3s cubic-bezier(.34,1.56,.64,1);
    flex-shrink: 0;
}
.icon-btn:hover, .theme-toggle:hover {
    border-color: var(--orange);
    color: var(--orange);
    transform: scale(1.08);
}
.icon-btn svg, .theme-toggle svg {
    width: 18px; height: 18px;
    stroke: currentColor; fill: none; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
    transition: transform .4s cubic-bezier(.34,1.56,.64,1);
}
.icon-btn:hover svg { transform: rotate(15deg); }
.theme-toggle:hover svg { transform: rotate(30deg); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- Hero ---------- */
.hero {
    text-align: center;
    padding: 3rem 2rem 1.5rem;
    max-width: 760px;
    margin: 0 auto;
}
.hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: .7rem;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--orange);
    margin-bottom: 1.2rem;
}
.eyebrow-line { display: block; width: 28px; height: 1.5px; background: currentColor; opacity: .45; }

.hero h1 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(2.4rem, 5.5vw, 4rem);
    line-height: 1;
    letter-spacing: -1.2px;
    margin-bottom: 1.1rem;
}
.hero h1 em { font-style: italic; color: var(--orange); }

.hero-sub {
    max-width: 560px;
    margin: 0 auto;
    color: var(--ink-light);
    font-size: 1rem;
    line-height: 1.65;
}
.hero-sub em { font-style: italic; color: var(--ink); }

/* ---------- Phase 1: word entry ---------- */
.entry-wrap {
    max-width: 540px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 4rem;
}
.entry-card {
    background: var(--card-bg);
    border: 1.5px solid var(--card-border);
    border-radius: 22px;
    padding: 1.8rem;
    box-shadow: 0 14px 40px var(--shadow-color);
}
.entry-label {
    display: block;
    font-weight: 600;
    font-size: .98rem;
    margin-bottom: .9rem;
    color: var(--ink);
}
.entry-eyebrow {
    display: inline-block;
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--orange);
    background: rgba(232,87,42,.08);
    padding: .25rem .6rem;
    border-radius: 100px;
    margin-right: .6rem;
    vertical-align: middle;
}
.entry-row {
    display: flex;
    gap: .7rem;
    margin-bottom: .9rem;
}
#secretInput {
    flex: 1;
    min-width: 0;
    padding: .9rem 1.1rem;
    background: var(--bg);
    border: 1.5px solid var(--card-border);
    border-radius: 14px;
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 1.5rem;
    letter-spacing: 6px;
    text-align: center;
    text-transform: uppercase;
    outline: none;
    transition: border-color .2s, background .2s, box-shadow .2s;
}
#secretInput::placeholder { color: var(--ink-light); opacity: .6; letter-spacing: 4px; }
#secretInput:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(232,87,42,.12);
}
.entry-hint {
    font-size: .82rem;
    color: var(--ink-light);
    line-height: 1.55;
    text-align: center;
}

/* ---------- Phase 2: game (grid + notebook) ---------- */
.game-wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 2rem 4rem;
}
/* Two-track layout, capped widths on both tracks so the visible content
   stays balanced at any viewport. justify-content:center keeps the pair
   centered in the wrap regardless of remaining space. */
.game-grid {
    display: grid;
    grid-template-columns: minmax(0, 420px) minmax(0, 720px);
    gap: 2.6rem;
    justify-content: center;
    align-items: start;
}

.grid-col {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.grid-meta {
    width: 100%;
    max-width: 400px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    flex-wrap: wrap;
}
.grid-secret {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: .78rem;
    color: var(--ink-light);
}
.grid-secret strong {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1.15rem;
    color: var(--orange);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 0 .15rem;
}
.grid-reset {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--ink-light);
    border-radius: 100px;
    padding: .25rem .65rem;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all .2s;
}
.grid-reset:hover { border-color: var(--orange); color: var(--orange); }
.grid-turn {
    font-family: var(--font-mono);
    font-size: .75rem;
    color: var(--ink-light);
    letter-spacing: .03em;
}

.board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 8px;
    padding: 6px;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 5 / 6;
}
.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--tile-empty-border);
    border-radius: 10px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(1.6rem, 6vw, 2.2rem);
    text-transform: uppercase;
    user-select: none;
    background: transparent;
    color: var(--ink);
    transition: transform .15s, border-color .2s, background .2s, color .2s;
    aspect-ratio: 1 / 1;
}
.tile.filled {
    border-color: var(--tile-filled-border);
}

/* Tiles in the active (currently-being-coloured) row are clickable */
.row.active .tile {
    cursor: pointer;
}
.row.active .tile:hover {
    transform: scale(1.04);
    border-color: var(--orange);
}

/* Tile state colours — match liars-wordle palette */
.tile.state-correct, .tile.state-present, .tile.state-absent {
    border-color: transparent;
    color: #1a1a1a;
}
.tile.state-correct { background: var(--tile-correct); color: #fff; }
.tile.state-present { background: var(--tile-present); }
.tile.state-absent  { background: var(--tile-absent); color: #fff; }
[data-theme="dark"] .tile.state-present { color: #1a1a1a; }
[data-theme="dark"] .tile.state-absent { color: #e8e4dc; }

/* Pop in when a guess arrives */
.row.appearing .tile {
    animation: tile-pop-in .35s cubic-bezier(.16,1,.3,1) both;
}
.row.appearing .tile:nth-child(1) { animation-delay: 0s; }
.row.appearing .tile:nth-child(2) { animation-delay: .06s; }
.row.appearing .tile:nth-child(3) { animation-delay: .12s; }
.row.appearing .tile:nth-child(4) { animation-delay: .18s; }
.row.appearing .tile:nth-child(5) { animation-delay: .24s; }
@keyframes tile-pop-in {
    from { opacity: 0; transform: translateY(8px) scale(.92); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Mini variant for the how-to */
.tile.mini {
    width: 32px; height: 32px;
    aspect-ratio: 1 / 1;
    font-size: 1rem;
    border-radius: 6px;
}

/* Confirm bar (sits below the grid while a row is active) */
.confirm-bar {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .7rem;
    margin-top: .5rem;
}
.confirm-hint {
    font-size: .82rem;
    color: var(--ink-light);
    text-align: center;
    font-style: italic;
    font-family: var(--font-display);
    font-size: 1rem;
}

/* ---------- Notebook panel ---------- */
.notebook {
    background: var(--paper);
    border: 1.5px solid var(--card-border);
    border-radius: 18px;
    box-shadow: 0 14px 40px var(--shadow-color);
    overflow: hidden;
    position: relative;
    min-height: 420px;
    display: flex;
    flex-direction: column;
}
.notebook::before {
    /* the red margin line */
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    left: 64px;
    width: 1px;
    background: var(--paper-margin);
    opacity: .55;
    pointer-events: none;
}
.notebook-head {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: 1rem 1.4rem;
    border-bottom: 1px dashed var(--paper-line);
    font-family: var(--font-mono);
    font-size: .72rem;
    font-weight: 500;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink-light);
    background: linear-gradient(to bottom, rgba(0,0,0,.015), transparent);
}
.notebook-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--teal);
    animation: blink-dot 1.6s ease-in-out infinite;
}
.notebook-dot.thinking { background: var(--orange); }
@keyframes blink-dot {
    0%,100% { opacity: 1; }
    50% { opacity: .3; }
}
.notebook-body {
    flex: 1;
    padding: 1.2rem 1.4rem 1.6rem 5.2rem;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent 31px,
        var(--paper-line) 31px,
        var(--paper-line) 32px
    );
    line-height: 32px;
    font-family: var(--font-mono);
    font-size: .82rem;
    color: var(--ink);
    overflow-y: auto;
    max-height: 70vh;
}
.notebook-placeholder {
    color: var(--ink-light);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 1.05rem;
    line-height: 32px;
}
.note-entry {
    margin-bottom: 1rem;
    animation: note-slide .45s cubic-bezier(.16,1,.3,1) both;
}
@keyframes note-slide {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.note-head {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    margin-bottom: .25rem;
}
.note-turn {
    font-weight: 600;
    color: var(--orange);
    font-size: .72rem;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.note-guess {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.15rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink);
}
.note-reasoning {
    color: var(--ink);
    white-space: pre-wrap;
}
.note-thinking {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--ink-light);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 1.05rem;
    line-height: 32px;
}
.note-thinking::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--orange);
    animation: blink-dot 1s ease-in-out infinite;
}
.note-error {
    color: var(--orange);
    font-style: italic;
    font-family: var(--font-display);
    font-size: 1rem;
}

/* ---------- Modal (mirrors liars-wordle) ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 9, 8, .55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: fade-in .25s ease;
}
.modal-card {
    position: relative;
    z-index: 1;
    background: var(--card-bg);
    border: 1.5px solid var(--card-border);
    border-radius: 22px;
    padding: 2rem 1.8rem;
    max-width: 460px;
    width: 100%;
    box-shadow: 0 30px 80px var(--shadow-strong);
    animation: pop-in .35s cubic-bezier(.16,1,.3,1);
    max-height: 85vh;
    overflow-y: auto;
}
.modal-close {
    position: absolute;
    top: .8rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ink-light);
    cursor: pointer;
    transition: color .15s, transform .15s;
}
.modal-close:hover { color: var(--orange); transform: rotate(90deg); }
.modal-card h2 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.85rem;
    line-height: 1.05;
    letter-spacing: -.5px;
    margin-bottom: .8rem;
}
.modal-card h2 em { font-style: italic; color: var(--orange); }
.modal-card p {
    color: var(--ink-light);
    font-size: .92rem;
    line-height: 1.6;
    margin-bottom: .8rem;
}
.modal-card p em { font-style: italic; color: var(--ink); }
.how-tiles {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin-bottom: .55rem;
}
.tile-label { font-size: .9rem; color: var(--ink-light); }
.how-twist { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--card-border); }
.how-foot { font-size: .82rem; opacity: .8; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
    from { opacity: 0; transform: translateY(20px) scale(.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.end-answer {
    text-align: center;
    margin-bottom: 1.2rem !important;
    color: var(--ink) !important;
    font-size: 1rem !important;
}
.end-answer strong {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1.5rem;
    color: var(--orange);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0 .25rem;
}
.end-blurb {
    text-align: center;
    margin-bottom: 1.4rem !important;
    color: var(--ink-light) !important;
    font-size: .95rem !important;
    line-height: 1.6 !important;
}
.end-actions {
    display: flex;
    gap: .6rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: .88rem;
    padding: .75rem 1.4rem;
    border-radius: 100px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all .3s cubic-bezier(.34,1.56,.64,1);
    color: inherit;
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }
.btn-fill { background: var(--ink); color: var(--bg); }
.btn-fill:hover:not(:disabled) { background: var(--orange); color: #fff; transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 30px rgba(232,87,42,.3); }
.btn-outline { background: transparent; border: 1.5px solid var(--card-border); color: var(--ink); }
.btn-outline:hover:not(:disabled) { border-color: var(--ink); transform: scale(1.03); }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    top: 5.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--cream);
    padding: .75rem 1.2rem;
    border-radius: 100px;
    font-size: .85rem;
    font-weight: 600;
    box-shadow: 0 12px 30px var(--shadow-strong);
    z-index: 250;
    animation: toast-in .25s ease;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, -8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Footer ---------- */
footer {
    border-top: 1px solid var(--card-border);
    padding: 2rem 2.5rem;
    margin-top: 2rem;
    transition: border-color .4s;
}
.footer-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: .85rem;
    color: var(--ink-light);
}
.footer-copy { font-size: .85rem; }
.footer-inner a {
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px dotted var(--ink-light);
    transition: color .2s, border-color .2s;
}
.footer-inner a:hover { color: var(--orange); border-bottom-color: var(--orange); }
.footer-links { display: flex; gap: 1.5rem; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .game-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    .grid-col { width: 100%; align-items: center; }
    .notebook { min-height: 300px; }
    .notebook-body { max-height: 50vh; }
}
@media (max-width: 540px) {
    nav { padding: .8rem 1rem; }
    .nav-back { display: none; }
    .hero { padding: 2rem 1rem 1rem; }
    .hero h1 { font-size: clamp(2rem, 8vw, 2.8rem); }
    .entry-wrap { padding: 1rem 1rem 2rem; }
    .entry-card { padding: 1.4rem; }
    .entry-row { flex-direction: column; }
    #secretInput { font-size: 1.3rem; letter-spacing: 4px; }
    .game-wrap { padding: 1rem .8rem 2rem; }
    .board { max-width: 320px; gap: 5px; padding: 4px; }
    .row { gap: 5px; }
    .tile { font-size: 1.6rem; border-radius: 8px; }
    .notebook-body {
        padding: 1rem 1.2rem 1.2rem 4.4rem;
        font-size: .78rem;
    }
    .notebook::before { left: 52px; }
    .modal-card { padding: 1.6rem 1.3rem; }
    .modal-card h2 { font-size: 1.5rem; }
    footer { padding: 1.2rem 1rem; }
    .footer-inner { font-size: .78rem; }
    .footer-links { gap: 1rem; }
}
