@font-face {
  font-family: 'BankGothic';
  src: url('Fonts/bgothm.ttf') format('truetype');
  font-weight: 700;
}

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #0d0f14;
  --surface: #13161e;
  --surface2: #1a1e2a;
  --border: #252a38;
  --border-bright: #353c52;
  --accent: #e8ff47;
  --accent-dim: rgba(232,255,71,0.12);
  --accent-glow: rgba(232,255,71,0.25);
  --success: #00e5a0;
  --success-dim: rgba(0,229,160,0.12);
  --danger: #ff4d6a;
  --danger-dim: rgba(255,77,106,0.12);
  --text: #e8ecf4;
  --text-muted: #5a6282;
  --text-dim: #8892aa;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'BankGothic', 'Oswald', system-ui, sans-serif;
  --body: 'JetBrains Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--mono);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 28px 20px 48px;
  overflow-x: hidden;
}

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

.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto 0 60px;
}

/* ── Header ── */
header {
  margin-bottom: 24px;
}

header h1 {
  white-space: nowrap;
  overflow: visible;
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--text);
}

.accent { color: var(--accent); }

.subtitle {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 400;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.panel-label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-icon { font-size: 15px; line-height: 1; }

.btn.primary {
  background: var(--accent);
  min-width: 140px; /* tune to fit "Generating…" + spinner */
  color: #0d0f14;
  font-size: 16px;
  border-color: var(--accent);
}
.btn.primary:hover {
  background: #f5ff7a;
  box-shadow: 0 0 20px var(--accent-glow);
}

@keyframes btn-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-glow); }
  50%       { opacity: 0.75; box-shadow: 0 0 18px 4px var(--accent-glow); }
}
.btn.primary.generating {
  animation: btn-pulse 0.9s ease-in-out infinite;
  cursor: default;
}

.btn.success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(0,229,160,0.3);
}
.btn.success:hover {
  background: rgba(0,229,160,0.2);
  box-shadow: 0 0 14px rgba(0,229,160,0.2);
}

.btn.ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border-bright);
}
.btn.ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ─────────────────────────────────────────────
   MAIN LAYOUT
   2-row × 3-col CSS grid.
   Row 1 = topbars (auto height, all same row so they align)
   Row 2 = cards   (cards are exactly the same height by grid)
   Columns: 300px | auto | 1fr
   ───────────────────────────────────────────── */
.main-layout {
  display: grid;
  grid-template-columns: 300px auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 8px;
  align-items: end;   /* topbars bottom-align so buttons sit just above their cards */
}

/* Topbars: row 1 */
.topbar-clues   { grid-column: 1; grid-row: 1; display: flex; align-items: center; gap: 10px; }
.topbar-answers { grid-column: 2; grid-row: 1; display: flex; align-items: center; justify-content: center; }
.topbar-grid    { grid-column: 3; grid-row: 1; display: flex; align-items: center; gap: 10px; }

/* Cards: row 2 — grid forces identical height */
.clues-card   { grid-column: 1; grid-row: 2; align-self: stretch; display: flex; flex-direction: column; }
.answers-card { grid-column: 2; grid-row: 2; align-self: stretch; width: 120px; }
.grid-card    { grid-column: 3; grid-row: 2; align-self: stretch; }

/* Clues list fills card height — no extra space below last clue */
#cluesList {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* distribute clues evenly top-to-bottom */
  gap: 0;                          /* gap comes from space-between */
  list-style: none;
  counter-reset: clue-counter;
}

/* answers rows must match grid row height */
.answers-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.answer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 48px;
}

.answer-label {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}

.answer-select {
  width: 48px;
  height: 34px;
  padding: 0 4px;
  border-radius: 6px;
  border: 1px solid var(--border-bright);
  background: var(--surface2);
  color: #c8d0e8;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.answer-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.answer-select option { background: var(--surface); }

/* Feedback: sits in grid topbar row, never affects card heights */
.feedback {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex: 1;          /* grows to fill available space, never pushing timer */
  min-width: 0;     /* allows text to truncate rather than overflow */
}
.feedback.correct {
  color: var(--success);
  background: var(--success-dim);
  border-color: rgba(0,229,160,0.25);
}
.feedback.incorrect {
  color: var(--danger);
  background: var(--danger-dim);
  border-color: rgba(255,77,106,0.25);
}

.timer {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  margin-left: auto;   /* pushes it to the right edge */
}
.timer.running {
  color: var(--accent);
}
.timer.stopped {
  color: var(--success);
}

/* ── Difficulty selector ── */
.difficulty-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 4px;
}

