:root {
    --paper: #f7f6f1;
    --surface: #fffefa;
    --ink: #1c2825;
    --muted: #66706d;
    --line: #d8d9d1;
    --line-strong: #aeb4ad;
    --yellow: #d9a51b;
    --yellow-soft: #f7e7aa;
    --green: #24734f;
    --green-soft: #cce7d9;
    --gray-note: #59615f;
    --accent: #173f36;
    --danger: #a44235;
    --radius: 12px;
    --tile: clamp(2.2rem, 9.6vw, 2.55rem);
    color-scheme: light;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 50% -12rem, rgba(36, 115, 79, .08), transparent 26rem),
        var(--paper);
    -webkit-tap-highlight-color: transparent;
}

button, a { font: inherit; }
button { color: inherit; }

button:focus-visible, a:focus-visible {
    outline: 3px solid rgba(36, 115, 79, .45);
    outline-offset: 3px;
}

.app-shell {
    width: min(100%, 31rem);
    min-height: 100vh;
    margin: 0 auto;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.masthead {
    display: grid;
    grid-template-columns: 2.5rem 1fr 2.5rem;
    align-items: start;
    gap: .65rem;
    padding: .3rem 0 1.05rem;
    border-bottom: 1px solid var(--line);
}

.brand-lockup { text-align: center; }
.eyebrow {
    margin: 0 0 .22rem;
    color: var(--green);
    font-size: .69rem;
    font-weight: 750;
    letter-spacing: .13em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
    margin-bottom: .2rem;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2.1rem, 10vw, 2.8rem);
    font-weight: 600;
    letter-spacing: .03em;
    line-height: .95;
    text-transform: uppercase;
}

.tagline { margin-bottom: 0; color: var(--muted); font-size: .82rem; }
.masthead-spacer { width: 2.5rem; }

.icon-button {
    display: inline-grid;
    width: 2.35rem;
    height: 2.35rem;
    padding: 0;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: transparent;
    font-size: 1rem;
    font-weight: 750;
    cursor: pointer;
}

.puzzle-heading { padding: 1rem 0 .25rem; text-align: center; }
.puzzle-heading h2 { margin-bottom: .16rem; font-size: 1rem; letter-spacing: .035em; }
.puzzle-heading p { margin-bottom: 0; color: var(--muted); font-size: .78rem; }
.game-code { color: var(--ink); font-weight: 800; letter-spacing: .14em; }

.message {
    display: grid;
    min-height: 2rem;
    place-items: center;
    padding: .22rem 0;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}
.message[data-tone="error"] { color: var(--danger); }
.message[data-tone="success"] { color: var(--green); }

.board { display: grid; gap: .34rem; }
.guess-row {
    display: grid;
    grid-template-columns: auto minmax(6.9rem, 1fr);
    min-height: var(--tile);
    align-items: center;
    gap: .5rem;
}
.guess-word { display: grid; grid-template-columns: repeat(5, var(--tile)); gap: .26rem; }

.tile {
    position: relative;
    display: grid;
    width: var(--tile);
    height: var(--tile);
    padding: 0;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    color: var(--ink);
    background: var(--surface);
    font-size: clamp(1.05rem, 5.2vw, 1.35rem);
    font-weight: 780;
    line-height: 1;
    text-transform: uppercase;
}

