:root {
  --bg: #14181f;
  --bg-raise: #1c222c;
  --ink: #f4efe6;
  --muted: #a7b0be;
  --line: rgba(244, 239, 230, 0.12);
  --board: #8b919b;
  --board-deep: #636973;
  --hole: #10141b;
  --p1: #f5c451;
  --p1-deep: #c8921a;
  --p2: #ef5d4a;
  --p2-deep: #b43328;
  --win: #fff7d6;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --cell: clamp(42px, 8vw, 68px);
  --gap: 8px;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -10%, #243044 0%, transparent 55%),
    var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

button, .column {
  font: inherit;
  color: inherit;
}

.app {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(28px, calc(12px + env(safe-area-inset-top))) 0 max(48px, calc(16px + env(safe-area-inset-bottom)));
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.match-line {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.game-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-btn, .btn {
  border-radius: 999px;
  cursor: pointer;
}

.ghost-btn, .btn.btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 8px 14px;
}

.btn {
  border: 0;
  padding: 12px 18px;
  font-weight: 650;
}

.btn.gold {
  background: var(--p1);
  color: #1a140c;
}

.btn.primary {
  background: var(--ink);
  color: #1a140c;
}

.sound-toggle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--ink);
  cursor: pointer;
}

.sound-toggle.is-muted { color: var(--muted); }

.eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.status {
  margin: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  margin-bottom: 18px;
}

.segment {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
}

.seg, .text-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.seg {
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--muted);
}

.seg.is-active {
  background: var(--ink);
  color: #1a140c;
  font-weight: 650;
}

