/* ==========================================================================
   Paper Football Scoreboard — Styles
   Mobile-first, NFL-inspired electronic scoreboard aesthetic
   ========================================================================== */

:root {
  /* Colors — stadium night / LED board */
  --color-bg: #0a1628;
  --color-bg-elevated: #111f38;
  --color-bg-panel: #0f1e36;
  --color-surface: #162a4a;
  --color-border: #2a4570;
  --color-border-bright: #3d6eb5;

  --color-text: #e8f0fc;
  --color-text-muted: #8fa8cc;
  --color-text-dim: #5a7499;

  --color-accent: #00e676;
  --color-accent-dim: #00c853;
  --color-accent-glow: rgba(0, 230, 118, 0.35);

  --color-p1: #4fc3f7;
  --color-p1-bg: rgba(79, 195, 247, 0.12);
  --color-p1-border: rgba(79, 195, 247, 0.4);

  --color-p2: #ff7043;
  --color-p2-bg: rgba(255, 112, 67, 0.12);
  --color-p2-border: rgba(255, 112, 67, 0.4);

  --color-warning: #ffab00;
  --color-danger: #ff5252;
  --color-danger-glow: rgba(255, 82, 82, 0.4);

  --color-score-flash: #fff59d;

  /* Typography */
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Barlow Condensed', 'Inter', sans-serif;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Layout */
  --header-h: auto;
  --footer-h: 4rem;
  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;

  /* Touch targets */
  --touch-min: 3rem;

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 600ms;

  /* Scoreboard LED effect */
  --digit-glow: 0 0 20px var(--color-accent-glow), 0 0 40px rgba(0, 230, 118, 0.15);
}

.u-hidden {
  display: none !important;
}

/* Reset & base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Stadium background texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(0, 230, 118, 0.08) 0%, transparent 60%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 40px,
      rgba(255, 255, 255, 0.015) 40px,
      rgba(255, 255, 255, 0.015) 41px
    );
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: var(--space-md);
  padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
  padding-top: max(var(--space-md), env(safe-area-inset-top));
  animation: screenIn var(--duration-normal) var(--ease-out);
}

.screen[hidden] {
  display: none !important;
}

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

/* Scoreboard digit typography */
.scoreboard-digits {
  font-family: var(--font-display);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: var(--digit-glow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  min-height: var(--touch-min);
  cursor: pointer;
  transition:
    background var(--duration-fast),
    border-color var(--duration-fast),
    transform var(--duration-fast),
    box-shadow var(--duration-fast),
    opacity var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

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

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

.btn--primary {
  background: var(--color-accent);
  color: #041a0e;
  border-color: var(--color-accent-dim);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-accent-dim);
  box-shadow: 0 0 20px var(--color-accent-glow);
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--color-border-bright);
  background: var(--color-bg-elevated);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
  padding: 0.5rem 0.75rem;
  min-height: auto;
}

.btn--ghost:hover:not(:disabled) {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.06);
}

.btn--large {
  font-size: 1.0625rem;
  padding: 1rem 1.5rem;
  min-height: 3.25rem;
  width: 100%;
}

.btn--icon {
  padding: 0.625rem;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
}

.btn svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

/* ==========================================================================
   Setup Screen
   ========================================================================== */

.screen--setup {
  justify-content: center;
  padding-top: max(var(--space-md), env(safe-area-inset-top));
  padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
}

.setup-header {
  text-align: center;
  padding: var(--space-md) 0 var(--space-sm);
  flex-shrink: 0;
}

.setup-header__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: var(--color-accent-glow);
  border: 2px solid var(--color-accent);
  margin-bottom: var(--space-sm);
  color: var(--color-accent);
}

.setup-header__badge svg {
  width: 1.625rem;
  height: 1.625rem;
}

.setup-header__title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--color-text);
}

.setup-header__subtitle {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: var(--space-xs);
}

.setup-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
  flex-shrink: 0;
}

.setup-progress__dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--color-border);
  transition: background var(--duration-fast), transform var(--duration-fast);
}

.setup-progress__dot--active {
  background: var(--color-accent);
  transform: scale(1.25);
}

.setup-progress__line {
  width: 3rem;
  height: 2px;
  background: var(--color-border);
}

.setup-step-label {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
  flex-shrink: 0;
}

.setup-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 28rem;
  margin: 0 auto;
  width: 100%;
}

