:root {
  --bg-0: #0a0613;
  --bg-1: #130b26;
  --bg-2: #1c1140;
  --panel: rgba(28, 18, 64, 0.72);
  --panel-solid: #1a1138;
  --border: rgba(150, 120, 255, 0.22);
  --ink: #f3efff;
  --ink-soft: #b9aee6;
  --ink-dim: #8579b8;
  --gold: #ffd24a;
  --gold-deep: #f5a623;
  --purple: #8b5cf6;
  --blue: #3b82f6;
  --green: #2fd07a;
  --red: #ff5470;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --font: "Poppins", "Heebo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg-2), var(--bg-0));
  color: var(--ink);
  font-family: var(--font);
}

/* Hebrew / RTL gets a font with stronger Hebrew coverage. */
html[dir="rtl"] body { font-family: "Heebo", "Poppins", system-ui, sans-serif; }

.aurora {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(600px 400px at 15% 20%, rgba(139, 92, 246, 0.18), transparent 70%),
    radial-gradient(500px 400px at 85% 30%, rgba(59, 130, 246, 0.16), transparent 70%),
    radial-gradient(700px 500px at 50% 110%, rgba(245, 166, 35, 0.1), transparent 70%);
  z-index: 0;
}

.topbar,
.app,
.footer { position: relative; z-index: 1; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 40px);
  max-width: 1040px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.brand-mark { color: var(--gold); filter: drop-shadow(0 0 8px rgba(255, 210, 74, 0.6)); }
.brand-name { letter-spacing: 0.3px; }
.topbar-actions { display: flex; gap: 10px; }

.ghost-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  padding: 8px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--gold); }

/* ---------- Layout ---------- */
.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: clamp(8px, 3vw, 28px) clamp(16px, 4vw, 40px) 60px;
  min-height: 60vh;
}

.footer {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.8rem;
  padding: 24px 16px 36px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: clamp(20px, 4vw, 36px);
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #2a1b00;
  box-shadow: 0 10px 26px rgba(245, 166, 35, 0.35);
}
.btn-primary:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn-secondary {
  background: rgba(139, 92, 246, 0.18);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:not(:disabled):hover { border-color: var(--purple); }
.btn-block { width: 100%; }

/* ---------- Hero / upload ---------- */
.hero { text-align: center; margin-bottom: 22px; }
.hero h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  margin: 0 0 10px;
  background: linear-gradient(120deg, var(--gold), #fff 60%, var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { color: var(--ink-soft); margin: 0 auto; max-width: 560px; line-height: 1.5; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: clamp(28px, 6vw, 56px);
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
  background: rgba(255, 255, 255, 0.02);
}
.dropzone:hover,
.dropzone.drag {
  border-color: var(--gold);
  background: rgba(255, 210, 74, 0.06);
  transform: translateY(-2px);
}
.dropzone .dz-icon { font-size: 3rem; }
.dropzone h3 { margin: 12px 0 6px; }
.dropzone p { color: var(--ink-dim); margin: 0; font-size: 0.9rem; }

.feature-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 22px;
}
.feature {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.feature b { display: block; color: var(--ink); margin-bottom: 4px; }

.banner {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  border: 1px solid;
}
.banner-warn { background: rgba(245, 166, 35, 0.12); border-color: var(--gold-deep); color: #ffe2a8; }
.banner-info { background: rgba(59, 130, 246, 0.12); border-color: var(--blue); color: #bcd7ff; }

/* ---------- Setup ---------- */
.setup-grid { display: grid; gap: 20px; }
.field-label { font-weight: 700; margin: 0 0 10px; display: block; }
.field-hint { color: var(--ink-dim); font-size: 0.82rem; margin: 6px 0 0; }

.doc-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 6px;
}
.doc-summary .pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--purple); color: var(--ink); }
.chip.active {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.4), rgba(59, 130, 246, 0.3));
  border-color: var(--purple);
  color: #fff;
}

select,
input[type="text"],
input[type="number"] {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
}
select:focus,
input:focus { outline: none; border-color: var(--gold); }

.toggle-row { display: flex; align-items: center; gap: 12px; }
.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  transition: 0.2s;
  cursor: pointer;
}
.slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  inset-inline-start: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--purple); }
.switch input:checked + .slider::before { transform: translateX(20px); }
html[dir="rtl"] .switch input:checked + .slider::before { transform: translateX(-20px); }

/* ---------- Gameplay ---------- */
.game-layout { display: grid; grid-template-columns: 1fr 240px; gap: 22px; align-items: start; }
@media (max-width: 820px) {
  .game-layout { grid-template-columns: 1fr; }
  /* On mobile, drop the prize ladder — the advancement bar carries the info. */
  .ladder-box { display: none; }
  .progress-label { flex-wrap: wrap; gap: 2px 10px; font-size: 0.8rem; }
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.hud-stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  text-align: center;
  min-width: 84px;
}
.hud-stat .v { font-weight: 800; font-size: 1.1rem; color: var(--gold); }
.hud-stat .k { font-size: 0.7rem; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.82rem;
  margin-bottom: 6px;
}
.progress-label .pl-left { font-weight: 700; color: var(--ink); }
.progress-label .pl-right { color: var(--ink-soft); }

