:root {
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: #202e58;
  background: #f6f6ff;
  font-synthesis: none;
  --ink: #202e58;
  --muted: #4c5877;
  --blue: #354ca5;
  --gold: #ffd16a;
  --line: #d9dff0;
  --tray: #e7ebfa;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; color: inherit; }
:focus-visible { outline: 3px solid #7654bd; outline-offset: 3px; }
::selection { background: var(--gold); color: var(--ink); }
.masthead { border-bottom: 1px solid var(--line); }
.topbar {
  max-width: 1100px; margin: auto; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; color: var(--ink);
  text-decoration: none; font-size: 23px; font-weight: 800; letter-spacing: -.03em;
}
.brand img { border-radius: 10px; }
.record {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 10px; background: white; font-size: 13px; font-weight: 700;
}
.record-dot { width: 10px; height: 10px; border: 2px solid var(--blue); border-radius: 50%; }
.record[aria-pressed="true"] .record-dot { background: #ae284e; border-color: #ae284e; }
.stage {
  display: grid; grid-template-columns: minmax(225px, 300px) minmax(0, 498px);
  align-items: start; justify-content: center; gap: clamp(32px, 6vw, 90px);
  padding: clamp(32px, 6vw, 74px) max(24px, env(safe-area-inset-right))
    max(30px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
h1, h2, p { margin: 0; }
h1 { font-weight: 800; font-size: clamp(38px, 5vw, 60px); line-height: 1; letter-spacing: -.04em; }
.lead { margin-top: 14px; max-width: 28ch; font-size: 17px; line-height: 1.5; color: var(--muted); }
.game { padding: clamp(12px, 2.2vw, 22px); border-radius: 18px; border: 1px solid var(--line); background: white; }
.hud { display: flex; align-items: start; justify-content: space-between; min-height: 74px; padding: 0 4px; margin-bottom: 8px; }
.stat-label { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.target, .clock output { font-weight: 700; font-variant-numeric: tabular-nums; font-size: clamp(25px, 4vw, 32px); }
.target { display: inline-grid; place-items: center; min-width: 47px; height: 45px; border-radius: 10px; background: var(--gold); margin-top: 3px; }
.clock { text-align: right; }
.clock output { display: block; padding-top: 5px; }
.board-wrap { position: relative; }
.board {
  position: relative; aspect-ratio: 1; border-radius: 12px; background: var(--tray);
  user-select: none; overflow: hidden; container-type: inline-size;
}
.tile, .preview-tile {
  position: absolute; display: block; padding: 0; border: 0; color: var(--ink);
  background: var(--tile-fill, white); font-weight: 700; font-variant-numeric: tabular-nums;
}
.tile > span, .preview-tile > span {
  position: absolute; left: var(--glyph-x); top: var(--glyph-y);
  translate: -50% -50%; rotate: var(--glyph-turn); pointer-events: none;
  line-height: 1;
}
.tile:focus-visible { outline-offset: -3px; background: #fff0c4; }
.tile:active:not([aria-disabled="true"]) > span { scale: 1.12; }
.tile.found { color: #425178 !important; background: #b9ddda; cursor: default; }
.tile.miss { background: #fbcdd9; color: #802044 !important; }
.tile.found > span, .tile.miss > span { animation: tap .25s ease-out; }
@keyframes tap { 45% { scale: 1.29; } }
.conceal .tile:not(.found) > span { visibility: hidden; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; border-radius: 12px; }
.intro { background: #d6ddf2ba; }
.board.obscured .tile > span { visibility: hidden; }
.board.obscured { filter: blur(2px); }
.primary, .secondary {
  min-height: 46px; padding: 10px 16px; border: 1px solid transparent; border-radius: 10px; font-weight: 800;
}
.primary { background: var(--gold); color: var(--ink); }
.primary span { margin-left: 5px; }
.secondary { background: var(--blue); color: #fff; }
.intro-card {
  width: min(100%, 250px); padding: 16px; background: white; border-radius: 14px;
  box-shadow: 0 9px 24px #202e5828; text-align: center;
}
#intro-rule { font-size: 17px; font-weight: 800; }
.demo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 10px auto 6px; max-width: 138px; }
.demo span { display: grid; place-items: center; aspect-ratio: 1.25; border-radius: 5px; background: var(--tray); font-weight: 800; }
.demo span.active { background: var(--gold); animation: tap .25s ease-out; }
.intro-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#countdown { color: var(--muted); font-size: 14px; font-weight: 700; }
.quiet { border: 0; border-radius: 6px; background: transparent; min-height: 44px; padding: 0 9px; color: var(--blue); font-weight: 750; }
.progress-row { display: flex; align-items: center; gap: 12px; margin-top: 13px; font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums; }
progress { flex: 1; height: 8px; border: 0; border-radius: 8px; appearance: none; overflow: hidden; background: var(--tray); color: var(--blue); }
progress::-webkit-progress-bar { background: var(--tray); }
progress::-webkit-progress-value { background: var(--blue); border-radius: 8px; }
progress::-moz-progress-bar { background: var(--blue); border-radius: 8px; }
.restart { margin: 4px -5px -8px; font-size: 13px; }
.recording .sidebar { display: none; }
.recording .stage { grid-template-columns: minmax(0, 510px); padding-top: clamp(14px, 4vw, 40px); }
.recording .masthead { border: 0; }
.recording .topbar { max-width: 558px; }
.recording .restart { display: none; }
dialog {
  width: min(calc(100% - 24px), 448px); padding: 0; border: 0; border-radius: 18px;
  color: var(--ink); background: #fff; box-shadow: 0 18px 65px #202e5845;
}
dialog::backdrop { background: #161e3e80; }
.result-content { position: relative; padding: 25px clamp(13px, 5vw, 28px) 10px; text-align: center; }
h2 { font-size: clamp(25px, 7vw, 34px); letter-spacing: -.03em; }
#comparison { margin-top: 5px; color: var(--muted); }
.result-stats { display: grid; grid-template-columns: 1.15fr 1.2fr .7fr; gap: 6px; margin: 17px 0; }
.result-stats div { padding: 12px 3px; border-radius: 9px; background: #eef1fc; }
.result-stats dt { font-size: 12px; color: var(--muted); font-weight: 700; }
.result-stats dd { font-size: clamp(16px, 5vw, 22px); margin: 3px 0 0; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 8px; }
.result-actions button { flex: 1; font-size: 14px; padding-inline: 8px; }
#share-status { margin-top: 5px; font-size: 13px; color: var(--muted); }
#copy-fallback { text-align: left; margin-top: 12px; font-size: 13px; }
#share-link { width: 100%; padding: 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
#confetti { position: absolute; pointer-events: none; inset: 0; overflow: hidden; }
#confetti i {
  position: absolute; left: var(--x); top: 25%; width: 7px; height: 7px;
  border-radius: 50%; background: var(--color); animation: burst .88s cubic-bezier(.15,.75,.35,1) var(--delay) both;
}
@keyframes burst {
  from { transform: translate(0,0) scale(.25); opacity: 0; }
  26% { opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(1.15); opacity: 0; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 690px) {
  .stage { grid-template-columns: minmax(0, 465px); gap: 14px; padding-top: 18px; }
  .topbar { min-height: 62px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; }
  h1 { font-size: 36px; }
  .lead { max-width: none; margin-top: 5px; font-size: 14px; }
  .hud { min-height: 64px; margin-bottom: 5px; }
  .target { min-width: 39px; height: 37px; }
}
@media (max-width: 440px) {
  .stage, .topbar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .game { padding: 8px; }
}
@media (hover: hover) {
  .tile:hover:not([aria-disabled="true"]) { background: #f9edcd; }
  .tile.miss:hover { background: #fbcdd9; }
  .quiet:hover, .record:hover { background: #edf0fd; }
  .primary:hover { background: #ffc450; }
  .secondary:hover { background: #263a87; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  #confetti { display: none; }
}
.header-actions, .game-tools { display: flex; align-items: center; gap: 8px; }
.game-tools { align-items: flex-start; }
.game-tools .clock { margin-right: 7px; }
.game-tools .icon-button { margin-top: 7px; }
.icon-button {
  display: grid; place-items: center; min-width: 44px; min-height: 44px;
  padding: 4px; border: 1px solid var(--line); border-radius: 11px;
  color: var(--blue); background: #fff; font-weight: 700; font-size: 19px;
}
.icon-button[aria-pressed="false"], .icon-button:disabled { opacity: .62; }
button:disabled { cursor: default; }
.menu {
  width: min(100%, 600px); margin: auto;
  padding: 24px max(16px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.menu h1 { font-size: clamp(30px, 8vw, 44px); }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0 18px; }
.endless { font-size: 14px; color: #126d72; font-weight: 700; white-space: nowrap; }
.back { margin-left: -8px; }
.muted { color: var(--muted); font-size: 14px; }
.home-hero, .home-links, .resume-row, .settings-panel { border-radius: 16px; background: white; border: 1px solid var(--line); }
.home-hero { overflow: hidden; }
.hero-art { height: clamp(126px, 37vw, 195px); display: grid; place-items: center; position: relative; background: #d8e5e8; }
.hero-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero-art .emblem { width: 82px; height: 82px; rotate: -7deg; box-shadow: 0 8px 18px #202e5840; }
.hero-detail { padding: 16px; }
.hero-detail h2 { margin: 3px 0; font-size: clamp(23px, 7vw, 32px); }
.hero-detail .primary { margin-top: 16px; background: var(--blue); color: white; display: flex; justify-content: space-between; }
.full { width: 100%; }
.home-links { margin-top: 16px; overflow: hidden; }
.home-links button, .resume-row, .practice-play {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  width: 100%; min-height: 68px; padding: 10px 13px; text-align: left;
}
.home-links button, .practice-play { border: 0; background: transparent; }
.home-links button + button { border-top: 1px solid var(--line); }
.home-links strong, .resume-row strong, .practice-play strong { display: block; font-size: 17px; }
.home-links small, .resume-row small, .practice-play small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.link-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: var(--tray); color: var(--blue); font-size: 25px; }
.link-icon.teal { background: #e2f2ed; color: #126d72; }
.chapter-picker { margin: 20px 0 10px; display: flex; justify-content: space-between; align-items: center; text-align: center; }
.chapter-picker h2 { font-size: clamp(17px, 5.2vw, 24px); }
.level-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(3px, 1vw, 8px); margin-top: 9px; }
.level-grid button {
  min-height: 58px; display: grid; place-items: center; align-content: center; gap: 2px;
  padding: 3px 0; background: white; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; font-weight: 700;
}
.level-grid button:disabled { opacity: .62; }
.level-grid button[aria-current] { background: var(--gold); border-color: #e3b247; }
.emblem { flex: none; width: 52px; height: 52px; position: relative; display: block; background: var(--tray); overflow: hidden; border-radius: 8px; container-type: inline-size; }
.emblem .preview-tile { pointer-events: none; }
.emblem .preview-highlight { background: var(--gold); }
.level-grid .emblem { width: 26px; height: 26px; border-radius: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs { padding: 4px; background: var(--tray); border-radius: 12px; }
.chip { min-height: 42px; border-radius: 8px; padding: 4px 8px; border: 0; background: transparent; font-size: 13px; font-weight: 700; }
.tabs .chip { flex: 1; }
.chip[aria-pressed="true"] { background: var(--blue); color: white; }
.timer-picker { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 14px 0; font-weight: 700; }
select { min-height: 40px; background: white; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 7px; font: inherit; max-width: 100%; }
.practice-card { border-top: 1px solid var(--line); padding: 8px 0 12px; }
.practice-play { padding: 6px 4px; border-radius: 8px; }
.practice-card > label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin: 7px 0; }
.practice-card select { flex: 0 1 auto; min-width: 0; }
.practice-card .chip { border: 1px solid var(--line); min-height: 37px; padding-inline: 9px; }
.history-best { margin-top: 6px; color: var(--blue); font-size: 14px; font-weight: 700; }
.history-help { margin-top: 12px; }
.practice-card details { margin-top: 5px; font-size: 14px; }
.practice-card ul { margin: 5px 0; padding-left: 20px; }
.practice-card li { margin-block: 6px; }
.practice-card time { display: block; font-size: 12px; color: var(--muted); }
.settings-panel { padding: 12px 14px; margin-top: 12px; }
.settings-panel .setting, .settings-panel summary { min-height: 45px; font-weight: 700; }
.settings-panel summary { padding-block: 10px; cursor: pointer; }
.settings-panel p { font-size: 14px; margin: 5px 0 10px; color: var(--muted); overflow-wrap: anywhere; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.setting input { accent-color: var(--blue); width: 22px; height: 22px; }
.setting-hint { margin: 0 !important; }
#intro-extra { font-size: 13px; color: var(--muted); }
.cover { background: #d6ddf2e8; }
.cover .intro-card h2 { font-size: 24px; }
#cover-detail { font-size: 14px; margin: 8px 0 12px; }
#record[aria-pressed="true"] { background: #fff; }
#board:is([data-board="rotating"],[data-board="timedWheel"],[data-board="spinningType"],[data-board="radial"]) { background: #f7ede3; }
#board:is([data-board="mosaic"],[data-board="orbit"],[data-board="reverseHex"]) { background: #183045; }
#board:is([data-board="gem"],[data-board="gemReverse"],[data-board="pieces"],[data-board="sideways"],[data-board="reshuffle"],[data-board="letters"]) { background: #303946; }
#board:is([data-board="prism"],[data-board="triangles"]) {
  background: conic-gradient(from 24deg at 43% 47%, #8f9dc4, #bdade5, #8caed5, #dad4f4, #7492b9, #8f9dc4);
}
#board[data-board="sprintHex"] { background: #453411; }
#board[data-board="quadrants"] {
  background: linear-gradient(0deg, transparent 49%, #fff 49% 51%, transparent 51%),
    linear-gradient(90deg, transparent 49%, #fff 49% 51%, transparent 51%), #e9e8d9;
}
#result { background: #253664; color: white; }
#result .quiet, #result .result-stats dt, #result #comparison, #result #share-status { color: #e1e8f7; }
#result .result-stats div { background: #ffffff18; }
#result .secondary { background: #ffffff22; }
#result .secondary:hover { background: #ffffff33; }
.result-mark { font-size: 24px; font-weight: 800; background: #ffffff16; color: var(--gold); width: 45px; height: 45px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 4px; }
#result-source { font-size: 14px; color: #e1e8f7; }
#result-note { color: var(--gold); margin: 8px 0; font-size: 14px; }
#next-puzzle { margin: 7px 0; color: var(--ink); }
#copy-fallback { color: #e1e8f7; }
@media (max-width:690px) {
  .sidebar h1 { font-size: clamp(26px, 7vw, 36px); }
  .sidebar .back { min-height: 38px; }
  .sidebar #cue { display: none; }
  .game-tools .clock { margin-right: 2px; }
}
@media (hover:hover) {
  .home-links button:hover, .practice-play:hover, .resume-row:hover, .icon-button:hover:enabled { background: #edf0fd; }
}
.tap-pop {
  position: absolute; z-index: 1; display: grid; place-items: center; width: 34px; height: 34px;
  translate: -50% -50%; border-radius: 50%; background: #126d72; color: white; font-weight: 800;
  box-shadow: 0 2px 6px #20385655; animation: tap-pop .33s ease-out forwards; pointer-events: none;
}
@keyframes tap-pop {
  from { scale: .6; opacity: .85; }
  48% { scale: 1.12; opacity: 1; }
  to { scale: .72; opacity: 0; }
}
