/* DOWNPOUR — colour and mood.
   Late-night ink, one violet light source, a little aqua for the good news. */

:root {
  --ink:        #06080f;
  --ink-2:      #0a0e18;
  --surface:    rgba(255, 255, 255, 0.045);
  --surface-2:  rgba(255, 255, 255, 0.075);
  --line:       rgba(255, 255, 255, 0.09);
  --line-soft:  rgba(255, 255, 255, 0.05);
  --text:       #e9edf8;
  --muted:      #8c94ab;
  --dim:        #5d6479;

  --violet:     #7c6bff;
  --violet-dim: rgba(124, 107, 255, 0.16);
  --aqua:       #34d2c2;
  --rose:       #ff7a93;
  --amber:      #ffc46b;

  --radius:     18px;
  --radius-sm:  12px;

  --font-display: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#rain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.5;
}

.glow {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(48% 42% at 22% 12%, rgba(124, 107, 255, 0.20), transparent 70%),
    radial-gradient(40% 40% at 82% 78%, rgba(52, 210, 194, 0.12), transparent 70%),
    radial-gradient(60% 50% at 50% 110%, rgba(255, 122, 147, 0.08), transparent 70%);
  filter: blur(20px);
}

.screen {
  position: relative;
  z-index: 1;
  display: none;
  height: 100%;
  overflow: auto;
}
.screen.is-active { display: block; }

/* ─────────────── shared bits ─────────────── */

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.022));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.btn {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 14px 22px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.14s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, #8b7bff, #6a56f0);
  box-shadow: 0 10px 30px -12px rgba(124, 107, 255, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  color: #fff;
}
.btn-primary:hover { box-shadow: 0 16px 40px -14px rgba(124, 107, 255, 1); }

.btn-ghost {
  border-color: var(--line);
  background: var(--surface);
}
.btn-ghost:hover { background: var(--surface-2); border-color: rgba(255, 255, 255, 0.18); }

.btn-block { width: 100%; }
.btn-note {
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.6);
  text-transform: lowercase;
}

.linkish {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.18s ease;
}
.linkish:hover { color: var(--text); }

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.05);
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}

.error {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--rose);
  text-align: center;
}

/* ─────────────── landing ─────────────── */

.landing {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: clamp(32px, 8vh, 92px) 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.landing-head { text-align: center; }

.mark {
  display: flex;
  gap: 5px;
  justify-content: center;
  margin-bottom: 22px;
}
.mark span {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  animation: markfall 2.6s ease-in-out infinite;
}
.mark span:nth-child(1) { background: var(--violet); }
.mark span:nth-child(2) { background: var(--aqua); animation-delay: 0.18s; }
.mark span:nth-child(3) { background: var(--rose); animation-delay: 0.36s; }

@keyframes markfall {
  0%, 100% { transform: translateY(-4px); opacity: 0.55; }
  50%      { transform: translateY(4px);  opacity: 1; }
}

.wordmark {
  margin: 0;
  font-size: clamp(46px, 11vw, 78px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.95;
  background: linear-gradient(170deg, #ffffff 20%, #a9a3e8 60%, #6f6ab0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 14px 0 0;
  font-size: 17px;
  color: var(--text);
  opacity: 0.85;
}

.blurb {
  margin: 18px auto 0;
  max-width: 44ch;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--muted);
}

.join-panel { padding: 24px; }

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

input[type="text"] {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
input[type="text"]:focus {
  border-color: rgba(124, 107, 255, 0.7);
  box-shadow: 0 0 0 4px var(--violet-dim);
}
input::placeholder { color: var(--dim); }

.rule {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0;
  color: var(--dim);
  font-size: 12px;
}
.rule::before, .rule::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

.join-row { display: flex; gap: 10px; }
.join-row .btn { flex: 0 0 auto; padding-inline: 26px; }

.code-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.42em;
  text-align: center;
  text-transform: uppercase;
}

.landing-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  margin-top: auto;
  padding-top: 12px;
}

.keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--dim);
}
.keys li { display: flex; align-items: center; gap: 5px; }

/* ─────────────── room chrome ─────────────── */

#screen-room { display: none; }
#screen-room.is-active { display: flex; flex-direction: column; }

