/* ============================================================
   NBADLE – styles.css
   "Arena scoreboard": dark court, solid result tiles, condensed type.
   ============================================================ */

:root {
  --bg: #161616;
  --surface: #1e1e1e;
  --surface-2: #292929;
  --surface-3: #353535;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eeeeee;
  --muted: #9a9a9a;
  --accent: #ff6b1a;
  --accent-hover: #ff7f38;
  --on-accent: #1a1204;

  --match: #15803d;
  --on-match: #ffffff;
  --partial: #f59e0b;
  --on-partial: #1a1204;
  --miss: #383838;
  --on-miss: #d2d2d2;
  --danger: #ef4444;
  --input-surface: #0e0e0e;
  --overlay: rgba(7, 7, 7, 0.72);
  --keyboard-surface: rgba(14, 14, 14, 0.96);
  --result-win: #4ade80;
  --result-loss: #f87171;
  --error-text: #fca5a5;

  --font-display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --reveal-step: 90ms;
}

:root[data-theme="light"] {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f0ece5;
  --surface-3: #e5ded5;
  --line: rgba(65, 47, 30, 0.12);
  --line-strong: rgba(65, 47, 30, 0.22);
  --text: #241b14;
  --muted: #6b6259;
  --accent: #d9520c;
  --accent-hover: #b93e00;
  --on-accent: #fffaf5;
  --match: #167843;
  --partial: #c98009;
  --miss: #d8d1c8;
  --on-miss: #3d332a;
  --danger: #c73b3b;
  --input-surface: #f7f3ed;
  --overlay: rgba(36, 27, 20, 0.5);
  --keyboard-surface: rgba(246, 243, 238, 0.96);
  /* The dark theme's pastels are unreadable on white (1.7-2.8:1); these pass AA */
  --result-win: #15803d;
  --result-loss: #b91c1c;
  --error-text: #b91c1c;
  --shadow: 0 10px 30px rgba(70, 49, 28, 0.15);
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--text);
  background-color: var(--bg);
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

/* Modal headings take programmatic focus for screen readers; they aren't interactive */
.modal h2[tabindex="-1"]:focus,
.modal h2[tabindex="-1"]:focus-visible {
  outline: none;
}

[data-lucide],
svg.lucide {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
}

.app {
  width: 100%;
  max-width: 1040px;
}

/* ============================================================
   BRAND
   ============================================================ */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  font-family: var(--font-display);
  font-weight: 800;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--accent);
  line-height: 1;
}

.brand-ball {
  width: 0.8em;
  height: 0.8em;
  fill: var(--accent);
  stroke: var(--on-accent);
  stroke-width: 1.6;
}
.brand-ball circle {
  stroke: none;
}

.brand--hero {
  font-size: clamp(3.4rem, 17vw, 7rem);
}

.brand--sm {
  font-size: 1.6rem;
}

/* ============================================================
   SCREENS
   ============================================================ */
.screen {
  padding: 8px 0 24px;
}

.screen--landing {
  position: relative;
  min-height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  text-align: center;
}

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

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.theme-toggle--corner {
  position: absolute;
  top: 8px;
  right: 0;
}

.screen-bar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  margin-bottom: 20px;
}
.screen-bar .brand {
  justify-self: center;
}

.screen-title {
  margin: 0 0 6px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.9rem;
  letter-spacing: 0.01em;
}

.screen-sub {
  margin: 0 auto 20px;
  max-width: 420px;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.theme-toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line-strong));
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn--ghost {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--text);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--surface-3);
}

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

.btn--block {
  width: 100%;
}
.btn--wide {
  width: 100%;
  max-width: 320px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.link-btn:hover {
  color: var(--text);
}
.link-btn--danger:hover {
  color: var(--danger);
}

/* ============================================================
   MODE CARDS
   ============================================================ */
.mode-grid {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 18px 18px;
  text-align: left;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.mode-card:hover {
  border-color: rgba(255, 107, 26, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 107, 26, 0.25), 0 12px 30px rgba(255, 107, 26, 0.12);
}
.mode-card:active {
  transform: scale(0.99);
}

.mode-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 107, 26, 0.12);
  color: var(--accent);
  font-size: 1.5rem;
}

.mode-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.mode-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1;
}

.mode-desc {
  color: var(--muted);
  font-size: 0.88rem;
}

.mode-chevron {
  color: var(--muted);
  font-size: 1.3rem;
}

