:root{
  --ink:#f2e9df;
  --gold:#ffce6b;
  --coral:#ff8a6a;
  --coral-deep:#ef5d6d;
  --safe:#5fd08a;
  --warn:#ffc24a;
  --danger:#ff5a52;
  --panel:#fff8ef;
  --panel-ink:#43354a;
  --panel-soft:#fff1e2;
  --panel-line:#ffe0c2;
  --glass:rgba(255,255,255,.07);
  --glass-line:rgba(255,255,255,.12);
}

*{ box-sizing:border-box; }
html,body{ margin:0; height:100%; }
body{
  font-family:'Quicksand', ui-rounded, 'Segoe UI Rounded', 'Segoe UI', system-ui, sans-serif;
  color:var(--ink);
  background:radial-gradient(125% 100% at 50% 0%, #3c2f4d 0%, #2c2238 52%, #1d1628 100%) fixed;
  -webkit-user-select:none; user-select:none;
  -webkit-tap-highlight-color:transparent;
  overflow:hidden;
}

.game{
  display:flex; flex-direction:column;
  width:100%; max-width:460px; height:100dvh; margin:0 auto;
  padding:8px 8px calc(6px + env(safe-area-inset-bottom)); gap:7px;
}

/* ----------------------------- HUD ----------------------------- */
.hud{ display:flex; align-items:stretch; gap:6px; flex:0 0 auto; }
.stat{
  flex:1 1 0; min-width:0; text-align:center; padding:5px 4px; border-radius:13px;
  background:var(--glass); border:1px solid var(--glass-line);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.1);
}
.stat .lbl{ display:block; font-size:.52rem; letter-spacing:.1em; text-transform:uppercase; opacity:.62; font-weight:800; }
.stat .val{ font-size:1.22rem; font-weight:900; line-height:1.15; font-variant-numeric:tabular-nums; }
.stat.chain.hot .val{ color:var(--gold); animation:chainpulse .4s ease; }
@keyframes chainpulse{ 0%{ transform:scale(1.3);} 100%{ transform:scale(1);} }

.iconbtn{
  flex:0 0 auto; min-width:44px; min-height:44px; width:44px; border-radius:13px; font-size:1.1rem;
  cursor:pointer; color:var(--ink);
  background:var(--glass); border:1px solid var(--glass-line);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.1); transition:transform .1s;
}
.iconbtn:active{ transform:translateY(1px); }

