@font-face { font-family: Fredoka; font-weight: 500; font-display: swap; src: url('/fonts/fredoka-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: Fredoka; font-weight: 600; font-display: swap; src: url('/fonts/fredoka-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: Fredoka; font-weight: 700; font-display: swap; src: url('/fonts/fredoka-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --ink: #3b2530; --cream: #fdf3dc; --gold: #ffd36e;
  --page: #f3dfc6; --panel: #fbead2; --panel-text: #3b2530; --line: #3b253066;
  --card: #fffaf0; --locked: #ecd9bd; --accent: #8a3f50;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #160d19; --panel: #2b1a2e; --panel-text: #fdf3dc; --line: #fdf3dc66;
    --card: #fdf3dc; --locked: #d9cbb2; --accent: #ffd36e;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--page); }
body { display: flex; align-items: center; justify-content: center; color: var(--ink); font: 500 16px/1.35 Fredoka, system-ui, 'Noto Sans SC', 'PingFang SC', 'Noto Sans Devanagari', 'Noto Sans Arabic', sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #5b8def; outline-offset: 2px; }
#field:focus { outline: none; }

#stage { position: relative; width: min(100vw, calc(100dvh * 9 / 16)); height: min(100dvh, calc(100vw * 22 / 9)); overflow: hidden; container-type: size; }
@media (min-width: 600px) and (min-height: 600px) {
  #stage { width: calc(92dvh * 9 / 16); height: 92dvh; border-radius: 22px; box-shadow: 0 20px 60px #0005; }
}
#field { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#layer { position: absolute; inset: 0; pointer-events: none; }
#leave { position: absolute; top: 8px; inset-inline-end: 8px; }
#unsaved { position: absolute; inset-inline: 12px; top: calc(max(12px, env(safe-area-inset-top)) + 48px); z-index: 1; margin: 0; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 12px; background: #ffe0d6; color: var(--ink); font-size: 12px; line-height: 1.2; text-align: center; pointer-events: none; }
#unsaved:empty { display: none; }
.screen { position: absolute; inset: 0; pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px; }

.home { justify-content: space-between; padding-block: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-bottom)); }
.top, .bottom { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.topline { width: 100%; display: flex; justify-content: space-between; }
.title { margin: 0; text-align: center; font-size: min(13cqw, 7.5cqh); line-height: 1; font-weight: 700; color: #fff3d6; -webkit-text-stroke: 7px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.title span { display: block; color: var(--gold); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; max-width: 100%; padding: 4px 13px; border: 3px solid var(--ink); border-radius: 999px; background: var(--cream); color: var(--ink); font-weight: 700; text-decoration: none; }
.chip bdi { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round { width: 44px; min-height: 44px; justify-content: center; padding: 0; }
.games { width: 100%; max-width: 340px; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
.game { grid-column: span 2; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 5px 3px; border: 3px solid var(--ink); border-radius: 14px; background: var(--cream); box-shadow: 0 4px 0 var(--ink); line-height: 1.15; }
.game.featured { grid-column: span 3; background: var(--gold); padding-block: 9px; }
.game .symbol { font-size: 21px; }
.game .name { max-width: 100%; font-size: 12.5px; font-weight: 700; overflow-wrap: anywhere; hyphens: auto; }
.game.featured .name { font-size: 15px; }
.game .best { display: flex; gap: 3px; font-size: 12px; }
.game .best .symbol { font-size: 11px; }
.game:active, .button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.menu { width: 100%; max-width: 340px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.menu .button { min-width: 0; flex-direction: column; gap: 0; padding: 4px 2px; font-size: 12.5px; }
.menu .button span:last-child { max-width: 100%; overflow-wrap: anywhere; }
.legal { display: flex; gap: 4px 18px; font-size: 13px; }
.legal a { color: #fff6df; padding: 6px 2px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 210px; min-height: 46px; padding: 8px 18px; border: 3px solid var(--ink); border-radius: 16px; background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 var(--ink); font-weight: 700; text-align: center; text-decoration: none; }
.button.quiet { background: var(--cream); }
.button:disabled { opacity: .6; }
.back { width: 44px; height: 44px; flex: none; padding: 0; border: 3px solid var(--ink); border-radius: 12px; background: var(--cream); color: var(--ink); font-weight: 700; }
[dir=rtl] .arrow { display: inline-block; transform: scaleX(-1); }

.panel { align-items: stretch; background: var(--panel); color: var(--panel-text); padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.bar { display: flex; align-items: center; gap: 8px; }
.bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 19px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .wallet { flex: none; font-size: 13px; }
.preview { width: 100%; height: 28cqh; flex: none; border-radius: 16px; }
.tabs { display: flex; gap: 6px; flex: none; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.tab { flex: none; display: flex; align-items: center; gap: 5px; min-height: 40px; padding: 4px 12px; border: 2px solid var(--line); border-radius: 999px; background: transparent; font-size: 14px; font-weight: 600; }
.tabs.wrap { flex-wrap: wrap; }
.tabs.wrap .tab { max-width: 100%; overflow-wrap: anywhere; }
.tab[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: var(--cream); }
@media (prefers-color-scheme: dark) { .tab[aria-pressed=true] { background: var(--cream); border-color: var(--cream); color: var(--ink); } }
.grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: max-content; gap: 8px; align-content: start; padding: 3px; }
.item { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 3px; border: 3px solid transparent; border-radius: 14px; background: var(--card); color: var(--ink); line-height: 1.15; }
.item.locked { background: var(--locked); }
.item[aria-pressed=true] { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--gold); }
.item .symbol { font-size: 25px; min-height: 30px; }
.item .name { max-width: 100%; font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.price { font-size: 12px; font-weight: 700; color: #8f4210; }
.price.owned { color: #2f6b25; }
.swatch { width: 26px; height: 26px; flex: none; margin-block: 2px; border: 2px solid var(--ink); border-radius: 50%; }
.actions { display: flex; gap: 8px; flex: none; }
.actions .button:first-child { flex: 1; min-width: 0; }
.square { min-width: 52px; padding-inline: 8px; }

.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.intro { margin: 8px 4px 12px; text-align: center; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.card { min-width: 0; min-height: 120px; padding: 0; display: flex; flex-direction: column; border: 3px solid var(--ink); border-radius: 16px; overflow: hidden; background: var(--card); color: var(--ink); }
.card canvas { width: 100%; aspect-ratio: 1; }
.card .name { width: 100%; padding: 6px; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.card[aria-pressed=true] { border-color: var(--gold); outline: 3px solid var(--gold); outline-offset: -5px; }
.card.new, .hidden-set { align-items: center; justify-content: center; gap: 6px; padding: 12px; text-align: center; background: transparent; color: var(--panel-text); border: 3px dashed var(--line); }
.card.new { font-weight: 700; }
.card.new .symbol, .hidden-set .symbol { font-size: 30px; }
.hidden-set .hint { font-size: 12.5px; font-style: italic; }
.number { font-size: 12px; }
.section { display: flex; gap: 6px; margin: 14px 2px 6px; font-size: 16px; color: var(--accent); }
.story { width: 100%; display: flex; align-items: center; gap: 10px; margin-bottom: 6px; padding: 8px 12px; border: 0; border-radius: 12px; background: var(--card); color: var(--ink); text-align: start; }
.story.locked { background: transparent; color: var(--panel-text); border: 1px dashed var(--line); font-size: 13px; }
.story b, .story i { display: block; }
.story b { font-size: 14px; }
.story i { font-size: 12px; }
.ranks { margin: 0; padding: 0; list-style: none; }
.rank { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; padding: 8px 12px; border-radius: 12px; background: var(--card); color: var(--ink); }
.rank.mine { background: var(--gold); }
.rank .place { min-width: 26px; font-weight: 700; }
.rank .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .score { font-weight: 700; }
.ranks.own { margin-top: 14px; }
.settings { display: flex; flex-direction: column; gap: 12px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px; padding: 6px 12px; border-radius: 12px; background: var(--card); color: var(--ink); font-weight: 600; }
.setting select { min-height: 40px; padding: 4px 8px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; }
.setting input { width: 24px; height: 24px; }
.plain { align-self: center; min-height: 44px; border: 0; background: none; text-decoration: underline; }

.over { justify-content: center; background: #0004; overflow-y: auto; }
.verdict { margin: 0; color: #ff8f6b; font-size: 36px; text-align: center; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.result { width: 100%; max-width: 300px; padding: 12px 18px; border: 4px solid var(--ink); border-radius: 20px; background: var(--cream); text-align: center; box-shadow: 0 5px 0 var(--ink); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: #b43f20; color: #fff; font-size: 13px; font-weight: 700; }
.numbers { display: flex; justify-content: space-around; gap: 20px; }
.numbers small { display: block; color: #6f431b; }
.numbers b { font-size: 38px; line-height: 1.1; }
.earned { margin: 6px 0 0; color: #2f6b25; font-weight: 700; }
.status { margin: 4px 0 0; font-size: 14px; }
.status:empty { display: none; }
.status a { color: inherit; }

.sheet { width: min(340px, 92vw); max-height: 92dvh; padding: 16px; overflow-y: auto; border: 4px solid var(--ink); border-radius: 20px; background: var(--cream); color: var(--ink); }
.sheet::backdrop { background: #000b; }
.portrait { display: block; width: 100%; height: min(260px, 32dvh); margin-bottom: 10px; border-radius: 12px; }
.sheet h2 { margin: 0 0 8px; font-size: 20px; text-align: center; overflow-wrap: anywhere; }
.sheet p { margin: 0 0 8px; font-size: 15px; line-height: 1.45; }
.sheet .verse { color: #8a3f50; font-style: italic; font-weight: 600; }
.sheet .centred { text-align: center; }
.sheet input { width: 100%; min-height: 44px; margin-bottom: 10px; padding: 8px 12px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; }
.choices { display: flex; flex-direction: column; gap: 10px; padding-bottom: 5px; }
.choices .button { min-width: 0; }
:lang(zh-Hans) .verse, :lang(zh-Hans) .story i, :lang(zh-Hans) .hint, :lang(ar) .verse, :lang(ar) .story i, :lang(ar) .hint { font-style: normal; }

@container (max-height: 560px) {
  .screen { gap: 6px; }
  .game { padding-block: 2px; }
  .game.featured { padding-block: 4px; }
  .game .symbol { font-size: 16px; }
  .preview { height: 22cqh; }
  .tabs.wrap .tab { padding-inline: 7px; font-size: 13px; }
  .legal a { padding-block: 2px; }
}

/* Swatches: the colours of the catalogue; the CSP allows no style attributes. */
.swatch.c-std { background: #f7f1e3; }
.swatch.c-schnee { background: #ffffff; }
.swatch.c-gruen { background: #a8d89a; }
.swatch.c-pink { background: #f4a7c0; }
.swatch.c-rot { background: #ef7a6a; }
.swatch.c-mint { background: #b2ecd6; }
.swatch.c-orange { background: #f7b56b; }
.swatch.c-blau { background: #a9bcf2; }
.swatch.c-lila { background: #c9aef0; }
.swatch.c-braun { background: #a8754f; }
.swatch.c-schwarz { background: #3a3a42; }
.swatch.c-gold { background: #f4cf57; }
.swatch.c-regen { background: conic-gradient(red,orange,yellow,lime,cyan,blue,magenta,red); }
