/* Pocket Arcade - "print shop" look: paper, deep-blue ink, spot colours, hard offset shadows. */
@font-face { font-family: 'Bricolage'; src: url('../fonts/bricolage.woff2') format('woff2-variations'); font-weight: 200 800; font-stretch: 75% 100%; font-display: swap; }
@font-face { font-family: 'Instrument'; src: url('../fonts/instrument.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Instrument'; src: url('../fonts/instrument-italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --paper: #F3EBDD; --paper-2: #E9DFCC; --card: #FBF6EC; --ink: #1D2748; --ink-2: #5B6283; --line: #1D2748;
  --red: #EE5438; --teal: #17998B; --gold: #F2B33D; --pink: #F08CB0; --blue: #4A86F0; --violet: #7C62D8; --green: #62AE4A; --orange: #F58A2E;
  --shadow: #1D2748; --dot: rgba(29, 39, 72, .10); --overlay: rgba(29, 39, 72, .45);
  --accent: var(--red);
  --font: 'Bricolage', 'Segoe UI', system-ui, sans-serif; --serif: 'Instrument', Georgia, serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --r: 14px; --bw: 2px;
  color-scheme: light;
}
:root[data-theme='night'] {
  --paper: #141A30; --paper-2: #1B2340; --card: #222B4D; --ink: #F3EBDD; --ink-2: #A9AFCB; --line: #F3EBDD;
  --red: #FF6A4D; --teal: #2CC2B1; --gold: #F7C255; --pink: #F59ABB; --blue: #6CA0FF; --violet: #9B85F0; --green: #7DCB63; --orange: #FF9D47;
  --shadow: #070A16; --dot: rgba(243, 235, 221, .07); --overlay: rgba(4, 6, 14, .6);
  color-scheme: dark;
}
[data-c='red'] { --accent: var(--red); } [data-c='teal'] { --accent: var(--teal); } [data-c='gold'] { --accent: var(--gold); }
[data-c='pink'] { --accent: var(--pink); } [data-c='blue'] { --accent: var(--blue); } [data-c='violet'] { --accent: var(--violet); }
[data-c='green'] { --accent: var(--green); } [data-c='orange'] { --accent: var(--orange); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-stretch: 92%; color: var(--ink); background: var(--paper);
  overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; overflow: hidden; font-size: 16px; line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
body::before { /* halftone paper grain */
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: radial-gradient(var(--dot) 1px, transparent 1.4px); background-size: 7px 7px;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
svg { display: block; }

#app { position: fixed; inset: 0; z-index: 1; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- Home ---------- */
#home { overflow-y: auto; overflow-x: hidden; padding: calc(var(--sat) + 18px) 16px calc(var(--sab) + 28px); -webkit-overflow-scrolling: touch; touch-action: pan-y; display: block; }
#home .masthead { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
#home .logo { font-weight: 800; font-stretch: 75%; font-size: clamp(52px, 17vw, 74px); line-height: .84; letter-spacing: -.02em; text-transform: uppercase; position: relative; }
#home .logo span { display: block; position: relative; }
#home .logo .l1 { color: var(--ink); text-shadow: 3px 3px 0 var(--red); }
#home .logo .l2 { color: var(--ink); text-shadow: 3px 3px 0 var(--teal); margin-left: .5em; }
#home .logo-star { position: absolute; right: -34px; top: -6px; width: 34px; height: 34px; color: var(--gold); animation: spin 14s linear infinite; }
#home .strap { font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--ink-2); margin: 12px 0 16px; }
#home .cats { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 2px 16px 6px; scrollbar-width: none; touch-action: pan-x; }
#home .cats::-webkit-scrollbar { display: none; }
#home .cat { flex: none; padding: 7px 14px; border: var(--bw) solid var(--line); border-radius: 999px; font-weight: 700; font-size: 14px; background: var(--card); transition: transform .12s, background .15s; }
#home .cat[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
#home .cat:active { transform: scale(.95); }
#home .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#home .tile {
  position: relative; text-align: left; background: var(--card); border: var(--bw) solid var(--line); border-radius: 18px; padding: 10px 10px 11px;
  box-shadow: 4px 4px 0 var(--shadow); transition: transform .1s, box-shadow .1s; display: flex; flex-direction: column; min-width: 0;
  animation: rise .45s cubic-bezier(.2, .9, .3, 1.2) backwards;
}
#home .tile:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--shadow); }
#home .tile-art { aspect-ratio: 5 / 4; border-radius: 11px; background: var(--accent); border: var(--bw) solid var(--line); overflow: hidden; position: relative; color: var(--ink); }
#home .tile-art::after { content: ''; position: absolute; inset: 0; background-image: radial-gradient(rgba(255, 255, 255, .28) 1.2px, transparent 1.6px); background-size: 8px 8px; mix-blend-mode: soft-light; pointer-events: none; }
#home .tile-art svg { width: 100%; height: 100%; }
#home .tile-name { font-weight: 800; font-size: 18px; font-stretch: 84%; margin-top: 9px; line-height: 1.05; letter-spacing: -.01em; }
#home .tile-tag { font-family: var(--serif); font-style: italic; color: var(--ink-2); font-size: 14.5px; line-height: 1.15; margin-top: 3px; }
#home .tile-badge { position: absolute; top: 4px; right: 4px; z-index: 2; background: var(--ink); color: var(--paper); font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; transform: rotate(3deg); max-width: 70%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#home .tile.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px; }
#home .tile.wide .tile-art { width: 42%; flex: none; }
#home .tile.wide .tile-name { font-size: 24px; margin-top: 0; }
#home .tile-kicker { font-size: 11.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 4px; }
#home .foot { margin-top: 26px; text-align: center; color: var(--ink-2); font-size: 13px; font-family: var(--serif); font-style: italic; }
.update-pill { position: fixed; left: 50%; bottom: calc(var(--sab) + 16px); transform: translateX(-50%); z-index: 5; }

/* ---------- Play screen ---------- */
#play { background: var(--paper); }
#play > .bar { flex: none; display: flex; align-items: center; gap: 4px; padding: calc(var(--sat) + 6px) 8px 6px; min-height: calc(var(--sat) + 56px); border-bottom: var(--bw) solid var(--line); background: var(--card); position: relative; z-index: 2; }
#play > .bar h1 { flex: 1; min-width: 0; font-size: 21px; font-weight: 800; font-stretch: 80%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; padding-left: 2px; }
#play .bar-actions { display: flex; gap: 2px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; flex: none; transition: transform .1s, background .15s; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { transform: scale(.88); background: var(--paper-2); }
.icon-btn:disabled { opacity: .3; pointer-events: none; }
#stage { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; overflow: hidden; padding-bottom: var(--sab); }
#stage canvas { touch-action: none; display: block; }

/* ---------- Kit: shared pieces for games ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: var(--r);
  border: var(--bw) solid var(--line); background: var(--card); font-weight: 700; font-size: 16px; box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .08s, box-shadow .08s; white-space: nowrap;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
.btn.primary { background: var(--accent); color: #1D2748; }
.btn.dark { background: var(--ink); color: var(--paper); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 11px; box-shadow: 2px 2px 0 var(--shadow); }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn svg { width: 20px; height: 20px; }
.hud { flex: none; display: flex; align-items: stretch; justify-content: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.stat { min-width: 72px; padding: 5px 12px 6px; border: var(--bw) solid var(--line); border-radius: 12px; background: var(--card); text-align: center; }
.stat small { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }
.stat b { display: block; font-size: 20px; font-weight: 800; font-stretch: 84%; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat.accent { background: var(--accent); color: #1D2748; } .stat.accent small { color: rgba(29, 39, 72, .75); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: var(--bw) solid var(--line); background: var(--card); font-weight: 700; font-size: 14px; }
.chip.on { background: var(--ink); color: var(--paper); }
.seg { display: inline-flex; border: var(--bw) solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.seg button { padding: 8px 14px; font-weight: 700; font-size: 14px; border-right: var(--bw) solid var(--line); min-height: 38px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.fill { flex: 1; min-height: 0; position: relative; }
.center { display: grid; place-items: center; }
.toolbar { flex: none; display: flex; justify-content: center; gap: 10px; padding: 10px 12px 14px; flex-wrap: wrap; }
.msg { text-align: center; font-family: var(--serif); font-style: italic; font-size: 18px; color: var(--ink-2); padding: 4px 12px; min-height: 30px; }
.panel { background: var(--card); border: var(--bw) solid var(--line); border-radius: var(--r); box-shadow: 4px 4px 0 var(--shadow); }
.muted { color: var(--ink-2); }
.serif { font-family: var(--serif); font-style: italic; }

/* ---------- Overlays: sheets, toasts ---------- */
#overlays { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.scrim { position: absolute; inset: 0; background: var(--overlay); pointer-events: auto; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s both; }
.scrim.center-sheet { align-items: center; padding: 20px; }
.sheet {
  width: 100%; max-width: 480px; max-height: 88%; overflow-y: auto; background: var(--card); border: var(--bw) solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0; padding: 20px 20px calc(var(--sab) + 20px); animation: up .28s cubic-bezier(.2, .9, .3, 1.1) both; touch-action: pan-y; position: relative;
}
.center-sheet .sheet { border-bottom: var(--bw) solid var(--line); border-radius: 22px; box-shadow: 6px 6px 0 var(--shadow); animation-name: pop; padding-bottom: 20px; }
.scrim.out { animation: fade .16s reverse both; } .scrim.out .sheet { animation: down .16s ease-in both; }
.sheet h2 { font-size: 28px; font-weight: 800; font-stretch: 78%; line-height: 1; letter-spacing: -.01em; margin-bottom: 10px; padding-right: 40px; }
.sheet h3 { font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin: 18px 0 8px; }
.sheet p, .sheet li { font-size: 16px; line-height: 1.45; }
.sheet p + p { margin-top: 8px; }
.sheet ul, .sheet ol { margin: 8px 0; padding-left: 22px; }
.sheet li + li { margin-top: 5px; }
.sheet .x { position: absolute; top: 10px; right: 10px; }
.sheet-btns { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.sheet-btns .btn { flex: 1; }
.sheet-lead { font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--ink-2); }
.opt { display: flex; width: 100%; align-items: center; gap: 12px; text-align: left; padding: 12px 14px; border: var(--bw) solid var(--line); border-radius: var(--r); background: var(--paper); margin-top: 9px; transition: transform .08s; }
.opt:active { transform: scale(.98); }
.opt[aria-pressed='true'] { background: var(--accent); color: #1D2748; box-shadow: 3px 3px 0 var(--shadow); }
.opt b { display: block; font-size: 17px; font-weight: 800; }
.opt span { display: block; font-size: 14px; opacity: .8; }
.opt .tick { margin-left: auto; width: 22px; height: 22px; opacity: 0; } .opt[aria-pressed='true'] .tick { opacity: 1; }
.sheet .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1.5px dashed var(--ink-2); font-weight: 700; }
.sheet .row:last-of-type { border-bottom: 0; }
.switch { width: 54px; height: 32px; border-radius: 999px; border: var(--bw) solid var(--line); background: var(--paper-2); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); transition: transform .18s cubic-bezier(.3, 1.4, .5, 1); }
.switch[aria-checked='true'] { background: var(--teal); } .switch[aria-checked='true']::after { transform: translateX(22px); }
.result-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.result-stats .stat { flex: 1; }
.result-mark { width: 64px; height: 64px; margin-bottom: 10px; color: var(--accent); }
.toast { position: absolute; left: 50%; top: calc(var(--sat) + 70px); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 15px; animation: toast 2.2s both; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; z-index: 3; }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes rise { from { transform: translateY(26px) rotate(-1.5deg); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -12px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes screen-in { from { opacity: 0; transform: scale(.97); } }
.screen.enter { animation: screen-in .22s ease-out both; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (min-width: 560px) { #home .grid { grid-template-columns: repeat(3, 1fr); } #home { padding-left: max(16px, calc(50vw - 330px)); padding-right: max(16px, calc(50vw - 330px)); } }
