/* ==========================================================================
   4 in a Row — Telegram Mini App
   Design language: deep "arcade cabinet" board on a Telegram-native surface.
   The board keeps its own dramatic palette in both themes; everything around
   it adapts to the host theme via --tg-theme-* variables.
   ========================================================================== */

:root {
  /* ---- Telegram theme bridge (with sane fallbacks) ---- */
  --bg: var(--tg-theme-bg-color, #0f1620);
  --surface: var(--tg-theme-secondary-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f7fa);
  --hint: var(--tg-theme-hint-color, #8a97a8);
  --link: var(--tg-theme-link-color, #62aaf2);
  --accent: var(--tg-theme-button-color, #4b8bf4);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, var(--surface));
  --separator: var(--tg-theme-section-separator-color, rgba(255, 255, 255, 0.08));

  /* ---- Board palette (theme-independent by design) ---- */
  --board-face: linear-gradient(180deg, #3d7ce8 0%, #2b5fc4 55%, #204aa0 100%);
  --board-edge: #16326e;
  --board-well: #0b1220;
  --board-well-soft: #101a2c;

  --p1: #ff4f63;
  --p1-deep: #c81437;
  --p1-glow: rgba(255, 79, 99, 0.55);
  --p2: #ffcf45;
  --p2-deep: #e2870a;
  --p2-glow: rgba(255, 207, 69, 0.5);

  --good: #34c759;
  --bad: #ff453a;

  /* ---- Geometry ---- */
  --cell: 48px;
  --radius-l: 22px;
  --radius-m: 16px;
  --radius-s: 12px;
  --gap: 12px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.28);
}

/* Light host theme: soften shadows, keep the board vivid. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --surface: var(--tg-theme-secondary-bg-color, #f1f4f8);
    --text: var(--tg-theme-text-color, #12181f);
    --hint: var(--tg-theme-hint-color, #7a8794);
    --separator: var(--tg-theme-section-separator-color, rgba(0, 0, 0, 0.08));
    --shadow-card: 0 8px 24px rgba(20, 30, 50, 0.12);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* Author-level `display` declarations outrank the UA rule for [hidden], so
   pin it down once — several elements are toggled via the hidden attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ==========================================================================
   Shell & screens
   ========================================================================== */

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

/* Ambient glow behind everything — gives the flat theme background depth. */
.app::before {
  content: "";
  position: absolute;
  inset: -30% -20% auto -20%;
  height: 70%;
  background:
    radial-gradient(45% 55% at 22% 18%, var(--p1-glow), transparent 70%),
    radial-gradient(45% 55% at 80% 8%, var(--p2-glow), transparent 70%);
  opacity: 0.18;
  filter: blur(20px);
  pointer-events: none;
  z-index: 0;
}

.fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 12px);
  overflow: hidden;
}

.app[data-screen="boot"] .screen--boot,
.app[data-screen="menu"] .screen--menu,
.app[data-screen="lobby"] .screen--lobby,
.app[data-screen="game"] .screen--game,
.app[data-screen="error"] .screen--error {
  display: flex;
  animation: screenIn 0.3s var(--ease-out) both;
}

@keyframes screenIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ==========================================================================
   Boot
   ========================================================================== */

.screen--boot {
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.boot__logo {
  display: flex;
  gap: 10px;
}

.boot__logo .chip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  animation: bootBounce 1.1s var(--ease-out) infinite;
}

.chip--a {
  background: linear-gradient(160deg, var(--p1), var(--p1-deep));
  box-shadow: 0 4px 10px var(--p1-glow);
}
.chip--b {
  background: linear-gradient(160deg, var(--p2), var(--p2-deep));
  box-shadow: 0 4px 10px var(--p2-glow);
}

.boot__logo .chip:nth-child(2) {
  animation-delay: 0.12s;
}
.boot__logo .chip:nth-child(3) {
  animation-delay: 0.24s;
}
.boot__logo .chip:nth-child(4) {
  animation-delay: 0.36s;
}

@keyframes bootBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-14px);
  }
}

.boot__label {
  margin: 0;
  color: var(--hint);
  font-size: 15px;
  letter-spacing: 0.01em;
}

/* ==========================================================================
   Menu
   ========================================================================== */

.screen--menu {
  justify-content: space-between;
}

.hero {
  padding: 26px 4px 8px;
  text-align: left;
}

