:root {
  color-scheme: dark;
  --bg: #07080d;
  --ink: #f7f7fb;
  --muted: #aeb7ca;
  --panel: rgba(16, 20, 34, 0.72);
  --panel-strong: rgba(20, 27, 46, 0.92);
  --glass: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.16);
  --shadow: rgba(0, 0, 0, 0.46);
  --red: #ff3f74;
  --red-dark: #9e1d4a;
  --gold: #ffd45a;
  --gold-dark: #b87811;
  --cyan: #34e4c8;
  --blue: #5f7cff;
  --green: #8ef06f;
  --danger: #ff6c53;
  --board: #18213b;
  --board-edge: #34457f;
  --slot: #080b15;
  --radius: 8px;
  --cell-gap: 10px;
  --cell-pad: 14px;
  --board-max: 710px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(95, 124, 255, 0.18), transparent 32%),
    linear-gradient(225deg, rgba(52, 228, 200, 0.12), transparent 35%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 54px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.028) 0 1px, transparent 1px 54px),
    #07080d;
}

button {
  font: inherit;
}

.ambient-canvas,
.effects-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: screen;
}

.ambient-canvas {
  opacity: 0.58;
}

.effects-canvas {
  z-index: 2;
  opacity: 1;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand-stack {
  min-width: 0;
}

.eyebrow,
.round-card span,
.match-footer {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 3.6rem;
  line-height: 0.9;
  letter-spacing: 0;
  color: transparent;
  background: linear-gradient(90deg, #ffffff, #ffd45a 34%, #34e4c8 68%, #ff3f74);
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: 0 18px 70px rgba(95, 124, 255, 0.22);
}

.control-cluster,
.match-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.setup-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.segmented-control {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(18px);
}

.difficulty-control[hidden] {
  display: none;
}

.segment {
  min-height: 36px;
  min-width: 88px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.segment:hover,
.segment:focus-visible {
  color: var(--ink);
  outline: none;
}

.segment.active {
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.08)),
    rgba(52, 228, 200, 0.12);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
}

.text-button,
.icon-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.06)),
    rgba(255, 255, 255, 0.08);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.text-button {
  min-height: 44px;
  padding: 0 16px;
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 900;
}

.text-button:hover,
.icon-button:hover,
.text-button:focus-visible,
.icon-button:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(52, 228, 200, 0.72);
  outline: none;
}

.text-button:active,
.icon-button:active {
  transform: translateY(0) scale(0.98);
}

.text-button.ghost {
  background: rgba(255, 255, 255, 0.06);
}

.text-button:disabled,
.icon-button:disabled {
  cursor: default;
  opacity: 0.45;
  transform: none;
}

.score-strip {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 12px;
}

.player-card,
.round-card {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.045)),
    var(--panel);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
}

.player-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.player-card::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 200ms ease;
}

.player-card.active::before {
  opacity: 1;
}

.player-one::before {
  background: linear-gradient(90deg, rgba(255, 63, 116, 0.26), transparent 70%);
}

.player-two::before {
  background: linear-gradient(90deg, rgba(255, 212, 90, 0.26), transparent 70%);
}

.player-card > * {
  position: relative;
}

.score-token {
  width: 48px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow:
    inset -8px -10px 18px rgba(0, 0, 0, 0.22),
    inset 7px 8px 16px rgba(255, 255, 255, 0.32),
    0 12px 28px rgba(0, 0, 0, 0.32);
}

.player-one .score-token {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.95) 0 7%, transparent 8%),
    linear-gradient(145deg, #ff8faf, var(--red) 48%, var(--red-dark));
}

.player-two .score-token {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.95) 0 7%, transparent 8%),
    linear-gradient(145deg, #fff0a4, var(--gold) 48%, var(--gold-dark));
}

.player-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-copy span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.player-copy strong {
  font-size: 2rem;
  line-height: 1;
}

.round-card {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
}

.round-card strong {
  max-width: 100%;
  font-size: 1.15rem;
  line-height: 1.18;
}

.play-stage {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}

.board-zone {
  width: min(var(--board-max), calc(100vw - 32px));
  display: grid;
  gap: 10px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--cell-gap);
  padding: 0 var(--cell-pad);
  min-height: 42px;
}

.preview-slot {
  display: grid;
  place-items: center;
}

.preview-disc {
  width: 58%;
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: 0;
  transform: translateY(8px) scale(0.84);
  transition: opacity 140ms ease, transform 140ms ease;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.32));
}

.preview-slot.visible .preview-disc {
  opacity: 0.72;
  transform: translateY(0) scale(1);
}

.preview-disc.player-one {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.96) 0 7%, transparent 8%),
    linear-gradient(145deg, #ff8faf, var(--red) 46%, var(--red-dark));
}

.preview-disc.player-two {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.96) 0 7%, transparent 8%),
    linear-gradient(145deg, #fff0a4, var(--gold) 46%, var(--gold-dark));
}

