/* Rubble Rumble styles. Colour tokens only on :root; dark theme via prefers-color-scheme and data-theme. */
:root {
  --bg: #eef1f8;
  --bg-deep: #dfe4f0;
  --panel: #ffffff;
  --ink: #141829;
  --muted: #5b6380;
  --line: #c9d0e3;
  --accent: #0e8aa6;
  --accent-ink: #ffffff;
  --accent-2: #c2347a;
  --well: #0b0d18;
  --well-grid: rgba(255,255,255,0.06);
  --ghost: rgba(255,255,255,0.4);
  --focus: #ff9f1c;
  --danger: #c23434;
  --ok: #1f9d55;
  --rune: #6b3fd1;
  --on-strong: #ffffff;
  --overlay: rgba(6,8,18,0.72);
  --overlay-sub: #cfd6ff;
  --scrim: rgba(0,0,0,0.6);
  --shadow: rgba(0,0,0,0.35);
  --gold: #e3c233;
  --gold-lt: #f6e58a;
  --gold-dk: #8f7715;
  --dead-tint: rgba(10,8,20,0.55);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1020;
    --bg-deep: #070912;
    --panel: #161b30;
    --ink: #e9edff;
    --muted: #97a0c4;
    --line: #2b3353;
    --accent: #5ee7ff;
    --accent-ink: #06202a;
    --accent-2: #ff5ea8;
    --well: #080a14;
    --well-grid: rgba(255,255,255,0.05);
    --ghost: rgba(255,255,255,0.35);
    --focus: #ffb347;
    --danger: #ff6b6b;
    --ok: #4fd98a;
    --rune: #b48bff;
    --on-strong: #ffffff;
    --overlay: rgba(6,8,18,0.72);
    --overlay-sub: #cfd6ff;
    --scrim: rgba(0,0,0,0.6);
    --shadow: rgba(0,0,0,0.5);
    --gold: #e3c233;
    --gold-lt: #f6e58a;
    --gold-dk: #8f7715;
    --dead-tint: rgba(10,8,20,0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1020;
  --bg-deep: #070912;
  --panel: #161b30;
  --ink: #e9edff;
  --muted: #97a0c4;
  --line: #2b3353;
  --accent: #5ee7ff;
  --accent-ink: #06202a;
  --accent-2: #ff5ea8;
  --well: #080a14;
  --well-grid: rgba(255,255,255,0.05);
  --ghost: rgba(255,255,255,0.35);
  --focus: #ffb347;
  --danger: #ff6b6b;
  --ok: #4fd98a;
  --rune: #b48bff;
  --on-strong: #ffffff;
  --overlay: rgba(6,8,18,0.72);
  --overlay-sub: #cfd6ff;
  --scrim: rgba(0,0,0,0.6);
  --shadow: rgba(0,0,0,0.5);
  --gold: #e3c233;
  --gold-lt: #f6e58a;
  --gold-dk: #8f7715;
  --dead-tint: rgba(10,8,20,0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
                    radial-gradient(ellipse at 100% 110%, color-mix(in srgb, var(--accent-2) 14%, transparent), transparent 50%);
  color: var(--ink);
  font-family: "Nunito Sans", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, .brand, .room-code, .stat, .overlay-text { font-family: "Russo One", "Arial Black", Impact, sans-serif; font-weight: 400; letter-spacing: 0.01em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
kbd { font: 600 0.85em "Nunito Sans", monospace; background: var(--bg-deep); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 70%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-size: 1.25rem; }
.brand-gem { width: 28px; height: 28px; fill: var(--accent); }
.brand-gem .f1 { fill: color-mix(in srgb, var(--accent) 50%, white); }
.brand-gem .f2 { fill: color-mix(in srgb, var(--accent) 60%, black); }
.topbar-mid { flex: 1; min-width: 0; color: var(--muted); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-family: "Russo One", sans-serif; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .spk { fill: currentColor; }
.icon-btn svg .cross { display: none; }
.icon-btn[aria-pressed="true"] svg .wave { display: none; }
.icon-btn[aria-pressed="true"] svg .cross { display: block; stroke: var(--danger); }

/* screens */
.screen { width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 16px 32px; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; margin-bottom: 20px; }
.hero-text { min-width: 0; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.6rem); margin: 8px 0 8px; line-height: 1.1; }
.lede { color: var(--muted); max-width: 60ch; margin: 0 0 14px; font-size: 1.05rem; }
.name-row { max-width: 360px; }
.hero-art { width: clamp(140px, 22vw, 240px); height: auto; }
.hero-art .shard path { fill: var(--accent); }
.hero-art .shard .lt { fill: color-mix(in srgb, var(--accent) 45%, white); }
.hero-art .shard .dk { fill: color-mix(in srgb, var(--accent) 55%, black); }
.hero-art .shard.b path { fill: var(--accent-2); }
.hero-art .shard.b .lt { fill: color-mix(in srgb, var(--accent-2) 45%, white); }
.hero-art .shard.b .dk { fill: color-mix(in srgb, var(--accent-2) 55%, black); }
.hero-art .shard.c path { fill: var(--gold); }
.hero-art .shard.c .lt { fill: var(--gold-lt); }
.hero-art .shard.c .dk { fill: var(--gold-dk); }
.hero-art .shard.r path { fill: var(--rune); }
.hero-art .shard.r .lt { fill: color-mix(in srgb, var(--rune) 55%, white); }
.hero-art .shard.r text { fill: var(--on-strong); font: 700 16px "Russo One", sans-serif; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; min-width: 0; }
.card h2 { margin: 0 0 10px; font-size: 1.1rem; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 12px; }
.hint.error { color: var(--danger); min-height: 1.2em; margin-top: 10px; }
.field-label { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 6px 0 4px; }
.text, .select { width: 100%; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; }
.text.code { font-family: "Russo One", monospace; letter-spacing: 0.3em; text-transform: uppercase; font-size: 1.3rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row.center { justify-content: center; }
.control { min-width: 0; flex: 1 1 100px; }
.control.grow { flex: 2 1 120px; }
.join-row { margin-top: 12px; }
.btn { padding: 11px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 800; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--ok); color: var(--on-strong); border-color: transparent; }
.card .btn.primary { width: 100%; margin-top: 10px; }
.runes { margin-top: 24px; }
.runes h2 { font-size: 1.1rem; }
.rune-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.rune-list li { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-width: 0; }
.rune-list.compact { grid-template-columns: 1fr 1fr; margin: 14px 0; }
.rune-list.compact li { padding: 6px 8px; font-size: 0.85rem; }
.rune-glyph { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 8px; background: var(--rune); color: var(--on-strong); display: inline-flex; align-items: center; justify-content: center; font-family: "Russo One", sans-serif; font-size: 1.1rem; box-shadow: inset 0 -3px 0 var(--shadow), inset 0 2px 0 color-mix(in srgb, var(--on-strong) 35%, transparent); }
.rune-list b { display: block; }
.rune-list span { color: var(--muted); font-size: 0.9rem; }
.rune-list .rune-glyph, .touch-front .rune-glyph { color: var(--on-strong); font-size: 1.1rem; }

/* lobby */
.lobby { max-width: 520px; margin: 0 auto; }
.room-code { font-size: 3rem; letter-spacing: 0.3em; margin: 0 0 6px; color: var(--accent); }
.player-list { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 6px; }
.player-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); min-width: 0; }
.player-list .tag { color: var(--muted); font-size: 0.85rem; }
.player-list .tag.ready { color: var(--ok); font-weight: 800; }
.player-list .tag.watching { color: var(--accent); }
.player-list li > span:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.player-list .mute-btn { min-height: 28px; padding: 2px 10px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 0.8rem; font-weight: 700; cursor: pointer; }
.player-list .mute-btn:hover { border-color: var(--accent); color: var(--ink); }
.player-list .mute-btn[aria-pressed="true"] { border-color: var(--danger); color: var(--danger); }
.chat { margin: 0 0 14px; }
.chat-list { list-style: none; margin: 0 0 8px; padding: 8px 10px; height: 132px; overflow-y: auto; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font-size: 0.9rem; display: flex; flex-direction: column; gap: 3px; overflow-wrap: anywhere; }
.chat-list:empty::before { content: "No messages yet."; color: var(--muted); }
.chat-list b { margin-right: 6px; }
.chat-list li.me b { color: var(--accent); }
.chat-form { display: flex; gap: 8px; }
.chat-form .text { flex: 1; }
.chat-form.compact { margin-top: 6px; }
.chat-form.compact .text { padding: 6px 8px; font-size: 0.85rem; border-radius: 8px; }

/* game */
.screen.game { padding: 12px 16px 16px; }
.arena {
  display: grid; gap: 12px; align-items: start; justify-content: center;
  grid-template-columns: 180px minmax(0, auto) minmax(240px, 340px);
  grid-template-areas: "left field right";
}
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side-left { grid-area: left; } .side-right { grid-area: right; }
.area-field { grid-area: field; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.panel-title { margin: 0 0 6px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); display: flex; justify-content: space-between; }
.panel canvas { display: block; border-radius: 6px; background: var(--bg); }
.stats { display: grid; gap: 4px; }
.stats div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat { font-size: 1.1rem; }
.field-wrap { position: relative; justify-self: center; }
#cv-field { display: block; border-radius: 10px; border: 2px solid var(--line); background: var(--well); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent), 0 20px 50px var(--shadow); }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--overlay); color: var(--on-strong); border-radius: 10px; text-align: center; padding: 16px; }
.overlay-text { font-size: clamp(1.4rem, 5vw, 2.4rem); margin: 0; }
.overlay-sub { margin: 0; color: var(--overlay-sub); }
.next { display: grid; grid-template-columns: 1fr; gap: 6px; }
.next canvas { margin: 0 auto; }
.rival-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.rival { display: flex; flex-direction: column; gap: 3px; align-items: center; min-width: 0; cursor: pointer; }
.rival canvas { width: 100%; max-width: 110px; aspect-ratio: 12/22; height: auto; border: 1px solid var(--line); background: var(--well); }
.rival .name { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.rival .num { font-family: "Russo One", sans-serif; color: var(--accent); margin-right: 4px; }
.rival.dead .name { color: var(--muted); text-decoration: line-through; }
.log-list { list-style: none; margin: 0; padding: 0; font-size: 0.82rem; display: grid; gap: 3px; max-height: 150px; overflow: hidden; }
.log-list li { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-list li.me { color: var(--ink); }
.log-list li.bad { color: var(--danger); }
.log-list li.good { color: var(--ok); }
.log-list li.chat { color: var(--ink); font-style: italic; }

/* spectating a round in progress: no own field, controls or runes */
.watch-label { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); margin: 0; padding: 3px 10px; border-radius: 999px; background: var(--overlay); color: var(--on-strong); font-size: 0.8rem; font-weight: 800; white-space: nowrap; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.spectating .area-hold, .spectating .area-stats, .spectating .area-inv, .spectating .area-next { display: none; }
.spectating .touch { display: none !important; }
.screen.game.spectating { padding-bottom: 16px; }
.rival.watched canvas { outline: 2px solid var(--accent); outline-offset: 1px; }

.inv-list { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; min-height: 30px; }
.inv-list li { width: 26px; height: 26px; border-radius: 6px; background: var(--rune); color: var(--on-strong); display: inline-flex; align-items: center; justify-content: center; font-family: "Russo One", sans-serif; font-size: 0.85rem; opacity: 0.55; box-shadow: inset 0 -2px 0 var(--shadow); }
.inv-list li:first-child { opacity: 1; outline: 2px solid var(--accent); }
.inv-front { font-size: 0.85rem; margin: 0 0 8px; color: var(--muted); min-height: 2.4em; }
.inv-front b { color: var(--ink); }
.target-row { display: flex; flex-wrap: wrap; gap: 4px; }
.target-row button { min-width: 36px; height: 36px; padding: 0 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-weight: 800; font-size: 0.8rem; }
.target-row button.self { border-color: var(--accent); }
.target-row button.discard { border-color: var(--danger); color: var(--danger); }
.target-row button[disabled] { opacity: 0.4; cursor: default; }

/* touch controls */
.touch { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; gap: 6px; flex-direction: column; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--panel) 92%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(8px); }
.touch-row { display: flex; gap: 6px; }
.touch-runes { align-items: center; }
.touch-front { flex: 0 0 auto; max-width: 40%; min-width: 0; font-size: 0.78rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.touch-front .rune-glyph { width: 26px; height: 26px; font-size: 0.85rem; flex-basis: 26px; vertical-align: middle; margin-right: 4px; }
.touch-runes .target-row { flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; }
.touch-runes .target-row button { height: 40px; min-width: 40px; flex: 0 0 auto; }
.tbtn { flex: 1; min-width: 0; height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 1.3rem; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.tbtn.wide { flex: 1.6; }
.tbtn:active { background: var(--accent); color: var(--accent-ink); }
@media (pointer: coarse) { .touch { display: flex; } .screen.game { padding-bottom: 200px; } }

/* help modal */
.modal { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; max-width: 640px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-box h2 { margin-top: 0; }
.keys { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.keys th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 8px 4px 0; white-space: nowrap; }
.keys td { padding: 4px 12px 4px 0; }

/* responsive */
@media (max-width: 900px) {
  .screen.game { padding-top: 8px; }
  .arena {
    gap: 8px; grid-template-columns: auto auto minmax(0, 1fr); grid-template-rows: auto auto auto auto auto;
    grid-template-areas: "hold next stats" "field field field" "inv inv inv" "rivals rivals rivals" "log log log";
  }
  .side { display: contents; }
  .area-hold { grid-area: hold; } .area-stats { grid-area: stats; } .area-inv { grid-area: inv; }
  .area-next { grid-area: next; } .area-rivals { grid-area: rivals; } .area-log { grid-area: log; }
  .panel { padding: 6px 8px; }
  .panel-title { margin-bottom: 4px; font-size: 0.65rem; }
  .panel-title kbd { display: none; }
  .area-hold canvas { width: 48px; height: 38px; }
  .next { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
  .next .panel-title { flex-basis: 100%; }
  .next canvas { width: 40px; height: 32px; margin: 0; }
  .stats { gap: 0; }
  .stats div { font-size: 0.72rem; gap: 6px; }
  .stat-label { font-size: 0.68rem; }
  .stat { font-size: 0.85rem; }
  .field-wrap { justify-self: center; }
  .rival-grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
  .rival .name { font-size: 0.7rem; }
  .log-list { max-height: 90px; }
  .keys th, .keys td { display: block; padding: 2px 0; }
  .rune-list.compact { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .screen { padding: 14px 16px 24px; }
  .hero { grid-template-columns: 1fr; }
  .hero-art { display: none; }
  .room-code { font-size: 2.2rem; }
  .topbar-mid { display: none; }
}
/* menu footer + document pages (privacy) */
.menu-foot { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 0.9rem; }
.menu-foot a, .doc a:not(.btn) { color: var(--accent); }
.screen.doc { max-width: 760px; line-height: 1.55; }
.doc h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 8px 0 6px; }
.doc h2 { font-size: 1.1rem; margin: 26px 0 8px; }
.doc ul { padding-left: 1.2em; }
.doc li { margin: 4px 0; }
.doc .btn { display: inline-flex; align-items: center; text-decoration: none; margin-top: 12px; color: var(--ink); }
.doc-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.doc-table th, .doc-table td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.doc-table th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
@media (max-width: 600px) {
  .doc-table thead { display: none; }
  .doc-table tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .doc-table td { display: block; border: 0; padding: 2px 10px; }
  .doc-table td:first-child { font-weight: 800; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
