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

:root {
  --bg: #0c2921;
  --bg-card: rgba(244, 237, 224, 0.05);
  --bg-elevated: rgba(0, 0, 0, 0.25);
  --text: #f4ede0;
  --text-muted: rgba(244, 237, 224, 0.65);
  --accent: #c9a227;
  --accent-soft: rgba(201, 162, 39, 0.16);
  --success: #8fd9a8;
  --danger: #e38b8b;
  --border: rgba(244, 237, 224, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Inter", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --font-mono: "JetBrains Mono", monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: radial-gradient(ellipse at top, #1f5c47 0%, #123829 55%, var(--bg) 100%);
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 0 calc(5rem + var(--safe-bottom));
  min-height: 100dvh;
}

.main-views {
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 1rem;
  padding: 28px 16px 20px;
  animation: fadeIn 0.25s ease;
}

.screen--active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.app-shell {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-header { text-align: center; margin-bottom: 8px; max-width: 520px; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.28em;
  color: var(--accent);
  margin-bottom: 6px;
}
.title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 34px;
  margin: 0;
  letter-spacing: -0.01em;
}
.subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}
.hero-sub {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
}

.player-list, .result-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  margin-top: 18px;
}
.result-list { margin-top: 22px; }

.card-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}
.card-btn:active { transform: scale(0.97); }
.card-btn.locked { cursor: default; }
.card-btn.locked:active { transform: none; }
.card-btn.tapped {
  border: 1.5px solid var(--accent);
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.16), rgba(244, 237, 224, 0.06));
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.25) inset;
}

.row-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(244, 237, 224, 0.12);
  color: rgba(244, 237, 224, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.circle-gold { background: var(--accent); color: #123829; }

.name-wrap { position: relative; min-width: 0; }
.name-label {
  display: inline-block;
  max-width: 100%;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 1px dashed rgba(244, 237, 224, 0.25);
  cursor: text;
}
.name-input {
  background: var(--bg-elevated);
  border: 1px solid rgba(244, 237, 224, 0.3);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  width: 140px;
}

.point-pop {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 2px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 19px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
  animation: popFloat 1100ms ease forwards;
}
@keyframes popFloat {
  0%   { transform: translate(-50%, 8px) scale(0.85); opacity: 0; }
  18%  { transform: translate(-50%, -2px) scale(1.12); opacity: 1; }
  70%  { transform: translate(-50%, -16px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -30px) scale(0.92); opacity: 0; }
}

.controls-row {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  width: 100%;
  max-width: 420px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn:disabled { cursor: default; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-ghost {
  background: rgba(244, 237, 224, 0.12);
  color: var(--text);
}
.btn-primary {
  background: var(--accent);
  color: #123829;
}
.btn-danger-text { color: var(--danger); }

.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-radius: var(--radius);
  animation-fill-mode: backwards;
}
.result-left { display: flex; align-items: center; gap: 14px; }
.result-name { font-size: 17px; font-weight: 600; }
.result-score { font-family: var(--font-display); font-weight: 700; font-size: 24px; }

.history { margin-top: 32px; width: 100%; max-width: 420px; }
.history-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: rgba(244, 237, 224, 0.45);
  margin-bottom: 10px;
}
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-row {
  font-size: 13px;
  color: rgba(244, 237, 224, 0.7);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.history-round { color: var(--accent); font-weight: 700; }

.pulse { animation: pulseIn 380ms ease; }
.reveal { animation: revealIn 480ms ease; }
@keyframes pulseIn {
  0% { transform: scale(0.9); opacity: 0.4; }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes revealIn {
  0% { transform: translateY(10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
}
.card h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
}
.hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.empty-state {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.5rem 1rem calc(0.65rem + var(--safe-bottom));
  background: rgba(12, 41, 33, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.55rem 0.5rem;
  cursor: pointer;
}
.bottom-nav-btn--active {
  background: var(--accent-soft);
  color: var(--accent);
}
.bottom-nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.stats-header {
  text-align: center;
  padding: 0.5rem 0;
}
.stats-header h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0;
}
.stats-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem;
}
.stats-tab {
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  padding: 0.65rem;
  cursor: pointer;
}
.stats-tab--active {
  background: var(--accent-soft);
  color: var(--accent);
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
}
.stat-card-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.stat-card-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.stat-card-hint {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.player-stat-list { padding: 0.35rem; }
.player-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0.8rem 0.65rem;
  cursor: pointer;
}
.player-stat-row:hover,
.player-stat-row:focus-visible {
  background: rgba(255, 255, 255, 0.04);
}
.player-stat-row + .player-stat-row {
  border-top: 1px solid var(--border);
}
.player-stat-name { font-weight: 700; font-size: 1rem; }
.player-stat-id {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 0.1rem;
}
.player-stat-metrics {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.player-stat-metrics strong { color: var(--text); }
.player-detail-header { margin-bottom: 1rem; }
.player-detail-header h2 {
  margin: 0;
  font-family: var(--font-display);
}
.back-btn {
  align-self: flex-start;
  margin-bottom: 0.35rem;
}
.leaderboard-row {
  display: grid;
  grid-template-columns: 1.75rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0.7rem 0.25rem;
  cursor: pointer;
}
.leaderboard-row:hover,
.leaderboard-row:focus-visible {
  background: rgba(255, 255, 255, 0.04);
}
.leaderboard-row + .leaderboard-row {
  border-top: 1px solid var(--border);
}
.leaderboard-rank { font-weight: 700; color: var(--accent); }
.leaderboard-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.recent-game {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.recent-game:last-child { border-bottom: none; }
.recent-game-top { font-size: 0.92rem; }
.recent-game-meta {
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #123829;
  color: var(--text);
  padding: 1.25rem;
  max-width: calc(100vw - 2rem);
  width: 420px;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.55); }
.modal h2 {
  font-family: var(--font-display);
  margin: 0 0 0.5rem;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.import-textarea {
  width: 100%;
  margin: 0 0 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  padding: 0.75rem;
  resize: vertical;
}
.import-file {
  width: 100%;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  .card-btn, .pulse, .reveal, .point-pop, .screen { animation: none !important; transition: none !important; }
}

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