.setup-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  min-height: 0;
  animation: setupStepIn var(--duration-normal) var(--ease-out);
}

.setup-step[hidden] {
  display: none !important;
}

.setup-step--active {
  display: flex;
}

@keyframes setupStepIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.setup-step__actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: var(--space-sm);
  margin-top: auto;
  flex-shrink: 0;
}

.setup-form__submit {
  margin-top: auto;
  flex-shrink: 0;
}

.form-group {
  border: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.form-group__legend {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.form-group__legend--sub {
  margin-top: var(--space-sm);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.field__label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.field__input {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.875rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-panel);
  color: var(--color-text);
  min-height: var(--touch-min);
  transition: border-color var(--duration-fast);
}

.field__input:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* Radio cards */
.radio-cards {
  display: flex;
  gap: var(--space-sm);
}

.radio-card {
  flex-basis: 50%;
  cursor: pointer;
}

.radio-card input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio-card__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-md);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-panel);
  transition: border-color var(--duration-fast), background var(--duration-fast);
  height: 100%;
}

.radio-card__content svg {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--color-text-muted);
}

.radio-card__title {
  font-weight: 700;
  font-size: 1rem;
}

.radio-card__desc {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.radio-card input:focus-visible + .radio-card__content {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.radio-card input:checked + .radio-card__content {
  border-color: var(--color-accent);
  background: rgba(0, 230, 118, 0.08);
}

.radio-card input:checked + .radio-card__content svg {
  color: var(--color-accent);
}

/* Segmented control */
.segmented {
  display: flex;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.segmented__item {
  flex: 1;
  cursor: pointer;
}

.segmented__item input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.segmented__item span {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.875rem;
  font-size: 0.9375rem;
  font-weight: 600;
  background: var(--color-bg-panel);
  color: var(--color-text-muted);
  transition: background var(--duration-fast), color var(--duration-fast);
  min-height: var(--touch-min);
}

.segmented__item input:focus-visible + span {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
  z-index: 1;
  position: relative;
}

.segmented__item input:checked + span {
  background: var(--color-accent);
  color: #041a0e;
}

@media (orientation: landscape) and (max-height: 500px) {
  .screen--setup {
    padding: 0.5rem 1rem;
  }

  .setup-header {
    padding: 0.25rem 0;
  }

  .setup-header__badge {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.25rem;
  }

  .setup-header__badge svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .setup-header__title {
    font-size: 1.25rem;
  }

  .setup-header__subtitle,
  .setup-step-label {
    display: none;
  }

  .setup-progress {
    margin-bottom: 0.375rem;
  }

  .setup-step {
    gap: var(--space-sm);
  }
}

/* ==========================================================================
   Game Screen
   ========================================================================== */

.screen--game {
  /*padding: var(--space-sm);
  gap: var(--space-sm);*/
  padding: 20px;
  gap: 1rem;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.timer-panel {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: 1;
  min-width: 0;
}

.timer-panel__period {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent);
  white-space: nowrap;
}

.timer-panel__clock {
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  color: var(--color-accent);
  line-height: 1;
  min-width: 5ch;
}

.timer-panel__clock--warning {
  color: var(--color-warning);
  animation: countdownPulse 1s ease-in-out infinite;
}

.timer-panel__clock--critical {
  color: var(--color-danger);
  animation: countdownPulse 0.5s ease-in-out infinite;
}

@keyframes countdownPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.85; transform: scale(1.04); }
}

.timer-panel__controls {
  display: flex;
  gap: var(--space-xs);
}

.btn--timer {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  color: var(--color-accent);
}

.btn--timer:hover:not(:disabled) {
  border-color: var(--color-accent);
}

.target-panel {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  flex: 1;
}

.target-panel__label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.target-panel__value {
  font-size: clamp(1.5rem, 5vw, 2rem);
  color: var(--color-accent);
}

.btn--history {
  font-size: 0.8125rem;
  flex-shrink: 0;
}

/* Scoreboard layout — portrait stack */
.scoreboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-height: 0;
}

.scoreboard__vs {
  text-align: center;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 800;
  color: var(--color-text-dim);
  letter-spacing: 0.2em;
  padding: var(--space-xs) 0;
  flex-shrink: 0;
}

