:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: rgba(14, 17, 23, 0.96);
  --panel-soft: rgba(18, 22, 28, 0.9);
  --line: rgba(210, 220, 230, 0.12);
  --line-strong: rgba(210, 220, 230, 0.2);
  --text: #f1f4f7;
  --muted: #99a4b3;
  --accent: #d0a65e;
  --accent-soft: rgba(208, 166, 94, 0.16);
  --danger: #c66666;
  --success: #89bfa4;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font-ui: "Avenir Next", "Bahnschrift", "Segoe UI", sans-serif;
  --font-display: "DIN Condensed", "Bahnschrift", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Mono", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-ui);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 22%),
    radial-gradient(circle at 20% 10%, rgba(208, 166, 94, 0.08), transparent 30%),
    radial-gradient(circle at 85% 0%, rgba(136, 146, 160, 0.08), transparent 26%),
    linear-gradient(180deg, #050608 0%, #090b0f 48%, #050608 100%);
  color: var(--text);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.35;
  pointer-events: none;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent 92%);
}

.bg-shell {
  position: fixed;
  width: 28rem;
  height: 28rem;
  border-radius: 32px;
  pointer-events: none;
  opacity: 0.12;
  filter: blur(2px);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.shell-a {
  top: -8rem;
  left: -7rem;
  background: linear-gradient(135deg, rgba(208, 166, 94, 0.55), rgba(208, 166, 94, 0.05));
}

.shell-b {
  right: -8rem;
  bottom: -9rem;
  background: linear-gradient(135deg, rgba(122, 132, 145, 0.55), rgba(122, 132, 145, 0.05));
}

.app-shell {
  width: min(1260px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 44px;
  position: relative;
  z-index: 1;
}

.card,
.overlay-panel {
  background: linear-gradient(180deg, var(--panel), rgba(8, 10, 13, 0.98));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr auto;
  gap: 18px;
  align-items: start;
  padding: 22px;
  margin-bottom: 18px;
}

.eyebrow,
.mini-badge {
  font-size: 0.74rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero h1 {
  margin: 8px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 5.2rem);
  line-height: 0.88;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.lede {
  margin: 0;
  max-width: 60ch;
  color: #cbd2db;
  font-size: 0.98rem;
  line-height: 1.8;
}

.hero-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

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

.card {
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2,
.section-head h4 {
  margin: 0;
  letter-spacing: 0.02em;
}

.section-head h2 {
  font-size: 1.02rem;
}

.section-head h4 {
  font-size: 0.96rem;
}

.status-copy {
  margin: 0 0 14px;
  color: #c8d1da;
  line-height: 1.7;
}

.status-pill,
.turn-badge,
.winner-badge,
.mini-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
}

.status-pill {
  min-width: 112px;
}

.team-btn,
.ghost-btn,
.primary-btn,
.icon-btn {
  min-height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  color: var(--text);
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.icon-btn {
  min-width: 46px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
}

.team-switch,
.button-row,
.room-row,
.range-row {
  display: flex;
  gap: 10px;
}

.team-switch {
  margin-bottom: 14px;
}

.team-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.team-btn.active {
  border-color: rgba(208, 166, 94, 0.7);
  background: var(--accent-soft);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.primary-btn {
  border: 1px solid rgba(208, 166, 94, 0.5);
  background: linear-gradient(180deg, rgba(208, 166, 94, 0.2), rgba(208, 166, 94, 0.08));
}

.team-btn:hover,
.ghost-btn:hover,
.primary-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  background-color: rgba(255, 255, 255, 0.06);
}

.field {
  display: grid;
  gap: 8px;
  color: #d8dee5;
}

.config-form {
  display: grid;
  gap: 12px;
}

.room-input,
.config-form input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}

.room-input:focus,
.config-form input:focus {
  border-color: rgba(208, 166, 94, 0.65);
  box-shadow: 0 0 0 3px rgba(208, 166, 94, 0.12);
}

.range-row {
  align-items: center;
}

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

.answer-pill {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(208, 166, 94, 0.25);
  background: rgba(208, 166, 94, 0.08);
}

.answer-label {
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

#answer-value {
  font-family: var(--font-display);
  font-size: 2rem;
  line-height: 1;
  color: #f2e2be;
}

.stat {
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.stat span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat strong {
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.scoreboard {
  display: grid;
  gap: 12px;
}

.lobby-card {
  overflow: hidden;
}

.participants {
  display: grid;
  gap: 12px;
}

.participant-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    linear-gradient(90deg, rgba(208, 166, 94, 0.08), transparent 42%);
  border: 1px solid var(--line);
}

.participant-main {
  min-width: 0;
}

.participant-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.participant-team {
  min-width: 36px;
  min-height: 36px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  border: 1px solid rgba(208, 166, 94, 0.38);
  background: rgba(208, 166, 94, 0.1);
  color: #f2e2be;
}

.participant-name {
  min-width: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.participant-name.self::after {
  content: "YOU";
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
}

.participant-meta {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ready-badge {
  min-width: 92px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ready-badge.ready {
  border-color: rgba(137, 191, 164, 0.52);
  background: rgba(137, 191, 164, 0.14);
  color: #d8f1e2;
}

.ready-badge.waiting {
  background: rgba(255, 255, 255, 0.04);
  color: #cfd7df;
}

.participants-empty {
  padding: 20px 16px;
  border-radius: 16px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  color: var(--muted);
  text-align: center;
}

.score-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.score-name {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  font-size: 1rem;
}

.score-cells {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18px, 1fr));
  gap: 6px;
}

.cell {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}

.cell.filled {
  background: linear-gradient(180deg, rgba(208, 166, 94, 0.7), rgba(160, 120, 60, 0.72));
  border-color: rgba(208, 166, 94, 0.9);
  color: rgba(15, 12, 7, 0.98);
  box-shadow: none;
  font-size: 11px;
}

.score-total {
  min-width: 74px;
  text-align: right;
  color: #d6dde5;
  font-variant-numeric: tabular-nums;
}

.stage-shell {
  width: min(100%, 720px);
  margin: 0 auto;
}

.number-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(18, 21, 26, 0.98), rgba(8, 10, 14, 0.98));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.number-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.03)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: auto, 96px 96px;
  pointer-events: none;
  opacity: 0.55;
}

.number-stage.locked {
  filter: grayscale(0.7);
  opacity: 0.56;
}

.number-token {
  position: absolute;
  display: inline-grid;
  place-items: center;
  width: var(--token-size, 58px);
  height: var(--token-size, 58px);
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(220, 225, 230, 0.14);
  background: linear-gradient(180deg, rgba(28, 31, 36, 0.96), rgba(12, 14, 18, 0.96));
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1rem;
  box-shadow: none;
  touch-action: manipulation;
  user-select: none;
  transform: translate(-50%, -50%) rotate(var(--token-rotate, 0deg)) skew(var(--token-skew, 0deg)) scale(var(--token-scale, 1));
}

.number-token-label {
  display: inline-block;
  transform: rotate(var(--token-text-rotate, 0deg));
  text-orientation: mixed;
  letter-spacing: 0.04em;
}

.number-token::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent);
  opacity: 0;
  transition: opacity 120ms ease;
}