@media (min-width: 720px) {
  .mode-grid {
    grid-template-columns: 1fr 1fr;
    max-width: 720px;
  }
}

/* ============================================================
   SWITCH / TOGGLES
   ============================================================ */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background 0.2s;
  cursor: pointer;
}
.slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s;
}
.switch input:checked + .slider {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
  background: var(--on-accent);
}
.switch input:focus-visible + .slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch--sm {
  width: 36px;
  height: 22px;
}
.switch--sm .slider::before {
  width: 16px;
  height: 16px;
}
.switch--sm input:checked + .slider::before {
  transform: translateX(14px);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 560px;
  margin: 14px auto 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
}
.toggle-title {
  display: block;
  font-weight: 600;
}
.toggle-desc {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ============================================================
   VERSUS: PIN
   ============================================================ */
.pin-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 420px;
  margin: 12px auto 0;
  padding: 28px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
}

.pin-caption {
  margin: 0;
  color: var(--muted);
}

.pin-display {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3rem, 16vw, 4.5rem);
  letter-spacing: 0.14em;
  padding: 8px 18px 8px 26px;
  border-radius: var(--radius);
  background: var(--input-surface);
  border: 1px solid var(--line-strong);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.waiting-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

.pin-input {
  width: 100%;
  max-width: 320px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 10px 12px 10px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--input-surface);
  color: var(--accent);
}
.pin-input::placeholder {
  color: rgba(154, 154, 154, 0.35);
}
.pin-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-error {
  margin: 0;
  color: var(--error-text);
  font-size: 0.9rem;
}

/* ============================================================
   GAME HEADER
   ============================================================ */
.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.game-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.mode-pill {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.starter-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-right: 2px;
}

/* ============================================================
   VERSUS SCOREBOARD
   ============================================================ */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--input-surface);
  border: 1px solid var(--line-strong);
}

.score {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.score--opp {
  align-items: flex-end;
}

.score-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.score-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.score--opp .score-value {
  color: var(--text);
}

.score-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.score-vs {
  font-family: var(--font-display);
  font-weight: 800;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--muted);
}

.score-pin {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.score-pin strong {
  color: var(--text);
  letter-spacing: 0.12em;
}

.loading {
  display: none;
  margin: 0 0 12px;
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   SEARCH + HINT
   ============================================================ */
.play-area {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.search-col {
  min-width: 0;
}

.input-container {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

#player-input {
  width: 100%;
  height: 52px;
  padding: 0 16px 0 42px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 16px; /* 16px+ prevents iOS zoom on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
}
#player-input::placeholder {
  color: var(--muted);
}
#player-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 107, 26, 0.18);
}
#player-input:disabled {
  opacity: 0.55;
}

.autocomplete {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 320px;
  overflow-y: auto;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}
.autocomplete:empty {
  display: none;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.ac-item:last-child {
  border-bottom: 0;
}
.ac-item.is-active,
.ac-item:hover {
  background: var(--surface-3);
}
.ac-logo {
  width: 26px;
  height: 26px;
}
.ac-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ac-name strong {
  color: var(--accent);
  font-weight: 700;
}
.ac-team {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.ac-item.is-guessed {
  opacity: 0.4;
  cursor: not-allowed;
}
.ac-item.is-guessed .ac-team::after {
  content: " · guessed";
}

.guess-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  min-height: 32px;
}

.pips {
  display: flex;
  gap: 6px;
}
.pips:empty {
  display: none;
}
.pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background 0.2s, border-color 0.2s;
}
.pip.is-used {
  background: var(--accent);
  border-color: var(--accent);
}
.pip.is-won {
  background: var(--match);
  border-color: var(--match);
}

.guess-count-text {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

#give-up-button {
  margin-left: auto;
}

.hint-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint-image-wrapper {
  position: relative;
  display: none; /* phones: only after a hint is shown */
  height: 150px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #eeeeee;
}
.hint-panel.is-revealed .hint-image-wrapper {
  display: block;
}

#silhouette-img,
#team-logo-img {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#team-logo-img {
  padding: 18px;
}

#silhouette-canvas {
  display: none;
}

.hint-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #787878;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.9rem;
}
.hint-placeholder [data-lucide],
.hint-placeholder svg {
  font-size: 1.8rem;
}

