:root {
  --ink: #16161d;
  --paper: #fffdf7;
  --p0: #2346d8;
  --p1: #d62839;
  --muted: rgba(22, 22, 29, 0.6);
  --glass: rgba(255, 253, 247, 0.82);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e9e3d5;
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#arena {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#ui {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: safe center;
  padding: 16px;
  overflow-y: auto;
  pointer-events: none;
}

.screen {
  display: none;
  pointer-events: auto;
  animation: rise 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.screen.on { display: block; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2.5px solid var(--ink);
  border-radius: 22px;
  box-shadow: 6px 6px 0 var(--ink);
  padding: 32px;
  max-width: min(560px, 100%);
}
.center { text-align: center; }

.logo {
  margin: 0;
  font-size: clamp(64px, 14vw, 120px);
  line-height: 0.85;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--p0);
}
.logo span { display: block; color: var(--p1); margin-left: 0.6em; }

h2 { margin: 6px 0 8px; font-size: clamp(30px, 6vw, 46px); letter-spacing: -0.03em; line-height: 1; }
.lede { color: var(--muted); font-size: 17px; margin: 10px 0 22px; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.fine { font-size: 13px; color: var(--muted); margin: 16px 0 0; }

.names { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 22px; }
.names label { font-size: 13px; font-weight: 700; display: grid; gap: 6px; }
.names .p0 { color: var(--p0); }
.names .p1 { color: var(--p1); }

input {
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
  min-width: 0;
}
input:focus { outline: 3px solid rgba(35, 70, 216, 0.25); }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  background: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(22, 22, 29, 0.35);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 rgba(22, 22, 29, 0.35); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 transparent; }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.btn.big { font-size: 20px; padding: 15px 28px; }
.btn.ghost { background: var(--paper); color: var(--ink); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.chip {
  font-weight: 700;
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* draw screen */
#s-draw.on { display: block; width: min(980px, 100%); }
.draw-wrap { display: flex; gap: 16px; align-items: flex-start; justify-content: center; }
.draw-main { padding: 16px; max-width: 640px; width: 100%; }
.draw-head, .draw-foot { display: flex; align-items: center; gap: 12px; }
.draw-head { margin-bottom: 12px; }
.draw-foot { margin-top: 12px; }
#board {
  width: 100%;
  aspect-ratio: 520 / 400;
  display: block;
  border: 2px solid var(--ink);
  border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
  background: var(--paper);
}
.meter {
  flex: 1;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
  background: rgba(22, 22, 29, 0.06);
}
.meter span {
  position: absolute; right: 8px; top: -2px;
  font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em;
}
#ink-fill { height: 100%; width: 100%; transition: width 0.1s; }
.timer {
  font-size: 26px;
  font-weight: 700;
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.timer.hurry { color: var(--p1); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

.opp { display: none; padding: 14px; text-align: center; max-width: 290px; }
.opp.on { display: block; }
.opp canvas { width: 100%; height: auto; }
.cname { font-family: "Caveat", cursive; font-size: 32px; margin: 0; line-height: 1; }

/* wake */
.dots { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
.dots i {
  width: 16px; height: 16px; border-radius: 50%; background: var(--p0);
  animation: bob 0.7s infinite alternate ease-in-out;
}
.dots i:nth-child(2) { background: var(--ink); animation-delay: 0.15s; }
.dots i:nth-child(3) { background: var(--p1); animation-delay: 0.3s; }
@keyframes bob { to { transform: translateY(-14px); } }

/* reveal */
#s-reveal.on { display: flex; flex-direction: column; align-items: center; gap: 20px; width: min(1000px, 100%); }
.reveal { display: flex; align-items: center; gap: 18px; width: 100%; justify-content: center; }
.fcard {
  flex: 1;
  max-width: 440px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2.5px solid var(--ink);
  border-radius: 22px;
  box-shadow: 6px 6px 0 var(--ink);
  padding: 12px 12px 16px;
  animation: rise 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
.fcard.p1 { animation-delay: 0.12s; }
.fcard canvas { width: 100%; height: auto; max-height: 30vh; object-fit: contain; display: block; }
.meta { padding: 0 8px; }
.meta .cname { font-size: 38px; }
.fcard.p0 .cname { color: var(--p0); }
.fcard.p1 .cname { color: var(--p1); }
.meta .tag { margin: 4px 0 10px; color: var(--muted); font-size: 15px; min-height: 1.2em; }
.stats { display: flex; flex-wrap: wrap; gap: 6px; }
.stats span {
  font-size: 13px; font-weight: 700;
  border: 2px solid var(--ink); border-radius: 99px; padding: 3px 10px; background: var(--paper);
}
.stats .hp { background: var(--ink); color: #fff; }
.stats.moves { margin-bottom: 6px; }
.stats.moves span { font-size: 14px; background: var(--ink); color: #fff; }
.fcard.p0 .stats.moves span { background: var(--p0); border-color: var(--p0); }
.fcard.p1 .stats.moves span { background: var(--p1); border-color: var(--p1); }
.identity { margin: 2px 0 0; font-weight: 700; font-size: 15px; }
.vs { font-size: 44px; font-weight: 700; letter-spacing: -0.04em; }
.src { font-size: 12px; color: var(--muted); margin-top: 8px; }

.score { font-size: 54px; font-weight: 700; margin: 6px 0; letter-spacing: -0.03em; }
.score b:first-child { color: var(--p0); }
.score b:last-child { color: var(--p1); }
#final-cv { width: min(420px, 100%); height: auto; }

/* title + online */
.modes { display: grid; gap: 12px; }
.modes .btn { width: 100%; }
.btn.wide { width: 100%; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 700; margin: 6px 0 16px; }
.or { text-align: center; color: var(--muted); font-size: 14px; margin: 16px 0 10px; }
.join { display: flex; gap: 10px; }
.join input { text-transform: uppercase; letter-spacing: 0.25em; text-align: center; font-size: 24px; }
.error { color: var(--p1); font-weight: 700; min-height: 1.3em; margin: 12px 0; }
.code { font-size: clamp(56px, 14vw, 88px); font-weight: 700; letter-spacing: 0.12em; margin: 0 0 8px; line-height: 1; }
.share { display: flex; gap: 8px; margin-bottom: 18px; }
.share input { font-size: 14px; font-weight: 500; }
.players { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.players li { border: 2px solid var(--ink); border-radius: 12px; padding: 10px 14px; font-weight: 700; display: flex; justify-content: space-between; background: var(--paper); }
.players li.p0 { color: var(--p0); }
.players li.p1 { color: var(--p1); }
.players li.empty { color: var(--muted); border-style: dashed; font-weight: 500; }
.players small { color: var(--muted); font-weight: 500; }

.btn.private { margin-top: 10px; }
.rooms { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.rooms li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 2px solid var(--ink); border-radius: 12px; padding: 8px 8px 8px 14px; background: var(--paper);
}
.rooms li span { font-weight: 700; }
.rooms li small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.rooms li .btn { padding: 8px 14px; font-size: 14px; }
.board { list-style: none; padding: 0; margin: 8px 0 12px; display: grid; gap: 4px; max-height: 52vh; overflow-y: auto; }
.board li {
  display: grid; grid-template-columns: 2.4em 1fr auto auto; gap: 12px; align-items: center;
  padding: 8px 12px; border-radius: 10px; font-variant-numeric: tabular-nums;
}
.board li:nth-child(odd) { background: rgba(22, 22, 29, 0.05); }
.board li.me { outline: 2.5px solid var(--p0); background: rgba(35, 70, 216, 0.08); }
.board .rk { font-weight: 700; color: var(--muted); }
.board .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .rt { font-weight: 700; }
.board .wl { color: var(--muted); font-size: 13px; }
.board li.empty { display: block; text-align: center; color: var(--muted); }
.rating { font-weight: 700; font-size: 18px; margin: 0 0 14px; min-height: 1.2em; }
.rating .up { color: #1d8a4e; }
.rating .down { color: var(--p1); }

.mute {
  position: fixed; right: 14px; bottom: 14px;
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--paper);
  font-size: 18px; cursor: pointer; z-index: 5;
}
.mute.off { opacity: 0.4; text-decoration: line-through; }

@media (max-width: 760px) {
  .card { padding: 22px; }
  .draw-wrap { flex-direction: column-reverse; align-items: stretch; }
  .opp { max-width: none; display: none; }
  .opp.on { display: flex; align-items: center; gap: 10px; padding: 8px; }
  .opp canvas { width: 120px; }
  .reveal { flex-direction: column; gap: 8px; }
  .fcard { width: 100%; }
  .vs { font-size: 28px; }
  .draw-foot { flex-wrap: wrap; }
  .draw-foot input { flex: 1 1 100%; }
  .draw-foot .btn { flex: 1; }
  #ui { overflow-y: auto; align-items: start; }
}
