:root {
  --ink: #1d2433;
  --muted: #5b6577;
  --panel: rgba(255, 255, 255, 0.9);
  --line: rgba(29, 36, 51, 0.14);
  --accent: #2f6fde;
  --good: #1f9d55;
  --warn: #d97706;
  --bad: #c2410c;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fd3f0; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(15, 30, 55, 0.35); z-index: 20; padding: 16px; }
.card { background: #fff; border-radius: 16px; padding: 24px; width: min(420px, 100%); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); }
.card h1 { margin: 0 0 4px; font-size: 32px; }
.sub { margin: 0 0 16px; color: var(--muted); }
label { display: block; margin: 10px 0; font-weight: 600; }
label input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 10px 0; }
legend { font-weight: 600; margin-bottom: 6px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.colors button[aria-pressed='true'] { border-color: var(--ink); }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.primary:disabled { opacity: 0.5; }
#join-form .primary { width: 100%; margin-top: 8px; padding: 12px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
.small { font-size: 13px; color: var(--muted); }

.panel { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; z-index: 5; backdrop-filter: blur(6px); }
#top-left { top: 12px; left: 12px; min-width: 200px; font-size: 14px; }
.who { font-weight: 700; }
.xp { margin: 2px 0 6px; color: var(--muted); }
.mastery { font-size: 12px; margin-top: 4px; }
.bar { height: 6px; background: #e5e9f0; border-radius: 3px; overflow: hidden; margin-top: 2px; }
.bar i { display: block; height: 100%; background: var(--good); }
#quest { top: 12px; right: 12px; width: 250px; font-size: 14px; }
#quest h2 { font-size: 15px; margin: 0 0 6px; }
#quest ol { margin: 0; padding-left: 20px; }
#quest li { margin: 3px 0; }
#quest li.done { color: var(--good); text-decoration: line-through; }
#minimap { display: block; margin: 10px auto 0; width: 110px; height: 220px; border-radius: 8px; }
#quest h3 { font-size: 13px; margin: 10px 0 4px; }
#quest-side .gems { display: flex; gap: 4px; }
#quest-side .gem { font-size: 18px; filter: grayscale(1); opacity: 0.35; }
#quest-side .gem.got { filter: drop-shadow(0 0 4px var(--c)); opacity: 1; }
#quest-side p { margin: 4px 0 0; }

#bottom-bar { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; z-index: 6; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 24px); }
.tool { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.tool.on { background: #dff3e6; border-color: var(--good); }
.tool.stuck { color: var(--bad); }
.tool.primary { background: var(--accent); color: #fff; }

#chat { left: 12px; bottom: 12px; width: 300px; font-size: 13px; }
#chat-log { max-height: 140px; overflow-y: auto; margin-bottom: 6px; }
#chat-log p { margin: 2px 0; }
#chat-log .teacher { color: var(--warn); font-weight: 600; }
#chat-presets { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; max-height: 58px; overflow-y: auto; }
#chat-presets button { font-size: 12px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 8px; }
#chat-input { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.help { position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%); z-index: 4; background: rgba(255,255,255,.7); padding: 2px 10px; border-radius: 999px; }

.pill { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 999px; z-index: 6; }
.notice { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: #fff7e6; border: 2px solid var(--warn); padding: 10px 16px; border-radius: 12px; z-index: 8; max-width: 60%; font-weight: 600; }
.frozen { top: 64px; background: #eef2ff; border-color: var(--accent); }
.toast { position: fixed; top: 30%; left: 50%; transform: translateX(-50%); background: var(--good); color: #fff; padding: 14px 22px; border-radius: 14px; font-size: 20px; font-weight: 700; z-index: 9; box-shadow: 0 8px 30px rgba(0,0,0,.25); }

.challenge { width: min(520px, 100%); position: relative; }
.challenge h2 { margin: 4px 0 8px; }
.tag { display: inline-block; margin: 0; font-size: 12px; background: #eef2ff; color: var(--accent); padding: 2px 8px; border-radius: 999px; }
.close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 26px; color: var(--muted); }
#ch-clues { padding-left: 18px; }
#ch-clues li { margin: 4px 0; font-weight: 600; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0; }
.choices button { padding: 14px; font-size: 20px; border: 2px solid var(--line); border-radius: 12px; background: #fff; }
.choices button:hover { border-color: var(--accent); }
.answer-row { display: flex; gap: 8px; margin: 10px 0; }
.answer-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 18px; }
#ch-feedback .hint { background: #fff7e6; border-left: 4px solid var(--warn); padding: 8px 10px; border-radius: 6px; margin: 8px 0; }
#ch-feedback .example { background: #eef2ff; border-left: 4px solid var(--accent); padding: 8px 10px; border-radius: 6px; margin: 8px 0; }
#ch-feedback .ok { color: var(--good); font-weight: 700; font-size: 18px; }

#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
.bubble { position: absolute; transform: translate(-50%, -100%); width: 96px; height: 72px; border-radius: 14px; overflow: hidden; border: 3px solid #fff; box-shadow: 0 4px 14px rgba(0,0,0,.3); background: #000; }
.bubble video { width: 100%; height: 100%; object-fit: cover; }
.bubble.self video { transform: scaleX(-1); }

@media (max-width: 1100px) { .help { display: none; } }
@media (max-width: 760px) {
  #quest { width: 180px; font-size: 12px; }
  #minimap { display: none; }
  #chat { width: calc(100% - 24px); bottom: 64px; }
  #chat-log { max-height: 70px; }
  .help { display: none; }
  .notice { max-width: 90%; }
}