.hero__badge {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hero__title {
  margin: 14px 0 8px;
  font-size: clamp(34px, 11vw, 46px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.hero__num {
  font-size: 1.35em;
  background: linear-gradient(150deg, var(--p1), var(--p2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 18px var(--p1-glow));
}

.hero__sub {
  margin: 0;
  max-width: 30ch;
  color: var(--hint);
  font-size: 15px;
}

/* Decorative "connected four" that fills the space between hero and actions. */
.heroart {
  position: relative;
  flex: 1;
  min-height: 130px;
  margin: 6px 0 18px;
  pointer-events: none;
}

.heroart__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 16px 30px rgba(6, 14, 40, 0.55));
}

/* The winning row lights up one disc at a time, then all together. */
.ha-win {
  transform-box: fill-box;
  transform-origin: center;
  animation: haTrace 4.4s var(--ease-out) infinite;
}

.ha-win--1 {
  animation-delay: 0s;
}
.ha-win--2 {
  animation-delay: 0.22s;
}
.ha-win--3 {
  animation-delay: 0.44s;
}
.ha-win--4 {
  animation-delay: 0.66s;
}

@keyframes haTrace {
  0%,
  30%,
  100% {
    transform: scale(1);
    filter: none;
  }
  10% {
    transform: scale(1.1);
    filter: drop-shadow(0 0 10px var(--p1-glow)) brightness(1.15);
  }
  20% {
    transform: scale(1);
  }
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  color: var(--hint);
  font-size: 13px;
}

.menu__you {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 16px;
  border-radius: var(--radius-m);
  background: var(--section-bg);
  text-align: left;
  transition:
    transform 0.14s var(--ease-out),
    filter 0.14s var(--ease-out),
    opacity 0.14s var(--ease-out);
}

.btn:active {
  transform: scale(0.975);
  filter: brightness(0.94);
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn__icon {
  flex: 0 0 auto;
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.btn__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.btn__title {
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.btn__hint {
  font-size: 13px;
  color: var(--hint);
}

.btn--primary {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--accent) 100%, white 6%),
    var(--accent)
  );
  color: var(--accent-text);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 38%, transparent);
}

.btn--primary .btn__hint {
  color: color-mix(in srgb, var(--accent-text) 78%, transparent);
}

.btn--ghost {
  background: var(--section-bg);
  box-shadow: inset 0 0 0 1px var(--separator);
}

.btn--quiet {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--separator);
}

.btn--quiet .btn__title,
.btn--quiet .btn__icon {
  color: var(--text);
}

.linkbtn {
  align-self: center;
  margin-top: 14px;
  padding: 8px 14px;
  color: var(--hint);
  font-size: 14px;
  border-radius: 10px;
}

.linkbtn:active {
  background: var(--separator);
}

.iconbtn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--section-bg);
  font-size: 16px;
}

.iconbtn__off,
.iconbtn[aria-pressed="false"] .iconbtn__on {
  display: none;
}
.iconbtn[aria-pressed="false"] .iconbtn__off {
  display: block;
}

.chipbtn {
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--section-bg);
  box-shadow: inset 0 0 0 1px var(--separator);
  font-size: 14px;
  font-weight: 560;
  color: var(--hint);
  transition: transform 0.14s var(--ease-out);
}

.chipbtn:active {
  transform: scale(0.94);
}

.chipbtn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.chipbtn .iconbtn__off,
.chipbtn[aria-pressed="false"] .iconbtn__on {
  display: none;
}
.chipbtn[aria-pressed="false"] .iconbtn__off {
  display: inline;
}

/* ==========================================================================
   Lobby
   ========================================================================== */

.screen--lobby {
  align-items: center;
  justify-content: center;
}

.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.lobby__pulse {
  position: relative;
  width: 96px;
  height: 96px;
  margin-bottom: 22px;
}

.lobby__pulse span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  animation: pulseRing 2.1s var(--ease-out) infinite;
}

.lobby__pulse span:nth-child(2) {
  animation-delay: 0.7s;
}
.lobby__pulse span:nth-child(3) {
  animation-delay: 1.4s;
}

.lobby__pulse::after {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--p1), var(--p2));
  box-shadow: 0 6px 20px var(--p1-glow);
}

