/* ==========================================================================
   J! Study — Main Stylesheet
   ========================================================================== */

/* --- Custom Properties --- */
:root {
  --primary: #060ce9;
  --primary-hover: #0508c0;
  --primary-light: #f0f4ff;
  --gold: #d4a017;
  --correct: #27ae60;
  --correct-bg: #d4edda;
  --correct-text: #155724;
  --correct-border: #c3e6cb;
  --wrong: #c0392b;
  --wrong-bg: #f8d7da;
  --wrong-text: #721c24;
  --wrong-border: #f5c6cb;
  --warning: #f39c12;
  --muted: #888;
  --text: #1a1a1a;
  --text-secondary: #555;
  --bg: #f5f5f5;
  --bg-white: #fff;
  --border: #ddd;
  --border-light: #eee;
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* --- Reset & Base --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-stack); color: var(--text); background: var(--bg); }
a { color: #1a5bb5; text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Navigation --- */
nav {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 52px;
  position: relative;
}
nav a { color: #fff; font-weight: 500; }
nav a:hover { text-decoration: none; opacity: 0.85; }
.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 12px 0;
  margin-right: 8px;
  white-space: nowrap;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0;
}
.nav-links a {
  padding: 14px 16px;
  font-size: 14px;
  transition: background 0.15s;
  white-space: nowrap;
}
.nav-links a:hover,
.nav-links a.active {
  background: rgba(255,255,255,0.15);
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  white-space: nowrap;
}
.nav-icon {
  font-size: 18px;
  padding: 6px;
  opacity: 0.9;
  display: flex;
  align-items: center;
}
.nav-icon:hover { opacity: 1; }
.nav-icon svg { width: 20px; height: 20px; fill: currentColor; }
.nav-avatar { width: 24px; height: 24px; border-radius: 50%; vertical-align: middle; }
.nav-user { font-size: 13px; opacity: 0.8; }
.nav-btn {
  font-size: 13px;
  padding: 5px 14px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
}
.nav-btn:hover { background: rgba(255,255,255,0.15); }

/* Hamburger toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  margin-left: auto;
  line-height: 1;
}

/* --- Container --- */
.container { max-width: 1200px; margin: 24px auto; padding: 0 24px; }

/* --- Typography --- */
h1 { margin-bottom: 16px; font-size: 24px; }
h2 { margin: 24px 0 12px; font-size: 20px; color: var(--primary); }
h3 { margin: 16px 0 8px; font-size: 16px; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; margin-bottom: 16px; background: var(--bg-white); }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: 14px; }
th { background: var(--primary); color: #fff; font-weight: 500; }
tr:hover { background: var(--primary-light); }

/* --- Pagination --- */
.pagination { margin: 16px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Forms --- */
.search-form { margin-bottom: 20px; display: flex; gap: 8px; flex-wrap: wrap; }
.search-form input[type=text] { padding: 8px 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; width: 400px; max-width: 100%; }
.search-form button { padding: 8px 16px; background: var(--primary); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }

select {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  background: var(--bg-white);
}

input[type=text], input[type=password], input[type=email] {
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}

/* --- Buttons --- */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  background: var(--bg-white);
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-correct { background: var(--correct-bg); color: var(--correct-text); border-color: var(--correct-border); }
.btn-wrong { background: var(--wrong-bg); color: var(--wrong-text); border-color: var(--wrong-border); }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* --- Tags --- */
.tag { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 600; }
.tag-right { background: var(--correct-bg); color: var(--correct-text); }
.tag-wrong { background: var(--wrong-bg); color: var(--wrong-text); }
.tag-dd { background: #fff3cd; color: #856404; }
.tag-regular { background: #e2e3e5; color: #383d41; }
.tag-tournament { background: #cce5ff; color: #004085; }
.tag-type { background: #e2e3e5; color: #383d41; font-size: 11px; }
.tag-type.special { background: #cce5ff; color: #004085; }

/* --- Cards --- */
.card { background: var(--bg-white); border: 1px solid var(--border); border-radius: 6px; padding: 16px; margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.value { font-weight: 700; color: var(--gold); }

/* --- Utility Classes --- */
.active-link { font-weight: 700; text-decoration: underline; }
.text-correct { color: var(--correct); }
.text-wrong { color: var(--wrong); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }

/* --- Progress Bars --- */
.progress-bar {
  height: 12px;
  background: var(--border-light);
  border-radius: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 6px;
}

/* --- Alert/Error --- */
.alert { padding: 10px 14px; border-radius: 4px; margin-bottom: 16px; }
.alert-error { background: var(--wrong-bg); color: var(--wrong-text); }
.alert-success { background: var(--correct-bg); color: var(--correct-text); }

/* --- Auth Forms --- */
.auth-wrap { max-width: 400px; margin: 60px auto; }
.auth-wrap label { display: block; margin-bottom: 4px; }
.auth-wrap label span { font-weight: 500; display: block; margin-bottom: 4px; }
.auth-wrap input[type=text],
.auth-wrap input[type=password],
.auth-wrap input[type=email] { width: 100%; }
.auth-wrap form { display: flex; flex-direction: column; gap: 12px; }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 10px 16px; border: 1px solid var(--border);
  border-radius: 4px; background: #fff; color: var(--text); font-size: 14px;
  font-weight: 600; text-decoration: none; cursor: pointer; transition: background 0.15s;
}
.google-btn:hover { background: #f8f8f8; color: var(--text); }
.auth-divider {
  display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--muted); font-size: 13px;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* --- Board styles (game detail & play) --- */
.board-cat { font-weight: 700; text-align: center; background: var(--primary); color: #fff; padding: 10px; font-size: 13px; text-transform: uppercase; }
.board-clue { vertical-align: top; padding: 10px; font-size: 13px; min-width: 180px; }
.board-clue .answer { color: var(--text-secondary); margin-top: 4px; font-style: italic; }
.board-clue .responders { margin-top: 4px; }
.fj-response { padding: 8px 0; border-bottom: 1px solid var(--border-light); }
.fj-response:last-child { border-bottom: none; }

/* --- Game board (play) --- */
.game-cell { cursor: pointer; text-align: center; vertical-align: middle; padding: 12px !important; min-width: 140px; }
.game-cell.unrevealed { background: var(--primary); color: var(--gold); font-weight: 700; font-size: 18px; }
.game-cell.unrevealed:hover { background: #0810ff; }
.game-cell.revealed { background: var(--bg-white); font-size: 12px; }
.game-cell.correct { background: var(--correct-bg); }
.game-cell.wrong { background: var(--wrong-bg); }
.game-cell.skipped { background: #e9ecef; color: var(--muted); }
.game-cell.revealed:hover { opacity: 0.8; }
.game-cat { font-weight: 700; text-align: center; background: var(--primary); color: #fff; padding: 10px !important; font-size: 12px; text-transform: uppercase; }

/* --- Clue Modal (play) --- */
.clue-modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; }
.clue-modal-content { background: var(--primary); color: #fff; padding: 40px; border-radius: 8px; max-width: 700px; width: 90%; text-align: center; }
.clue-modal-content .category { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; opacity: 0.8; }
.clue-modal-content .clue-text { font-size: 22px; line-height: 1.4; margin: 16px 0; }
.clue-modal-content .answer { font-size: 20px; color: var(--gold); font-weight: 700; margin: 16px 0; }
.clue-modal-content .dd-note { font-size: 12px; color: var(--warning); margin-top: 4px; }
.clue-modal-content .modal-btns { margin-top: 24px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.clue-modal-content .modal-btns button { padding: 12px 24px; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; }
.clue-modal-content .modal-btns .btn-right { background: var(--correct); color: #fff; }
.clue-modal-content .modal-btns .btn-wrong { background: var(--wrong); color: #fff; }
.clue-modal-content .modal-btns .btn-reveal { background: var(--warning); color: #fff; }
.clue-modal-content .modal-btns .btn-skip { background: #6c757d; color: #fff; }
.clue-modal-content .rescore-note { font-size: 12px; opacity: 0.7; margin-top: 8px; }
.clue-modal-content .modal-btns .active-choice { outline: 3px solid #fff; outline-offset: 2px; }

/* --- Score Chart (play) --- */
.score-bar-entry { display: flex; align-items: center; gap: 4px; margin-bottom: 2px; font-size: 11px; }
.score-bar-entry .bar { height: 14px; border-radius: 2px; min-width: 2px; }
.score-bar-entry .bar.positive { background: var(--correct); }
.score-bar-entry .bar.negative { background: var(--wrong); }
.score-bar-entry .bar.skip-bar { background: #ccc; }
.score-bar-entry .lbl { color: var(--muted); white-space: nowrap; min-width: 50px; text-align: right; }
.score-bar-entry .val { min-width: 60px; }

/* --- Round Summary (play) --- */
.round-summary { background: #f8f9fa; border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px; margin: 12px 0; }
.round-summary h3 { margin: 0 0 8px; font-size: 15px; color: var(--primary); }
.round-summary .rs-stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.round-summary .rs-cats { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }

/* --- Decade Checkbox (play) --- */
.decade-check { font-size: 14px; cursor: pointer; white-space: nowrap; }
.decade-check input { margin-right: 3px; }

/* --- Play Review --- */
.rv-cat { font-weight: 700; text-align: center; background: var(--primary); color: #fff; padding: 10px; }
.rv-cell { vertical-align: top; padding: 10px; font-size: 13px; min-width: 160px; }
.rv-correct { background: var(--correct-bg); }
.rv-wrong { background: var(--wrong-bg); }
.rv-skipped { background: #e9ecef; }
.rv-unanswered { background: var(--bg-white); opacity: 0.6; }
.rv-value { font-weight: 700; color: var(--gold); margin-bottom: 4px; }
.rv-q { font-size: 12px; color: #333; margin-bottom: 4px; }
.rv-a { font-size: 12px; color: var(--text-secondary); font-style: italic; }
.rv-tag { margin-top: 4px; font-size: 11px; font-weight: 600; }
.rv-correct .rv-tag { color: var(--correct-text); }
.rv-wrong .rv-tag { color: var(--wrong-text); }
.rv-skipped .rv-tag { color: #666; }

/* --- Chart Bars (research, answer_detail) --- */
.chart-wrap { border-top: 1px solid var(--border); padding-top: 4px; }
.chart-bars { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 20px; }
.chart-col { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 0; cursor: default; }
.chart-col:hover .chart-bar { opacity: 0.7; }
.chart-val { font-size: 10px; color: #666; height: 16px; line-height: 16px; white-space: nowrap; }
.chart-bar { min-width: 4px; border-radius: 2px 2px 0 0; transition: opacity 0.15s; }
.chart-bar-blue { background: var(--primary); }
.chart-bar-red { background: var(--wrong); }
.chart-bar-green { background: var(--correct); }
.chart-label { font-size: 10px; color: var(--muted); margin-top: 2px; height: 14px; white-space: nowrap; }

/* --- Review Page --- */
.btn-approve { background: var(--correct); color: #fff; border: none; }
.btn-reject { background: var(--wrong); color: #fff; border: none; }
tr.resolved { opacity: 0.4; }

/* --- Game Type Filter (settings) --- */
.gt-filter { position: relative; }
.gt-panel {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  max-height: 420px;
  overflow-y: auto;
}
.gt-shortcuts { padding: 8px 10px; border-bottom: 1px solid var(--border-light); display: flex; gap: 6px; }
.gt-shortcuts button {
  padding: 3px 10px; font-size: 11px; border: 1px solid #ccc;
  border-radius: 3px; cursor: pointer; background: #f8f8f8; color: #333;
}
.gt-shortcuts button:hover { background: #e8e8f8; }
.gt-item {
  display: flex; align-items: center; padding: 4px 10px; font-size: 12px;
  color: #333; cursor: pointer;
}
.gt-item:hover { background: var(--primary-light); }
.gt-item input { margin-right: 8px; cursor: pointer; }
.gt-item .gt-count { margin-left: auto; color: #999; font-size: 11px; }
.gt-apply {
  display: block; width: calc(100% - 20px); margin: 8px 10px;
  padding: 6px; background: var(--primary); color: #fff; border: none;
  border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.gt-apply:hover { background: var(--primary-hover); }

/* --- Topic Guide Page --- */
.guide-btn { display: inline-block; padding: 8px 20px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; font-weight: 600; text-decoration: none; }
.guide-btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.guide-btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }

/* --- Prose Guide --- */
.pg-content h2 { color: var(--primary); border-bottom: 2px solid var(--border-light); padding-bottom: 4px; margin: 24px 0 12px; }
.pg-content h3 { margin: 16px 0 8px; }
.pg-content ul, .pg-content ol { padding-left: 24px; margin: 8px 0; }
.pg-content li { margin: 4px 0; line-height: 1.5; }

/* --- Settings Page --- */
.settings-section { margin-bottom: 32px; }
.settings-section h2 { margin-bottom: 16px; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.settings-check {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.settings-check:hover { background: var(--primary-light); }
.settings-check input { margin-right: 8px; }
.settings-link-list { list-style: none; padding: 0; }
.settings-link-list li { padding: 8px 0; border-bottom: 1px solid var(--border-light); }
.settings-link-list li:last-child { border-bottom: none; }
.settings-link-list a { font-weight: 500; }

/* --- Tab Navigation --- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  text-decoration: none;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Homepage --- */
.home-hero { text-align: center; padding: 40px 0 28px; }
.home-title { font-size: 36px; font-weight: 800; color: var(--primary); letter-spacing: 2px; margin-bottom: 8px; }
.home-subtitle { font-size: 18px; color: #555; max-width: 600px; margin: 0 auto; }
.home-hero-actions { margin-top: 20px; display: flex; gap: 12px; justify-content: center; }
.btn-lg { padding: 14px 32px; font-size: 16px; font-weight: 600; }

.home-stats-card { margin-bottom: 20px; }
.home-stats-row { display: flex; gap: 32px; flex-wrap: wrap; }
.home-stat { text-align: center; min-width: 80px; }
.home-stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }

.home-recs { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.home-rec-card { flex: 1; min-width: 200px; max-width: 320px; text-decoration: none; color: inherit; transition: box-shadow 0.15s; }
.home-rec-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-decoration: none; color: inherit; }
.home-rec-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.home-rec-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.home-rec-dot-weak { background: var(--wrong); }
.home-rec-dot-due_review { background: var(--warning); }
.home-rec-dot-unstudied { background: var(--primary); }

.home-recent-games { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.home-game-card { flex: 1; min-width: 140px; max-width: 200px; text-decoration: none; color: inherit; text-align: center; transition: box-shadow 0.15s; }
.home-game-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); text-decoration: none; color: inherit; }
.home-game-score { font-size: 24px; font-weight: 700; color: var(--primary); }

.home-features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }
.home-feature-card { text-decoration: none; color: inherit; transition: box-shadow 0.15s, transform 0.15s; text-align: center; padding: 24px 16px; }
.home-feature-card:hover { box-shadow: 0 2px 12px rgba(6,12,233,0.12); transform: translateY(-2px); text-decoration: none; color: inherit; }
.home-feature-card h3 { margin: 10px 0 6px; color: var(--primary); }
.home-feature-card .muted { font-size: 13px; line-height: 1.5; }
.home-feature-icon { line-height: 1; }

.home-platform-stats { display: flex; justify-content: center; gap: 32px; flex-wrap: wrap; padding: 20px 0; border-top: 1px solid var(--border); margin-top: 8px; }
.home-ps-item { font-size: 14px; text-align: center; }
.home-ps-item strong { color: var(--primary); }

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* --- Tablet (768px) --- */
@media (max-width: 768px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    background: var(--primary);
    flex-direction: column;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }
  .nav-links a {
    padding: 12px 24px;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
  nav.nav-open .nav-links { display: flex; }
  .nav-right { margin-left: auto; gap: 8px; }
  .brand { margin-right: auto; }

  .container { padding: 0 16px; margin: 16px auto; }
  h1 { font-size: 20px; }
  h2 { font-size: 18px; }

  .search-form { flex-direction: column; }
  .search-form input[type=text] { width: 100%; }

  /* Stack study layout */
  .study-layout { flex-direction: column !important; }
  .study-layout > div { min-width: 0 !important; }

  /* Table scroll */
  table { display: table; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }

  /* Board horizontal scroll */
  .board-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Stack flex layouts */
  .stack-mobile { flex-direction: column !important; }

  /* Homepage */
  .home-hero { padding: 24px 0 16px; }
  .home-title { font-size: 28px; }
  .home-subtitle { font-size: 16px; }
  .home-features { grid-template-columns: repeat(2, 1fr); }
  .home-stats-row { gap: 20px; }
  .home-stat-value { font-size: 22px; }
  .home-platform-stats { gap: 20px; }
  .home-rec-card { max-width: 100%; }
}

/* --- Mobile (480px) --- */
@media (max-width: 480px) {
  .container { padding: 0 12px; margin: 12px auto; }
  h1 { font-size: 18px; }
  h2 { font-size: 16px; }
  .card { padding: 12px; }

  /* Clue modal nearly full-screen */
  .clue-modal-content {
    padding: 24px 16px;
    max-width: 100%;
    width: 96%;
    border-radius: 4px;
  }
  .clue-modal-content .clue-text { font-size: 18px; }
  .clue-modal-content .modal-btns button { padding: 10px 16px; font-size: 14px; }

  /* Game board cells smaller */
  .game-cell { min-width: 100px !important; padding: 8px !important; font-size: 14px; }
  .game-cat { padding: 6px !important; font-size: 10px; }

  .btn { padding: 8px 16px; font-size: 13px; }

  /* Filters stack */
  .filter-row { flex-direction: column; gap: 8px; }
  .filter-row select { width: 100%; }

  /* Homepage */
  .home-title { font-size: 24px; }
  .home-subtitle { font-size: 14px; }
  .home-features { grid-template-columns: 1fr; }
  .btn-lg { padding: 12px 24px; font-size: 15px; }
  .home-hero-actions { flex-direction: column; align-items: center; }
  .home-game-card { max-width: 100%; }
}
