:root{
  /* the page colours follow the world; main.js sets these from render/background.js */
  --top:#7CC8FF;
  --bottom:#FFD9E8;
  --card:#FFFFFF;
  --text:#3B2340;
  --muted:#7A6585;
  --line:rgba(59,35,64,.12);
  --line-strong:rgba(59,35,64,.24);
  --pink:#FF6B8E;
  --pink-dark:#D93C66;
  --gold:#FFC21A;
  --display:'Baloo 2', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --body:'Quicksand', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  color-scheme:light;
}

*{ box-sizing:border-box; }
html,body{ overscroll-behavior:none; }
body{
  margin:0;
  min-height:100vh;
  color:var(--text);
  font-family:var(--body);
  font-weight:600;
  -webkit-font-smoothing:antialiased;
  background:linear-gradient(180deg, var(--top) 0%, var(--bottom) 100%);
  background-attachment:fixed;
  transition:background .5s ease;
  overflow-x:hidden;
  -webkit-tap-highlight-color:transparent;
}
button{ font:inherit; color:inherit; }
[hidden]{ display:none !important; }

.site-nav{
  position:relative; z-index:3;
  max-width:560px; margin:0 auto; padding:12px 16px 0;
  display:flex; align-items:center; gap:8px;
}
.site-nav .grow{ flex:1; }
.site-nav a{
  display:inline-flex; align-items:center; gap:7px;
  text-decoration:none; color:var(--muted);
  font-weight:700; font-size:.82rem;
  background:rgba(255,255,255,.85); border:1px solid var(--line);
  border-radius:999px; padding:7px 15px 7px 11px;
  transition:transform .15s ease, color .15s ease, border-color .15s ease;
}
.site-nav a:hover{ transform:translateX(-2px); color:var(--text); border-color:var(--line-strong); }
.site-nav a:focus-visible{ outline:2px solid var(--text); outline-offset:2px; }
.site-nav a svg{ width:14px; height:14px; }

.icon-btn{
  cursor:pointer; width:36px; height:36px; border-radius:50%; flex:none;
  display:inline-flex; align-items:center; justify-content:center;
  color:var(--muted); background:rgba(255,255,255,.85); border:1px solid var(--line);
  transition:color .15s ease, border-color .15s ease, transform .15s ease;
}
.icon-btn:hover{ color:var(--text); border-color:var(--line-strong); transform:translateY(-1px) rotate(-6deg); }
.icon-btn:focus-visible{ outline:2px solid var(--text); outline-offset:2px; }
.icon-btn svg{ width:18px; height:18px; }
.icon-btn b{ font-family:var(--display); font-weight:800; font-size:1.05rem; }
#soundBtn .off{ display:none; }
#soundBtn[aria-pressed="false"] .on{ display:none; }
#soundBtn[aria-pressed="false"] .off{ display:inline; }

.page{
  position:relative; z-index:1; margin:0 auto; padding:2px 16px 30px;
  /* keep the whole board on screen: the board is 440 × 640 */
  max-width:clamp(320px, calc((100vh - 175px) * 0.6875 + 32px), 560px);
}

.hero{ text-align:center; margin:2px 0 8px; }
.hero h1{
  font-family:var(--display); font-weight:800;
  font-size:clamp(1.7rem, 5vw, 2.3rem); line-height:1.05; margin:0;
  color:#fff;
  text-shadow:0 3px 0 rgba(59,35,64,.25), 0 6px 16px rgba(59,35,64,.25);
}
@media (prefers-reduced-motion:no-preference){
  .hero h1{ animation:float 3.2s ease-in-out infinite; }
}
@keyframes float{ 50%{ transform:translateY(-3px) rotate(-1deg); } }

/* ---------- score bar ---------- */
.hud{ display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:8px; margin:0 0 8px; }
.pill{
  display:inline-flex; align-items:center; gap:6px; min-width:0;
  background:rgba(255,255,255,.9); border-radius:999px; padding:5px 12px;
  box-shadow:0 3px 0 rgba(59,35,64,.1);
  font-size:.85rem; white-space:nowrap;
}
.pill.where{ justify-self:start; font-family:var(--display); font-weight:800; color:var(--pink-dark); }
.pill.score{ justify-self:center; padding:4px 18px; }
.pill.score b{ font-family:var(--display); font-weight:800; font-size:1.25rem; line-height:1.2; font-variant-numeric:tabular-nums; }
.pill.goal{ justify-self:end; color:var(--muted); }
.pill.goal small{ font-size:.75rem; }
.stars{ color:var(--gold); letter-spacing:1px; font-size:.95rem; }
.stars i, .lv-stars i{ font-style:normal; color:rgba(59,35,64,.18); }
@media (prefers-reduced-motion:no-preference){
  .pill.score.bump{ animation:bump .35s ease; }
}
@keyframes bump{ 0%{ transform:scale(1); } 35%{ transform:scale(1.14) rotate(-2deg); } 100%{ transform:scale(1); } }