@keyframes pulseRing {
  0% {
    transform: scale(0.35);
    opacity: 0.9;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

.lobby__title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lobby__sub {
  margin: 0 0 20px;
  color: var(--hint);
  font-size: 14px;
  max-width: 30ch;
}

.roomcode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 14px;
  margin-bottom: 18px;
  border-radius: var(--radius-m);
  background: var(--section-bg);
  box-shadow: inset 0 0 0 1px var(--separator);
}

.roomcode__label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--hint);
}

.roomcode__value {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.lobby__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* ==========================================================================
   Game — players strip
   ========================================================================== */

.screen--game {
  gap: 10px;
}

.players {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.player {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-s);
  background: var(--section-bg);
  box-shadow: inset 0 0 0 1px transparent;
  transition:
    box-shadow 0.25s var(--ease-out),
    background 0.25s var(--ease-out);
}

.player[data-side="them"] {
  flex-direction: row-reverse;
  text-align: right;
}

.player.is-active {
  box-shadow:
    inset 0 0 0 1.5px var(--seat-color, var(--accent)),
    0 0 18px -4px var(--seat-glow, transparent);
}

.player.is-offline {
  opacity: 0.55;
}

.player__avatar {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--seat-grad, linear-gradient(150deg, #6b7a8f, #47535f));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.player__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.player__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.player__name {
  font-size: 14px;
  font-weight: 620;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player__status {
  font-size: 11.5px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 14px;
}

.player.is-offline .player__status {
  color: var(--bad);
}

/* The move clock renders as a thin progress line along the bottom of the card. */
.player::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--seat-color, var(--accent));
  transform-origin: left center;
  transform: scaleX(var(--clock, 0));
  opacity: 0;
  transition: opacity 0.2s var(--ease-out);
}

.player.is-active::after {
  opacity: 0.9;
}

.player.is-urgent::after {
  background: var(--bad);
  animation: urgentBlink 0.7s steps(2, end) infinite;
}

@keyframes urgentBlink {
  50% {
    opacity: 0.25;
  }
}

.players__score {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding: 4px 8px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--hint);
}

.players__dash {
  opacity: 0.5;
}

/* ==========================================================================
   Game — turn bar
   ========================================================================== */

.turnbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--section-bg);
  align-self: center;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background 0.25s var(--ease-out);
}

.turnbar__disc {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--turn-color, var(--hint));
  box-shadow: 0 0 0 0 var(--turn-glow, transparent);
}

.turnbar.is-mine {
  background: color-mix(in srgb, var(--turn-color, var(--accent)) 18%, var(--section-bg));
}

.turnbar.is-mine .turnbar__disc {
  animation: turnPing 1.6s var(--ease-out) infinite;
}

@keyframes turnPing {
  0% {
    box-shadow: 0 0 0 0 var(--turn-glow);
  }
  70% {
    box-shadow: 0 0 0 9px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* ==========================================================================
   Game — the board
   ========================================================================== */

.boardwrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ghosts {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  width: var(--board-w, 100%);
  height: 20px;
  flex: 0 0 auto;
}

.ghosts__arrow {
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--seat-glow, transparent));
  color: var(--seat-color, var(--accent));
  opacity: 0;
  transform: translateY(-4px);
  transition:
    opacity 0.16s var(--ease-out),
    transform 0.16s var(--ease-out);
}

.ghosts__arrow.is-on {
  opacity: 1;
  transform: none;
  animation: arrowNudge 1s var(--ease-out) infinite;
}

@keyframes arrowNudge {
  50% {
    transform: translateY(3px);
  }
}

.board {
  position: relative;
  width: var(--board-w, 336px);
  height: var(--board-h, 288px);
  border-radius: var(--radius-l);
  flex: 0 0 auto;
  box-shadow:
    0 18px 40px -12px rgba(6, 14, 40, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  isolation: isolate;
}

.board__back {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--board-well-soft), var(--board-well) 70%);
}

.board__discs {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
}

/*
 * The perforated board face: one continuous gradient across the whole board,
 * with a hole punched per cell by a tiled radial-gradient mask. Tiling the mask
 * (instead of masking 42 separate cells) keeps the gradient unbroken.
 */
