:root {
  --bg-deep: #0c0a10;
  --bg-mid: #14121a;
  --surface: rgba(28, 24, 34, 0.9);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f2f0f6;
  --text-muted: #9a94a8;
  --accent: #e86a5a;
  --accent-soft: rgba(232, 106, 90, 0.18);
  --accent-glow: rgba(232, 106, 90, 0.35);
  --danger: #e07a7a;
  --success: #7bc9a0;
  --sq-light: #2a2430;
  --sq-dark: #5c4038;
  --sq-dark-hover: #6d4f44;
  --disc-red: #d94a3a;
  --disc-black: #1e1c24;
  --radius: 18px;
  --radius-sm: 10px;
  --board-size: min(92vmin, 520px);
  --font-body: "DM Sans", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-deep);
  background-image:
    radial-gradient(ellipse 70% 45% at 50% -10%, rgba(232, 106, 90, 0.14), transparent 55%),
    linear-gradient(168deg, var(--bg-deep), var(--bg-mid) 50%, #08060a);
  background-attachment: fixed;
}

a { color: var(--accent); }

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.top__brand { display: flex; align-items: center; gap: 0.85rem; }
.top__glyph { font-size: 1.75rem; color: var(--accent); filter: drop-shadow(0 0 10px var(--accent-glow)); }
.brand { font-family: var(--font-display); font-size: 1.55rem; font-weight: 600; margin: 0; }
.tag { margin: 0.15rem 0 0; color: var(--text-muted); font-size: 0.9rem; }
.top__actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

.pill {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.pill--idle { color: var(--text-muted); }
.pill--ok { color: var(--success); border-color: rgba(123, 201, 160, 0.35); background: rgba(123, 201, 160, 0.1); }
.pill--bad { color: var(--danger); border-color: rgba(224, 122, 122, 0.35); }

.lobby { max-width: 520px; margin: 0 auto; }
.lobby__title { font-family: var(--font-display); font-size: clamp(1.6rem, 4vw, 2rem); margin: 0 0 0.6rem; }
.lobby__lead { margin: 0; color: var(--text-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  margin-top: 1.25rem;
  backdrop-filter: blur(12px);
}
.card--cpu__title { margin: 0 0 0.4rem; font-family: var(--font-display); font-size: 1.15rem; }
.card--cpu__lead { margin: 0 0 1rem; font-size: 0.92rem; color: var(--text-muted); }

.field { display: block; margin-bottom: 1rem; }
.field__label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field__optional { font-weight: 400; text-transform: none; letter-spacing: 0; }
.field__input {
  width: 100%;
  padding: 0.75rem 1rem;
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.field__input:focus {
  border-color: rgba(232, 106, 90, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field__input--code {
  font-family: ui-monospace, monospace;
  font-size: 1.35rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.field__input--select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%239a94a8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2rem;
}

.card__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.1rem; }
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
}
.btn--primary {
  color: #fff;
  background: linear-gradient(135deg, #f08070, var(--accent));
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn--ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}
.btn--danger {
  color: #fff;
  background: rgba(224, 122, 122, 0.25);
  border: 1px solid rgba(224, 122, 122, 0.4);
}
.btn--small { font-size: 0.82rem; padding: 0.4rem 0.85rem; }
.btn--block { width: 100%; margin-top: 0.25rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.form-error { margin: 0.75rem 0 0; color: var(--danger); font-size: 0.9rem; }
.lobby__features { margin: 2rem 0 0; padding: 0; list-style: none; color: var(--text-muted); font-size: 0.92rem; }
.lobby__features li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }

.game {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 860px) {
  .game { grid-template-columns: 1fr; }
  .game__side { order: 2; }
  .board-stage { order: 1; }
}

.game__side { display: flex; flex-direction: column; gap: 0.85rem; }
.room-card, .status-card, .players-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
}
.room-card__label { margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.room-card__code-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.35rem; }
.room-card__code { font-family: ui-monospace, monospace; font-size: 1.5rem; font-weight: 700; letter-spacing: 0.15em; color: var(--accent); }
.room-card__role { margin: 0.5rem 0 0; font-size: 0.88rem; color: var(--text-muted); }

.qr-share { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); text-align: center; }
.qr-share__frame { display: inline-block; padding: 0.5rem; background: #f4f0e8; border-radius: var(--radius-sm); }
.qr-share__img { display: block; width: 200px; height: 200px; }

.status-card__turn { margin: 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }
.status-card__msg { margin: 0.35rem 0 0; font-size: 0.88rem; color: var(--text-muted); min-height: 1.2em; }
.status-card__msg--error { color: var(--danger); }
.status-card__msg--turn { color: var(--accent); }

.player-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; padding: 0.35rem 0; }
.player-row__dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--border); }
.player-row--red .player-row__dot { background: var(--disc-red); }
.player-row--black .player-row__dot { background: var(--disc-black); }
.player-row__seat { margin-left: auto; color: var(--text-muted); font-size: 0.82rem; }
.player-row__points {
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 1.5rem;
  text-align: right;
}
.player-row__material {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 2.5rem;
  text-align: right;
}
.players-card__legend {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 0 0 0.35rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.players-card__legend span { min-width: 2.5rem; text-align: right; }
.players-card__legend span:first-child { min-width: 1.5rem; }

.game__actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.board-stage { width: 100%; }
.board-stage__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.board-stage__status { margin: 0; font-size: 0.88rem; font-weight: 600; color: var(--text-muted); }
.game__board-wrap { display: flex; justify-content: center; }

.board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35), 0 24px 60px rgba(0, 0, 0, 0.5), 0 0 60px var(--accent-glow);
}
.board--flipped { transform: rotate(180deg); }
.board--flipped .disc { transform: rotate(180deg); }

.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq--light { background: var(--sq-light); }
.sq--dark { background: var(--sq-dark); cursor: default; }
.sq--dark.sq--can-play { cursor: pointer; }
.sq--dark.sq--can-play:hover { background: var(--sq-dark-hover); }
.sq--selected { box-shadow: inset 0 0 0 3px var(--accent); }
.sq--target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(232, 106, 90, 0.55);
  box-shadow: 0 0 12px var(--accent-glow);
}
.sq--must-continue { box-shadow: inset 0 0 0 3px #f0c878; animation: pulse 1s ease infinite; }
@keyframes pulse {
  50% { box-shadow: inset 0 0 0 4px rgba(240, 200, 120, 0.9); }
}

.disc {
  width: 72%;
  height: 72%;
  border-radius: 50%;
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.disc--red { background: radial-gradient(circle at 35% 30%, #ff8a7a, var(--disc-red)); }
.disc--black { background: radial-gradient(circle at 35% 30%, #4a4658, var(--disc-black)); }
.disc--king::after {
  content: "♔";
  position: absolute;
  font-size: 0.55rem;
  color: rgba(255, 255, 255, 0.85);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.disc--king { position: relative; box-shadow: inset 0 0 0 2px rgba(255, 215, 120, 0.7), inset 0 -3px 6px rgba(0, 0, 0, 0.35); }

.board-stage:fullscreen,
.board-stage--immersive {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  background: var(--bg-deep);
  --board-size: min(calc(100vmin - 5rem), calc(100vw - 2rem));
}
body.board-stage-open { overflow: hidden; }

.foot { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.foot__muted { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
