/* ── Top nav ── */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  z-index: 50;
  backdrop-filter: blur(8px);
  background: rgba(15,12,41,.35);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.nav-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
}

@media (max-width: 600px) {
  .top-nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 16px 12px;
  }
  .nav-title {
    max-width: 100%;
    white-space: normal;
  }
  .nav-links {
    gap: 6px;
  }
  .nav-link {
    font-size: .78rem;
    padding: 5px 10px;
  }
}
.nav-links {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.nav-link {
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  padding: 7px 14px;
  border: 1px solid #3a3570;
  border-radius: 20px;
  transition: color .2s, border-color .2s;
  backdrop-filter: blur(6px);
  background: rgba(15,12,41,.5);
}
.nav-link:hover { color: var(--accent); border-color: var(--accent); }

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

:root {
  --bg:        #0f0c29;
  --bg2:       #1a1640;
  --card:      #231e52;
  --accent:    #e8b84b;
  --accent2:   #f06292;
  --green:     #66bb6a;
  --blue:      #42a5f5;
  --text:      #f0eeff;
  --muted:     #9993cc;
  --radius:    16px;
  --shadow:    0 8px 32px rgba(0,0,0,.45);
}

html, body {
  min-height: 100%;
  background: linear-gradient(160deg, var(--bg) 0%, #1b0033 100%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.center { text-align: center; }

/* ── Layout ── */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
}

/* ── Landing / login ── */
.brand {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--accent);
  margin-bottom: 4px;
}
.brand-sub {
  font-size: .95rem;
  color: var(--muted);
  margin-bottom: 28px;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 2px solid var(--bg2);
  background: var(--bg2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}
.search-wrap input:focus {
  border-color: var(--accent);
}
.search-wrap input::placeholder { color: var(--muted); }

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg2);
  border-radius: 10px;
  border: 1px solid #3a3570;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: var(--shadow);
}
.dropdown-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: .97rem;
  transition: background .15s;
}
.dropdown-item:hover, .dropdown-item.active {
  background: #2e2860;
  color: var(--accent);
}

.btn-primary {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  background: var(--accent);
  color: #1a1200;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
}
.btn-primary:hover  { opacity: .9; }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* ── Player screen ── */
.player-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}
.player-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.player-name span { display: block; font-size: .8rem; font-weight: 400; color: var(--muted); }

