:root {
  --ink: #3a2e5c;
  --panel: rgba(255, 255, 255, 0.94);
  --pri: #7c4dff;
  --pri-d: #5b34d6;
  --accent: #ffb703;
  --good: #2ecc71;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Comic Sans MS", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ink); background: #bfe3ff; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }

/* ---------- overlays & panels ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; pointer-events: none; }
.overlay .panel { pointer-events: auto; }
#promo, #over, #confirm, #nogl { background: rgba(40, 20, 90, 0.35); backdrop-filter: blur(3px); pointer-events: auto; }
.panel {
  position: relative; width: min(560px, 100%); max-height: 100%; overflow: auto;
  background: var(--panel); border-radius: 28px; padding: 28px 26px 24px;
  box-shadow: 0 18px 50px rgba(60, 30, 140, 0.35), 0 0 0 4px rgba(255, 255, 255, 0.6) inset;
  text-align: center; animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.panel.small { width: min(420px, 100%); }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
h1 { margin: 6px 0 4px; font-size: clamp(1.7rem, 5vw, 2.4rem); }
h2 { margin: 0 0 6px; font-size: 1.6rem; }
.logo { display: inline-block; animation: wiggle 2.4s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.sub { margin: 4px 0 16px; color: #62588a; font-size: 1.02rem; }
.label { margin: 14px 0 8px; font-weight: 700; }
.note { min-height: 1.4em; color: #c0392b; font-weight: 700; margin: 10px 0 0; }
.home-link { position: absolute; left: 18px; top: 14px; font-size: 0.85rem; color: #7a70a8; text-decoration: none; }
.home-link:hover { text-decoration: underline; }
.big-emoji { font-size: 4rem; line-height: 1; animation: wiggle 1.2s ease-in-out infinite; }

/* ---------- buttons ---------- */
button { font-family: inherit; color: inherit; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 8px; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 8px; cursor: pointer;
  background: linear-gradient(180deg, #fff, #f1ebff); border: 3px solid #d9ccff; border-radius: 20px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s; font-size: 1rem;
}
.card .emoji { font-size: 2.4rem; }
.card small { color: #7a70a8; }
.card:hover, .card:focus-visible { transform: translateY(-4px) scale(1.03); border-color: var(--pri); box-shadow: 0 8px 18px rgba(124, 77, 255, 0.28); outline: none; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choices.four { grid-template-columns: repeat(4, 1fr); }
.choice {
  display: flex; flex-direction: column; align-items: center; padding: 12px 6px; cursor: pointer; font-weight: 700; font-size: 1rem;
  background: #fff; border: 3px solid #e1d8fa; border-radius: 16px; transition: all 0.12s;
}
.choice small { font-weight: 400; color: #7a70a8; }
.choice:hover, .choice:focus-visible { border-color: var(--pri); outline: none; }
.choice.selected { border-color: var(--pri); background: #efe8ff; box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.2); }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.row.stack { flex-direction: column; align-items: center; }
.btn {
  border: 0; border-radius: 999px; padding: 12px 24px; font-size: 1.05rem; font-weight: 800; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
.btn.sm { padding: 8px 16px; font-size: 0.95rem; }
.btn.primary { background: linear-gradient(180deg, #9a73ff, var(--pri)); color: #fff; box-shadow: 0 5px 0 var(--pri-d); }
.btn.primary:hover { transform: translateY(-2px); filter: brightness(1.06); }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--pri-d); }
.btn.ghost { background: #efeaff; color: var(--pri-d); }
.btn.ghost:hover { background: #e4dbff; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input[type=text], #nick {
  width: min(320px, 100%); font: inherit; font-size: 1.15rem; text-align: center; padding: 12px 16px;
  border: 3px solid #d9ccff; border-radius: 16px; color: var(--ink);
}
.toggle { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--pri); }
.pill { display: inline-block; font-size: 0.9rem; background: #efe8ff; color: var(--pri-d); border-radius: 999px; padding: 3px 12px; vertical-align: middle; }

/* ---------- learn ---------- */
.learn-list { text-align: left; display: grid; gap: 6px; max-height: 52vh; overflow: auto; padding: 2px; }
.learn-list h3 { margin: 12px 0 4px; font-size: 1.05rem; }
.lesson-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; cursor: pointer; font-size: 1rem; font-weight: 700; text-align: left;
  background: #f6f2ff; border: 3px solid transparent; border-radius: 14px; transition: all 0.12s;
}
.lesson-btn:hover, .lesson-btn:focus-visible { border-color: var(--pri); outline: none; }
.lesson-btn .e { font-size: 1.4rem; width: 1.8rem; text-align: center; }
.lesson-btn .t { flex: 1; }
.lesson-btn .done { font-size: 1.2rem; }
.lesson-btn.next { background: #fff3c4; border-color: var(--accent); }
.lesson {
  position: absolute; top: 66px; left: 50%; transform: translateX(-50%); width: min(94vw, 560px); text-align: center;
  background: #fff8d9; border: 3px solid var(--accent); border-radius: 18px; padding: 8px 14px; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.2);
  display: flex; flex-direction: column; gap: 2px; font-weight: 700;
}
.lesson b { font-size: 1.05rem; }
.lesson span { font-weight: 600; font-size: 0.95rem; }

/* ---------- lobby ---------- */
.lobby { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; text-align: left; }
.lobby li { display: flex; align-items: center; gap: 10px; background: #f6f2ff; border-radius: 14px; padding: 8px 12px; }
.lobby .who { flex: 1; font-weight: 800; }
.lobby .state { font-size: 0.85rem; color: #7a70a8; }
.lobby .me { color: var(--pri-d); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.status {
  flex: 1; max-width: 520px; margin: 0 auto; text-align: center; font-weight: 800; font-size: 1.05rem;
  background: var(--panel); padding: 10px 18px; border-radius: 999px; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25);
}
.status.warn { background: #fff0f0; color: #c0392b; animation: shake 0.5s; }
.status.think::after { content: "..."; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--panel); font-size: 1.3rem; cursor: pointer;
  box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); transition: transform 0.12s;
}
.icon-btn:hover { transform: scale(1.1); }
.player-card {
  position: absolute; left: 10px; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 20px);
  background: var(--panel); padding: 8px 14px; border-radius: 999px; font-weight: 800; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.2);
  border: 3px solid transparent; transition: border-color 0.2s, transform 0.2s;
}
.player-card.top { top: 68px; }
.player-card.bottom { bottom: 92px; }
.player-card.active { border-color: var(--accent); transform: scale(1.04); }
.player-card .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #8b7fc0; flex: none; }
.player-card .dot.w { background: #fff; }
.player-card .dot.b { background: #6a4cb0; }
.player-card .captured { font-size: 1.15rem; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-card .captured .cw { color: #bdb4d9; text-shadow: 0 0 1px #5b4a8c, 0 0 2px #5b4a8c; }
.player-card .captured .cb { color: #6a4cb0; }
.bubble { position: absolute; left: 50%; top: -42px; transform: translateX(-50%); background: #fff; border-radius: 16px; padding: 4px 12px; font-size: 1.5rem; box-shadow: 0 4px 12px rgba(0,0,0,.2); animation: pop .3s; }
.tip {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); max-width: min(92vw, 460px); text-align: center;
  background: #fff8d9; border: 3px solid var(--accent); padding: 8px 16px; border-radius: 18px; font-weight: 700; animation: pop 0.25s;
}
.toolbar { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 66px; padding: 8px 10px; font-size: 1.4rem;
  background: var(--panel); border: 0; border-radius: 18px; cursor: pointer; box-shadow: 0 4px 0 rgba(91, 52, 214, 0.35);
}
.tool span { font-size: 0.72rem; font-weight: 800; }
.tool:hover:not(:disabled) { transform: translateY(-2px); }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }
.emotes { position: absolute; right: 10px; bottom: 100px; display: flex; flex-direction: column; gap: 6px; }
.emotes button { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--panel); font-size: 1.3rem; font-weight: 800; cursor: pointer; box-shadow: 0 3px 10px rgba(0,0,0,.2); }
.emotes button:hover { transform: scale(1.12); }

.toast-invite {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: #fff; padding: 12px 18px; border-radius: 22px; font-weight: 800; box-shadow: 0 10px 30px rgba(60, 30, 140, 0.4); border: 3px solid var(--pri); animation: pop 0.3s; max-width: 94vw;
}

@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .card { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 16px; }
  .card .emoji { font-size: 2rem; }
  .card small { margin-left: auto; }
  .panel { padding: 24px 16px 18px; border-radius: 22px; }
  .tool { min-width: 56px; padding: 6px 8px; font-size: 1.2rem; }
  .player-card.bottom { bottom: 84px; }
  .emotes { flex-direction: row; right: auto; left: 50%; transform: translateX(-50%); bottom: 82px; flex-wrap: wrap; justify-content: center; width: 94vw; }
  .emotes button { width: 38px; height: 38px; font-size: 1.05rem; }
  .player-card.bottom { bottom: 134px; }
  .tip { bottom: 190px; }
}
@media (prefers-reduced-motion: reduce) {
  .logo, .big-emoji, .panel, .tip, .toast-invite { animation: none; }
}
