/* ─── CSS Variables ─────────────────────────────────────── */
:root {
  --blue-deep:    #0a0f3c;
  --blue-board:   #0d1a6b;
  --blue-cell:    #1535a8;
  --blue-hover:   #1e46c9;
  --gold:         #f5c518;
  --gold-dim:     #c9a00a;
  --gold-dark:    #7a6000;
  --white:        #ffffff;
  --off-white:    #e8eaf6;
  --gray-muted:   #8892b0;
  --green:        #22c55e;
  --red:          #ef4444;
  --cell-shadow:  0 4px 16px rgba(0,0,0,0.5);
  --modal-bg:     rgba(5, 10, 40, 0.92);
  --radius:       8px;
  --radius-lg:    14px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'DM Sans', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background-color: var(--blue-deep);
  color: var(--white);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ─── Utilities ─────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.15s, box-shadow 0.2s;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background-color: var(--gold);
  color: var(--blue-deep);
}
.btn-primary:hover:not(:disabled) {
  background-color: #ffd740;
  box-shadow: 0 0 20px rgba(245, 197, 24, 0.45);
}
.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-ghost {
  background-color: rgba(255,255,255,0.08);
  color: var(--off-white);
  border: 1px solid rgba(255,255,255,0.12);
}
.btn-ghost:hover {
  background-color: rgba(255,255,255,0.15);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 6px 14px;
}

/* ─── Header ────────────────────────────────────────────── */
header {
  width: 100%;
  padding: 18px 32px;
  border-bottom: 2px solid rgba(245, 197, 24, 0.25);
  position: relative;
  z-index: 10;
  background: linear-gradient(180deg, rgba(5,10,50,0.9) 0%, transparent 100%);
}

.header-inner {
  max-width: 1300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.logo {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow:
    0 0 30px rgba(245, 197, 24, 0.5),
    0 2px 0 var(--gold-dark);
  user-select: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 18px;
}

.score-display {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}
.score-label {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--gray-muted);
  font-weight: 600;
}
.score-value {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  transition: color 0.4s;
  line-height: 1;
}
.score-value.negative { color: var(--red); }

/* ─── Main ──────────────────────────────────────────────── */
main {
  width: 100%;
  max-width: 1300px;
  padding: 28px 24px 48px;
  position: relative;
  z-index: 10;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
}