/* Player panels */
.player-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--radius-xl);
  border: 2px solid var(--color-border);
  background: var(--color-bg-panel);
  min-height: 0;
  transition: border-color var(--duration-normal), box-shadow var(--duration-normal);
}

.player-panel--p1 {
  border-color: var(--color-p1-border);
  background: linear-gradient(160deg, var(--color-p1-bg) 0%, var(--color-bg-panel) 50%);
}

.player-panel--p2 {
  border-color: var(--color-p2-border);
  background: linear-gradient(160deg, var(--color-p2-bg) 0%, var(--color-bg-panel) 50%);
}

.player-panel__header {
  text-align: center;
}

.player-panel__name {
  font-size: clamp(0.875rem, 3vw, 1.125rem);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-panel__score-wrap {
  position: relative;
  display: inline-block;
}

.player-panel__score {
  font-size: clamp(3.5rem, 18vw, 6rem);
  line-height: 1;
  color: var(--color-text);
  display: block;
  transition: color var(--duration-fast);
}

/* Score animations */
.player-panel__score--pulse {
  animation: scorePulse var(--duration-slow) var(--ease-out);
}

@keyframes scorePulse {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.12); color: var(--color-accent); }
  100% { transform: scale(1); }
}

.player-panel__score--leader-flash {
  animation: leaderFlash 0.8s var(--ease-out);
}

@keyframes leaderFlash {
  0%, 100% { color: var(--color-text); text-shadow: var(--digit-glow); }
  25%, 75% { color: var(--color-score-flash); text-shadow: 0 0 30px rgba(255, 245, 157, 0.8); }
  50%      { color: var(--color-accent); }
}

/* OOB section */
.player-panel__oob {
  display: flex;
  align-items: center;
  /*gap: var(--space-sm);*/
  gap: 1rem;
  flex-wrap: wrap;
  padding: var(--space-sm) var(--space-md);
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
}

.player-panel__oob-label {
  /*font-size: 0.6875rem;*/
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
  flex: 1;
  min-width: 5rem;
}

.player-panel__oob-count {
  font-family: var(--font-display);
  font-weight: 800;
  /*font-size: 1.125rem;*/
  font-size: 1.875rem;
  color: var(--color-warning);
  min-width: 3.5ch;
}

.player-panel__oob-count--alert {
  animation: oobAlert 0.6s ease-in-out 3;
  color: var(--color-danger);
}

@keyframes oobAlert {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.2); }
}

.btn--oob {
  /*font-size: 0.8125rem;*/
  font-size: 1rem;
  padding: 0.5rem 0.875rem;
  min-height: 2.5rem;
  background: rgba(255, 171, 0, 0.15);
  border: 2px solid rgba(255, 171, 0, 0.4);
  color: var(--color-warning);
}

.btn--oob:hover:not(:disabled) {
  background: rgba(255, 171, 0, 0.25);
}

/* Scoring phases — TD OR conversion options */
.player-panel__scoring {
  margin-top: auto;
}

.scoring-phase {
  display: grid;
  gap: var(--space-sm);
}

.scoring-phase--td {
  grid-template-columns: 1fr;
}

.scoring-phase--conv {
  grid-template-columns: repeat(3, 1fr);
}

.scoring-phase[hidden] {
  display: none !important;
}

.btn--score {
  flex-direction: column;
  gap: 0.125rem;
  padding: var(--space-md) var(--space-sm);
  min-height: 4.5rem;
  border-radius: var(--radius-lg);
  border-width: 2px;
}