.number-token:hover::after,
.number-token.active::after,
.number-token:focus-visible::after {
  opacity: 1;
}

.number-token.selected {
  border-color: rgba(208, 166, 94, 0.85);
  background: linear-gradient(180deg, rgba(48, 40, 24, 0.98), rgba(24, 20, 14, 0.98));
}

.number-token.locked {
  opacity: 0.45;
  filter: grayscale(0.6);
  pointer-events: none;
}

.log {
  min-height: 120px;
  max-height: 280px;
  overflow: auto;
  color: #cfd7df;
  line-height: 1.7;
}

.log-entry {
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.log-entry:first-child {
  border-top: 0;
  padding-top: 0;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 4, 6, 0.76);
  backdrop-filter: blur(6px);
  z-index: 4;
  padding: 18px;
}

.overlay-panel {
  width: min(92vw, 540px);
  padding: 26px;
  text-align: center;
}

.overlay-number {
  margin: 16px auto 10px;
  font-family: var(--font-display);
  font-size: clamp(4rem, 18vw, 8rem);
  line-height: 0.9;
  color: #f2e2be;
}

.overlay-countdown {
  min-height: 1.2em;
  margin-top: 8px;
  color: var(--muted);
}

.overlay-countdown.timeout-strong {
  margin-top: 18px;
  min-height: auto;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 10vw, 5rem);
  line-height: 1;
  color: #f2e2be;
  text-shadow: 0 0 24px rgba(208, 166, 94, 0.25);
}

