/* Blinkwire: everything inside the stage. The page shell comes from kit/shell.css.
   The stage is always "cream paper" (also in dark mode), so the brand tokens are pinned to their light values in .ui.
   Sizes are in em: main.js sets the .ui font-size from the stage size, and adds .portrait to the stage when it is tall. */
.stage { --stage-ratio: 16 / 10; --stage-ratio-n: 1.6; background: #fbf6ec; }
@media (max-width: 760px), (orientation: portrait) and (max-width: 1000px) {
  .stage { --stage-ratio: 5 / 8; --stage-ratio-n: 0.625; }
}

.ui {
  position: absolute; inset: 0; pointer-events: none; font: 400 16px/1.3 var(--font-body); color: #17131f; color-scheme: light;
  --edge: #17131f; --ink: #17131f; --ink-2: #453e52; --muted: #6b6377; --surface: #fffdf8; --surface-2: #f1e7d3; --line: #e4d8c0; --orange-text: #c93a10;
}
.ui [hidden] { display: none !important; }
.ui button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; font-family: inherit; color: inherit; }
.ui h2, .ui h3 { color: var(--ink); }
.ui .eyebrow { font-size: 0.68em; color: var(--muted); }
.ui .btn { font-size: 1em; padding: 0.8em 1.35em; }
.ui .btn.small { font-size: 0.9em; padding: 0.65em 1em; }
.ui .btn.primary { color: var(--ink); }
.slot { pointer-events: none; min-width: 0; min-height: 0; }

.iconbtn { flex: none; display: grid; place-items: center; width: 2.6em; height: 2.6em; min-width: 40px; min-height: 40px; padding: 0; border: 2px solid var(--edge); border-radius: 0.8em; background: var(--surface); box-shadow: 2.5px 2.5px 0 var(--edge); cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; }
.iconbtn svg { width: 1.4em; height: 1.4em; }
.iconbtn:hover { background: var(--yellow); }
.iconbtn:active { transform: translate(2px, 2px); box-shadow: 0.5px 0.5px 0 var(--edge); }
.iconbtn:disabled { opacity: 0.35; pointer-events: none; }

/* ---- screens */
.screen { position: absolute; inset: 0; pointer-events: auto; }

.title { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "head slot" "menu slot"; column-gap: 1.6em; padding: 2em 2.2em 2.2em; }
.title-head { grid-area: head; }
.title .slot { grid-area: slot; }
.title-menu { grid-area: menu; align-self: end; display: grid; gap: 0.85em; }
.wordmark { font-size: 4.4em; margin-top: 0.12em; }
.wordmark em { font-style: italic; font-weight: 700; color: var(--orange); }
.howto { margin-top: 0.7em; font-size: 1.08em; color: var(--ink-2); max-width: 21em; }
.bigbtn { display: grid; gap: 0.25em; text-align: left; padding: 0.75em 1.15em 0.85em; border: 2px solid var(--edge); border-radius: 1.1em; background: var(--surface); box-shadow: 4px 4px 0 var(--edge); cursor: pointer; transition: transform 0.12s, box-shadow 0.12s; }
.bigbtn b { font: 800 1.6em/1 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; letter-spacing: -0.03em; }
.bigbtn span { font: 500 0.72em/1.3 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; }
.bigbtn.orange { background: var(--orange); transform: rotate(-0.6deg); }
.bigbtn.yellow { background: var(--yellow); transform: rotate(0.5deg); }
.bigbtn.mint { background: var(--mint); transform: rotate(-0.3deg); }
.bigbtn:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--edge); }
.bigbtn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--edge); }
.portrait .title { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "head" "slot" "menu"; padding: 1.3em 1.1em 1.2em; row-gap: 0.4em; }
.portrait .wordmark { font-size: 3.5em; }
.portrait .title-menu { gap: 0.7em; }

