/* Colors as tokens so dark mode (shared/theme.js) only has to swap values. */
:root {
    --bg: #f7faf9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #dfe7e4;
    --tile: #ffffff;
    --tile-edge: #cfd8d4;
    --change: #f2b33d;
    --change-edge: #c4861a;
    --change-text: #2a1c02;
    --done: #3fae6b;
    --done-edge: #2b8650;
    --done-text: #ffffff;
    --rail: #c58b5c;
    --accent: #2f7d68;
    --bad: #c8363c;
    --btn-bg: #1f2937;
    --btn-text: #ffffff;
    --key: #e4ebe8;
    --key-press: #cdd8d3;
    --hint-bg: #fdf3dc;
    --shadow: rgba(0, 0, 0, .08);
    --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
    --bg: #121615; --card: #1b201f; --text: #e8edeb; --muted: #9da7a3; --border: #2e3633;
    --tile: #252b29; --tile-edge: #3a4440; --change: #e0a32e; --change-edge: #a87414; --change-text: #1f1502;
    --done: #389a5f; --done-edge: #25693f; --done-text: #ffffff; --rail: #8f6440; --accent: #6cc3a8;
    --bad: #ff6b70; --btn-bg: #e8edeb; --btn-text: #121615; --key: #2b3230; --key-press: #3c4643; --hint-bg: #33291a;
    --shadow: rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* No double-tap zoom (pinch zoom still works) */
html { touch-action: manipulation; }
body {
    margin: 0;
    font-family: var(--ui);
    background: var(--bg);
    color: var(--text);
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

main {
    max-width: 520px; margin: 0 auto; padding-block: 64px 48px;
    display: flex; flex-direction: column; gap: 14px;
}
header { text-align: center; display: flex; flex-direction: column; gap: 4px; }
h1 { margin: 0; font-size: 32px; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--muted); font-size: 15px; }

.goal { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.goal-words { font-size: 18px; letter-spacing: .04em; }
.goal-count { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---------- The ladder: rungs of letter tiles between two rails ---------- */
.ladder {
    --t: min(50px, 13vw);
    position: relative; align-self: center; padding: 10px 20px;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    user-select: none; -webkit-user-select: none;
}
.ladder::before, .ladder::after {
    content: ""; position: absolute; top: 0; bottom: 0; width: 7px; border-radius: 4px; background: var(--rail);
}
.ladder::before { left: 0; }
.ladder::after { right: 0; }
.rungs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rung { display: flex; gap: 6px; justify-content: center; }
.tile {
    width: var(--t); height: var(--t); display: grid; place-items: center; padding: 0;
    border: 2px solid var(--tile-edge); border-bottom-width: 4px; border-radius: 8px;
    background: var(--tile); font-size: calc(var(--t) * .5); font-weight: 700; line-height: 1;
}
.tile.changed { background: var(--change); border-color: var(--change-edge); color: var(--change-text); }
.rung.start .tile { color: var(--muted); }
.rung.done .tile { background: var(--done); border-color: var(--done-edge); color: var(--done-text); }
.target .tile { border-style: dashed; border-bottom-width: 2px; border-color: var(--done); color: var(--done-edge); background: transparent; }
:root[data-theme="dark"] .target .tile { color: var(--done); }
.gap { margin: -4px 0; color: var(--muted); font-size: 18px; line-height: 1; }

/* The word being typed */
.rung.active .cell { cursor: pointer; -webkit-tap-highlight-color: transparent; border-style: dashed; border-bottom-width: 2px; }
.rung.active .cell.changed { border-style: solid; border-bottom-width: 4px; }
.rung.active .cell.cursor { border-color: var(--accent); border-style: solid; box-shadow: 0 0 0 2px var(--accent); }
.rung.active .cell.changed.cursor { border-color: var(--accent); }
/* The letter a hint says to change */
.rung.active .cell.hinted::after {
    content: "💡"; position: absolute; top: -10px; right: -8px; font-size: 14px; line-height: 1;
}
.rung.active .cell { position: relative; }
.rung.active { scroll-margin-bottom: 340px; scroll-margin-top: 16px; }
.rung.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { translate: -8px 0; } 40%, 80% { translate: 8px 0; } }
.rung.fresh .tile.changed, .rung.fresh.done .tile { animation: pop .25s ease-out; }
@keyframes pop { 50% { scale: 1.12; } }

.msg {
    margin: -4px auto; min-height: 30px; padding: 5px 12px; border-radius: 6px; font-size: 14px; font-weight: 600;
    text-align: center; opacity: 0; transition: opacity .15s;
}
.msg.show { opacity: 1; }
.msg.bad { background: var(--btn-bg); color: var(--btn-text); }
.msg.win { background: var(--done); color: var(--done-text); }
.msg.show:not(.bad):not(.win) { background: var(--card); border: 1px solid var(--border); }

/* ---------- Result ---------- */
.result {
    border: 1px solid var(--border); background: var(--card); border-radius: 12px; padding: 14px 16px;
    text-align: center;
}
.result h2 { margin: 0 0 4px; font-size: 20px; }
.result p { margin: 0; color: var(--muted); font-size: 14px; }
.result .solution-label { margin: 12px 0 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.solution { --t: 30px; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.solution li { display: flex; gap: 4px; }
.solution span {
    width: var(--t); height: var(--t); display: grid; place-items: center; border-radius: 6px;
    background: var(--key); font-weight: 700; font-size: 15px;
}
.solution span.changed { background: var(--change); color: var(--change-text); }
.solution li.done span { background: var(--done); color: var(--done-text); }

/* ---------- Keyboard: sticks to the bottom of the screen while the ladder scrolls ---------- */
.play {
    position: sticky; bottom: 0; z-index: 1; margin-inline: -8px; padding: 8px 8px max(10px, env(safe-area-inset-bottom, 0px));
    background: var(--bg); display: flex; flex-direction: column; gap: 10px; user-select: none; -webkit-user-select: none;
}
.keyboard { display: flex; flex-direction: column; gap: 6px; }
.krow { display: flex; justify-content: center; gap: 5px; }
.key {
    flex: 1 1 0; max-width: 44px; min-width: 0; height: 48px; padding: 0; border: 0; border-radius: 6px;
    background: var(--key); font-size: 16px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.key.wide { flex-grow: 1.5; max-width: 66px; font-size: 18px; }
.key:active { background: var(--key-press); }
.controls { display: flex; justify-content: center; gap: 6px; }
.autofill {
    align-self: center; display: flex; align-items: center; gap: 8px; min-height: 28px;
    font-size: 14px; color: var(--muted); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.autofill input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.autofill:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.hint {
    margin: 0; padding: 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.4; text-align: center;
    background: var(--hint-bg); border: 1px solid var(--change); color: var(--text);
}
.pill {
    flex: 1; min-width: 0; max-width: 140px; height: 44px; padding: 0 8px; border-radius: 999px; cursor: pointer; white-space: nowrap;
    border: 1px solid var(--border); background: var(--card); font-size: 15px; -webkit-tap-highlight-color: transparent;
}
.pill:active { background: var(--key); }
.pill:disabled { cursor: default; color: var(--muted); opacity: .6; }
.pill.primary { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); font-weight: 700; }
@media (hover: hover) { .key:hover { background: var(--key-press); } }

/* ---------- Tools, rules ---------- */
.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tools button {
    border: 1px solid var(--border); background: transparent; border-radius: 8px;
    padding: 6px 12px; font-size: 14px; cursor: pointer;
}
#resultsBtn { background: var(--done); color: var(--done-text); border-color: var(--done); font-weight: 600; }

.rules {
    border: 1px solid var(--border); background: var(--card); border-radius: 10px; padding: 4px 16px 12px;
    font-size: 14px; line-height: 1.5;
}
.rules h2 { font-size: 16px; margin: 12px 0 4px; }
.rules ul { margin: 0; padding-left: 20px; }
.rules p { margin: 8px 0 0; color: var(--muted); }
kbd {
    font: inherit; font-size: 12px; padding: 1px 5px; border: 1px solid var(--border);
    border-bottom-width: 2px; border-radius: 4px; background: var(--bg);
}

/* ---------- Dialogs ---------- */
.sheet {
    width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 20px;
    border: 1px solid var(--border); border-radius: 14px; background: var(--card); color: var(--text);
    box-shadow: 0 12px 40px var(--shadow);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet h2 { margin: 0 32px 10px 0; font-size: 20px; }
.sheet .close {
    position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%;
    border: 0; background: transparent; cursor: pointer; font-size: 16px; color: var(--muted);
}
.note { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.intro-ladder { margin: 4px 0 14px; }
.intro-steps { margin: 0; padding-left: 20px; font-size: 15px; line-height: 1.45; }
.intro-steps li + li { margin-top: 6px; }
.intro-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.intro-actions button { padding: 10px 18px; border-radius: 999px; font-weight: 700; cursor: pointer; }
.intro-hide { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.intro-ok { background: var(--done); color: var(--done-text); border: 1px solid var(--done); }

@media (prefers-reduced-motion: reduce) {
    .rung.shake, .rung.fresh .tile { animation: none !important; }
}