.modal-panel {
  width: min(96vw, 980px);
  text-align: left;
  max-height: min(92vh, 920px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-head h3 {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.8rem);
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.modal-card {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
}

.modal-feedback {
  grid-column: 1 / -1;
}

.overlay-panel h3 {
  margin: 8px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3.5rem);
}

.overlay-panel p {
  margin: 0;
  color: #d1d8e0;
}

.hidden {
  display: none !important;
}

.shake {
  animation: shake 420ms ease both;
}

.flash {
  animation: flash 650ms ease both;
}

.celebrate {
  animation: celebrate 900ms ease both;
}

@keyframes shake {
  10%,
  90% {
    transform: translate3d(-1px, 0, 0);
  }
  20%,
  80% {
    transform: translate3d(2px, 0, 0);
  }
  30%,
  50%,
  70% {
    transform: translate3d(-4px, 0, 0);
  }
  40%,
  60% {
    transform: translate3d(4px, 0, 0);
  }
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 rgba(208, 166, 94, 0);
  }
  30% {
    box-shadow: 0 0 0 4px rgba(208, 166, 94, 0.08);
  }
  100% {
    box-shadow: 0 0 0 rgba(208, 166, 94, 0);
  }
}

@keyframes celebrate {
  0% {
    transform: translateY(10px);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 1024px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .overlay {
    align-items: start;
    padding: 12px 8px;
  }

  .app-shell {
    width: min(100vw - 14px, 1280px);
    padding-top: 8px;
  }

  .hero,
  .card,
  .overlay-panel {
    padding: 14px;
    border-radius: 16px;
  }

  .hero {
    gap: 14px;
  }

  .hero h1 {
    font-size: clamp(2rem, 12vw, 3.4rem);
  }

  .lede {
    font-size: 0.94rem;
    line-height: 1.7;
  }

  .hero-tools {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .status-pill {
    min-width: auto;
    width: fit-content;
  }

  .section-head {
    align-items: flex-start;
  }

  .section-head h2 {
    font-size: 0.98rem;
  }

  .mini-badge,
  .turn-badge,
  .winner-badge {
    min-height: 28px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .answer-pill {
    padding: 12px 14px;
  }

  #answer-value {
    font-size: 1.7rem;
  }

  .stats {
    gap: 10px;
  }

  .stat {
    padding: 12px;
  }

  .stat strong {
    font-size: 1rem;
  }

  .score-row {
    grid-template-columns: 72px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 12px;
  }

  .participant-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .participant-top {
    align-items: flex-start;
  }

  .ready-badge {
    width: 100%;
  }

  .score-total {
    min-width: 58px;
    text-align: right;
    font-size: 0.82rem;
  }

  .score-name {
    font-size: 0.88rem;
  }

  .score-cells {
    gap: 4px;
  }

  .cell {
    width: 15px;
    height: 15px;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .stage-shell {
    width: 100%;
  }

  .number-stage {
    border-radius: 18px;
  }

  .number-token {
    width: var(--token-size, 46px);
    height: var(--token-size, 46px);
    border-radius: 11px;
    font-size: 0.88rem;
  }

  .number-token-label {
    font-size: 0.9em;
  }

  .modal-grid {
    gap: 12px;
  }

  .modal-card {
    padding: 14px;
  }

  .modal-panel {
    max-height: calc(100vh - 24px);
  }

  .room-row,
  .range-row,
  .button-row,
  .team-switch {
    gap: 8px;
  }

  .room-input,
  .config-form input,
  .team-btn,
  .ghost-btn,
  .primary-btn {
    min-height: 44px;
  }

  .log {
    max-height: 220px;
  }
}