.text-btn {
  padding: 8px 4px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-btn:hover, .seg:hover { color: var(--ink); }
.seg.is-active:hover { color: #1a140c; }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.score {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
}

.score strong {
  margin-left: auto;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.score-draw {
  min-width: 92px;
  flex-direction: column;
  justify-content: center;
  gap: 0;
  text-align: center;
}

.score-draw strong { margin-left: 0; }

.score-name { color: var(--muted); font-size: 14px; }

.score.is-turn {
  border-color: rgba(245, 196, 81, 0.7);
}

.score-p2.is-turn {
  border-color: rgba(239, 93, 74, 0.75);
}

.token {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex: none;
}

.token-p1 {
  background: radial-gradient(circle at 35% 35%, #ffe7a3, var(--p1) 42%, var(--p1-deep));
}

.token-p2 {
  background: radial-gradient(circle at 35% 35%, #ffb2a8, var(--p2) 45%, var(--p2-deep));
}

.table {
  display: flex;
  justify-content: center;
}

.rack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.clear-layer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  pointer-events: none;
  overflow: visible;
}

.board-frame {
  padding: 14px 14px 28px;
  border-radius: 28px;
  background: linear-gradient(180deg, #a4aab3, var(--board) 18%, var(--board-deep));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.previews, .board {
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  gap: var(--gap);
}

.previews {
  height: calc(var(--cell) * 0.72);
  margin-bottom: 8px;
  padding: 0 14px;
  align-items: end;
}

.preview, .cell {
  width: var(--cell);
  height: var(--cell);
}

.preview {
  height: calc(var(--cell) * 0.72);
  display: grid;
  place-items: center;
}

.ghost {
  width: calc(var(--cell) - 10px);
  height: calc(var(--cell) - 10px);
  border-radius: 50%;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.column:hover .ghost, .column:focus-visible .ghost, .preview.is-show .ghost {
  opacity: 0.9;
  transform: none;
}

.board {
  position: relative;
}

.column {
  display: grid;
  gap: var(--gap);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
}

.column:focus-visible {
  outline: 2px solid var(--win);
  outline-offset: 4px;
}

.column:disabled { cursor: default; }

.cell {
  border-radius: 50%;
  background: var(--hole);
  box-shadow:
    inset 0 8px 12px rgba(0, 0, 0, 0.45),
    inset 0 -2px 0 rgba(255, 255, 255, 0.05);
  display: grid;
  place-items: center;
  position: relative;
  overflow: visible;
}

.disc {
  width: calc(var(--cell) - 10px);
  height: calc(var(--cell) - 10px);
  border-radius: 50%;
  animation: drop 0.34s cubic-bezier(0.2, 0.75, 0.2, 1) both;
  position: relative;
  z-index: 1;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
}

@keyframes fall-out {
  to { transform: translateY(var(--fall-distance)); }
}

.disc.is-win {
  z-index: 3;
  animation: pop 0.45s ease both;
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 6px rgba(16, 20, 27, 0.45),
    0 0 16px rgba(255, 255, 255, 0.95);
}

.disc.is-falling {
  position: absolute;
  z-index: 7;
  margin: 0;
  animation: fall-out 1.25s cubic-bezier(0.45, 0.05, 0.9, 0.45) forwards;
}

.board.has-winner .disc:not(.is-win) { opacity: 0.45; }

.hint {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

@keyframes drop {
  from { transform: translateY(calc(-1 * var(--drop))); }
  to { transform: translateY(0); }
}

@keyframes pop {
  0% { transform: scale(0.92); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@media (max-width: 640px) {
  .top { align-items: flex-start; flex-direction: column; }
  .status { white-space: normal; }
  .score-draw { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .disc, .ghost { animation: none; transition: none; }
  .streamer { animation: none; display: none; }
  .celebration-message { animation: none; }
}

[hidden] { display: none !important; }

.lobby-overlay {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    max(20px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.lobby-card {
  width: min(100%, 420px);
  padding: 28px 24px 22px;
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bg-raise);
  box-shadow: var(--shadow);
}

.lobby-card section {
  display: grid;
  gap: 14px;
}

.lobby-brand {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
}

.lobby-mark {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: url("icon-192.png?v=1") center / cover no-repeat;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.lobby-title {
  margin: 0;
  font-size: clamp(36px, 8vw, 48px);
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.byline {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--p1);
}

.lobby-copy, .lobby-hint, .lobby-share-status, .lobby-prose p, .lobby-label {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.lobby-prose { display: grid; gap: 12px; }
.lobby-prose a { color: var(--p1); }

.lobby-section, .lobby-actions { display: grid; gap: 12px; }

.lobby-nav {
  display: flex;
  justify-content: flex-start;
}

.lobby-button { width: 100%; }

.lobby-button-primary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
}

.lobby-button-hint {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.75;
}

.lobby-footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.lobby-text-link {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.lobby-input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 16px;
  outline: none;
}

.lobby-input:focus { border-color: var(--p1); }

.lobby-code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  text-align: center;
}

.lobby-error {
  margin: 0;
  color: #ffb2a8;
}

.lobby-code-mark {
  margin: 0;
  text-align: center;
  font-size: 40px;
  font-weight: 750;
  letter-spacing: 0.18em;
  padding-left: 0.18em;
}

.lobby-seats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.lobby-seats li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.lobby-seats small { color: var(--muted); }

.lobby-seats .is-empty { opacity: 0.65; }

.seat-token {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  vertical-align: -2px;
}

.btn:disabled, .lobby-choice button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.lobby-choice {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.lobby-choice button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.lobby-choice button.is-selected {
  background: var(--ink);
  color: #1a140c;
}

.color-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.swatch.swatch-light {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.swatch.is-selected {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.swatch:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.lobby-option {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  overflow: hidden;
}

.streamers { position: absolute; inset: 0; }

.streamer {
  position: absolute;
  top: -20vh;
  border-radius: 3px;
  opacity: 0.92;
  transform-origin: center top;
  animation-name: streamer-fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.18);
}

.celebration-message {
  position: absolute;
  left: 50%;
  top: 46%;
  width: max-content;
  max-width: calc(100vw - 2rem);
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 12px 22px;
  border-radius: 999px;
  background: rgba(18, 20, 26, 0.9);
  border: 1px solid rgba(245, 196, 81, 0.8);
  font-size: clamp(36px, 6vw, 64px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  text-align: center;
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
  animation: message-in 480ms ease both;
}

@keyframes streamer-fall {
  0% { transform: translate3d(0, -25vh, 0) rotate(var(--spin-start)); }
  100% { transform: translate3d(var(--drift), 125vh, 0) rotate(var(--spin-end)); }
}

@keyframes message-in {
  from { opacity: 0; transform: translate(-50%, -40%); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 10, 14, 0.72);
}

.confirm-dialog {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
  padding: 22px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg-raise);
}

.confirm-dialog h2 { margin: 0; font-size: 24px; }
.confirm-dialog p { margin: 0; color: var(--muted); }

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 640px) {
  .game-actions { width: 100%; }
}