.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 16px clamp(14px, 3vw, 32px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar > :last-child { justify-self: end; }

.topbar-mid {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-brand {
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 13px;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: default;
}
button.chip { cursor: pointer; transition: background 0.18s ease, color 0.18s ease; }
button.chip:hover { background: var(--surface-2); color: var(--text); }

.chip-key {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}
.chip-code strong {
  font-family: var(--font-mono);
  font-size: 17px;
  letter-spacing: 0.28em;
  color: var(--text);
}
.chip-hint { font-size: 11px; color: var(--dim); }
.chip-code.copied .chip-hint { color: var(--aqua); }

/* ─────────────── stage ─────────────── */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 200px minmax(0, auto) 300px;
  gap: clamp(14px, 2vw, 26px);
  justify-content: center;
  align-items: start;
  padding: clamp(14px, 2.4vh, 26px) clamp(14px, 3vw, 32px) 24px;
  overflow: auto;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.tile { padding: 14px 16px; }

.tile-title {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

/* The canvases keep their own aspect ratio, so cap the width or the
   next-queue column grows taller than the board it sits beside. */
.mini-canvas { display: block; width: 100%; height: auto; margin: 0 auto; }
#canvas-hold { max-width: 104px; }
#canvas-next { max-width: 88px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat span {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}
.stat strong {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  color: var(--text);
}

.legend dl { margin: 0; display: grid; gap: 7px; }
.legend div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.legend dt { display: flex; gap: 3px; }
.legend dd { margin: 0; font-size: 12px; color: var(--muted); }

/* ─────────────── board ─────────────── */

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.board-frame {
  position: relative;
  height: min(76vh, 680px);
  aspect-ratio: 1 / 2;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
    rgba(0, 0, 0, 0.5);
  box-shadow: 0 40px 90px -50px rgba(0, 0, 0, 1), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

#canvas-board { display: block; width: 100%; height: 100%; }

.gauge {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 5px;
  height: 100%;
  background: rgba(255, 255, 255, 0.04);
}
#gauge-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(180deg, var(--rose), #ff4d6d);
  box-shadow: 0 0 18px rgba(255, 77, 109, 0.8);
  transition: height 0.18s ease;
}

.flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(70% 50% at 50% 60%, rgba(255, 122, 147, 0.5), transparent 70%);
}
.flash.hit { animation: hitflash 0.45s ease-out; }
@keyframes hitflash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

.ticker {
  margin: 0;
  min-height: 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  text-align: center;
}

/* ─────────────── overlay ─────────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: linear-gradient(180deg, rgba(6, 8, 15, 0.86), rgba(6, 8, 15, 0.95));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
}
.overlay.is-open { display: flex; }
.overlay-body { width: 100%; max-width: 320px; }

.overlay h2 {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.overlay p {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}
.overlay .btn { width: 100%; margin-top: 8px; }

.big-code {
  display: block;
  margin: 6px 0 16px;
  font-family: var(--font-mono);
  font-size: 42px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: #fff;
  text-shadow: 0 0 40px rgba(124, 107, 255, 0.7);
}

.countdown {
  font-family: var(--font-mono);
  font-size: 92px;
  font-weight: 600;
  line-height: 1;
  color: #fff;
  animation: pop 0.5s ease-out;
}
@keyframes pop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}

.roster { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.roster li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.035);
  font-size: 13.5px;
}
.roster .tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}
.roster .tag.on { color: var(--aqua); }
.roster .place {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.roster li.win {
  border-color: rgba(52, 210, 194, 0.45);
  background: rgba(52, 210, 194, 0.09);
}
.roster li.me strong::after {
  content: ' (you)';
  color: var(--dim);
  font-weight: 400;
}

/* ─────────────── opponents ─────────────── */

.opponents { flex: 1 1 auto; min-height: 0; }

.opponent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
}

.empty-note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--dim);
}

.opponent {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: rgba(0, 0, 0, 0.3);
  transition: border-color 0.2s ease, opacity 0.2s ease;
}
.opponent.dead { opacity: 0.42; }
.opponent.target { border-color: rgba(255, 122, 147, 0.65); }

.opponent canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
}

.opponent-name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
}
.opponent-name strong {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opponent-name span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--dim);
}

/* ─────────────── narrow desktop / tablet ─────────────── */

@media (max-width: 1180px) {
  .stage { grid-template-columns: 170px minmax(0, auto) 240px; }
}

@media (max-width: 940px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
  }
  .rail {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    max-width: 460px;
  }
  .rail .tile { flex: 1 1 180px; }
  .board-frame { height: min(62vh, 560px); }
  .legend { display: none; }
}
