:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.86);
  --panel-border: rgba(148, 163, 184, 0.2);
  --text: #eff6ff;
  --muted: #94a3b8;
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --danger: #ef4444;
  --used: #334155;
  --shadow: 0 24px 70px rgba(2, 8, 23, 0.45);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(245, 158, 11, 0.2), transparent 30%),
    linear-gradient(180deg, #0b1224 0%, #091120 100%);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 1000px);
  margin: 0 auto;
  padding: 16px 12px 24px;
}

.topbar,
.status-row,
.controls-row,
.modal-head,
.modal-actions,
.setup-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  margin-bottom: 18px;
}

.content {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.panel {
  display: none;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel.active,
.inner-panel {
  display: block;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field.compact {
  min-width: 220px;
}

.field select,
.field input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.segment,
.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.segment:hover,
.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover {
  transform: translateY(-1px);
}

.segment {
  background: rgba(30, 41, 59, 0.95);
  color: var(--text);
}

.segment.is-active,
.primary-btn {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #1c1917;
  font-weight: 700;
}

.secondary-btn {
  background: rgba(37, 99, 235, 0.85);
  color: white;
  font-weight: 600;
}

.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.24);
}

.danger-btn {
  background: rgba(239, 68, 68, 0.95);
  color: white;
  font-weight: 600;
}

.icon-btn {
  min-width: 48px;
  padding-inline: 0;
}

.player-inputs,
.scoreboard {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.toggle-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.player-card,
.score-card,
.status-card {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.status-row {
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.status-card {
  flex: 1;
  min-width: 150px;
}

.status-card span,
.score-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}

.score-card.active-player {
  outline: 2px solid rgba(245, 158, 11, 0.8);
}

.board {
  overflow-x: hidden;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.board-cell,
.board-header {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  border-radius: 16px;
  min-width: 0;
  word-break: break-word;
}

.board-header {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.14);
  font-weight: 700;
}

.board-cell {
  border: 0;
  color: white;
  background: linear-gradient(160deg, #2563eb 0%, #1d4ed8 100%);
  font-size: 1.15rem;
  font-weight: 800;
}

.board-cell.used,
.board-cell:disabled {
  background: var(--used);
  color: var(--muted);
  cursor: not-allowed;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
}

.modal.hidden,
.answer-block.hidden,
.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: min(92vw, 640px);
  max-height: min(88vh, 760px);
  border-radius: 24px;
  padding: 20px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.96));
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: var(--shadow);
  animation: modal-enter 0.22s ease;
  overflow-y: auto;
}

.modal-body {
  padding: 12px 0 20px;
}

.question-text {
  font-size: 1.2rem;
  line-height: 1.5;
}

.answer-block {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.28);
}

.answer-block span {
  display: block;
  color: #86efac;
  margin-bottom: 6px;
}

#scorePlayerField {
  margin-top: 16px;
}

.form-error {
  min-height: 1.4em;
  margin-top: 14px;
  color: #fca5a5;
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding-inline: 8px;
  }

  .topbar,
  .controls-row,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .board-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .board-cell,
  .board-header {
    min-height: 56px;
    font-size: 0.82rem;
    padding: 6px;
    border-radius: 12px;
  }

  .panel {
    padding: 12px;
  }

  .status-card,
  .player-card,
  .score-card {
    padding: 12px;
  }

  .field select,
  .field input,
  .segment,
  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn {
    min-height: 42px;
    padding: 10px 12px;
  }

  .modal-card {
    width: min(96vw, 640px);
    padding: 16px;
  }
}