.board__face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: var(--board-face);
  --hole-mask: radial-gradient(circle closest-side at 50% 50%, transparent 0 72%, #000 73%);
  -webkit-mask-image: var(--hole-mask);
  mask-image: var(--hole-mask);
  -webkit-mask-size: calc(100% / 7) calc(100% / 6);
  mask-size: calc(100% / 7) calc(100% / 6);
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

.board__rims {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
}

.rim {
  place-self: center;
  width: 72%;
  height: 72%;
  border-radius: 50%;
  box-shadow:
    inset 0 2px 5px rgba(0, 0, 0, 0.6),
    inset 0 -1px 1px rgba(255, 255, 255, 0.07);
}

.board__cols {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-radius: inherit;
  overflow: hidden;
}

.col {
  position: relative;
  background: transparent;
  transition: background 0.16s var(--ease-out);
}

/* A soft "targeting beam" down the column: strongest at the top, so it never
   washes out the wells the discs sit in. */
.col.is-armed {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--seat-color, #fff) 30%, transparent) 0%,
    color-mix(in srgb, var(--seat-color, #fff) 12%, transparent) 45%,
    transparent 92%
  );
}

.col[disabled] {
  pointer-events: none;
}

.board.is-locked .board__cols {
  pointer-events: none;
}

/* ---- discs ---- */

.disc {
  position: absolute;
  width: calc(100% / 7);
  height: calc(100% / 6);
  left: calc(var(--c) * 100% / 7);
  top: calc(var(--r) * 100% / 6);
  display: grid;
  place-items: center;
  will-change: transform;
}

.disc__inner {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  background: var(--disc-grad);
  box-shadow:
    inset 0 -3px 6px rgba(0, 0, 0, 0.35),
    inset 0 3px 5px rgba(255, 255, 255, 0.32),
    0 2px 6px rgba(0, 0, 0, 0.4);
  position: relative;
}

.disc__inner::after {
  content: "";
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.22);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.06));
}

.disc--p1 {
  --disc-grad: linear-gradient(165deg, #ff7385 0%, var(--p1) 42%, var(--p1-deep) 100%);
}
.disc--p2 {
  --disc-grad: linear-gradient(165deg, #ffe07a 0%, var(--p2) 42%, var(--p2-deep) 100%);
}

.disc--drop {
  animation: discDrop var(--fall, 320ms) linear both;
}

@keyframes discDrop {
  0% {
    transform: translateY(var(--from));
    animation-timing-function: cubic-bezier(0.45, 0, 0.9, 0.35);
  }
  62% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.3, 0, 0.7, 1);
  }
  76% {
    transform: translateY(-11%);
  }
  88% {
    transform: translateY(0);
    animation-timing-function: cubic-bezier(0.3, 0, 0.7, 1);
  }
  95% {
    transform: translateY(-3.5%);
  }
  100% {
    transform: translateY(0);
  }
}

.disc--drop .disc__inner {
  animation: discSquash var(--fall, 320ms) linear both;
}

@keyframes discSquash {
  0%,
  55% {
    transform: scale(1, 1);
  }
  64% {
    transform: scale(1.1, 0.88);
  }
  74% {
    transform: scale(0.97, 1.03);
  }
  100% {
    transform: scale(1, 1);
  }
}

.disc--ghost {
  opacity: 0.45;
  transition:
    left 0.13s var(--ease-out),
    top 0.13s var(--ease-out),
    opacity 0.15s linear;
}

.disc--ghost .disc__inner {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.5);
  background: var(--disc-grad);
}

/* winning line */
.board.has-win .disc:not(.disc--win) {
  filter: saturate(0.35) brightness(0.62);
  transition: filter 0.4s var(--ease-out);
}

.disc--win .disc__inner {
  animation: winPop 1.15s var(--ease-out) infinite;
  box-shadow:
    inset 0 -3px 6px rgba(0, 0, 0, 0.3),
    inset 0 3px 5px rgba(255, 255, 255, 0.45),
    0 0 0 3.5px #fff,
    0 0 0 6px var(--seat-glow, rgba(255, 255, 255, 0.4)),
    0 0 26px 6px var(--seat-glow, rgba(255, 255, 255, 0.5));
}

@keyframes winPop {
  0%,
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
  45% {
    transform: scale(1.12);
    filter: brightness(1.18);
  }
}

.board.is-shake {
  animation: boardShake 0.36s var(--ease-out);
}

@keyframes boardShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  60% {
    transform: translateX(5px);
  }
  85% {
    transform: translateX(-2px);
  }
}

.gamebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* ==========================================================================
   Sheets (result / rules)
   ========================================================================== */