.progress-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), var(--gold));
  transition: width 0.4s ease;
}

.timer-bar { height: 6px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.timer-fill { height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); transition: width 1s linear; }
.timer-fill.danger { background: linear-gradient(90deg, var(--gold-deep), var(--red)); }

.q-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.badge {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge.easy { background: rgba(47, 208, 122, 0.18); color: var(--green); }
.badge.medium { background: rgba(245, 166, 35, 0.18); color: var(--gold); }
.badge.hard { background: rgba(255, 84, 112, 0.18); color: var(--red); }
.badge.points { background: rgba(139, 92, 246, 0.2); color: #cbb6ff; }

.question-text {
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  font-weight: 600;
  line-height: 1.45;
  margin: 6px 0 20px;
}

.choices { display: grid; gap: 12px; }
.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: start;
  background: linear-gradient(100deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}
.choice:not(:disabled):hover { border-color: var(--gold); transform: translateY(-1px); }
.choice .letter {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  font-weight: 800;
  color: var(--gold);
}
.choice.selected { border-color: var(--gold); background: linear-gradient(100deg, rgba(255,210,74,0.18), rgba(245,166,35,0.12)); }
.choice.correct {
  border-color: var(--green);
  background: linear-gradient(100deg, rgba(47, 208, 122, 0.25), rgba(47, 208, 122, 0.1));
  animation: pop 0.4s ease;
}
.choice.wrong {
  border-color: var(--red);
  background: linear-gradient(100deg, rgba(255, 84, 112, 0.25), rgba(255, 84, 112, 0.1));
  animation: shake 0.4s ease;
}
.choice.removed { opacity: 0.25; text-decoration: line-through; pointer-events: none; }
.choice:disabled { cursor: default; }

@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.03); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.actions-row { display: flex; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

.feedback {
  margin-top: 18px;
  border-radius: 12px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  animation: fadeUp 0.3s ease;
}
.feedback.ok { border-color: var(--green); }
.feedback.bad { border-color: var(--red); }
.feedback .verdict { font-weight: 800; margin-bottom: 6px; }
.feedback .verdict.ok { color: var(--green); }
.feedback .verdict.bad { color: var(--red); }
.feedback .explanation { color: var(--ink-soft); line-height: 1.5; }
.feedback .source { margin-top: 8px; font-size: 0.82rem; color: var(--ink-dim); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Lifelines + ladder side panel */
.side-panel { display: grid; gap: 18px; }
.panel-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.panel-box h4 { margin: 0 0 12px; font-size: 0.85rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.5px; }
.lifelines { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lifeline {
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  cursor: pointer;
  text-align: center;
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink);
  transition: all 0.15s ease;
}
.lifeline .ico { font-size: 1.3rem; display: block; margin-bottom: 4px; }
.lifeline .count { color: var(--ink-dim); font-size: 0.72rem; }
.lifeline:not(:disabled):hover { border-color: var(--gold); transform: translateY(-1px); }
.lifeline:disabled { opacity: 0.35; cursor: not-allowed; }

.ladder { display: flex; flex-direction: column-reverse; gap: 4px; }
.rung {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--ink-dim);
}
.rung .lv { font-weight: 700; }
.rung.done { color: var(--green); }
.rung.current {
  background: linear-gradient(90deg, rgba(255, 210, 74, 0.25), transparent);
  color: var(--gold);
  font-weight: 700;
}

.lifeline-popup {
  margin-top: 14px;
  border: 1px dashed var(--gold-deep);
  background: rgba(245, 166, 35, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
  color: #ffe2a8;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: fadeUp 0.3s ease;
}
.lifeline-popup .src { display:block; margin-top:6px; color: var(--ink-dim); font-size: 0.78rem; }

/* ---------- Results ---------- */
.score-hero { text-align: center; margin-bottom: 24px; }
.score-hero .big {
  font-size: clamp(2.6rem, 9vw, 4.5rem);
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255, 210, 74, 0.4);
}
.score-hero .sub { color: var(--ink-soft); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat-card { background: rgba(255,255,255,0.04); border: 1px solid var(--border); border-radius: 12px; padding: 16px; text-align: center; }
.stat-card .v { font-size: 1.6rem; font-weight: 800; }
.stat-card .v.good { color: var(--green); }
.stat-card .v.bad { color: var(--red); }
.stat-card .k { font-size: 0.78rem; color: var(--ink-dim); margin-top: 4px; }

.review-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: rgba(0, 0, 0, 0.18);
}
.review-item .q { font-weight: 600; margin-bottom: 8px; }
.review-line { font-size: 0.88rem; margin: 3px 0; }
.review-line.you-wrong { color: var(--red); }
.review-line.correct { color: var(--green); }
.review-line.expl { color: var(--ink-soft); }

.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { background: rgba(255, 84, 112, 0.14); border: 1px solid var(--red); color: #ffb3c1; border-radius: 999px; padding: 5px 12px; font-size: 0.82rem; }
.tag.rev { background: rgba(59,130,246,0.14); border-color: var(--blue); color: #bcd7ff; }

/* ---------- Loader ---------- */
.loader { text-align: center; padding: 50px 20px; }
.spinner {
  width: 54px;
  height: 54px;
  border: 5px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--gold);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader h3 { margin: 0 0 6px; }
.loader p { color: var(--ink-dim); }

.section-title { font-size: 1.05rem; font-weight: 700; margin: 26px 0 12px; }

/* ---------- Library / Admin pages ---------- */
.brand { cursor: pointer; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.page-head h2 { margin: 0 0 4px; }

.empty-state { text-align: center; padding: 36px 16px; }
.empty-state .dz-icon { font-size: 3rem; }
.empty-state h3 { margin: 10px 0 4px; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.book-card {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.book-card:hover { border-color: var(--gold); transform: translateY(-3px); box-shadow: var(--shadow); }
.book-cover {
  font-size: 2.4rem;
  height: 64px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(59, 130, 246, 0.18));
  border-radius: 10px;
  margin-bottom: 12px;
}
.book-title { font-weight: 700; line-height: 1.35; margin-bottom: 6px; }
.book-info { color: var(--ink-soft); font-size: 0.82rem; line-height: 1.4; margin-bottom: 8px; }
.book-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.book-pills .pill { font-size: 0.72rem; padding: 4px 9px; }
.book-meta { color: var(--ink-dim); font-size: 0.76rem; margin-top: 8px; }

.lock-box { text-align: center; padding: 28px 16px; display: flex; flex-direction: column; align-items: center; }
.lock-box .dz-icon { font-size: 2.6rem; margin-bottom: 8px; }
.lock-box input { margin-top: 6px; }

.manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.18);
}
.manage-info { flex: 1; min-width: 0; }
.manage-title { font-weight: 600; }
.manage-actions { display: flex; gap: 8px; flex: none; flex-wrap: wrap; }
.reorder-col { display: flex; flex-direction: column; gap: 3px; flex: none; }
.reorder-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  width: 30px;
  height: 24px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1;
}
.reorder-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.reorder-btn:not(:disabled):hover { border-color: var(--gold); color: var(--ink); }

.bank-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.bank-total { font-size: 0.8rem; font-weight: 700; color: var(--ink); }
.bank-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.bank-badge.easy { background: rgba(47, 208, 122, 0.16); color: var(--green); }
.bank-badge.medium { background: rgba(245, 166, 35, 0.16); color: var(--gold); }
.bank-badge.hard { background: rgba(255, 84, 112, 0.16); color: var(--red); }
.bank-building { font-size: 0.72rem; color: var(--gold); }
.bank-bar {
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 7px;
  max-width: 320px;
}
.bank-bar-fill { height: 100%; background: linear-gradient(90deg, var(--purple), var(--gold)); transition: width 0.4s ease; }
.ghost-btn.danger { color: #ffb3c1; border-color: rgba(255, 84, 112, 0.5); }
.ghost-btn.danger:hover { border-color: var(--red); color: #fff; }

/* ---------- Mobile / small screens ---------- */
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .brand-name { font-size: 0.95rem; }
  .ghost-btn { padding: 7px 11px; font-size: 0.78rem; }
  .app { padding: 8px 12px 48px; }
  .card { padding: 18px 15px; border-radius: 14px; }

  .hud { gap: 8px; }
  .hud-stat { min-width: 0; flex: 1; padding: 7px 6px; }
  .hud-stat .v { font-size: 1rem; }

  .question-text { margin: 4px 0 16px; }
  .choice { padding: 12px 13px; font-size: 0.95rem; gap: 10px; }
  .choice .letter { width: 30px; height: 30px; }

  .actions-row { gap: 10px; }
  .actions-row .btn { flex: 1; min-width: 0; padding: 13px 14px; }

  .lifelines { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .lifeline { padding: 10px 4px; font-size: 0.7rem; }
  .lifeline .ico { font-size: 1.15rem; }

  .feature-row { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .doc-summary .pill { font-size: 0.74rem; }
}

/* Avoid iOS zoom-on-focus by keeping inputs at >=16px on phones. */
@media (max-width: 600px) {
  select, input[type="text"], input[type="number"] { font-size: 16px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  inset-inline: 0;
  bottom: 26px;
  margin: 0 auto;
  width: max-content;
  max-width: 90%;
  background: var(--panel-solid);
  border: 1px solid var(--gold-deep);
  color: var(--ink);
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
  animation: fadeUp 0.25s ease;
}