/* ---------- board ---------- */
.board-wrap{
  position:relative;
  padding:6px;
  border-radius:24px;
  background:rgba(255,255,255,.4);
  box-shadow:0 18px 40px -18px rgba(59,35,64,.55), inset 0 0 0 1px rgba(255,255,255,.6);
}
#board{
  display:block; width:100%; aspect-ratio:440/640; border-radius:18px;
  touch-action:none; cursor:crosshair; user-select:none; -webkit-user-select:none;
}

.overlay{
  position:absolute; inset:6px; z-index:5; border-radius:18px;
  display:flex; align-items:center; justify-content:center;
  background:rgba(59,35,64,.32);
  -webkit-backdrop-filter:blur(4px); backdrop-filter:blur(4px);
  padding:12px; overflow:auto;
}
.card{
  width:min(420px, 100%); max-height:100%; overflow:auto;
  background:#fff; border-radius:22px; padding:18px 18px 16px;
  box-shadow:0 20px 40px -18px rgba(59,35,64,.5);
  display:flex; flex-direction:column; gap:12px; text-align:center;
}
@media (prefers-reduced-motion:no-preference){
  .card{ animation:pop-in .32s cubic-bezier(.34,1.56,.64,1); }
}
@keyframes pop-in{ from{ transform:scale(.85); opacity:0; } }
.card h2{ margin:0; font-family:var(--display); font-weight:800; font-size:1.6rem; line-height:1.1; color:var(--pink-dark); }
.card h2.title{ font-size:2rem; }
.card p{ margin:0; color:var(--muted); font-size:.92rem; line-height:1.5; }
.card p b{ color:var(--text); }

.buddy-row{ display:block; width:100%; height:64px; }
.buddy-row.small{ height:52px; }
@media (prefers-reduced-motion:no-preference){
  .buddy-row{ animation:bob 2.4s ease-in-out infinite; }
}
@keyframes bob{ 50%{ transform:translateY(-4px); } }