.sheet {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(var(--safe-bottom) + 16px);
  background: rgba(4, 8, 16, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.22s var(--ease-out) both;
}

.sheet[hidden] {
  display: none;
}

.sheet__card {
  width: 100%;
  max-width: 420px;
  padding: 24px 20px calc(20px);
  border-radius: 26px;
  background: var(--bg);
  box-shadow: var(--shadow-card);
  text-align: center;
  animation: sheetUp 0.36s var(--ease-spring) both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
}

@keyframes sheetUp {
  from {
    transform: translateY(40px) scale(0.97);
    opacity: 0;
  }
}

.result__icon {
  font-size: 54px;
  line-height: 1;
  margin-bottom: 10px;
  animation: iconPop 0.5s var(--ease-spring) 0.08s both;
}

@keyframes iconPop {
  from {
    transform: scale(0.3) rotate(-12deg);
    opacity: 0;
  }
}

.result__title {
  margin: 0 0 6px;
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.result__sub {
  margin: 0 0 18px;
  color: var(--hint);
  font-size: 14.5px;
}

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

.result__score-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  border-radius: var(--radius-s);
  background: var(--section-bg);
}

.result__score-name {
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result__score-val {
  font-size: 22px;
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.result__actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.rules {
  margin: 4px 0 20px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.rules li {
  position: relative;
  padding: 7px 0 7px 26px;
  font-size: 14.5px;
  color: var(--text);
}

.rules li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 14px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--p1), var(--p2));
}

/* ==========================================================================
   Message box (errors)
   ========================================================================== */

.screen--error {
  align-items: center;
  justify-content: center;
}

.msgbox {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.msgbox__icon {
  font-size: 52px;
  margin-bottom: 12px;
}

.msgbox__title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.msgbox__text {
  margin: 0 0 22px;
  color: var(--hint);
  font-size: 15px;
}

.msgbox__actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ==========================================================================
   Toast & network banner
   ========================================================================== */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 78px);
  z-index: 70;
  max-width: calc(100% - 40px);
  padding: 11px 16px;
  border-radius: 14px;
  background: rgba(10, 16, 26, 0.92);
  color: #fff;
  font-size: 14px;
  text-align: center;
  transform: translate(-50%, 14px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.22s var(--ease-out),
    transform 0.22s var(--ease-out);
}

.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

.netbanner {
  position: absolute;
  top: calc(var(--safe-top) + 6px);
  left: 50%;
  z-index: 65;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 69, 58, 0.16);
  color: var(--bad);
  font-size: 12.5px;
  font-weight: 600;
  transform: translate(-50%, -6px);
  animation: bannerIn 0.25s var(--ease-out) both;
  backdrop-filter: blur(8px);
}

.netbanner[hidden] {
  display: none;
}

/* Make room for the banner instead of letting it cover the player cards. */
.screen {
  transition: padding-top 0.2s var(--ease-out);
}

.app.is-offline .screen--game,
.app.is-offline .screen--lobby {
  padding-top: calc(var(--safe-top) + 48px);
}

@keyframes bannerIn {
  from {
    opacity: 0;
    transform: translate(-50%, -18px);
  }
}

.netbanner__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: urgentBlink 1s steps(2, end) infinite;
}

/* ==========================================================================
   Seat theming helpers (applied by JS)
   ========================================================================== */

[data-seat="1"] {
  --seat-color: var(--p1);
  --seat-glow: var(--p1-glow);
  --seat-grad: linear-gradient(150deg, #ff7385, var(--p1-deep));
}

[data-seat="2"] {
  --seat-color: var(--p2);
  --seat-glow: var(--p2-glow);
  --seat-grad: linear-gradient(150deg, #ffe07a, var(--p2-deep));
}

/* ==========================================================================
   Accessibility / motion
   ========================================================================== */

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

@media (min-width: 500px) {
  .screen {
    padding-left: max(16px, calc((100% - 460px) / 2));
    padding-right: max(16px, calc((100% - 460px) / 2));
  }
}

/* Very short viewports: shave vertical rhythm so the board always fits. */
@media (max-height: 620px) {
  .hero {
    padding-top: 14px;
  }
  .hero__title {
    font-size: 32px;
  }
  .btn {
    padding: 12px 14px;
  }
  .screen--game {
    gap: 6px;
  }
}
