:root {
  color-scheme: dark;
  --bg: #10211c;
  --bg-2: #173028;
  --line: #3c5c50;
  --text: #f6f3ea;
  --muted: #c5d5cc;
  --gold: #f0b429;
  --copper: #d4893a;
  --ink: #1a140e;
  --bottom: #e07048;
  --top: #6ea2ff;
  --danger: #ffb4a8;
  --ok: #b7e3a2;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(240, 180, 41, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  padding: 16px 20px 8px;
}

.eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: 1.8rem;
  letter-spacing: -0.03em;
}

.top-note {
  margin: 0;
  max-width: 360px;
  color: var(--muted);
  text-align: right;
}

body.in-match h1 { font-size: 1.25rem; }
body.in-match .top-note { display: none; }

.menu-panel {
  width: min(640px, calc(100% - 28px));
  margin: 8px auto 28px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}

.lede {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.45;
}

.modes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.modes label, .field {
  background: #10241f;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.modes label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 650;
}

.stack { display: grid; gap: 10px; }

.field {
  display: grid;
  gap: 6px;
}

.field span, .slider-line span { color: var(--muted); font-size: 0.92rem; }

.field input[type="number"], .field select {
  width: 100%;
  background: #0c1b17;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.seed-line, .slider-line {
  display: flex;
  gap: 8px;
  align-items: center;
}

.seed-line input { flex: 1; }

input[type="range"] { flex: 1; accent-color: var(--gold); }

.primary, .ghost {
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary { background: var(--copper); color: var(--ink); }
.primary:hover { filter: brightness(1.05); }

.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 14px 0 8px;
}

.roster li {
  display: flex;
  gap: 6px;
  align-items: center;
  background: #10241f;
  border-radius: 999px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
}

.cost {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.85rem;
}

.fine { margin: 0; color: var(--muted); font-size: 0.92rem; }

.match {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 0 12px 12px;
}

.match-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.arena-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}

.side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.where { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.side.right { align-items: flex-end; text-align: right; }
.side strong {
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
.dot.bottom { background: var(--bottom); }
.dot.top { background: var(--top); }
.side.right .dot { margin-right: 0; margin-left: 6px; }

.pips { display: inline-flex; gap: 4px; }
.pips i {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  border: 2px solid var(--gold);
  display: block;
}
.pips i.on { background: var(--gold); }

.clock-wrap { text-align: center; }
.clock {
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0;
}
.badge {
  display: inline-block;
  margin-top: 2px;
  background: var(--gold);
  color: var(--ink);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.scorebar,
.hint,
.arena-stage {
  width: min(100%, calc((100dvh - 390px) * 18 / 32));
}

.arena-stage {
  margin: 0;
  aspect-ratio: 18 / 32;
  position: relative;
  background: #0c1b17;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
}

#arena {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hint {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  color: var(--muted);
}
.hint.warn { color: var(--danger); }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.controls, .elixir-box, .hand-wrap, .feed, .tele {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.speeds { display: flex; gap: 6px; }
.speeds button, #pause, #exit {
  background: #10241f;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
}
.speeds button[aria-pressed="true"] {
  background: var(--gold);
  color: var(--ink);
  border-color: var(--gold);
}

.elixir-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.elixir-row:first-child { margin-top: 0; }
.elixir-row span { font-size: 0.92rem; }
.bar {
  height: 12px;
  background: #0c1b17;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #b7791f, var(--gold));
}
.val { font-variant-numeric: tabular-nums; min-width: 2.4rem; text-align: right; }

.hand {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.card-btn {
  background: #10241f;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 6px 4px 8px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.card-btn svg { width: 36px; height: 36px; }
.card-btn strong { font-size: 0.75rem; line-height: 1.15; text-align: center; }
.card-btn[aria-pressed="true"] {
  border-color: var(--gold);
  background: #24361c;
}
.card-btn.pricey { opacity: 0.55; }
.next-card { margin: 8px 0 0; color: var(--muted); font-size: 0.92rem; }

.feed h2, .tele h2, .sidebar h2 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}
.feed ol, .tap-list { margin: 0; padding-left: 18px; color: var(--muted); }
.feed li, .tap-list li { margin: 2px 0; }

.tele-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.tele h3 { margin: 0; font-size: 1rem; }
.tag {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 800;
  background: #10241f;
  border: 1px solid var(--line);
}
.tag.muy { background: #3d2a1c; color: #ffd7a8; border-color: #a86b32; }
.tag.bastante { background: #2c331c; color: var(--gold); }
.tag.irregular { background: #1c3330; color: var(--ok); }
.blurb { margin: 4px 0 8px; color: var(--muted); font-size: 0.88rem; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin: 0;
}
.stats div { min-width: 0; }
.stats dt { color: var(--muted); font-size: 0.78rem; }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

.cards-line { margin: 8px 0; font-size: 0.88rem; }

.tapmap {
  width: 100%;
  height: 92px;
  border-radius: 8px;
  display: block;
  background: #1d3830;
}

.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.latency {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.02rem;
}
.latency span { color: var(--muted); font-weight: 650; font-size: 0.82rem; }
code { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 0.88em; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 5;
}

.dialog {
  width: min(560px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  background: #1b312a;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
}

.dialog h2 { margin: 0 0 6px; font-size: 1.8rem; }
.dialog .line { margin: 0 0 12px; color: var(--muted); line-height: 1.4; }
.score-end {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: #10241f;
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.end-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.end-recap { display: grid; gap: 8px; }
.end-recap article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.end-recap h3 { margin: 0 0 4px; font-size: 1rem; }
.end-recap p { margin: 0; color: var(--muted); }

@media (min-width: 980px) {
  .match-layout {
    flex-direction: row;
    align-items: stretch;
  }
  .arena-col {
    flex: 1.1;
    justify-content: center;
  }
  #app {
    height: 100dvh;
    overflow: hidden;
  }
  .scorebar,
  .hint,
  .arena-stage {
    width: min(100%, calc((100dvh - 250px) * 18 / 32));
    max-height: calc(100dvh - 250px);
  }
  .arena-stage {
    height: min(calc(100dvh - 250px), calc(100% - 8px));
    width: auto;
    aspect-ratio: 18 / 32;
  }
  .sidebar {
    width: 390px;
    overflow: auto;
    padding-right: 2px;
  }
}

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .top-note { text-align: left; }
  .modes { grid-template-columns: 1fr; }
  .elixir-row { grid-template-columns: 76px 1fr auto; }
}