.next{
  flex:0 0 auto; position:relative; display:flex; flex-direction:column; align-items:center;
  width:62px; padding:3px 4px 4px; border-radius:13px; cursor:pointer; color:var(--ink);
  background:var(--glass); border:1px solid var(--glass-line);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.1); transition:transform .1s;
}
.next:active{ transform:translateY(1px); }
.next .lbl{ font-size:.5rem; letter-spacing:.08em; text-transform:uppercase; opacity:.62; font-weight:800; }
.next canvas{ width:42px; height:42px; display:block; }
.next .swap{
  position:absolute; right:-5px; top:-6px; width:19px; height:19px; border-radius:50%;
  display:flex; align-items:center; justify-content:center; font-size:.72rem; font-weight:900;
  background:linear-gradient(var(--coral),var(--coral-deep)); color:#fff;
  box-shadow:0 2px 5px rgba(0,0,0,.4);
}
.next.spent{ opacity:.55; }
.next.spent .swap{ background:#9a8f8a; }

/* ----------------------------- Stage / canvas ----------------------------- */
.stage{
  position:relative; flex:1 1 auto; min-height:0; border-radius:20px; overflow:hidden;
  box-shadow:0 22px 56px rgba(0,0,0,.5), inset 0 0 0 1px rgba(255,255,255,.05);
  touch-action:none;
}
.stage.shake{ animation:flinch .4s cubic-bezier(.36,.07,.19,.97); }
@keyframes flinch{
  0%,100%{ transform:translate(0,0); }
  20%{ transform:translate(-5px,3px) rotate(-.3deg); }
  45%{ transform:translate(5px,-2px) rotate(.3deg); }
  70%{ transform:translate(-3px,2px); }
}
.board{ display:block; width:100%; height:100%; }

/* ----------------------------- Overlays ----------------------------- */
.overlay{
  position:absolute; inset:0; z-index:20; display:flex; align-items:center; justify-content:center;
  padding:14px; background:rgba(18,12,24,.62); backdrop-filter:blur(5px); -webkit-backdrop-filter:blur(5px);
  opacity:0; pointer-events:none; transition:opacity .25s ease;
}
.overlay.active{ opacity:1; pointer-events:auto; }
.panel{
  width:100%; max-width:330px; max-height:100%; overflow-y:auto; text-align:center; color:var(--panel-ink);
  background:var(--panel); border-radius:22px; padding:20px 18px;
  box-shadow:0 20px 50px rgba(0,0,0,.5); border:3px solid #ffe6c2;
}
.panel.wide{ max-width:380px; }
.overlay.active .panel{ animation:panelin .35s cubic-bezier(.34,1.56,.64,1); }
@keyframes panelin{ from{ transform:translateY(16px) scale(.93); opacity:0;} to{ transform:none; opacity:1;} }

.logo{ font-size:1.95rem; font-weight:900; color:var(--coral-deep); line-height:1.05; letter-spacing:-.01em; }
.logo.small{ font-size:1.45rem; }
.logo-emoji{ font-size:1.5rem; display:inline-block; }
.tag{ margin:9px 0 13px; font-weight:600; opacity:.85; font-size:.92rem; line-height:1.35; }
.tag b{ color:var(--coral-deep); }

.rules{ list-style:none; padding:0; margin:0 auto 6px; display:inline-block; text-align:left; }
.rules li{ margin:9px 0; font-weight:600; font-size:.9rem; }
.rules b{ color:var(--coral-deep); }
.rules .emo{ display:inline-block; width:1.8rem; font-size:1.05rem; text-align:center; }

.btn{
  margin-top:6px; font-family:inherit; font-size:1.05rem; font-weight:800; color:#fff;
  background:linear-gradient(var(--coral),var(--coral-deep)); border:none; border-radius:15px; padding:12px 30px;
  cursor:pointer; box-shadow:0 6px 0 #c8455a, 0 10px 18px rgba(230,90,110,.4);
}
.btn:active{ transform:translateY(3px); box-shadow:0 3px 0 #c8455a; }

.sub-actions{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:14px; }
.sub-actions.center{ justify-content:center; gap:16px; }
.linkbtn{
  font-family:inherit; font-size:.9rem; font-weight:800; color:#9a4f38; cursor:pointer;
  background:none; border:none; padding:10px 8px; min-height:44px;
  display:inline-flex; align-items:center; text-decoration:underline; text-underline-offset:3px;
}
.linkbtn:active{ opacity:.7; }
.hi{ font-weight:700; opacity:.8; font-size:.9rem; }
.hi b{ color:var(--coral-deep); }

/* ----------------------------- Result ----------------------------- */
.rank{ font-size:1.1rem; font-weight:800; color:#c2607a; margin:2px 0 6px; }
.result-hero{ display:flex; align-items:center; justify-content:center; gap:12px; margin:6px 0 4px; }
.result-hero canvas{ width:88px; height:88px; }
.result-hero-label{ text-align:left; }
.result-hero-label .lbl{ display:block; font-size:.55rem; text-transform:uppercase; letter-spacing:.08em; font-weight:800; opacity:.6; }
.result-hero-label b{ font-size:1.15rem; color:var(--panel-ink); }
.scoreboard{ display:flex; gap:8px; margin-top:10px; }
.scoreboard>div{ flex:1; background:var(--panel-soft); border:2px solid var(--panel-line); border-radius:13px; padding:8px 4px; }
.scoreboard .lbl{ display:block; font-size:.54rem; text-transform:uppercase; letter-spacing:.06em; font-weight:800; opacity:.6; }
.scoreboard b{ font-size:1.18rem; font-variant-numeric:tabular-nums; }
.newhigh{ margin-top:10px; font-weight:900; color:var(--coral-deep); display:none; }
.newhigh.show{ display:block; animation:chainpulse .5s ease; }
.newfacts{ margin-top:10px; font-size:.82rem; font-weight:600; color:#8a6a52; text-align:left; }
.newfacts .nf{ margin:6px 0; padding:7px 9px; background:var(--panel-soft); border-radius:10px; border:1px solid var(--panel-line); }
.newfacts .nf b{ color:#c2607a; }

/* ----------------------------- Cat-alogue ----------------------------- */
.cat-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin:6px 0 14px; }
.cat-cell{
  position:relative; width:100%; font:inherit; color:inherit; appearance:none; -webkit-appearance:none;
  background:var(--panel-soft); border:2px solid var(--panel-line); border-radius:13px;
  padding:6px 4px 7px; text-align:center; cursor:pointer; transition:transform .12s, box-shadow .12s;
}
.cat-cell.locked{ opacity:.62; }
.cat-cell.unlocked:hover{ transform:translateY(-2px); box-shadow:0 6px 12px rgba(0,0,0,.12); }
.cat-cell canvas{ width:54px; height:54px; display:block; margin:0 auto; }
.cat-cell .cn{ font-size:.62rem; font-weight:800; color:var(--panel-ink); line-height:1.1; margin-top:2px; }
.cat-cell .cr{ font-size:.5rem; font-weight:800; text-transform:uppercase; letter-spacing:.05em; opacity:.7; }
.cat-cell .lockmark{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; font-size:1.4rem; }
.cat-fact{
  min-height:3.4em; font-size:.84rem; font-weight:600; color:#7a5a44; line-height:1.4;
  background:var(--panel-soft); border:1px solid var(--panel-line); border-radius:12px;
  padding:9px 11px; margin-bottom:14px;
}
.cat-fact b{ color:#c2607a; }
.cat-fact .src{ display:block; margin-top:4px; font-size:.66rem; opacity:.6; font-weight:600; }

.foot{ flex:0 0 auto; text-align:center; font-size:.68rem; opacity:.66; font-weight:600; }

/* ----------------------------- a11y ----------------------------- */
.visually-hidden{
  position:absolute !important; width:1px; height:1px; padding:0; margin:-1px;
  overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0;
}
/* visible keyboard focus on every control (mouse users stay clean via :focus-visible) */
.btn:focus-visible, .iconbtn:focus-visible, .next:focus-visible,
.linkbtn:focus-visible, .cat-cell:focus-visible{
  outline:3px solid var(--gold); outline-offset:2px;
}

@media (max-height:680px){
  .rules li{ margin:6px 0; font-size:.84rem; }
  .logo{ font-size:1.7rem; }
  .foot{ display:none; }
}
@media (max-width:360px){
  .stat .val{ font-size:1.05rem; }
  .next{ width:54px; }
  .next canvas{ width:36px; height:36px; }
  /* icon buttons keep their 44px min target even on small phones */
}
@media (prefers-reduced-motion:reduce){
  *{ animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; }
}
