:root {
  --bg: #1d1633;
  --panel: #2a2149;
  --panel2: #362b5e;
  --text: #f4efff;
  --muted: #a99fcc;
  --accent: #ffcc33;
  --accent2: #ff5fa2;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(circle at 20% 0%, #3b2a6e 0%, var(--bg) 55%) fixed;
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
}
header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#roomInfo { color: var(--muted); }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9em; }
.error { color: #ff7b7b; min-height: 1.2em; margin-top: 8px; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.panel h2, .panel h3 { margin: 0 0 10px; }

button {
  font: inherit;
  background: var(--panel2);
  color: var(--text);
  border: 2px solid #5a4a92;
  border-radius: 10px;
  padding: 7px 14px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
button:hover:not(:disabled) { background: #46397a; transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: default; }
button.big {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 10px 22px;
  background: linear-gradient(90deg, #ff9f1c, var(--accent2));
  border: none;
  color: #1d1633;
}
button.small { font-size: 0.8rem; padding: 3px 8px; }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.link:hover { background: none; }

input, select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  border: 2px solid #5a4a92;
  background: #1a1430;
  color: var(--text);
}
label { display: block; margin: 8px 0; }
label input:not([type=checkbox]), label select { display: block; margin-top: 4px; width: 100%; }
label.check { display: flex; gap: 8px; align-items: center; }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* home */
.home-panel { max-width: 420px; margin: 40px auto; text-align: center; }
.home-panel .tagline { font-size: 1.1rem; }
.row { display: flex; gap: 10px; justify-content: center; margin: 12px 0; }
.or { color: var(--muted); margin: 16px 0 4px; }
.code-input { width: 110px; text-transform: uppercase; text-align: center; font-size: 1.2rem; letter-spacing: 4px; }

/* lobby */
#lobby { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.bigcode { font-size: 1.6rem; font-weight: 800; letter-spacing: 4px; color: var(--accent); }
.lobby-players { list-style: none; padding: 0; }
.lobby-players li { padding: 6px 0; display: flex; align-items: center; gap: 6px; }
.lobby-players li button { margin-left: auto; }
.guide { max-height: 80vh; overflow: auto; }

/* game layout */
#game { display: grid; grid-template-columns: 1fr 320px; gap: 16px; padding: 0 16px 16px; max-width: 1500px; margin: 0 auto; }
#banner { padding: 6px 4px 10px; font-size: 1.05rem; }
.right { position: sticky; top: 8px; align-self: start; max-height: calc(100vh - 16px); display: flex; flex-direction: column; }
.log-panel { flex: 1; min-height: 200px; display: flex; flex-direction: column; overflow: hidden; }
#log { overflow-y: auto; font-size: 0.85rem; line-height: 1.4; flex: 1; max-height: 50vh; }
#log .turn { margin-top: 6px; font-weight: 700; color: var(--accent); }
#log .sep { margin: 10px 0 4px; color: var(--accent2); font-weight: 700; }

/* prompt */
.prompt {
  border: 3px solid var(--accent);
  animation: pulse 1.6s infinite;
}
.prompt-text { font-size: 1.15rem; font-weight: 700; margin-bottom: 10px; }
.prompt-options { display: flex; flex-wrap: wrap; gap: 8px; }
.prompt-options button { background: #4a3a8a; }
.roll-prompt .prompt-options button {
  font-size: 1.3rem;
  font-weight: 800;
  padding: 12px 28px;
  background: linear-gradient(90deg, #ff9f1c, var(--accent2));
  border: none;
  color: #1d1633;
}
.roll-prompt .prompt-options button + button { background: #4a3a8a; color: var(--text); }
.roll-prompt .prompt-text::after { content: '  (Space / Enter)'; font-weight: 400; font-size: 0.8rem; color: var(--muted); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 204, 51, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(255, 204, 51, 0); }
}

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.small-cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card {
  background: linear-gradient(160deg, #fff8e6, #ffe9c2);
  color: #2a1d3d;
  border-radius: 12px;
  padding: 10px;
  border-top: 6px solid var(--owner, #c9b37e);
  position: relative;
  font-size: 0.85rem;
}
.card.clickable { cursor: pointer; box-shadow: 0 0 0 3px var(--accent); transition: transform 0.12s; }
.card.clickable:hover { transform: translateY(-4px) rotate(-1deg); }
.card.faded { opacity: 0.45; }
.card.current { box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent); }
.card-emoji { font-size: 2rem; line-height: 1; }
.card-name { font-weight: 800; font-size: 1.05rem; }
.card-power { font-size: 0.7rem; font-weight: 700; color: #a3367a; letter-spacing: 0.5px; }
.card-text { margin-top: 4px; }
.card-status { margin-top: 6px; font-weight: 600; }
.card-sub { margin-top: 4px; font-style: italic; }
.race-cards { margin-top: 12px; }

.draft-order { margin-bottom: 10px; font-size: 0.9rem; }
.draft-order span { color: var(--muted); }
.draft-order span.now { color: var(--text); font-weight: 800; border-bottom: 3px solid var(--c); }
.draft-order span.done { opacity: 0.5; }

/* board */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 15.5 / 4.5;
  container-type: inline-size;
}
.board svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.board-bg { fill: #161616; }
.outline { fill: none; stroke: #fff; stroke-width: 0.035; }
.infield { fill: #0c0c0c; stroke: #fff; stroke-width: 0.035; }
.mild .infield { fill: #10170f; }
.wild .infield { fill: #140f1c; }
.tile { stroke: #111; stroke-width: 0.04; }
.tile.red { fill: #e5322d; }
.tile.pink { fill: #ec8fd2; }
.tile.yellow { fill: #f6c234; }
.tile.green { fill: #2fa64e; }
.tile.blue { fill: #5ba3e3; }
.tile.purple { fill: #8a4fc2; }
.tile.special { stroke: #3a1f5c; stroke-width: 0.07; }
.board text { text-anchor: middle; dominant-baseline: central; font-family: system-ui, sans-serif; }
.num.big { font-size: 0.42px; font-weight: 900; fill: #4a7fd0; }
.tile.red + .num.big { fill: #6aa8f0; }
.num.small { font-size: 0.17px; font-weight: 700; fill: rgba(0, 0, 0, 0.45); }
.trip-box { fill: #fff; stroke: #111; stroke-width: 0.025; }
.trip-text { font-size: 0.2px; font-weight: 900; fill: #e5322d; font-style: italic; }
.star { font-size: 0.85px; fill: #f6c234; stroke: #3a1f5c; stroke-width: 0.03; }
.star-num { font-size: 0.24px; font-weight: 900; fill: #3a1f5c; }
.arrow { fill: #fff; stroke: #3a1f5c; stroke-width: 0.03; }
.arrow-num { font-size: 0.24px; font-weight: 900; fill: #3a1f5c; }
.start-text { font-size: 0.5px; font-weight: 900; font-style: italic; fill: #e5322d; stroke: #111; stroke-width: 0.02; letter-spacing: -0.01px; }
.podium { fill: #f6c234; stroke: #111; stroke-width: 0.04; }
.pod-label { font-size: 0.2px; font-weight: 900; fill: #3a1f5c; }
.track-name {
  font-size: 0.95px; font-weight: 900; fill: #fff; stroke: #111; stroke-width: 0.03;
  letter-spacing: 0.03px; paint-order: stroke;
}
.decor { font-size: 0.5px; }

.die {
  position: absolute; transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.12); border-radius: 1.5cqw; padding: 0.4cqw 1.4cqw;
  font-size: 1.8cqw; color: #fff; text-align: center;
}
.die-row { display: flex; align-items: center; gap: 1cqw; justify-content: center; }
.die-face { font-size: 3.6cqw; line-height: 1; animation: roll 0.4s; }
@keyframes roll { from { transform: rotate(-200deg) scale(0.4); } to { transform: none; } }

.tokens { position: absolute; inset: 0; }
.token {
  position: absolute;
  width: 3.7cqw;
  height: 3.7cqw;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff;
  border: 0.45cqw solid var(--c);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1cqw;
  transition: left 0.55s cubic-bezier(.5, 1.6, .5, 1), top 0.55s cubic-bezier(.5, 1.6, .5, 1), opacity 0.4s;
  box-shadow: 0 0.3cqw 0.6cqw rgba(0, 0, 0, 0.45);
  cursor: help;
  z-index: 2;
}
.token span { transition: transform 0.3s; }
.token.tripped span { transform: rotate(90deg); }
.token.tripped::after { content: '💫'; position: absolute; top: -1.2cqw; right: -0.9cqw; font-size: 1.4cqw; }
.token.current { z-index: 3; box-shadow: 0 0 0 0.4cqw var(--accent), 0 0 1.6cqw var(--accent); }
.token.mine::before { content: ''; position: absolute; inset: -0.7cqw; border-radius: 50%; border: 0.2cqw dashed var(--c); opacity: 0.8; }
.token.out { opacity: 0; pointer-events: none; }
.token.hl { z-index: 4; box-shadow: 0 0 0 0.7cqw #fff, 0 0 2.4cqw #fff; }

.race-end { text-align: center; font-size: 1.1rem; margin-top: 12px; border: 3px solid var(--accent); }

/* scores */
.player-row { padding: 8px; border-radius: 10px; border-left: 5px solid var(--c); background: var(--panel2); margin-bottom: 8px; }
.player-row.you { outline: 2px solid rgba(255, 255, 255, 0.25); }
.pr-top { display: flex; align-items: center; gap: 6px; }
.pname { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pscore { font-size: 1.4rem; font-weight: 900; color: var(--accent); }
.pr-bottom { font-size: 0.85rem; min-height: 1em; }
.team { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.mini { font-size: 1.2rem; cursor: help; }
.mini.used { opacity: 0.3; filter: grayscale(1); }
.mini.inrace { background: rgba(255, 255, 255, 0.2); border-radius: 6px; }

.final ol { font-size: 1.2rem; }
.results { border-collapse: collapse; margin: 12px 0; }
.results td, .results th { padding: 4px 12px; border-bottom: 1px solid #4a3d7a; text-align: left; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #ff5f7a; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 100;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

@media (max-width: 900px) {
  #game, #lobby { grid-template-columns: 1fr; }
  .right { position: static; max-height: none; }
  #log { max-height: 260px; }
}