/* ─── Topic Browser ─────────────────────────────────────── */
.topic-browser {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

/* Search row */
.browser-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topic-search {
  flex: 1;
  max-width: 420px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 16px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  color: var(--white);
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
.topic-search:focus {
  border-color: var(--gold);
  background: rgba(255,255,255,0.1);
}
.topic-search::placeholder { color: rgba(255,255,255,0.3); }

.topic-count {
  font-size: 0.78rem;
  color: var(--gray-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ─── Category Filter Chips ─────────────────────────────── */
.category-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  /* Hide scrollbar cross-browser */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.category-filters::-webkit-scrollbar { display: none; }

.filter-chip {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.13);
  background: rgba(255,255,255,0.05);
  color: var(--gray-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s;
  letter-spacing: 0.04em;
}
.filter-chip:hover {
  background: rgba(255,255,255,0.11);
  color: var(--white);
  border-color: rgba(255,255,255,0.25);
}
.filter-chip.active {
  background: rgba(245, 197, 24, 0.14);
  border-color: rgba(245, 197, 24, 0.7);
  color: var(--gold);
  box-shadow: 0 0 10px rgba(245, 197, 24, 0.12);
}

/* ─── Topic Card Grid ───────────────────────────────────── */
.topic-grid {
  display: grid;
  /* auto-fill so adding new topics just flows in naturally */
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
}

.topic-card {
  background: linear-gradient(145deg, rgba(21,53,168,0.35) 0%, rgba(10,30,120,0.35) 100%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 18px 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  transition: transform 0.18s, background 0.18s, border-color 0.18s, box-shadow 0.18s;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.topic-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(245,197,24,0.06) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.2s;
}
.topic-card:hover {
  background: linear-gradient(145deg, rgba(30,70,201,0.45) 0%, rgba(15,50,170,0.45) 100%);
  border-color: rgba(255,255,255,0.18);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.topic-card:hover::before { opacity: 1; }

.topic-card.selected {
  background: linear-gradient(145deg, rgba(245,197,24,0.12) 0%, rgba(201,160,10,0.06) 100%);
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(245,197,24,0.3), 0 4px 20px rgba(245,197,24,0.15);
  transform: translateY(-2px);
}
.topic-card.selected::before { opacity: 1; }

/* Gold checkmark badge on selected card */
.topic-card.selected::after {
  content: '✓';
  position: absolute;
  top: 7px;
  right: 9px;
  font-size: 0.65rem;
  font-weight: 900;
  color: var(--gold);
  background: rgba(245,197,24,0.15);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.topic-card-icon {
  font-size: 1.9rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}
.topic-card-name {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--white);
  line-height: 1.3;
}
.topic-card-cat {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  color: var(--gray-muted);
  text-transform: uppercase;
}

/* Empty / error states inside the grid */
.browser-empty,
.browser-error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 0;
  color: var(--gray-muted);
  font-size: 0.92rem;
}

/* Footer row with play button */
.browser-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.selected-label {
  font-size: 0.82rem;
  color: var(--gray-muted);
  flex: 1;
}
.selected-label strong { color: var(--gold); font-weight: 600; }

/* ─── Now Playing Bar ───────────────────────────────────── */
.now-playing {
  width: 100%;
  background: linear-gradient(135deg, rgba(21,53,168,0.25) 0%, rgba(10,30,100,0.2) 100%);
  border: 1px solid rgba(245,197,24,0.22);
  border-radius: var(--radius);
  padding: 11px 20px;
}
.now-playing-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.now-playing-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(34,197,94,0.6);
  flex-shrink: 0;
  animation: pulse-pip 2s ease infinite;
}
@keyframes pulse-pip {
  0%, 100% { box-shadow: 0 0 6px rgba(34,197,94,0.5); }
  50%       { box-shadow: 0 0 14px rgba(34,197,94,0.9); }
}
.now-playing-label {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--gray-muted);
  text-transform: uppercase;
}
.now-playing-topic {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}
.now-playing-spacer { flex: 1; }

/* ─── Loading State ─────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--gray-muted);
  font-size: 0.95rem;
  padding: 60px 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(245, 197, 24, 0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Jeopardy Board ────────────────────────────────────── */
.jeopardy-board {
  display: grid;
  gap: 8px;
  width: 100%;
}

.cat-header {
  background: linear-gradient(135deg, var(--blue-board) 0%, #1130a0 100%);
  border: 1px solid rgba(245, 197, 24, 0.3);
  border-radius: var(--radius);
  padding: 16px 10px;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 1.3vw, 1rem);
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--white);
  box-shadow: var(--cell-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
}

.question-cell {
  background: linear-gradient(135deg, var(--blue-cell) 0%, #0f2d9e 100%);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.2vw, 1.6rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  cursor: pointer;
  box-shadow: var(--cell-shadow);
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  opacity: 0;
  animation: cellReveal 0.4s ease forwards;
}
.question-cell:hover {
  background: linear-gradient(135deg, var(--blue-hover) 0%, #2050e0 100%);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5), 0 0 20px rgba(245, 197, 24, 0.2);
  border-color: rgba(245, 197, 24, 0.4);
}
.question-cell.answered {
  background: linear-gradient(135deg, #1a1f4a 0%, #0e1335 100%);
  color: transparent;
  cursor: default;
  pointer-events: none;
  border-color: rgba(255,255,255,0.04);
  box-shadow: none;
}
.question-cell.answered::after {
  content: '✓';
  color: rgba(255,255,255,0.15);
  font-size: 1.4rem;
}
@keyframes cellReveal {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Modal ─────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal.open { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-bg);
  backdrop-filter: blur(6px);
}

.modal-content {
  position: relative;
  z-index: 1;
  background: linear-gradient(160deg, #0d1975 0%, #071254 100%);
  border: 1px solid rgba(245, 197, 24, 0.4);
  border-radius: var(--radius-lg);
  padding: 40px 36px 36px;
  width: min(92vw, 620px);
  box-shadow:
    0 0 0 1px rgba(245, 197, 24, 0.1),
    0 32px 80px rgba(0,0,0,0.8),
    0 0 60px rgba(21, 53, 168, 0.5);
  transform: scale(0.85);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}
.modal.open .modal-content {
  transform: scale(1);
  opacity: 1;
}

.close-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--gray-muted);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
  line-height: 1;
}
.close-btn:hover { background: rgba(255,255,255,0.18); color: var(--white); }
.close-btn.hidden { display: none !important; }

.modal-category-label {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gray-muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.modal-value-label {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(245, 197, 24, 0.4);
  margin-bottom: 20px;
  line-height: 1;
}
.question-text {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  font-weight: 700;
  line-height: 1.5;
  color: var(--white);
  margin-bottom: 28px;
  min-height: 48px;
}

.timer-bar-container {
  position: relative;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  margin-bottom: 22px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold));
  border-radius: 3px;
  transform-origin: left;
  transition: transform 1s linear, background-color 0.5s;
}
.time-left-text {
  position: absolute;
  right: 0;
  top: -20px;
  font-size: 0.75rem;
  color: var(--gray-muted);
  font-weight: 600;
}

.answer-row {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
#answer {
  flex: 1;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 11px 16px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
  color: var(--white);
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#answer:focus { border-color: var(--gold); background: rgba(255,255,255,0.1); }
#answer::placeholder { color: rgba(255,255,255,0.3); }

.result-area {
  border-radius: var(--radius);
  padding: 18px 20px;
  font-size: 0.95rem;
  line-height: 1.6;
  animation: resultSlide 0.4s ease forwards;
}
.result-area.correct  { background: rgba(34,197,94,0.12);  border: 1px solid rgba(34,197,94,0.4);  color: #86efac; }
.result-area.incorrect{ background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.35); color: #fca5a5; }
.result-area.timeup   { background: rgba(245,197,24,0.1);  border: 1px solid rgba(245,197,24,0.3); color: #fde68a; }

.result-headline   { font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.result-answers    { font-size: 0.85rem; opacity: 0.85; margin-bottom: 6px; }
.result-explanation{ font-size: 0.85rem; opacity: 0.75; font-style: italic; }
.result-closing-bar{
  margin-top: 12px; height: 3px;
  background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden;
}
.result-closing-fill{
  height: 100%; width: 100%;
  background: rgba(255,255,255,0.35); transform-origin: left;
}
@keyframes resultSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .logo { font-size: 1.5rem; }
  header { padding: 14px 16px; }
  main { padding: 16px 12px 40px; gap: 14px; }
  .topic-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
  .topic-card { padding: 14px 8px 12px; }
  .topic-card-icon { font-size: 1.5rem; }
  .topic-card-name { font-size: 0.75rem; }
  .jeopardy-board { gap: 5px; }
  .cat-header { padding: 10px 6px; min-height: 54px; font-size: 0.65rem; }
  .question-cell { min-height: 56px; padding: 10px 4px; }
  .modal-content { padding: 28px 20px 24px; }
  .modal-value-label { font-size: 1.5rem; }
  .question-text { font-size: 1rem; }
  .answer-row { flex-direction: column; }
  #answer { width: 100%; }
}

@media (max-width: 480px) {
  .score-display { display: none; }
  .topic-search { max-width: 100%; }
  .topic-grid { grid-template-columns: repeat(3, 1fr); }
  .browser-footer { flex-wrap: wrap; }
}