.levels, .free { display: flex; flex-direction: column; gap: 1em; padding: 1.3em 1.7em 1.3em; }
.bar { display: flex; align-items: center; gap: 0.8em; }
.bar h2 { flex: 1; font-size: 2.1em; }
.total { font: 500 0.85em var(--font-mono); letter-spacing: 0.04em; }
.total .star { font-style: normal; color: var(--orange); }
.chapter { display: flex; align-items: center; justify-content: center; gap: 1em; }
.chapter-name { display: grid; justify-items: center; gap: 0.15em; text-align: center; width: 17em; max-width: 100%; }
.chapter-name strong { font: 800 1.8em/1.05 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; letter-spacing: -0.03em; }
.chapter-name .blurb { font-size: 0.9em; color: var(--ink-2); }
.level-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 0.8em; width: 100%; max-width: 44em; max-height: 19em; margin: auto; }
.lvl { display: grid; align-content: center; justify-items: center; gap: 0.1em; padding: 0.3em; border: 2px solid var(--edge); border-radius: 1em; background: var(--surface); box-shadow: 3px 3px 0 var(--edge); cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; }
.lvl b { font: 800 1.9em/1 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; }
.lvl small { font: 500 0.66em var(--font-mono); letter-spacing: 0.04em; color: var(--ink-2); }
.lvl svg { width: 1.5em; height: 1.5em; }
.lvl.done { background: #fff0b3; }
.lvl.next { background: var(--orange); }
.lvl.next small { color: var(--ink); }
.lvl:hover { transform: translate(-1px, -2px); box-shadow: 4px 5px 0 var(--edge); }
.lvl:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--edge); }
.lvl.locked { background: transparent; border-style: dashed; box-shadow: none; color: var(--muted); cursor: default; transform: none; }
.portrait .levels, .portrait .free { padding: 1em 1em 1.1em; gap: 0.8em; }
.portrait .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 26em; gap: 0.65em; }
.portrait .lvl { grid-template-columns: 2.2em 1fr; grid-template-rows: auto auto; justify-items: start; column-gap: 0.5em; padding: 0.3em 0.8em; }
.portrait .lvl b { grid-row: 1 / 3; justify-self: center; }
.portrait .lvl svg { grid-row: 1 / 3; justify-self: center; }
.portrait .lvl.locked small { grid-row: 1 / 3; align-self: center; }
.dots { display: flex; justify-content: center; gap: 0.3em; }
.dots button { width: 2em; height: 2em; border: 0; background: none; padding: 0; cursor: pointer; display: grid; place-items: center; }
.dots button::before { content: ""; width: 0.8em; height: 0.8em; border: 2px solid var(--edge); border-radius: 50%; background: var(--surface); }
.dots button.on::before { background: var(--orange); }