@media (min-width: 768px) {
  .play-area {
    grid-template-columns: 1fr 210px;
    align-items: start;
    gap: 20px;
  }
  .hint-image-wrapper {
    display: block;
    height: auto;
    aspect-ratio: 200 / 170;
  }
}

/* ============================================================
   BOARD + TILES
   ============================================================ */
.board {
  --cols: minmax(150px, 2.3fr) repeat(7, minmax(0, 1fr));
}

.board-head {
  display: none;
}

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

.guess-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  perspective: 600px;
}

.guess-name {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 2px 4px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.1;
}
.guess-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.guess-num {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 54px;
  padding: 5px 2px;
  border-radius: var(--radius-sm);
  text-align: center;
  background: var(--miss);
  color: var(--on-miss);
  animation: tileFlip 0.45s ease both;
  animation-delay: calc(var(--i, 0) * var(--reveal-step));
  backface-visibility: hidden;
}
.tile.match {
  background: var(--match);
  color: var(--on-match);
}
.tile.partial {
  background: var(--partial);
  color: var(--on-partial);
}

.tile-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  line-height: 1;
}

.tile-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  max-width: 100%;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tile-arrow {
  font-size: 0.8em;
}

/* Light badge so dark logos (Spurs, Nets…) stay visible on dark tiles */
.tile-logo,
.ac-logo {
  width: 22px;
  height: 22px;
  padding: 2px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  object-fit: contain;
}
.tile--team .tile-value {
  flex-direction: column;
  gap: 1px;
  font-size: 0.8rem;
}

/* Remaining solo guesses */
.guess-row.is-ghost {
  background: transparent;
  border-style: dashed;
  border-color: var(--line);
}
.guess-row.is-ghost .tile {
  background: rgba(255, 255, 255, 0.025);
  animation: none;
}
.guess-row.is-ghost .guess-name {
  color: rgba(154, 154, 154, 0.35);
}

@keyframes tileFlip {
  0% {
    opacity: 0;
    transform: rotateX(-90deg);
  }
  60% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: rotateX(0);
  }
}

@keyframes tileBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  70% {
    transform: translateY(2px);
  }
}

.guess-row.is-win .tile {
  animation:
    tileFlip 0.45s ease both calc(var(--i, 0) * var(--reveal-step)),
    tileBounce 0.5s ease calc(var(--i, 0) * 70ms + 8 * var(--reveal-step));
}
.guess-row.is-win {
  border-color: rgba(21, 128, 61, 0.7);
  box-shadow: 0 0 0 1px rgba(21, 128, 61, 0.4), 0 0 28px rgba(21, 128, 61, 0.25);
}

/* Desktop: table layout with a shared header row */
@media (min-width: 768px) {
  .board-head {
    display: grid;
    grid-template-columns: var(--cols);
    gap: 6px;
    padding: 0 11px 8px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
  }
  .head-name {
    text-align: left;
  }

  .guess-row {
    grid-template-columns: var(--cols);
    gap: 6px;
    padding: 8px 10px;
    align-items: stretch;
  }

  .guess-name {
    grid-column: auto;
    padding: 0 6px 0 2px;
    font-size: 1.25rem;
  }

  .tile {
    min-height: 58px;
  }
  .tile-label {
    display: none;
  }
  .tile-value {
    font-size: 1.35rem;
  }
  .tile--team .tile-value {
    flex-direction: row;
    gap: 6px;
    font-size: 1.1rem;
  }
  .tile-logo {
    width: 28px;
    height: 28px;
  }
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  display: none; /* JS sets flex */
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 26px 22px 22px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
}

