:root {
  --bg: #fbf8f5;
  --surface: #ffffff;
  --surface-muted: #f4efe9;
  --border: #e7dfd6;
  --ink: #1c1917;
  --ink-muted: #655e58;
  --p1: #e11d48;
  --p1-soft: #fff1f2;
  --p1-border: #fecdd3;
  --p2: #0f766e;
  --p2-soft: #f0fdfa;
  --p2-border: #99f6e4;
  --correct: #059669;
  --correct-dark: #047857;
  --missed: #e11d48;
  --missed-dark: #be123c;
  --shadow-sm: 0 2px 8px rgba(28, 25, 23, 0.05);
  --shadow-md: 0 12px 30px rgba(28, 25, 23, 0.08);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 18px
    calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Typography */
.eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--p1);
  margin-bottom: 6px;
}

h1 {
  margin: 0;
  font-size: 1.85rem;
  line-height: 1.15;
  letter-spacing: -0.025em;
}

.subtitle {
  margin: 8px 0 0;
  font-size: 0.96rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

/* Player color gelpers */
.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.player-p1 .player-dot {
  background: var(--p1);
}

.player-p2 .player-dot {
  background: var(--p2);
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  transition: transform 0.12s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: #2e2926;
}

.btn-subtle {
  background: var(--surface-muted);
  color: var(--ink);
}

.btn-subtle:hover:not(:disabled) {
  background: #ebe3d9;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}

.btn-danger {
  background: var(--missed);
  color: #ffffff;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.86rem;
  border-radius: 10px;
}

.btn-lg {
  min-height: 54px;
  font-size: 1.02rem;
  border-radius: 16px;
}

.btn-block {
  width: 100%;
}

/* SETUP VIEW */
.view-setup {
  gap: 18px;
  justify-content: center;
}

.setup-header {
  text-align: center;
  padding: 6px 4px 0;
}

.resume-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

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

.resume-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--p2);
}

.resume-info strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.resume-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.field-heading-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.field-heading {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.deck-count {
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-weight: 500;
}

.field-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--p1);
}

.player-inputs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 0 14px;
  min-height: 50px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.input-wrap:focus-within {
  background: var(--surface);
  border-color: var(--ink);
}

.input-wrap input {
  border: none;
  background: transparent;
  width: 100%;
  outline: none;
  font-size: 1rem;
  font-weight: 500;
}

.input-wrap input::placeholder {
  color: #a8a29e;
  font-weight: 400;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented-option {
  position: relative;
  cursor: pointer;
}

.segmented-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.segmented-label strong {
  font-size: 0.92rem;
}

.segmented-label small {
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.segmented-option input:checked + .segmented-label {
  border-color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.category-chip {
  border: 1.5px solid var(--border);
  background: var(--bg);
  border-radius: 14px;
  padding: 10px 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.category-chip strong {
  font-size: 0.88rem;
}

.category-chip span {
  font-size: 0.75rem;
  color: var(--ink-muted);
}

.category-chip.selected {
  border-color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* GAMEPLAY VIEW */
.view-game {
  gap: 14px;
  justify-content: space-between;
}

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

.scoreboard {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.score-pill {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.score-pill.active.player-p1 {
  border-color: var(--p1);
  background: var(--p1-soft);
}

.score-pill.active.player-p2 {
  border-color: var(--p2);
  background: var(--p2-soft);
}

.score-name {
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.score-val {
  font-size: 0.84rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  border-radius: 12px;
  min-height: 38px;
  padding: 0 11px;
  font-size: 0.82rem;
  font-weight: 600;
  flex-shrink: 0;
}

.progress-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.halfway-banner {
  background: var(--p2-soft);
  border: 1px solid var(--p2-border);
  color: #115e59;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.88rem;
  text-align: center;
}

.card-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
}

.question-card {
  width: 100%;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top-width: 6px;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: cardIn 0.2s ease-out;
}

.question-card.player-p1 {
  border-top-color: var(--p1);
}

.question-card.player-p2 {
  border-top-color: var(--p2);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.turn-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
}

.question-card.player-p1 .turn-badge {
  background: var(--p1-soft);
  color: var(--p1);
}

.question-card.player-p2 .turn-badge {
  background: var(--p2-soft);
  color: var(--p2);
}

.category-badge {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-muted);
  padding: 5px 10px;
  border-radius: 999px;
}

.about-cue {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.question-text {
  margin: 4px 0 8px;
  font-size: clamp(1.32rem, 5.2vw, 1.62rem);
  line-height: 1.32;
  letter-spacing: -0.018em;
  color: var(--ink);
}

.judge-cue {
  margin: 6px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--surface-muted);
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.4;
}

.action-dock {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

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

.utility-row .btn {
  min-height: 42px;
  font-size: 0.88rem;
}

.judge-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-missed,
.btn-correct {
  min-height: 62px;
  font-size: 1.08rem;
  font-weight: 700;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}

.btn-missed {
  background: #ffffff;
  color: var(--missed);
  border: 2px solid var(--p1-border);
}

.btn-missed:hover:not(:disabled) {
  background: var(--p1-soft);
}

.btn-correct {
  background: var(--correct);
  color: #ffffff;
}

.btn-correct:hover:not(:disabled) {
  background: var(--correct-dark);
}

.btn-icon {
  font-size: 1.15rem;
  line-height: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-md);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 1.18rem;
}

.modal-card p {
  margin: 0 0 18px;
  font-size: 0.94rem;
  color: var(--ink-muted);
  line-height: 1.45;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* RESULTS VIEW */
.view-results {
  gap: 18px;
  padding-top: 8px;
}

.results-hero {
  text-align: center;
  padding: 6px 4px 0;
}

.results-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.result-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.result-card.is-winner.player-p1 {
  border-color: var(--p1);
  background: var(--p1-soft);
}

.result-card.is-winner.player-p2 {
  border-color: var(--p2);
  background: var(--p2-soft);
}

.result-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.result-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.winner-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--ink);
  color: #ffffff;
  flex-shrink: 0;
}

.result-score-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.result-score-line strong {
  font-size: 2.35rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.result-score-line span {
  font-size: 1rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.result-stats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-weight: 500;
}

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

.results-secondary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Recap */
.recap-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.recap-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.94rem;
  cursor: pointer;
}

.recap-summary::-webkit-details-marker {
  display: none;
}

.recap-chevron::after {
  content: '+';
  font-size: 1.2rem;
  color: var(--ink-muted);
}

.recap-section[open] .recap-chevron::after {
  content: '\2212';
}

.recap-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.filter-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.filter-chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.recap-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recap-item {
  border-top: 1px solid var(--surface-muted);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.recap-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.recap-outcome {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.recap-outcome.correct {
  background: #ecfdf5;
  color: var(--correct-dark);
}

.recap-outcome.missed {
  background: var(--p1-soft);
  color: var(--missed-dark);
}

.recap-question {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.38;
  color: var(--ink);
}

.recap-empty {
  padding: 12px 0 4px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.88rem;
}

@media (max-width: 360px) {
  .results-cards {
    grid-template-columns: 1fr;
  }
}