.stars { display: inline-flex; gap: 0.08em; font-size: 0.95em; line-height: 1; }
.stars i { font-style: normal; color: var(--surface-2); -webkit-text-stroke: 0.09em #b9ad97; paint-order: stroke fill; }
.stars i.on { color: var(--yellow); -webkit-text-stroke: 0.11em var(--edge); }
.lvl.done .stars i:not(.on) { color: #fff8dc; }
.stars.big { font-size: 3.4em; gap: 0.1em; }
.stars.big i:nth-child(2) { transform: translateY(-0.12em); }
.stars.pop i.on { animation: star-in 0.42s cubic-bezier(0.3, 1.7, 0.5, 1) both; }
.stars.pop i.on:nth-child(1) { animation-delay: 0.36s; }
.stars.pop i.on:nth-child(2) { animation-delay: 0.62s; }
.stars.pop i.on:nth-child(3) { animation-delay: 0.88s; }
@keyframes star-in { from { transform: scale(0) rotate(-50deg); opacity: 0; } }

.free-body { flex: 1; display: grid; align-content: center; justify-items: center; gap: 1em; }
.stepper { display: flex; align-items: center; gap: 0.9em; }
.stepper .lbl { width: 4em; font: 500 0.78em var(--font-mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stepper b { min-width: 1.5em; text-align: center; font: 800 2.3em/1 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; }
.switches { display: grid; gap: 0.5em; }
.switch { display: flex; align-items: center; gap: 0.8em; text-align: left; padding: 0.35em 0.4em; border: 0; background: none; cursor: pointer; border-radius: 0.8em; }
.switch i { flex: none; position: relative; width: 3em; height: 1.7em; border: 2px solid var(--edge); border-radius: 99px; background: var(--surface-2); transition: background 0.15s; }
.switch i::after { content: ""; position: absolute; top: 50%; left: 0.2em; width: 1.05em; height: 1.05em; margin-top: -0.525em; border-radius: 50%; background: var(--edge); transition: transform 0.15s; }
.switch[aria-checked="true"] i { background: var(--mint); }
.switch[aria-checked="true"] i::after { transform: translateX(1.3em); }
.switch span { display: grid; }
.switch b { font-weight: 700; }
.switch small { font-size: 0.82em; color: var(--ink-2); }
.note { font-size: 0.88em; color: var(--ink-2); text-align: center; max-width: 24em; }
.free .note:empty { display: none; }
.row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.7em; }
.col { display: grid; gap: 0.65em; width: 100%; }

/* ---- play: HUD beside the board (wide) or above and below it (tall) */
.play { position: absolute; inset: 0; display: grid; grid-template-columns: 15.5em minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.play::before { content: ""; grid-area: 1 / 1 / 3 / 2; background: var(--surface); border-right: 2px solid var(--edge); }
.hud { grid-area: 1 / 1; pointer-events: auto; display: flex; flex-direction: column; gap: 1em; padding: 1em 1em 0; min-height: 0; }
.tools { grid-area: 2 / 1; pointer-events: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.55em; padding: 1em; }
.play .slot { grid-area: 1 / 2 / 3 / 3; margin: 0.9em; }
.hud-top { display: flex; align-items: center; gap: 0.7em; flex-wrap: wrap; }
.lv { flex: 1; min-width: 0; display: grid; gap: 0.2em; }
.lv strong { font: 800 1.4em/1.05 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; letter-spacing: -0.03em; }
.portrait .lv strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lv-top { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3em 0.6em; }
.lv-top .eyebrow { white-space: nowrap; }
.chips { display: flex; gap: 0.35em; }
.chips:empty { display: none; }
.tag { font: 500 0.64em/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; padding: 0.4em 0.7em; border: 1.5px solid var(--edge); border-radius: 99px; background: var(--surface-2); }
.tag.blue { background: #d9daff; }
.stats { display: grid; gap: 0.55em; }
.stat { display: flex; align-items: baseline; gap: 0.6em; padding-bottom: 0.45em; border-bottom: 2px dashed var(--line); }
.stat b { min-width: 2.1em; font: 800 2em/1 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat b.over { color: var(--orange-text); }
.stat span { font: 500 0.7em/1.2 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stat em { font-style: normal; }
.portrait .stats.tight .stat em { display: none; }
.stat { white-space: nowrap; }
.stat i { font-style: normal; color: var(--ink); font-weight: 500; }
.tip { padding: 0.65em 0.85em; border: 2px solid var(--edge); border-radius: 0.9em; background: var(--yellow); box-shadow: 3px 3px 0 var(--edge); font-size: 0.95em; font-weight: 600; line-height: 1.3; transform: rotate(-1deg); }
.tool { display: grid; justify-items: center; align-content: center; gap: 0.25em; min-height: 46px; padding: 0.5em 0.1em 0.45em; border: 2px solid var(--edge); border-radius: 0.85em; background: var(--surface); box-shadow: 2.5px 2.5px 0 var(--edge); cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; }
.tool svg { width: 1.45em; height: 1.45em; display: block; }
.tool .ico { display: block; }
.tool > span:last-child { font: 500 0.62em/1 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.tool:hover { background: var(--yellow); }
.tool:active { transform: translate(2px, 2px); box-shadow: 0.5px 0.5px 0 var(--edge); }
.tool[aria-pressed="true"] { background: var(--pink); transform: translate(2px, 2px); box-shadow: 0.5px 0.5px 0 var(--edge); }
.tool:disabled { opacity: 0.38; pointer-events: none; }

.portrait .play { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
.portrait .play::before { display: none; }
.portrait .hud { grid-area: 1 / 1; gap: 0.45em; padding: 0.55em 0.75em 0.5em; background: var(--surface); border-bottom: 2px solid var(--edge); }
.portrait .play .slot { grid-area: 2 / 1; margin: 0.5em 0.15em 0.6em; }
.portrait .tools { grid-area: 3 / 1; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.45em; padding: 0.5em 0.65em 0.6em; background: var(--surface); border-top: 2px solid var(--edge); }
.portrait .hud-top { flex-wrap: nowrap; }
.portrait .stats { grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 0.6em; }
.portrait .stat { padding: 0; border: 0; gap: 0.4em; }
.portrait .stat b { min-width: 0; font-size: 1.45em; }
.portrait .stat span { font-size: 0.62em; }
.portrait .tip { transform: none; box-shadow: none; padding: 0.4em 0.7em; font-size: 0.9em; border-radius: 0.7em; }

/* ---- modals */
.modal { position: absolute; inset: 0; z-index: 5; pointer-events: auto; display: grid; place-items: center; padding: 1em; background: rgba(23, 19, 31, 0.5); }
.modal.solved { background: rgba(23, 19, 31, 0.14); justify-items: start; padding-left: 1.6em; }
.portrait .modal.solved { justify-items: center; align-items: end; padding: 0.7em; }
.sheet { display: grid; justify-items: center; gap: 0.8em; width: min(100%, 23.5em); max-height: 100%; overflow: auto; touch-action: pan-y; padding: 1.4em 1.4em 1.5em; text-align: center; border: 2px solid var(--edge); border-radius: 1.5em; background: var(--surface); box-shadow: 7px 7px 0 var(--edge); animation: sheet-in 0.3s cubic-bezier(0.3, 1.45, 0.5, 1); }
@keyframes sheet-in { from { transform: translateY(1.5em) scale(0.92) rotate(-1.5deg); opacity: 0; } }
.sheet h3 { font-size: 2.2em; }
.sheet p { color: var(--ink-2); }
.sheet .keys { font-size: 0.8em; line-height: 2; }
.sheet .keys kbd { font-size: 0.85em; }
.result { display: grid; gap: 0.3em; width: 100%; margin: 0; }
.result div { display: flex; justify-content: space-between; align-items: baseline; gap: 1.5em; padding-bottom: 0.3em; border-bottom: 2px dashed var(--line); }
.result dt { font: 500 0.72em var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.result dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; white-space: pre; }
.streak { display: flex; gap: 2em; }
.streak div { display: grid; }
.streak b { font: 800 2em/1 var(--font-display); font-variation-settings: "SOFT" 100, "WONK" 1; }
.streak span { font: 500 0.66em var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.days { display: flex; gap: 0.4em; }
.day { display: grid; justify-items: center; gap: 0.25em; }
.day span { font: 500 0.62em var(--font-mono); color: var(--muted); }
.day i { display: grid; place-items: center; width: 2.9em; height: 2.9em; border: 2px solid var(--edge); border-radius: 50%; background: var(--surface-2); font-style: normal; font-size: 0.68em; letter-spacing: -0.08em; color: var(--muted); }
.day.on i { background: var(--yellow); color: var(--ink); }
.day.today i { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4.5px var(--blue); }

.toast { position: absolute; left: 50%; bottom: 6.2em; z-index: 6; max-width: 88%; padding: 0.6em 1.1em; border-radius: 99px; background: var(--ink); color: #fbf6ec; font-size: 0.9em; font-weight: 600; text-align: center; transform: translateX(-50%); pointer-events: none; }
.toast.in { animation: toast-in 0.25s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes toast-in { from { transform: translateX(-50%) translateY(0.8em); opacity: 0; } }

/* Page (outside the stage): keys on the yellow Controls card stay readable in dark mode. */
.card.yellow kbd { background: #fffdf8; border-color: #17131f; }