.btn--score__points {
  font-family: var(--font-display);
  /*font-size: clamp(1.25rem, 5vw, 1.75rem);*/
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.btn--score__label {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

.btn--td {
  background: rgba(0, 230, 118, 0.15);
  border-color: rgba(0, 230, 118, 0.5);
  color: var(--color-accent);
}

.btn--td:hover:not(:disabled) {
  background: rgba(0, 230, 118, 0.25);
  box-shadow: 0 0 16px var(--color-accent-glow);
}

.btn--conv1 {
  background: rgba(79, 195, 247, 0.12);
  border-color: rgba(79, 195, 247, 0.4);
  color: var(--color-p1);
}

.btn--conv2 {
  background: rgba(255, 112, 67, 0.12);
  border-color: rgba(255, 112, 67, 0.4);
  color: var(--color-p2);
}

.btn--conv0 {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.btn--score:not(:disabled):hover {
  filter: brightness(1.1);
}

/* Game footer */
.game-footer {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  padding-top: var(--space-xs);
  flex-shrink: 0;
}

.btn--undo,
.btn--quit {
  flex: 1;
  max-width: 10rem;
}

/* History panel */
.history-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 45dvh;
  background: var(--color-bg-elevated);
  border-top: 2px solid var(--color-border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  animation: slideUp var(--duration-normal) var(--ease-out);
  padding-bottom: env(safe-area-inset-bottom);
}

.history-panel[hidden] {
  display: none !important;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.history-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.history-panel__title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

.history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: var(--space-sm) var(--space-md);
}

.history-list__item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.875rem;
  animation: historyItemIn var(--duration-normal) var(--ease-out);
}

@keyframes historyItemIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.history-list__icon {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.625rem;
  font-weight: 800;
  background: var(--color-surface);
}

.history-list__text {
  flex: 1;
  color: var(--color-text-muted);
}

.history-list__text strong {
  color: var(--color-text);
  font-weight: 600;
}

.history-list__points {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--color-accent);
  flex-shrink: 0;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: max(var(--space-md), env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
  width: min(90vw, 24rem);
}

.toast {
  background: var(--color-bg-elevated);
  border: 2px solid var(--color-border-bright);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: toastIn var(--duration-normal) var(--ease-out);
}

.toast--oob {
  border-color: var(--color-danger);
  background: rgba(255, 82, 82, 0.12);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.toast--out {
  animation: toastOut var(--duration-normal) var(--ease-out) forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-8px); }
}

/* Dialogs */
.dialog {
  border: 2px solid var(--color-border-bright);
  border-radius: var(--radius-xl);
  background: var(--color-bg-elevated);
  color: var(--color-text);
  padding: var(--space-xl);
  max-width: min(90vw, 24rem);
  width: calc(100% - 2rem);
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  margin: auto;
  position: fixed;
  inset: 0;
  height: fit-content;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}

.dialog::backdrop {
  background: rgba(5, 12, 24, 0.85);
  backdrop-filter: blur(4px);
}

.dialog__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: var(--space-sm);
}

.dialog__title--large {
  font-size: clamp(1.5rem, 5vw, 2rem);
}

.dialog__title--alert {
  color: var(--color-danger);
}

.dialog__text {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-lg);
}

.dialog__actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

.dialog__actions--stack {
  flex-direction: column;
}

/* Period overlay */
.dialog--period {
  position: relative;
  overflow: hidden;
}

.period-overlay__glow {
  position: absolute;
  inset: -50%;
  background: radial-gradient(circle, var(--color-accent-glow) 0%, transparent 60%);
  animation: periodGlow 2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes periodGlow {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50%      { opacity: 0.8; transform: scale(1.1); }
}

/* OOB modal */
.dialog--oob {
  position: relative;
  overflow: hidden;
  border-color: var(--color-danger);
}

.oob-alert__pulse {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--color-danger-glow) 0%, transparent 70%);
  animation: oobPulse 1s ease-in-out infinite;
  pointer-events: none;
}

@keyframes oobPulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 0.8; }
}

.btn--fg-in {
  background: var(--color-accent);
}

/* Block interactions when modal open */
.screen--game.is-blocked {
  pointer-events: none;
  user-select: none;
}

/* ==========================================================================
   Final Screen
   ========================================================================== */

.screen--final {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: var(--space-xl);
  position: relative;
  overflow: hidden;
}

.final-celebration {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.final-celebration__particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

.final-header__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  background: rgba(255, 215, 0, 0.15);
  border: 2px solid gold;
  color: gold;
  margin-bottom: var(--space-md);
  animation: trophyBounce 1s var(--ease-out);
}

.final-header__icon svg {
  width: 2.5rem;
  height: 2.5rem;
}

@keyframes trophyBounce {
  0%   { transform: scale(0) rotate(-20deg); }
  60%  { transform: scale(1.15) rotate(5deg); }
  100% { transform: scale(1) rotate(0); }
}

.final-header__result {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 6vw, 2.25rem);
  font-weight: 800;
  margin-bottom: var(--space-sm);
}

.final-header__score {
  font-size: clamp(2rem, 10vw, 3.5rem);
  color: var(--color-accent);
}

.final-stats {
  display: grid;
  gap: var(--space-md);
  width: 100%;
  max-width: 32rem;
}