.modal-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.9rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.modal-subtitle {
  margin: 20px 0 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal-text {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions .btn {
  flex: 1 1 140px;
}

/* Result */
.result-modal {
  text-align: center;
}

.result-kicker {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.result-title {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-weight: 800;
  font-style: italic;
  font-size: 2.6rem;
  line-height: 1;
  text-transform: uppercase;
}
.result-title.is-win {
  color: var(--result-win);
}
.result-title.is-loss {
  color: var(--result-loss);
}

.result-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.result-photo {
  position: relative;
  width: 180px;
  height: 140px;
  margin-bottom: 6px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.result-team-logo {
  position: absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  object-fit: contain;
  opacity: 0.22;
}
.result-headshot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom;
}

.result-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.7rem;
  text-transform: uppercase;
  line-height: 1.05;
}

.result-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-sub {
  margin: 12px 0 0;
  color: var(--text);
}
.result-sub:empty {
  display: none;
}

.result-grid {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 14px;
}
.result-grid:empty {
  display: none;
}
.result-grid-row {
  display: flex;
  gap: 3px;
}
.result-grid-cell {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--miss);
}
.result-grid-cell.match {
  background: var(--match);
}
.result-grid-cell.partial {
  background: var(--partial);
}

/* Stats */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}
.stat-row:empty {
  display: none;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.8rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.segment {
  padding: 6px 16px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.segment.is-active {
  background: var(--surface-3);
  color: var(--text);
}

.dist {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.dist-row {
  display: grid;
  grid-template-columns: 14px 1fr;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dist-bar {
  min-width: 24px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-3);
  text-align: right;
  font-size: 0.9rem;
}
.dist-bar.is-highlight {
  background: var(--match);
  color: var(--on-match);
}

/* Help */
.help-lead {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}
.help-modes {
  display: grid;
  gap: 8px;
}
.help-mode {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}
.help-mode-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}
.help-legend {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}
.legend-item {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.4;
}
.tile--demo {
  min-height: 42px;
  animation: none;
}
.legend-arrows {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text);
}
.help-extras {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}
.help-extras li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  line-height: 1.45;
}
.help-extras strong {
  color: var(--text);
}
.help-modal .btn--wide {
  display: flex;
  margin: 0 auto;
}

.confirm-modal {
  max-width: 380px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  top: max(20px, env(safe-area-inset-top));
  z-index: 1100;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============================================================
   ON-SCREEN KEYBOARD (touch devices)
   ============================================================ */
.osk {
  display: none; /* JS adds .osk--visible */
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 600;
  flex-direction: column;
  gap: 6px;
  padding: 8px 4px max(10px, env(safe-area-inset-bottom));
  background: var(--keyboard-surface);
  border-top: 1px solid var(--line-strong);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  user-select: none;
  -webkit-user-select: none;
}
.osk.osk--visible {
  display: flex;
}

/* Keeps page content above the keyboard */
body.osk-open {
  padding-bottom: max(225px, calc(210px + env(safe-area-inset-bottom)));
}

.osk-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 0 2px;
}

.osk-key {
  flex: 1;
  max-width: 40px;
  min-width: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  transition: background 0.06s, transform 0.06s;
}
.osk-key:active,
.osk-key.osk-key--pressed {
  background: #4a4a4a;
  transform: scale(0.95);
}

.osk-key--special {
  background: var(--surface-2);
}

.osk-key--back {
  flex: 1.4;
  max-width: 52px;
  background: var(--surface-2);
  font-size: 1.2rem;
}

.osk-key--space,
.osk-key--enter {
  max-width: none;
  font-size: 0.85rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.osk-key--space {
  flex: 4;
}
.osk-key--enter {
  flex: 2;
  background: var(--accent);
  color: var(--on-accent);
}
.osk-key--enter:active,
.osk-key--enter.osk-key--pressed {
  background: var(--accent-hover);
}

/* ============================================================
   SMALL PHONES
   ============================================================ */
@media (max-width: 767px) {
  /* Full division names overflow a seven-column phone board. The full name is
     retained in the tile's accessible label; this only swaps the visual text
     for its conventional short code (Southeast → SE, Pacific → PAC, etc.). */
  .tile--division .tile-value {
    font-size: 0;
  }
  .tile--division .tile-value::before {
    content: attr(data-compact-value);
    font-size: 0.95rem;
  }

  /* Tiles are ~45px wide here: tuck the arrow into the corner so values like
     6'11" keep the full width */
  .tile-arrow {
    position: absolute;
    top: 3px;
    right: 4px;
    font-size: 0.6rem;
  }
  .game-header .icon-btn {
    width: 36px;
    height: 36px;
  }
  .game-header .brand--sm {
    font-size: 1.4rem;
  }
  .header-actions {
    gap: 6px;
  }
}

@media (max-width: 380px) {
  body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .guess-row {
    gap: 4px;
    padding: 8px;
  }
  .tile-value {
    font-size: 0.95rem;
  }
  .tile-label {
    font-size: 0.56rem;
  }
}

@media (max-width: 340px) {
  .filter-label {
    display: none;
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
  .tile,
  .guess-row.is-win .tile {
    animation: fadeIn 0.2s ease both !important;
    animation-delay: 0s !important;
  }
  .modal,
  .live-dot {
    animation: none !important;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