button.tile { cursor: pointer; transition: transform 120ms ease, background-color 120ms ease; }
button.tile:active { transform: scale(.94); }
.tile-filled { border-color: var(--accent); animation: pop 120ms ease-out; }
.tile-empty { border-color: #e3e3dc; background: rgba(255, 255, 255, .38); }
.note-yellow { border-color: #b98600; background: var(--yellow-soft); }
.note-green { border-color: var(--green); background: var(--green-soft); }
.note-gray { border-color: var(--gray-note); color: #fff; background: var(--gray-note); }

.note-yellow::after, .note-green::after, .note-gray::after {
    position: absolute;
    right: 3px;
    bottom: 2px;
    font-size: .48rem;
    font-weight: 900;
    line-height: 1;
}
.note-yellow::after { content: "Y"; color: #775900; }
.note-green::after { content: "G"; color: var(--green); }
.note-gray::after { content: "×"; color: #fff; }

.guess-clues, .example-clues { display: flex; gap: .32rem; }
.clue {
    display: inline-flex;
    min-width: 2.45rem;
    padding: .34rem .4rem;
    align-items: baseline;
    justify-content: center;
    gap: .28rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 750;
    white-space: nowrap;
}
.clue b { font-size: .86rem; }
.clue-yellow { border-color: #dbc46c; background: var(--yellow-soft); color: #664d00; }
.clue-green { border-color: #8fc4a8; background: var(--green-soft); color: #174b35; }

.keyboard { display: grid; gap: .4rem; margin: 1.15rem -.3rem .95rem; }
.keyboard[hidden] { display: none; }
.key-row { display: flex; justify-content: center; gap: .27rem; }
.key {
    position: relative;
    height: 3rem;
    min-width: 0;
    padding: 0;
    flex: 1 1 0;
    border: 0;
    border-radius: 7px;
    background: #dde0db;
    box-shadow: 0 2px 0 #bec3bc;
    font-size: clamp(.76rem, 3.4vw, .9rem);
    font-weight: 760;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
}
.key.key-used { background: #c7cac5; box-shadow: 0 2px 0 #aeb3ac; color: #26312e; }
.key.note-gray { border: 1px solid #414846; background: var(--gray-note); box-shadow: 0 2px 0 #333936; color: #fff; }
.key.note-yellow { border: 1px solid #b98600; background: var(--yellow-soft); box-shadow: 0 2px 0 #d0b04e; color: #604900; }
.key.note-green { border: 1px solid var(--green); background: var(--green-soft); box-shadow: 0 2px 0 #83b59a; color: #174b35; }
.key:active { transform: translateY(2px); box-shadow: none; }
.key-wide { flex: 1.45 1 0; font-size: .68rem; }
.key:disabled { cursor: default; opacity: .55; }

.puzzle-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .25rem;
    padding: .75rem 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.puzzle-nav a, .puzzle-nav button {
    padding: .45rem .1rem;
    border: 0;
    color: var(--accent);
    background: transparent;
    font-size: .74rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.puzzle-nav [aria-disabled="true"], .puzzle-nav [aria-current="page"] { color: #9aa09c; cursor: default; }
.puzzle-nav button:disabled { color: #9aa09c; cursor: not-allowed; }
.note-hint { margin: .72rem auto 0; color: var(--muted); font-size: .68rem; line-height: 1.4; text-align: center; }

.game-result {
    margin: 1rem 0;
    padding: 1.15rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
    box-shadow: 0 12px 35px rgba(28, 40, 37, .06);
}
.result-kicker { margin-bottom: .22rem; color: var(--green); font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.game-result h2 { margin-bottom: .3rem; font-family: Georgia, serif; font-size: 1.55rem; }
.game-result > p:last-of-type { margin-bottom: 1rem; color: var(--muted); font-size: .82rem; }
.result-actions { display: flex; justify-content: center; gap: .5rem; }

.button, .primary-link {
    display: inline-flex;
    min-height: 2.65rem;
    padding: .68rem 1rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--accent);
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}
.button-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button:disabled { border-color: var(--line); color: var(--muted); background: #ecece6; cursor: not-allowed; }

footer { padding: 1.7rem 0 .5rem; color: var(--muted); font-size: .68rem; text-align: center; }
footer span { color: var(--ink); font-weight: 780; letter-spacing: .08em; }

.help-dialog {
    width: min(calc(100% - 2rem), 29rem);
    max-height: calc(100dvh - 2rem);
    padding: 1.25rem;
    border: 1px solid var(--line);
    border-radius: 18px;
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 25px 90px rgba(15, 25, 21, .24);
}
.help-dialog::backdrop { background: rgba(21, 31, 28, .52); backdrop-filter: blur(3px); }
.dialog-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.dialog-header h2 { margin-bottom: .7rem; font-family: Georgia, serif; font-size: 1.55rem; }
.help-dialog > p { color: #46514d; font-size: .88rem; line-height: 1.55; }
.clue-definitions { display: grid; gap: .5rem; margin: 1rem 0; }
.clue-definitions > div { padding: .72rem; border: 1px solid var(--line); border-radius: 10px; }
.clue-definitions dt { font-size: .76rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.clue-definitions dd { margin: .25rem 0 0 1.2rem; color: var(--muted); font-size: .79rem; line-height: 1.4; }
.clue-dot { display: inline-block; width: .65rem; height: .65rem; margin-right: .25rem; border-radius: 50%; }
.clue-dot-yellow { background: var(--yellow); }
.clue-dot-green { background: var(--green); }
.help-example { padding: .85rem; border-radius: 12px; background: var(--paper); }
.example-word { display: grid; grid-template-columns: repeat(5, 2.35rem); justify-content: center; gap: .25rem; }
.example-word span { display: grid; width: 2.35rem; height: 2.35rem; place-items: center; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); font-weight: 800; }
.example-clues { margin-top: .6rem; justify-content: center; }
.dialog-cta { width: 100%; margin-top: .2rem; }

.unavailable { padding: 18vh 1rem 20vh; text-align: center; }
.unavailable h2 { margin-bottom: .65rem; font-family: Georgia, serif; font-size: 1.8rem; }
.unavailable > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }

.nudge { animation: nudge 240ms ease-in-out; }
@keyframes pop { 0% { transform: scale(.88); } 100% { transform: scale(1); } }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-4px); } 70% { transform: translateX(4px); } }

@media (min-width: 34rem) {
    :root { --tile: 3.1rem; }
    .app-shell { padding-top: 1.6rem; }
    .keyboard { margin-left: 0; margin-right: 0; }
    .key { height: 3.15rem; }
}

@media (max-width: 374px) {
    :root { --tile: clamp(2.08rem, 9.4vw, 2.3rem); }
    .app-shell { padding-left: .65rem; padding-right: .65rem; }
    .guess-row { grid-template-columns: auto minmax(6.2rem, 1fr); gap: .4rem; }
    .guess-word { gap: .2rem; }
    .clue { min-width: 2.3rem; padding-left: .25rem; padding-right: .25rem; font-size: .62rem; }
    .key-row { gap: .2rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