.difficulty-label {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.difficulty-btns {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.diff-row {
  display: flex;
  gap: 3px;
}

.diff-btn {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}

.diff-btn:hover { border-color: var(--accent); color: var(--accent); }

.diff-btn.active[data-diff="easy"]   { background: rgba(0,229,160,0.15);  color: #00e5a0;       border-color: rgba(0,229,160,0.5); }
.diff-btn.active[data-diff="medium"] { background: rgba(232,255,71,0.12); color: var(--accent); border-color: rgba(232,255,71,0.5); }
.diff-btn.active[data-diff="hard"]   { background: rgba(255,160,50,0.15); color: #ffa032;       border-color: rgba(255,160,50,0.5); }
.diff-btn.active[data-diff="expert"] { background: rgba(255,77,106,0.15); color: var(--danger); border-color: rgba(255,77,106,0.5); }

/* ── Book sidebar (fixed, floats in right margin beside the grid) ── */
.books-sidebar {
  position: absolute;
  /* Sits just to the right of the centred 960px container */
  left: calc(50% + 500px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  /* Hide automatically when there's no room (container + 2×90px sidebar) */
  visibility: hidden;
}
@media (min-width: 1160px) {
  .books-sidebar { visibility: visible; }
}

.books-sidebar .books-label {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  align-self: center;
}

.books-sidebar .book-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  color: var(--text-dim);
  padding: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.2s ease;
}
.books-sidebar .book-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 14px var(--accent-glow);
}

.books-sidebar .book-cover {
  width: 120px;
  aspect-ratio: 1 / 1.3;  
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border-bright);
  display: block;
}

.books-sidebar .book-title {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .main-layout { display: flex; flex-direction: column; }
  .clues-card, .answers-card, .grid-card { width: 100%; }
  .answers-grid { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .answer-item { flex: 1 1 calc(33% - 8px); height: auto; }
  .cell { font-size: 0.8rem; height: 32px; }
}



/* ── Clues list items ── */
#cluesList li {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: #c8d0e8;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border-bright);
  line-height: 1.45;
  transition: color 0.25s ease, background 0.25s ease, border-color 0.25s ease;
  counter-increment: clue-counter;
}

#cluesList li::before {
  content: counter(clue-counter, decimal-leading-zero);
  font-size: 10px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 3px;
  letter-spacing: 0.05em;
}

.clue-placeholder {
  color: var(--text-muted) !important;
  font-style: italic;
}
.clue-placeholder::before { display: none !important; }

/* Clue states after check */
#cluesList li.clue-ok {
  color: var(--success) !important;
  background: var(--success-dim) !important;
  border-color: rgba(0,229,160,0.3) !important;
}
#cluesList li.clue-fail {
  color: var(--danger) !important;
  background: var(--danger-dim) !important;
  border-color: rgba(255,77,106,0.3) !important;
}
#cluesList li.clue-ok::before { color: rgba(0,229,160,0.5) !important; }
#cluesList li.clue-fail::before { color: rgba(255,77,106,0.5) !important; }

/* ── Elimination Grid ── */

.grid-rows {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.row-header {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  width: 28px;
  text-align: center;
  flex-shrink: 0;
  padding: 6px 0;
}

.row-cells {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  flex: 1;
}

.cell {
  aspect-ratio: 1;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface2);
  border: 1px solid var(--border-bright);
  cursor: pointer;
  user-select: none;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95rem;
  color: #c8d0e8;
  transition: all 0.04s ease;
  min-width: 0;
}

.cell:hover {
  border-color: var(--border-bright);
  color: var(--text);
  background: #1e2333;
}

.cell:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.cell.crossed {
  background: var(--bg);
  border-color: var(--border);
  color: var(--border-bright);
  font-weight: 400;
  opacity: 0.45;
}