.board-shell {
  position: relative;
  filter: drop-shadow(0 34px 58px rgba(0, 0, 0, 0.42));
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: var(--cell-gap);
  aspect-ratio: 7 / 6;
  padding: var(--cell-pad);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), transparent 30%),
    linear-gradient(315deg, rgba(52, 228, 200, 0.14), transparent 34%),
    linear-gradient(180deg, #243057, var(--board));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    inset 0 -18px 38px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(95, 124, 255, 0.18);
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(45deg, transparent 0 20px, rgba(255, 255, 255, 0.045) 20px 21px),
    linear-gradient(90deg, rgba(255, 63, 116, 0.14), transparent 32%, rgba(52, 228, 200, 0.14));
  pointer-events: none;
}

.slot {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 58%, var(--slot) 0 45%, rgba(18, 26, 49, 0.88) 46% 62%, rgba(255, 255, 255, 0.16) 63% 66%, rgba(7, 8, 13, 0.38) 67%),
    #11182b;
  box-shadow:
    inset 0 12px 18px rgba(0, 0, 0, 0.72),
    inset 0 -2px 2px rgba(255, 255, 255, 0.16);
  z-index: 1;
}

.slot.column-hover::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(52, 228, 200, 0.34);
  opacity: 0.7;
}

.disc {
  width: 82%;
  aspect-ratio: 1;
  border-radius: 50%;
  transform: scale(0);
  box-shadow:
    inset -10px -14px 20px rgba(0, 0, 0, 0.28),
    inset 8px 9px 16px rgba(255, 255, 255, 0.34),
    0 10px 22px rgba(0, 0, 0, 0.32);
}

.disc.player-one {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.96) 0 7%, transparent 8%),
    radial-gradient(circle at 68% 76%, rgba(255, 255, 255, 0.18), transparent 26%),
    linear-gradient(145deg, #ff8faf, var(--red) 46%, var(--red-dark));
}

.disc.player-two {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.96) 0 7%, transparent 8%),
    radial-gradient(circle at 68% 76%, rgba(255, 255, 255, 0.2), transparent 26%),
    linear-gradient(145deg, #fff0a4, var(--gold) 46%, var(--gold-dark));
}

.disc.placed {
  transform: scale(1);
}

.disc.fresh {
  animation: token-drop 420ms cubic-bezier(0.2, 0.86, 0.28, 1.18);
}

.slot.win .disc {
  animation: win-pulse 820ms ease-in-out infinite alternate;
}

.column-buttons {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  z-index: 3;
}

.column-button {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.column-button:focus-visible {
  outline: 3px solid rgba(52, 228, 200, 0.85);
  outline-offset: -7px;
}

.column-button:disabled {
  cursor: default;
}

.win-line {
  position: absolute;
  z-index: 4;
  height: 8px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, #ffffff, var(--cyan), var(--green));
  box-shadow:
    0 0 18px rgba(52, 228, 200, 0.82),
    0 0 34px rgba(142, 240, 111, 0.45);
  transform-origin: left center;
  transition: opacity 180ms ease;
}

.win-line.visible {
  opacity: 1;
}

.match-footer {
  min-height: 48px;
}

.match-footer span {
  min-width: 82px;
  color: var(--muted);
  text-align: right;
}

.toast[hidden] {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 12;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--ink);
  text-align: center;
  font-weight: 800;
  background: rgba(12, 16, 28, 0.92);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

@keyframes token-drop {
  0% {
    transform: translateY(-320%) scale(0.9);
  }
  68% {
    transform: translateY(8%) scale(1.03);
  }
  82% {
    transform: translateY(-5%) scale(0.99);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes win-pulse {
  from {
    filter: saturate(1) brightness(1);
  }
  to {
    filter: saturate(1.35) brightness(1.22);
  }
}

@media (min-width: 980px) {
  .app-shell {
    justify-content: center;
  }

  body[data-device="desktop"] .board-zone {
    width: min(720px, 64vh, calc(100vw - 48px));
  }
}

@media (max-width: 780px) {
  .app-shell {
    min-height: 100svh;
    padding: 14px;
    gap: 12px;
  }

  .game-header {
    align-items: flex-start;
  }

  h1 {
    font-size: 2.25rem;
    line-height: 0.95;
  }

  .control-cluster {
    gap: 8px;
  }

  .setup-strip {
    display: grid;
    grid-template-columns: 1fr;
  }

  .segmented-control {
    width: 100%;
  }

  .control-cluster .text-button {
    padding: 0 11px;
  }

  .score-strip {
    grid-template-columns: 1fr 1fr;
  }

  .round-card {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 72px;
    padding: 12px;
  }

  .player-card {
    min-height: 74px;
    padding: 12px;
  }

  .score-token {
    width: 40px;
  }

  .player-copy strong {
    font-size: 1.55rem;
  }

  .board-zone {
    width: min(100%, calc(100vw - 20px));
  }

  .preview-grid {
    min-height: 34px;
  }

  .board {
    border-radius: 16px;
  }

  .match-footer {
    justify-content: space-between;
  }
}

@media (max-width: 500px) {
  :root {
    --cell-gap: 6px;
    --cell-pad: 8px;
  }

  .game-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .control-cluster {
    justify-content: stretch;
    display: grid;
    grid-template-columns: 1fr 1fr 44px;
  }

  .text-button {
    min-height: 42px;
    padding: 0 12px;
  }

  .player-card {
    gap: 10px;
  }

  .player-copy span {
    font-size: 0.82rem;
  }

  .round-card strong {
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }

  .ambient-canvas,
  .effects-canvas {
    display: none;
  }
}