.final-stats__player {
  background: var(--color-bg-panel);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  text-align: left;
}

.final-stats__player-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.final-stats__player--p1 .final-stats__player-name { color: var(--color-p1); }
.final-stats__player--p2 .final-stats__player-name { color: var(--color-p2); }

.final-stats__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.final-stats__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.final-stats__label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
}

.final-stats__value {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
}

.final-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  width: 100%;
  max-width: 20rem;
}

/* ==========================================================================
   Landscape layout — phones in horizontal (primary use case)
   ========================================================================== */

@media (orientation: landscape) {
  .screen--game {
    /*padding: 0.25rem 0.5rem;
    padding-top: max(0.25rem, env(safe-area-inset-top));
    padding-bottom: max(0.25rem, env(safe-area-inset-bottom));
    gap: 0.25rem;*/
    padding: 20px;
    gap: 1rem;
  }

  .game-header {
    flex-wrap: nowrap;
    flex-shrink: 0;
    min-height: 0;
    gap: 0.375rem;
  }

  .timer-panel {
    gap: 0.5rem;
  }

  .timer-panel__period {
    font-size: 0.625rem;
  }

  .timer-panel__clock {
    font-size: clamp(1.25rem, 5vh, 2rem);
    min-width: 4.5ch;
  }

  .btn--history span {
    display: none;
  }

  .scoreboard {
    flex-direction: row;
    align-items: stretch;
    gap: 0.25rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .scoreboard__vs {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.125rem;
    font-size: 0.6875rem;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    flex-shrink: 0;
  }

  .player-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    padding: 0.375rem 0.5rem;
    gap: 0.25rem;
    overflow: hidden;
  }

  .player-panel__header {
    flex-shrink: 0;
  }

  .player-panel__name {
    font-size: clamp(0.625rem, 2.5vh, 0.8125rem);
    margin-bottom: 0;
  }

  .player-panel__score {
    font-size: clamp(2.5rem, 22vh, 5rem);
    line-height: 0.95;
  }

  .player-panel__oob {
    padding: 0.25rem 0.375rem;
    /*gap: 0.25rem;*/
    gap: 1rem;
    flex-shrink: 0;
  }

  .player-panel__oob-label {
    /*font-size: 0.5625rem;*/
    font-size: 0.8rem;
    min-width: auto;
    flex: 1;
  }

  .player-panel__oob-count {
    /*font-size: 0.875rem;*/
    font-size: 1.875rem;
  }

  .btn--oob {
    /*font-size: 0.6875rem;*/
    font-size: 1rem;
    padding: 0.25rem 0.5rem;
    min-height: 1.75rem;
  }

  .btn--oob svg {
    width: 0.875rem;
    height: 0.875rem;
  }

  .scoring-phase--conv {
    grid-template-columns: repeat(3, 1fr);
  }

  .btn--score {
    min-height: 2.75rem;
    padding: 0.375rem 0.25rem;
  }

  .btn--score__points {
    /*font-size: clamp(0.875rem, 3.5vh, 1.25rem);*/
    font-size: 2rem;
  }

  .btn--score__label {
    font-size: 0.5625rem;
  }

  .game-footer {
    padding-top: 0;
    flex-shrink: 0;
  }

  .btn--undo,
  .btn--quit {
    min-height: 2.25rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    max-width: 8rem;
  }
}

/* Extra-compact for short phone landscape (e.g. iPhone SE) */
@media (orientation: landscape) and (max-height: 430px) {
  .player-panel__score {
    font-size: clamp(2rem, 20vh, 3.5rem);
  }

  .btn--score {
    min-height: 2.25rem;
  }

  .dialog {
    padding: var(--space-md);
  }
}

/* Tablet & desktop enhancements */
@media (min-width: 768px) {
  .screen--setup,
  .screen--final {
    padding: var(--space-xl);
  }

  .setup-form {
    max-width: 32rem;
  }

  .history-panel {
    left: auto;
    right: var(--space-md);
    bottom: var(--space-md);
    max-width: 22rem;
    border-radius: var(--radius-xl);
    border: 2px solid var(--color-border);
    max-height: 60dvh;
  }
}

@media (min-width: 768px) and (orientation: portrait) {
  .btn--score {
    min-height: 5rem;
  }
}

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

  .screen {
    animation: none;
  }
}
