:root {
  --bg: #9ed36a; --ink: #1f2933; --card: #fffdf7; --muted: #6b7280; --line: #e5e0d4;
  --accent: #2f6fed; --good: #2f9e44; --bad: #e03131;
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body { -webkit-user-select: none; user-select: none; }
input { -webkit-user-select: text; user-select: text; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
button { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; cursor: pointer; color: var(--ink); }
button:hover { border-color: #c9c1ae; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; width: 100%; padding: 12px; }
button:disabled { opacity: .5; cursor: default; }

#hud { position: fixed; top: 0; inset-inline: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); pointer-events: none; }
#hud nav button { display: flex; gap: 6px; align-items: center; min-height: 36px; }
#hud > * { pointer-events: auto; }
#hud .stats, #hud nav { display: flex; gap: 12px; align-items: center; background: rgba(255,253,247,.94); border-radius: 12px; padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); }
#hud nav { gap: 6px; padding: 6px; }
#hud nav button { padding: 6px 10px; }
#hint { position: fixed; bottom: calc(14px + env(safe-area-inset-bottom)); inset-inline: 0; margin: auto; width: max-content; max-width: calc(100% - 32px); text-align: center;
  background: rgba(31,41,51,.8); color: #fff; padding: 8px 14px; border-radius: 999px; font-size: 14px; pointer-events: none; }

dialog { border: 0; border-radius: 16px; padding: 20px; width: min(440px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto;
  background: var(--card); box-shadow: 0 10px 40px rgba(0,0,0,.3); color: var(--ink); }
dialog::backdrop { background: rgba(20,30,20,.45); }
dialog h1, dialog h2 { margin: 0 0 14px; display: flex; justify-content: space-between; align-items: center; }
dialog form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input { font: inherit; font-size: 16px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
input[type=color] { height: 42px; padding: 3px; width: 100%; }
.error { color: var(--bad); margin: 0; min-height: 1.2em; font-size: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tabs .on { background: var(--ink); color: #fff; border-color: var(--ink); }
.lang-mini { padding: 4px 10px; font-size: 14px; }

#avatar-preview { justify-self: center; background: #eaf5dd; border-radius: 50%; }
#avatar-parts { display: grid; gap: 8px; }
.part { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.part > span { width: 80px; font-size: 14px; color: var(--muted); }
.swatch { width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 2px solid var(--line); font-size: 12px; }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.part.text .swatch { width: auto; border-radius: 8px; padding: 0 8px; }

#quiz-body { display: grid; gap: 12px; }
#quiz-body img { max-width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; justify-self: center; }
.q-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.timer { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.timer > i { display: block; height: 100%; background: var(--accent); transition: width .2s linear; }
.q-text { font-size: 18px; font-weight: 600; margin: 0; }
.options { display: grid; gap: 8px; }
.options button { text-align: start; padding: 12px; }
.options button.right { background: #d3f9d8; border-color: var(--good); }
.options button.wrong { background: #ffe3e3; border-color: var(--bad); }
.feedback { font-weight: 600; margin: 0; min-height: 1.3em; }
.feedback.good { color: var(--good); } .feedback.bad { color: var(--bad); }
.big { font-size: 40px; text-align: center; margin: 0; }

#shop-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
#shop-items button { display: grid; justify-items: center; gap: 4px; padding: 8px; }
#shop-items canvas { width: 80px; height: 80px; }
#shop-stack { margin: 0; color: var(--muted); font-size: 14px; }

#board-list { margin: 0; padding-inline-start: 28px; display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
#board-list li.me { font-weight: 700; color: var(--accent); }
#board-list li span { float: inline-end; }

#closed { position: fixed; top: calc(70px + env(safe-area-inset-top)); inset-inline: 0; margin: auto; width: max-content; max-width: calc(100% - 32px);
  text-align: center; background: #fff3bf; color: #5c4400; border: 1px solid #f0d77a; padding: 8px 14px; border-radius: 12px; font-weight: 600; pointer-events: none; }
.join { display: grid; justify-items: center; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; text-align: center; }
.join-qr { width: 150px; }
.join-qr svg { display: block; width: 100%; height: auto; }
.join small { font-size: 12px; direction: ltr; }
.join:empty { display: none; }
#tut-body { display: grid; gap: 12px; text-align: center; }
.tut-text { font-size: 18px; margin: 0; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }

/* character picker (welcome screen) */
.pick { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick legend { padding: 0; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.pick label { display: grid; justify-items: center; gap: 4px; padding: 8px; border: 2px solid var(--line); border-radius: 14px;
  background: #fff; cursor: pointer; color: var(--ink); font-weight: 600; font-size: 15px; }
.pick label:has(input:checked) { border-color: var(--accent); background: #eef4ff; }
.pick label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick canvas { width: 80px; height: 90px; }

/* ---------- phones ---------- */
@media (max-width: 600px) {
  #hud { flex-wrap: nowrap; gap: 6px; }
  #hud .stats { gap: 8px; padding: 6px 10px; font-size: 14px; min-width: 0; }
  #hud .stats span { white-space: nowrap; }
  #hud .stats strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 26vw; }
  #hud nav { gap: 4px; padding: 4px; flex-shrink: 0; }
  #hud nav button { padding: 6px 9px; min-width: 40px; min-height: 40px; justify-content: center; }
  .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #hint { font-size: 13px; }
  .join { display: none; } /* on a phone you're already here */
  #closed { top: calc(64px + env(safe-area-inset-top)); font-size: 14px; }

  /* dialogs become bottom sheets */
  dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  dialog h1 { font-size: 24px; }
  .options button { padding: 14px; font-size: 16px; }
  .q-text { font-size: 17px; }
  #quiz-body img { max-height: 30dvh; }

  #avatar-preview { width: 120px; height: 120px; }
  .part { gap: 6px; }
  .part > span { width: 100%; }
  .swatch { width: 34px; height: 34px; }
  .part.text .swatch { height: 34px; }

  #shop-items { grid-template-columns: repeat(3, 1fr); }
  #shop-items canvas { width: 64px; height: 64px; }
}
/* short landscape phones: keep dialogs usable */
@media (max-height: 480px) {
  dialog { max-height: 96dvh; padding-top: 12px; }
  #avatar-preview { width: 90px; height: 90px; }
  #quiz-body img { max-height: 24dvh; }
}