.btn-col{ display:flex; flex-direction:column; gap:10px; align-items:stretch; }
.btn-row{ display:flex; gap:8px; justify-content:center; flex-wrap:wrap; }
.cta{
  cursor:pointer; border:0; border-radius:999px; padding:10px 26px;
  font-family:var(--display); font-weight:800; font-size:1.1rem; color:#fff;
  background:linear-gradient(180deg, #FF8AA6, #F0507A);
  box-shadow:0 4px 0 #C7325C, 0 10px 18px -8px rgba(199,50,92,.6);
  transition:transform .12s ease;
}
.cta small{ display:block; font-size:.72rem; font-weight:700; opacity:.85; line-height:1; margin-top:1px; }
.cta:hover{ transform:translateY(-1px) scale(1.03); }
.cta:active{ transform:translateY(2px); box-shadow:0 2px 0 #C7325C; }
.cta:focus-visible{ outline:3px solid var(--text); outline-offset:3px; }
.cta.alt{ background:linear-gradient(180deg, #6CC0FF, #3A92E8); box-shadow:0 4px 0 #2370C0, 0 10px 18px -8px rgba(35,112,192,.6); }
.cta.alt:active{ box-shadow:0 2px 0 #2370C0; }
.cta.ghost{ background:#fff; color:var(--text); border:1px solid var(--line-strong); box-shadow:0 3px 0 rgba(59,35,64,.12); font-size:.95rem; padding:8px 18px; }
.cta.ghost small{ color:var(--muted); }

/* ---------- level list ---------- */
.worlds{ display:flex; flex-direction:column; gap:12px; text-align:left; max-height:min(52vh, 420px); overflow:auto; padding:2px 2px 4px; }
.world h3{ margin:0 0 6px; font-family:var(--display); font-weight:800; font-size:1.02rem; }
.world h3 small{ color:var(--muted); font-weight:700; font-size:.78rem; }
.lv-grid{ display:grid; grid-template-columns:repeat(5, 1fr); gap:6px; }
.lv{
  cursor:pointer; display:flex; flex-direction:column; align-items:center; gap:0;
  border:0; border-radius:14px; padding:6px 2px 4px;
  background:var(--w1, #E8F6FF); box-shadow:0 3px 0 var(--w2, #B8DDF5);
  transition:transform .12s ease;
}
.lv b{ font-family:var(--display); font-weight:800; font-size:1.1rem; line-height:1.1; }
.lv-stars{ font-size:.7rem; color:var(--gold); letter-spacing:1px; min-height:1em; line-height:1; }
.lv:hover:not(:disabled){ transform:translateY(-2px) rotate(-2deg); }
.lv:focus-visible{ outline:2px solid var(--text); outline-offset:2px; }
.lv.locked{ cursor:default; opacity:.45; }
.lv.locked b{ font-size:.85rem; }
.lv.current{ box-shadow:0 3px 0 var(--w2, #B8DDF5), 0 0 0 3px var(--pink); }
@media (prefers-reduced-motion:no-preference){
  .lv.current{ animation:nudge 1.8s ease-in-out infinite; }
}
@keyframes nudge{ 0%,80%,100%{ transform:none; } 87%{ transform:rotate(-6deg); } 94%{ transform:rotate(5deg); } }
.world[data-theme="meadow"]{ --w1:#E3F6DD; --w2:#B5E2A8; }
.world[data-theme="lagoon"]{ --w1:#DDF7FA; --w2:#A5E2EC; }
.world[data-theme="starry"]{ --w1:#ECE5FF; --w2:#C9B8F2; }
.world[data-theme="ember"]{ --w1:#FBE3D6; --w2:#E9A98A; }
.badge.expert{ background:#7A3A4E; color:#FFE9D6; animation:none; }

/* ---------- result cards ---------- */
.big-stars{ display:flex; justify-content:center; gap:6px; font-size:3.2rem; line-height:1; }
.big-star{ color:rgba(59,35,64,.14); }
.big-star.on{ color:var(--gold); text-shadow:0 3px 0 #D99A00; }
@media (prefers-reduced-motion:no-preference){
  .big-star.on{ animation:star-in .55s cubic-bezier(.34,1.56,.64,1) both; animation-delay:var(--d); }
  .big-star:nth-child(2){ transform:translateY(-8px); }
  .big-star.on:nth-child(2){ animation-name:star-in-mid; }
}
@keyframes star-in{ from{ transform:scale(0) rotate(-60deg); color:rgba(59,35,64,.14); text-shadow:none; } }
@keyframes star-in-mid{ from{ transform:translateY(-8px) scale(0) rotate(-60deg); color:rgba(59,35,64,.14); text-shadow:none; } to{ transform:translateY(-8px); } }
.score-line b{ font-family:var(--display); font-size:1.5rem; }
.badge{ display:inline-block; background:var(--gold); color:#5A3A00; border-radius:999px; padding:1px 9px; font-size:.75rem; font-weight:800; vertical-align:middle; }
@media (prefers-reduced-motion:no-preference){
  .badge{ animation:bump .6s ease .9s both; }
}

/* ---------- help ---------- */
.how{ text-align:left; font-size:.88rem; line-height:1.5; }
.how ul{ margin:4px 0 8px; padding-left:18px; }
.how li{ margin:4px 0; }
.how .small{ color:var(--muted); font-size:.82rem; margin-top:6px; }
.how ul.powers{ list-style:none; padding:0; display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.powers li{ display:flex; align-items:center; gap:8px; margin:0; background:#FFF4F8; border-radius:12px; padding:5px 8px 5px 4px; font-size:.8rem; line-height:1.3; }
.powers canvas{ flex:none; width:40px; height:40px; }

kbd{
  font-family:ui-monospace, monospace; font-size:.72rem; font-weight:700;
  background:#fff; border:1px solid var(--line-strong); border-bottom-width:2px;
  border-radius:5px; padding:1px 5px; color:var(--muted);
}
.keys-help{
  display:flex; flex-wrap:wrap; justify-content:center; gap:6px 14px;
  margin-top:12px; color:var(--text); font-size:.8rem; opacity:.8;
}
.dark .keys-help{ color:#fff; }
.touch-help{ display:none; text-align:center; color:#fff; text-shadow:0 1px 2px rgba(0,0,0,.35); font-size:.82rem; margin:10px 0 0; }
@media (hover:none){
  .keys-help, .keys-only{ display:none; }
  .touch-help{ display:block; }
}

@media (max-height:820px){
  .hero{ display:none; }
}

@media (max-width:520px){
  .site-nav{ padding:10px 10px 0; }
  .page{ padding:2px 8px 24px; }
  .hud{ gap:5px; }
  .pill{ padding:4px 9px; font-size:.78rem; }
  .pill.score{ padding:3px 12px; }
  .pill.score b{ font-size:1.1rem; }
  .board-wrap{ padding:4px; border-radius:20px; }
  #board{ border-radius:16px; }
  /* on phones the cards get the whole screen instead of just the board */
  .overlay{ position:fixed; inset:0; z-index:20; border-radius:0; padding:12px; align-items:flex-start; }
  .card{ margin:auto 0; padding:14px 12px 12px; gap:10px; }
  .card h2{ font-size:1.4rem; }
  .card h2.title{ font-size:1.7rem; }
  .how ul.powers{ grid-template-columns:1fr; }
  .worlds{ max-height:60vh; }
}