.btn-switch {
  background: transparent;
  border: 1px solid var(--muted);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .8rem;
  cursor: pointer;
  transition: border-color .2s, color .2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-switch:hover { border-color: var(--accent); color: var(--accent); }

/* Score stats */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}
.stat-box {
  background: var(--bg2);
  border-radius: 12px;
  padding: 16px 8px;
  text-align: center;
}
.stat-val {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
}
.stat-label {
  font-size: .72rem;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.stat-box.points .stat-val { color: var(--accent); }
.stat-box.strikes .stat-val { color: var(--blue); }
.stat-box.spares  .stat-val { color: var(--green); }

/* Pin grid */
.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.btn-pin {
  padding: 16px 4px;
  border-radius: 10px;
  border: 2px solid #3a3570;
  background: var(--bg2);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn-pin:hover  { background: #2e2860; border-color: var(--accent); }
.btn-pin:active { transform: scale(.94); }
.btn-pin:focus, .btn-pin:focus-visible  { outline: none; }
.btn-score:focus, .btn-score:focus-visible { outline: none; }
.btn-undo:focus, .btn-undo:focus-visible  { outline: none; }
.btn-pin, .btn-score, .btn-undo { -webkit-tap-highlight-color: transparent; }

/* Score buttons */
.score-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.btn-score {
  padding: 22px 8px;
  border-radius: 14px;
  border: none;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  letter-spacing: .02em;
}
.btn-score:active { transform: scale(.95); }
.btn-score.strike {
  background: linear-gradient(135deg, #1565c0, #42a5f5);
  color: #fff;
}
.btn-score.spare {
  background: linear-gradient(135deg, #2e7d32, #66bb6a);
  color: #fff;
}

.undo-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.btn-undo {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #3a3570;
  background: transparent;
  color: var(--muted);
  font-size: .8rem;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-undo:hover { border-color: var(--accent2); color: var(--accent2); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 50px;
  font-size: .95rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: transform .3s ease;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Frame log modal ── */
.log-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  backdrop-filter: blur(4px);
}
.log-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(480px, 92vw);
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  z-index: 201;
  overflow: hidden;
}
.log-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 20px 16px;
  border-bottom: 1px solid #2e2860;
}
.log-modal-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
}
.log-modal-sub {
  font-size: .8rem;
  color: var(--muted);
  margin-top: 3px;
}
.log-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color .15s;
  flex-shrink: 0;
}
.log-close:hover { color: var(--text); }
.log-entries {
  overflow-y: auto;
  padding: 12px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log-entry {
  display: grid;
  grid-template-columns: 28px 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .88rem;
}
.log-icon  { font-size: 1rem; text-align: center; }
.log-label { font-weight: 600; }
.log-pts   { color: var(--accent); font-weight: 700; }
.log-running { color: var(--muted); font-size: .8rem; }
.log-time  { color: var(--muted); font-size: .78rem; white-space: nowrap; }

.lb-clickable { cursor: pointer; }
.lb-clickable:hover td { filter: brightness(1.15); }
.row-highlight td { outline: 2px solid var(--accent); }
.row-highlight td:first-child { border-radius: 12px 0 0 12px; }
.row-highlight td:last-child  { border-radius: 0 12px 12px 0; }

.lb-find-bar {
  max-width: 860px;
  margin: 0 auto 12px;
  padding: 0 16px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.lb-find-bar input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 20px;
  border: 1px solid #3a3570;
  background: var(--card);
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border-color .2s;
}
.lb-find-bar input:focus { border-color: var(--accent); }
.lb-find-bar input::placeholder { color: var(--muted); }

/* ── Leaderboard ── */
body.lb-page {
  background: linear-gradient(160deg, #0f0c29 0%, #1b0033 100%);
  min-height: 100vh;
}

.lb-header {
  text-align: center;
  padding: 40px 20px 20px;
}
.lb-title {
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -1px;
}
.lb-sub {
  color: var(--muted);
  font-size: clamp(.85rem, 2vw, 1.1rem);
  margin-top: 6px;
}

.lb-table-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

table.lb-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  font-size: clamp(.85rem, 2vw, 1.1rem);
}
.lb-table thead th {
  color: var(--muted);
  font-size: .75rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 0 16px 8px;
  text-align: left;
}
.lb-table thead th:not(:first-child) { text-align: center; }

.lb-table tbody tr {
  background: var(--card);
  border-radius: 12px;
  transition: transform .2s;
}
.lb-table tbody tr td:first-child  { border-radius: 12px 0 0 12px; }
.lb-table tbody tr td:last-child   { border-radius: 0 12px 12px 0; }

.lb-table tbody tr.top-1 { background: linear-gradient(90deg, #7c5c00, #1a1640); }
.lb-table tbody tr.top-2 { background: linear-gradient(90deg, #3d3d4d, #1a1640); }
.lb-table tbody tr.top-3 { background: linear-gradient(90deg, #4a2800, #1a1640); }

.lb-table td {
  padding: 14px 16px;
  vertical-align: middle;
}
.lb-table td:not(:first-child):not(:nth-child(2)) { text-align: center; }

.rank-cell {
  font-size: 1.3rem;
  font-weight: 900;
  width: 52px;
  text-align: center !important;
}
.rank-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 900;
  font-size: .9rem;
}

.name-cell  { font-weight: 700; }
.pts-cell   { font-weight: 800; font-size: 1.2em; color: var(--accent); }
.medal-row  { font-size: 1.1rem; }

.finalist-badge {
  font-size: .7rem;
  background: var(--accent);
  color: #1a1200;
  border-radius: 20px;
  padding: 2px 8px;
  font-weight: 700;
  margin-left: 8px;
  vertical-align: middle;
}

.lb-footer {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  padding-bottom: 24px;
}

@media (max-width: 600px) {
  .card { padding: 24px 18px; }
  .score-btns { gap: 10px; }
  .btn-score { padding: 18px 4px; font-size: 1rem; }
  .page { padding-top: 100px; }
  .lb-header { padding-top: 100px !important; }

  /* Leaderboard table — tighter on mobile */
  .lb-table { font-size: .78rem; }
  .lb-table td, .lb-table th { padding: 10px 6px; }
  .rank-cell { width: 36px; }
  .pts-cell { font-size: 1em; }

  /* Log modal — centered popup on mobile */
  .log-modal {
    width: 92vw;
    max-height: 70vh;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  /* Log entries — drop timestamp, simplify columns */
  .log-entry {
    grid-template-columns: 24px 1fr auto auto;
  }
  .log-time { display: none; }
}