/* ── Difficulty selector ── */
.difficulty-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.difficulty-label {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.difficulty-btns {
  display: flex;
  gap: 3px;
}

.diff-btn {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 5px 9px;
  border-radius: 5px;
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.diff-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.diff-btn.active[data-diff="easy"]   { background: rgba(0,229,160,0.15); color: #00e5a0; border-color: rgba(0,229,160,0.5); }
.diff-btn.active[data-diff="medium"] { background: rgba(232,255,71,0.12); color: var(--accent); border-color: rgba(232,255,71,0.5); }
.diff-btn.active[data-diff="hard"]   { background: rgba(255,160,50,0.15); color: #ffa032; border-color: rgba(255,160,50,0.5); }
.diff-btn.active[data-diff="expert"] { background: rgba(255,77,106,0.15); color: var(--danger); border-color: rgba(255,77,106,0.5); }

/* ── Responsive ── */
@media (max-width: 700px) {
  .main-layout {
    flex-direction: column;
  }
  .clues-card {
    width: 100%;
  }
  .answers-card {
    width: 100%;
  }
  .answers-grid {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .answer-item {
    flex: 1 1 calc(33% - 8px);
    height: auto;
  }
  .cell {
    font-size: 0.8rem;
    height: 32px;
  }
}

/* ══════════════════════════════════════════
   HEADER TOP ROW
══════════════════════════════════════════ */
.header-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

/* ══════════════════════════════════════════
   HOW TO PLAY BUTTON
══════════════════════════════════════════ */
.btn-help {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--text-dim);
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 700;
  line-height: 1;
}
.btn-help:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 18px var(--accent-glow), 0 0 6px var(--accent-dim);
}

/* ══════════════════════════════════════════
   MODAL OVERLAY
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.85);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 14px;
  width: 100%;
  max-width: 960px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  position: relative;
  overflow: hidden;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

/* ── Modal tabs ── */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 20px;
  gap: 4px;
}
.modal-tab {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 14px 18px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
}
.modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.modal-tab:hover:not(.active) { color: var(--text-dim); }

/* ── Modal body ── */
.modal-body {
  overflow-y: auto;
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.modal-body.hidden { display: none; }

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

.modal-section-title {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--accent);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.modal-section p,
.modal-section li {
  font-family: var(--mono);
  font-size: 13px;
  color: #c8d0e8;
  line-height: 1.6;
}
.modal-section ul { padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.modal-section em { color: var(--accent); font-style: normal; }

/* tip grid for controls */
.tip-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.tip-row { display: flex; gap: 12px; align-items: flex-start; }
.tip-key {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--surface2);
  border: 1px solid var(--border-bright);
  border-radius: 5px;
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 1px;
}
.tip-desc { font-family: var(--mono); font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.tip-green { color: var(--success); font-weight: 700; }
.tip-red   { color: var(--danger);  font-weight: 700; }

/* difficulty legend */
.diff-legend {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.5;
}
.diff-chip {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid;
  white-space: nowrap;
  flex-shrink: 0;
}
.diff-chip.easy   { color: #00e5a0; background: rgba(0,229,160,0.12); border-color: rgba(0,229,160,0.4); }
.diff-chip.medium { color: var(--accent); background: rgba(232,255,71,0.10); border-color: rgba(232,255,71,0.4); }
.diff-chip.hard   { color: #ffa032; background: rgba(255,160,50,0.12); border-color: rgba(255,160,50,0.4); }
.diff-chip.expert { color: var(--danger); background: rgba(255,77,106,0.12); border-color: rgba(255,77,106,0.4); }

/* ── Clue type table (tab 2) ── */
.clue-table { display: flex; flex-direction: column; gap: 4px; }

.clue-group-label {
  font-family: 'BankGothic', 'Oswald', sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  padding: 10px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-top: 6px;
}
.clue-group-label:first-child { margin-top: 0; }

.clue-row {
  display: grid;
  grid-template-columns: 220px 1fr 240px;
  gap: 12px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid rgba(37,42,56,0.5);
}
.clue-ex {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}
.clue-def {
  font-family: var(--mono);
  font-size: 12px;
  color: #c8d0e8;
  line-height: 1.5;
}
.clue-note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  text-align: right;
  line-height: 1.4;
  max-width: 180px;
}

/* ══════════════════════════════════════════
   CLUE HOVER TOOLTIPS
══════════════════════════════════════════ */
#cluesList li[data-tip] { position: relative; cursor: help; }

#cluesList li[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  background: #1e2333;
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 11px;
  color: #c8d0e8;
  line-height: 1.5;
  white-space: normal;
  width: 260px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

#cluesList li[data-tip]:hover::after {
  opacity: 1;
  transform: translateY(0);
}
