:root {
  --bg: #111827;
  --panel: #172338;
  --panel-2: #202f49;
  --line: #30415d;
  --text: #f8fafc;
  --muted: #b7c5d8;
  --blue: #38bdf8;
  --mint: #5eead4;
  --red: #f05261;
  --yellow: #ffd85a;
  --hole: #0d1728;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.36);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 4%, rgba(94, 234, 212, 0.18), transparent 18rem),
    radial-gradient(circle at 92% 12%, rgba(56, 189, 248, 0.16), transparent 20rem),
    var(--bg);
  color: var(--text);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(620px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.topbar,
.status-card,
.footer-actions,
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--mint);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 9vw, 3.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 1.35rem;
  font-weight: 900;
}

.status-card {
  justify-content: space-between;
  min-height: 84px;
  padding: 14px;
  border: 1px solid rgba(94, 234, 212, 0.2);
  border-radius: 18px;
  background: rgba(23, 35, 56, 0.86);
  box-shadow: var(--shadow);
}

.status-label,
.status-text {
  margin: 0;
}

.status-label {
  font-size: 0.78rem;
  color: var(--mint);
  font-weight: 900;
  text-transform: uppercase;
}

.status-text {
  max-width: 35ch;
  color: var(--muted);
  line-height: 1.32;
}

.turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 94px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  font-weight: 900;
  white-space: nowrap;
}

.disc {
  display: inline-block;
  width: 24px;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 5px 5px 8px rgba(255, 255, 255, 0.28), inset -5px -8px 10px rgba(0, 0, 0, 0.28);
}

.disc.red,
.cell.red::after {
  background: var(--red);
}

.disc.yellow,
.cell.yellow::after {
  background: var(--yellow);
}

.disc.draw {
  background: linear-gradient(135deg, var(--red) 0 50%, var(--yellow) 50% 100%);
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  margin: 12px 0;
}

.difficulty-controls {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  margin-top: -4px;
}

.segmented,
.primary,
.secondary,
.column-buttons button {
  min-height: 44px;
  border-radius: 14px;
  font-weight: 900;
}

.segmented {
  border: 1px solid var(--line);
  background: rgba(32, 47, 73, 0.72);
  color: var(--muted);
}

.segmented.active {
  background: var(--mint);
  color: #0f172a;
}

.board-wrap {
  padding: 12px;
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 24px;
  background: rgba(13, 23, 40, 0.74);
  box-shadow: var(--shadow);
}

.column-buttons {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.column-buttons button {
  background: var(--panel-2);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
}

.column-buttons button:disabled {
  opacity: 0.38;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(5px, 1.6vw, 9px);
  padding: clamp(10px, 2.2vw, 16px);
  border: 3px solid #1d6cc6;
  border-radius: 22px;
  background: linear-gradient(160deg, #1f8ce6, #1759af);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--hole);
  box-shadow:
    inset 0 0 0 3px rgba(226, 241, 255, 0.84),
    inset 0 8px 14px rgba(0, 0, 0, 0.42);
}

.cell::after {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  transform: scale(0);
  transition: transform 150ms ease-out;
}

.cell.preview::after {
  background: rgba(248, 250, 252, 0.28);
  transform: scale(0.62);
}

.cell.red::after,
.cell.yellow::after {
  transform: scale(1);
}

.cell.last-drop::after {
  animation: tokenDrop 560ms cubic-bezier(0.2, 0.85, 0.24, 1.1);
}

.column-buttons button.preview {
  background: var(--mint);
  color: #0f172a;
}

.cell.win {
  box-shadow:
    0 0 0 4px var(--mint),
    inset 0 0 0 3px rgba(226, 241, 255, 0.9),
    inset 0 8px 14px rgba(0, 0, 0, 0.42);
}

.cell.win::after {
  filter: brightness(1.18) saturate(1.12);
}

.app-shell.is-win .status-card {
  border-color: rgba(94, 234, 212, 0.68);
  background: rgba(22, 78, 99, 0.78);
}

.app-shell.is-win .board {
  border-color: var(--mint);
}

.app-shell.is-win .turn-pill {
  background: rgba(94, 234, 212, 0.22);
  box-shadow: inset 0 0 0 1px rgba(94, 234, 212, 0.35);
}

.app-shell.is-draw .status-card {
  border-color: rgba(255, 216, 90, 0.55);
  background: rgba(48, 65, 93, 0.94);
}

.app-shell.is-draw .board {
  border-color: var(--yellow);
}

.app-shell.is-reconnecting .status-card {
  border-color: rgba(255, 216, 90, 0.45);
}

.footer-actions {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  margin-top: 12px;
}

.primary {
  background: var(--yellow);
  color: #111827;
}

.secondary {
  border: 1px solid var(--line);
  background: var(--panel);
}

.mini-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.mini-note p {
  margin: 0;
}

.leaderboard {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(13, 23, 40, 0.62);
  color: var(--muted);
  font: 800 0.82rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.segmented:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@media (max-width: 380px) {
  .status-card {
    align-items: flex-start;
    flex-direction: column;
  }
}

@keyframes tokenDrop {
  0% {
    transform: translateY(-82%) scale(0.72);
    filter: brightness(1.3);
  }

  72% {
    transform: translateY(3%) scale(1.04);
  }

  100% {
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}
