/* ===== RESET & ROOT ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0c1a12;
  --bg2:      #122019;
  --bg3:      #1a2e20;
  --card:     #172a1e;
  --card2:    #1e3326;
  --gold:     #c9982a;
  --gold2:    #e8bf5a;
  --gold3:    #f5d98a;
  --gold-dim: rgba(201,152,42,0.15);
  --gold-mid: rgba(201,152,42,0.35);
  --green:    #2ecc71;
  --red:      #e74c3c;
  --text:     #ecdec4;
  --text2:    #b0a07c;
  --text3:    #6e6048;
  --radius:   14px;
  --radius-sm:9px;
  --shadow:   0 6px 24px rgba(0,0,0,0.5);
  --transition: 0.25s ease;
  --font-main: 'Tajawal', sans-serif;
  --font-display: 'Amiri', serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.active { display: flex !important; }

/* SPLASH */
#splash {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 20%, #2a4a1e 0%, #0a1a0e 65%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.8s ease, transform 0.8s ease;
}
#splash.fade-out { opacity: 0; transform: scale(1.04); pointer-events: none; }
.splash-inner { text-align: center; animation: splashIn 0.9s cubic-bezier(0.16,1,0.3,1) forwards; }
@keyframes splashIn {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}
.splash-chest { margin-bottom: 22px; display: flex; justify-content: center; }
.chest-svg-splash {
  width: 100px; height: 75px;
  filter: drop-shadow(0 0 18px rgba(212,168,67,0.55));
  animation: chestBob 3s ease-in-out infinite;
}
@keyframes chestBob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50%       { transform: translateY(-10px) rotate(1.5deg); }
}
.splash-title {
  font-family: var(--font-display); font-size: 46px;
  color: var(--gold2); line-height: 1.2;
  text-shadow: 0 2px 24px rgba(201,152,42,0.5);
  margin-bottom: 8px;
}
.splash-sub { font-size: 15px; color: var(--text2); margin-bottom: 32px; }
.splash-dots { display: flex; gap: 8px; justify-content: center; }
.splash-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: dotBounce 1.2s ease-in-out infinite; }
.splash-dots span:nth-child(2) { animation-delay: 0.2s; }
.splash-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; }
  40%           { transform: scale(1.3); opacity: 1; }
}

/* APP */
#app { display: flex; flex-direction: column; min-height: 100vh; }
#app.hidden { display: none; }

/* TOPBAR */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg2);
  border-bottom: 1px solid var(--gold-mid);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  box-shadow: 0 1px 0 rgba(201,152,42,0.1), 0 2px 12px rgba(0,0,0,0.3);
  position: relative;
}
.topbar::after {
  content: '❖';
  position: absolute; left: 50%; transform: translateX(-50%); bottom: -9px;
  font-size: 10px; color: var(--gold-mid); background: var(--bg2); padding: 0 6px; line-height: 1; pointer-events: none;
}
.topbar-title { font-family: var(--font-display); font-size: 18px; color: var(--gold2); }
.icon-btn {
  background: none; border: none; color: var(--text2); cursor: pointer; padding: 6px; border-radius: 8px;
  display: flex; align-items: center;
  transition: color var(--transition), background var(--transition);
}
.icon-btn:hover { color: var(--gold2); background: var(--gold-dim); }

.content-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: min(260px, calc(100vw - 32px));
  background: var(--bg2);
  border: 1px solid var(--gold-mid);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 150;
  --arrow-left: 16px;
}
.content-popup.hidden { display: none !important; }
.content-popup::before {
  content: '';
  position: absolute;
  top: -8px;
  left: var(--arrow-left);
  width: 14px;
  height: 14px;
  background: var(--bg2);
  transform: rotate(45deg);
  border-top: 1px solid var(--gold-mid);
  border-left: 1px solid var(--gold-mid);
}
.content-option-btn {
  background: var(--bg3);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  text-align: right;
  padding: 12px 14px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.content-option-btn:hover {
  background: var(--card);
  border-color: var(--gold-mid);
}
.content-option-btn.active {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold2);
}

/* SEARCH BAR */
.search-bar {
  position: sticky; top: 57px; z-index: 99;
  background: var(--bg2); border-bottom: 1px solid rgba(201,152,42,0.12);
  padding: 10px 16px; display: flex; gap: 10px; align-items: center;
}
.search-bar.hidden { display: none !important; }
.search-bar input {
  flex: 1; background: var(--bg3); border: 1px solid var(--gold-mid);
  border-radius: 9px; padding: 10px 14px; color: var(--text);
  font-family: var(--font-main); font-size: 15px; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,152,42,0.1); }
.search-bar input::placeholder { color: var(--text3); }
.search-bar button { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 4px 8px; transition: color var(--transition); }
.search-bar button:hover { color: var(--gold); }

/* DRAWER */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 199; }
.overlay.hidden { display: none !important; }
.drawer {
  will-change: transform;
  position: fixed; top: 0; right: -300px; width: 280px; height: 100vh;
  background: var(--bg2); z-index: 200;
  transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
  display: flex; flex-direction: column;
  border-left: 1px solid var(--gold-mid); overflow: hidden;
}
.drawer.open { right: 0; }
.drawer-header {
  display: flex; align-items: center; gap: 10px; padding: 20px 16px 14px;
  font-family: var(--font-display); font-size: 20px; color: var(--gold2);
  border-bottom: 1px solid var(--gold-mid); position: relative;
}
.drawer-header::after {
  content: ''; position: absolute; bottom: -1px; left: 16px; right: 16px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.section-list { flex: 1; overflow-y: auto; padding: 6px 0; list-style: none; }
.section-list::-webkit-scrollbar { width: 4px; }
.section-list::-webkit-scrollbar-thumb { background: linear-gradient(180deg, var(--gold), var(--gold-dim)); border-radius: 4px; }
.section-item {
  padding: 12px 16px; cursor: pointer; font-size: 14px; color: var(--text2);
  transition: background var(--transition), color var(--transition); display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.03); position: relative;
}
.section-item:hover { background: var(--bg3); color: var(--text); }
.section-item.active { background: linear-gradient(90deg, var(--gold-dim) 0%, transparent 100%); color: var(--gold2); }
.section-item.active::before { content: ''; position: absolute; right: 0; top: 6px; bottom: 6px; width: 2px; background: var(--gold); border-radius: 1px; }
.section-item .count { font-size: 11px; background: var(--bg3); padding: 2px 8px; border-radius: 20px; color: var(--text3); font-family: var(--font-display); }
.section-item.active .count { background: var(--gold-dim); color: var(--gold); }
.drawer-footer { padding: 14px; border-top: 1px solid var(--gold-mid); display: flex; flex-direction: column; gap: 7px; }
.nav-pill {
  background: var(--bg3); border: 1px solid rgba(255,255,255,0.06); border-radius: 9px;
  padding: 10px 14px; color: var(--text2); font-family: var(--font-main); font-size: 14px;
  cursor: pointer; text-align: right; transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.nav-pill:hover { background: var(--card); color: var(--text); border-color: var(--gold-mid); }
.nav-pill.active { background: var(--gold-dim); color: var(--gold2); border-color: var(--gold-mid); }

/* MAIN / VIEWS */
main { flex: 1; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
.view { display: none; flex-direction: column; }
.view.active { display: flex; }
.view-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; gap: 8px; }
.section-badge { font-size: 13px; font-weight: 700; color: var(--gold2); background: var(--gold-dim); border: 1px solid var(--gold-mid); border-radius: 20px; padding: 4px 13px; font-family: var(--font-display); }
.counter-pill { font-size: 12px; color: var(--text3); background: var(--bg3); border-radius: 20px; padding: 4px 10px; font-family: var(--font-display); }

/* CARD LIST */
.card-list { padding: 8px 12px; display: flex; flex-direction: column; gap: 11px; }

/* ===== FLIP CARD SYSTEM ===== */
.qa-card-wrap {
  contain: layout style;
  perspective: 900px;
  animation: cardIn 0.18s ease both;
  /* height set dynamically via JS — uses auto on front, but flipper needs it */
  position: relative;
}
@keyframes cardIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.qa-card-flipper {
  /* CSS Grid trick: both faces occupy the same grid cell,
     so the wrapper height = max(front height, back height) automatically */
  display: grid;
  grid-template-columns: 1fr;
  will-change: transform;
  transform-style: preserve-3d;
  transition: transform 0.52s cubic-bezier(0.45, 0.05, 0.2, 1.0);
}
.qa-card-wrap.open .qa-card-flipper {
  transform: rotateY(180deg);
}

/* Both faces share base card styling */
.qa-face {
  grid-row: 1;
  grid-column: 1;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid rgba(201,152,42,0.18);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s;
  position: relative;
}
.qa-face::before, .qa-face::after {
  content: '✦'; position: absolute; font-size: 9px;
  color: rgba(201,152,42,0.22); pointer-events: none; line-height: 1;
  transition: color 0.25s;
}
.qa-face::before { top: 7px; right: 7px; }
.qa-face::after  { bottom: 7px; left: 7px; }
.qa-card-wrap:hover .qa-face { border-color: rgba(201,152,42,0.35); }
.qa-card-wrap:hover .qa-face::before,
.qa-card-wrap:hover .qa-face::after { color: var(--gold); }

/* FRONT */
.qa-face-front {
  /* in-flow, natural height */
}

/* BACK — same grid cell, rotated 180deg so it's hidden until flipped */
.qa-face-back {
  transform: rotateY(180deg);
  background: var(--card2);
  border-color: rgba(201,152,42,0.4);
  cursor: pointer;
}
.qa-face-back::before, .qa-face-back::after { color: var(--gold-mid); }

/* Shared header */
.qa-card-header { display: flex; align-items: flex-start; gap: 10px; padding: 14px 14px 10px; cursor: pointer; user-select: none; }
.qa-back-header { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; user-select: none; }
.qa-back-label {
  flex: 1;
  font-size: 11px; font-weight: 700; color: var(--gold); letter-spacing: 1px;
  text-transform: uppercase; font-family: var(--font-display); opacity: 0.85;
}

.qa-num {
  background: var(--gold-dim); color: var(--gold2); font-size: 12px; font-weight: 700;
  border-radius: 7px; padding: 3px 9px; white-space: nowrap; flex-shrink: 0;
  font-family: var(--font-display); border: 1px solid rgba(201,152,42,0.2);
}
.qa-question { flex: 1; font-size: 15px; font-weight: 500; line-height: 1.65; color: var(--text); }

/* Back divider */
.qa-back-divider {
  height: 1px;
  margin: 0 16px;
  background: linear-gradient(90deg, transparent, rgba(201,152,42,0.5), transparent);
}

/* Answer body on back face */
.qa-answer-body { padding: 14px 16px 16px; }
.qa-answer-text { font-size: 15.5px; line-height: 1.9; color: var(--text); font-family: var(--font-display); }

/* CHEST TOGGLE */
.qa-toggle {
  background: none; border: none; cursor: pointer; padding: 2px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; width: 32px; height: 32px;
}
.chest-icon { width: 28px; height: 21px; flex-shrink: 0; overflow: visible; transition: transform 0.25s; }
.chest-lid { transition: transform 0.38s cubic-bezier(0.34,1.56,0.64,1); transform-origin: 50% 100%; }
.chest-coins { transition: opacity 0.28s ease 0.12s, transform 0.28s ease 0.12s; opacity: 0; transform: translateY(3px); }

/* chest open state on BACK face — lid is open, coins visible */
.qa-face-back .chest-lid  { transform: rotate(-44deg) translateY(-1px); }
.qa-face-back .chest-coins { opacity: 1; transform: translateY(0); }
.qa-face-back .chest-icon  { transform: scale(1.08); }

/* Shared footer */
.qa-footer { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 14px; }
.qa-section-tag { font-size: 11px; color: var(--text3); background: var(--bg3); border-radius: 7px; padding: 2px 9px; border: 1px solid rgba(255,255,255,0.04); }

/* CARD ACTIONS (play + fav grouped) */
.card-actions { display: flex; align-items: center; gap: 4px; }

/* PLAY BUTTON */
.play-btn {
  background: none; border: none; cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  transition: color 0.2s, background 0.2s, transform 0.2s;
  flex-shrink: 0;
}
.play-btn:hover { color: var(--gold2); background: var(--gold-dim); transform: scale(1.15); }
.play-btn.playing {
  color: var(--gold2);
  background: var(--gold-dim);
  animation: audioRipple 1s ease-in-out infinite;
}
@keyframes audioRipple {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* FAV BUTTON */
.fav-btn { background: none; border: none; cursor: pointer; padding: 4px; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; transition: transform 0.2s ease; border-radius: 50%; }
.fav-btn svg { transition: fill 0.2s, stroke 0.2s; }
.fav-btn:hover { transform: scale(1.2); background: var(--gold-dim); }
.fav-btn.active { animation: coinPop 0.35s ease; }
@keyframes coinPop {
  0%  { transform: scale(1); }
  50% { transform: scale(1.45) rotate(12deg); }
  100%{ transform: scale(1); }
}

/* ===== SPARKLE PARTICLES ===== */
.sparkle-particle {
  position: fixed;
  pointer-events: none;
  z-index: 9000;
  user-select: none;
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
  line-height: 1;
  text-shadow: 0 0 6px currentColor;
}
@keyframes sparklefly {
  0%   { opacity: 1; transform: translate(calc(-50%), calc(-50%)) scale(1); }
  60%  { opacity: 0.85; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); }
}

/* Win shimmer overlay */
.win-shimmer {
  position: fixed; inset: 0; z-index: 8999; pointer-events: none;
  background: radial-gradient(ellipse at 50% 40%, rgba(240,201,106,0.13) 0%, transparent 70%);
  animation: shimmerFade 0.6s ease forwards;
}
@keyframes shimmerFade {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  100% { opacity: 0; }
}

/* NO RESULTS */
.no-results { text-align: center; padding: 60px 20px; color: var(--text3); }
.no-results-icon { font-size: 32px; color: var(--gold-mid); margin-bottom: 14px; display: block; font-family: var(--font-display); }
.no-results p { font-size: 16px; margin-bottom: 6px; color: var(--text2); }
.no-results small { font-size: 13px; }

/* QUIZ */
.quiz-setup { display: flex; flex-direction: column; align-items: center; padding: 36px 20px; gap: 18px; text-align: center; }
.quiz-chest-wrap { margin-bottom: 4px; }
.quiz-chest-svg { width: 88px; height: 66px; filter: drop-shadow(0 0 14px rgba(201,152,42,0.45)); animation: chestBob 3s ease-in-out infinite; }
.quiz-setup h2 { font-family: var(--font-display); font-size: 28px; color: var(--gold2); }
.quiz-setup p { color: var(--text2); font-size: 15px; }
.quiz-select { background: var(--bg3); border: 1px solid var(--gold-mid); border-radius: var(--radius-sm); padding: 12px 16px; color: var(--text); font-family: var(--font-main); font-size: 15px; width: 100%; max-width: 320px; outline: none; cursor: pointer; }
.quiz-select:focus { border-color: var(--gold); }
.quiz-count-row { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text2); }
.count-btns { display: flex; gap: 8px; }
.count-btn { background: var(--bg3); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; padding: 8px 16px; color: var(--text2); font-family: var(--font-main); font-size: 15px; cursor: pointer; transition: all var(--transition); }
.count-btn:hover { border-color: var(--gold-mid); color: var(--gold2); }
.count-btn.active { background: var(--gold-dim); border-color: var(--gold); color: var(--gold2); }
.start-btn {
  background: linear-gradient(135deg, #c9982a 0%, #a07820 100%);
  border: 1px solid rgba(255,220,100,0.3); border-radius: var(--radius-sm);
  padding: 14px 44px; color: #0c1a10; font-family: var(--font-main); font-size: 17px; font-weight: 800;
  cursor: pointer; transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 16px rgba(201,152,42,0.35), inset 0 1px 0 rgba(255,255,200,0.18);
  position: relative; overflow: hidden;
}
.start-btn::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 60%); pointer-events: none; }
.start-btn:hover { transform: translateY(-2px); box-shadow: 0 7px 22px rgba(201,152,42,0.45); }
.start-btn:active { transform: translateY(0); }

.quiz-game { display: flex; flex-direction: column; padding: 16px; gap: 14px; }
.quiz-game.hidden { display: none !important; }
.quiz-progress-wrap { display: flex; align-items: center; gap: 10px; }
.quiz-progress-bar { flex: 1; height: 7px; background: var(--bg3); border-radius: 4px; overflow: hidden; border: 1px solid rgba(201,152,42,0.12); }
#quizProgressFill { height: 100%; background: linear-gradient(90deg, var(--gold) 0%, var(--gold3) 100%); border-radius: 4px; transition: width 0.4s cubic-bezier(0.4,0,0.2,1); width: 0%; box-shadow: 0 0 8px rgba(201,152,42,0.4); }
#quizProgressText { font-size: 12px; color: var(--text3); white-space: nowrap; font-family: var(--font-display); }
.quiz-score-badge { background: var(--gold-dim); border: 1px solid var(--gold-mid); border-radius: 20px; padding: 6px 14px; font-size: 13px; color: var(--gold2); font-weight: 700; align-self: flex-start; font-family: var(--font-display); }
.quiz-card { background: var(--card); border-radius: var(--radius); border: 1px solid rgba(201,152,42,0.2); padding: 20px; position: relative; }
.quiz-card::before, .quiz-card::after { content: '✦'; position: absolute; font-size: 9px; color: rgba(201,152,42,0.25); line-height: 1; pointer-events: none; }
.quiz-card::before { top: 8px; right: 8px; }
.quiz-card::after  { bottom: 8px; left: 8px; }
.quiz-q-num { font-size: 12px; color: var(--gold); font-weight: 700; margin-bottom: 8px; font-family: var(--font-display); opacity: 0.8; }
.quiz-q-text { font-size: 17px; font-weight: 600; line-height: 1.7; color: var(--text); margin-bottom: 18px; }
.quiz-choices { display: flex; flex-direction: column; gap: 9px; }
.choice-btn { background: var(--bg3); border: 1.5px solid rgba(255,255,255,0.07); border-radius: var(--radius-sm); padding: 13px 16px; color: var(--text); font-family: var(--font-main); font-size: 15px; cursor: pointer; text-align: right; line-height: 1.5; transition: all var(--transition); }
.choice-btn:hover:not(:disabled) { border-color: var(--gold-mid); background: var(--gold-dim); }
.choice-btn.correct { background: rgba(46,204,113,0.12); border-color: #2ecc71; color: #2ecc71; }
.choice-btn.wrong   { background: rgba(231,76,60,0.12);  border-color: #e74c3c; color: #e98070; }
.choice-btn:disabled { cursor: default; }
.quiz-feedback { margin-top: 12px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14px; line-height: 1.6; }
.quiz-feedback.hidden { display: none; }
.quiz-feedback.correct { background: rgba(46,204,113,0.08); border: 1px solid rgba(46,204,113,0.3); color: #2ecc71; }
.quiz-feedback.wrong   { background: rgba(231,76,60,0.08);  border: 1px solid rgba(231,76,60,0.3);  color: #e98070; }
.next-btn { background: var(--card2); border: 1px solid var(--gold-mid); border-radius: var(--radius-sm); padding: 12px 22px; color: var(--gold2); font-family: var(--font-main); font-size: 15px; font-weight: 700; cursor: pointer; transition: all var(--transition); align-self: flex-end; }
.next-btn:hover { background: var(--gold-dim); }
.next-btn.hidden { display: none !important; }

.quiz-result { display: flex; flex-direction: column; align-items: center; padding: 48px 20px; gap: 16px; text-align: center; }
.quiz-result.hidden { display: none !important; }
.result-chest { width: 96px; height: 72px; filter: drop-shadow(0 0 16px rgba(201,152,42,0.5)); animation: chestBob 2.5s ease-in-out infinite; }
.quiz-result h2 { font-family: var(--font-display); font-size: 30px; color: var(--gold2); }
.result-score { font-size: 52px; font-weight: 800; color: var(--gold2); font-family: var(--font-display); text-shadow: 0 2px 14px rgba(201,152,42,0.4); }
.quiz-result p { color: var(--text2); font-size: 16px; max-width: 260px; line-height: 1.6; }

/* BOTTOM NAV */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg2); border-top: 1px solid var(--gold-mid); display: flex; height: calc(62px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); z-index: 100; box-shadow: 0 -2px 14px rgba(0,0,0,0.35); }
.bnav-btn { flex: 1; background: none; border: none; color: var(--text3); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-family: var(--font-main); font-size: 11px; transition: color var(--transition); padding: 8px 4px; position: relative; }
.bnav-btn::after { content: ''; position: absolute; bottom: 0; left: 22%; right: 22%; height: 2px; background: linear-gradient(90deg, transparent, var(--gold), transparent); transform: scaleX(0); transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1); border-radius: 1px; }
.bnav-btn.active::after { transform: scaleX(1); }
.bnav-btn.active { color: var(--gold2); }
.bnav-btn:hover { color: var(--text); }

/* SCROLLBAR */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dim) 100%);
  border-radius: 4px;
  border: 1px solid rgba(201,152,42,0.2);
}
::-webkit-scrollbar-thumb:hover { background: var(--gold2); }
::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }

/* TOAST */
.toast { position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%) translateY(10px); background: var(--card2); border: 1px solid var(--gold-mid); border-radius: 20px; padding: 9px 18px; font-size: 13px; color: var(--text); z-index: 999; opacity: 0; transition: opacity 0.3s, transform 0.3s; white-space: nowrap; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 600px) {
  .card-list  { max-width: 640px; margin: 0 auto; }
  .quiz-setup { max-width: 480px; margin: 0 auto; }
  .quiz-game  { max-width: 600px; margin: 0 auto; }
  .quiz-result{ max-width: 480px; margin: 0 auto; }
}

/* ===== ABOUT MODAL ===== */
.about-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.82);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  transition: opacity 0.3s;
}
.about-overlay.hidden {
  display: none !important;
}

.about-modal {
  background: var(--bg2);
  border: 1px solid var(--gold-mid);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px 24px 40px;
  position: relative;
  animation: modalSlideUp 0.38s cubic-bezier(0.34,1.56,0.64,1) forwards;
  /* gold top shimmer */
  box-shadow: 0 -4px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(201,152,42,0.3);
}
@keyframes modalSlideUp {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.about-modal::-webkit-scrollbar { width: 4px; }
.about-modal::-webkit-scrollbar-thumb { background: linear-gradient(180deg, var(--gold), var(--gold-dim)); border-radius: 4px; }

.about-close {
  position: absolute; top: 16px; left: 16px;
  background: var(--bg3); border: 1px solid rgba(255,255,255,0.07);
  border-radius: 50%; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2);
  transition: background 0.2s, color 0.2s;
}
.about-close:hover { background: var(--card2); color: var(--gold2); }

.about-chest {
  display: flex; justify-content: center; margin-bottom: 16px;
}
.about-chest svg {
  width: 80px; height: 60px;
  filter: drop-shadow(0 0 14px rgba(201,152,42,0.45));
  animation: chestBob 3s ease-in-out infinite;
}

.about-title {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 700;
  color: var(--gold2);
  text-align: center;
  margin-bottom: 16px;
  text-shadow: 0 2px 14px rgba(201,152,42,0.3);
}

.about-divider {
  height: 1px; margin: 16px 0;
  background: linear-gradient(90deg, transparent, var(--gold-mid), transparent);
}

.about-body {}
.about-body p {
  font-size: 14px; line-height: 1.8;
  color: var(--text2); margin-bottom: 14px;
}
.about-body p:last-of-type { margin-bottom: 0; }
.about-body strong { color: var(--text); font-weight: 700; }

.about-contact-title {
  font-size: 14px; font-weight: 700;
  color: var(--gold); letter-spacing: 0.5px;
  margin-bottom: 12px; margin-top: 4px;
  text-transform: uppercase; font-family: var(--font-display);
  opacity: 0.85;
}

.about-contact {
  list-style: none; display: flex; flex-direction: column; gap: 10px;
}
.about-contact li {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px;
}
.about-contact-label {
  font-size: 11px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.5px;
  min-width: 60px;
}
.about-contact a {
  color: var(--gold2); text-decoration: none;
  border-bottom: 1px solid rgba(201,152,42,0.3);
  padding-bottom: 1px;
  transition: color 0.2s, border-color 0.2s;
}
.about-contact a:hover { color: var(--gold3); border-color: var(--gold); }

/* About button in drawer — slightly different style */
.nav-pill-about {
  border-top: 1px solid rgba(201,152,42,0.1);
  margin-top: 4px; padding-top: 14px;
  color: var(--text3) !important;
  font-size: 13px;
}
.nav-pill-about:hover { color: var(--text2) !important; }

@media (min-width: 560px) {
  .about-overlay { align-items: center; padding: 20px; }
  .about-modal { border: 1px solid var(--gold-mid); border-radius: 22px; max-height: 80vh; }
}

/* ===== ADVANCED SEARCH ===== */

/* Scope buttons inside search bar */
.search-scope {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.scope-btn {
  background: var(--bg3);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 7px;
  padding: 5px 9px;
  color: var(--text3);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.scope-btn:hover { color: var(--text); border-color: var(--gold-mid); }
.scope-btn.active {
  background: var(--gold-dim);
  border-color: var(--gold-mid);
  color: var(--gold2);
}

/* Section filter pills row */
.search-filters {
  position: sticky;
  top: 103px; /* below search bar */
  z-index: 98;
  background: var(--bg2);
  border-bottom: 1px solid rgba(201,152,42,0.08);
  padding: 8px 12px;
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}
.search-filters::-webkit-scrollbar { height: 3px; }
.search-filters::-webkit-scrollbar-thumb { background: linear-gradient(90deg, var(--gold), var(--gold-dim)); border-radius: 4px; }
@media (hover: none) {
  .search-filters { scrollbar-width: none; }
  .search-filters::-webkit-scrollbar { display: none; }
}
.search-filters.hidden { display: none !important; }

.filter-pill {
  background: var(--bg3);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 20px;
  padding: 5px 13px;
  color: var(--text3);
  font-family: var(--font-main);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
}
.filter-pill:hover { color: var(--text); border-color: var(--gold-mid); }
.filter-pill.active {
  background: var(--gold-dim);
  border-color: var(--gold-mid);
  color: var(--gold2);
  font-weight: 600;
}

/* Highlight marks */
mark {
  background: none;
  color: var(--gold2);
  font-weight: 700;
  text-shadow: 0 0 8px rgba(201,152,42,0.6);
  border-bottom: 1px solid rgba(201,152,42,0.4);
}

/* ===== QUIZ MODES ===== */

/* Mode selector */
.quiz-mode-row {
  width: 100%; margin-bottom: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.quiz-mode-row label { font-size: 13px; color: var(--text3); }
.mode-btns { display: flex; gap: 8px; }
.mode-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--bg3); border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px; padding: 10px 14px; cursor: pointer;
  color: var(--text3); font-family: var(--font-main);
  transition: all 0.2s; min-width: 64px;
}
.mode-btn:hover { border-color: var(--gold-mid); color: var(--text); }
.mode-btn.active {
  background: var(--gold-dim); border-color: var(--gold-mid);
  color: var(--gold2);
}
.mode-icon { font-size: 18px; line-height: 1; }
.mode-label { font-size: 11px; font-weight: 600; }

/* ── BUILD mode ── */
.build-zone { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.build-answer {
  min-height: 52px; background: var(--bg3);
  border: 1px dashed rgba(201,152,42,0.3); border-radius: 12px;
  padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 7px;
  align-items: center; transition: border-color 0.2s;
}
.build-answer.build-correct { border-color: var(--green); border-style: solid; background: rgba(46,204,113,0.08); }
.build-answer.build-wrong   { border-color: var(--red);   border-style: solid; background: rgba(231,76,60,0.08); }
.build-placeholder { color: var(--text3); font-size: 13px; font-style: italic; }
.build-placed-tile {
  background: var(--gold-dim); border: 1px solid var(--gold-mid);
  color: var(--gold2); border-radius: 8px; padding: 4px 10px;
  font-size: 14px; font-family: var(--font-display);
}
.build-placed-tile.removable {
  cursor: pointer; transition: all 0.15s;
  position: relative;
}
.build-placed-tile.removable:hover {
  background: rgba(180, 40, 40, 0.2);
  border-color: rgba(220, 80, 80, 0.5);
  color: #f08080;
  transform: translateY(-1px);
}
.build-placed-tile.removable:hover::after {
  content: ' ×';
  font-size: 12px;
  opacity: 0.8;
}
.build-divider { height: 1px; background: linear-gradient(90deg, transparent, var(--gold-mid), transparent); }
.build-pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 4px 0; }
.build-tile {
  background: var(--card2); border: 1px solid rgba(201,152,42,0.2);
  color: var(--text); border-radius: 10px; padding: 7px 13px;
  font-size: 14px; font-family: var(--font-display);
  cursor: pointer; transition: all 0.18s;
}
.build-tile:hover { border-color: var(--gold-mid); color: var(--gold2); transform: translateY(-2px); }
.build-tile.placed { opacity: 0.35; background: var(--bg3); transform: none; }
.build-tile:disabled { cursor: default; }
.build-check-btn {
  align-self: center; background: var(--gold-dim);
  border: 1px solid var(--gold-mid); color: var(--gold2);
  border-radius: 12px; padding: 10px 28px; font-size: 15px;
  font-family: var(--font-main); font-weight: 700; cursor: pointer;
  transition: all 0.2s;
}
.build-check-btn:hover { background: var(--gold); color: var(--bg); }

/* ── BLANK mode ── */
.blank-zone { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.blank-text {
  background: var(--bg3); border-radius: 12px; padding: 14px 16px;
  font-size: 16px; line-height: 2; font-family: var(--font-display);
  color: var(--text); text-align: center;
}
.blank-slot {
  display: inline-block; min-width: 80px; border-bottom: 2px solid var(--gold);
  color: var(--gold); font-weight: 700; text-align: center;
  margin: 0 4px; letter-spacing: 4px;
}
.blank-filled {
  display: inline-block; padding: 1px 8px; border-radius: 6px; margin: 0 4px;
  font-weight: 700;
}
.blank-filled.correct { background: rgba(46,204,113,0.2); color: var(--green); }
.blank-filled.wrong   { background: rgba(231,76,60,0.2);  color: var(--red); }
.blank-choices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.blank-choice-btn {
  background: var(--card2); border: 1px solid rgba(201,152,42,0.2);
  color: var(--text); border-radius: 10px; padding: 8px 18px;
  font-size: 15px; font-family: var(--font-display);
  cursor: pointer; transition: all 0.18s;
}
.blank-choice-btn:hover { border-color: var(--gold-mid); color: var(--gold2); }
.blank-choice-btn.correct { background: rgba(46,204,113,0.15); border-color: var(--green); color: var(--green); }
.blank-choice-btn.wrong   { background: rgba(231,76,60,0.15);  border-color: var(--red);   color: var(--red); }

/* ── LISTEN mode ── */
.listen-zone { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.listen-play-btn {
  display: flex; align-items: center; gap: 10px;
  background: var(--gold-dim); border: 1px solid var(--gold-mid);
  color: var(--gold2); border-radius: 50px; padding: 12px 28px;
  font-size: 16px; font-family: var(--font-main); font-weight: 700;
  cursor: pointer; transition: all 0.2s;
}
.listen-play-btn:hover { background: var(--gold); color: var(--bg); }
.listen-play-btn.playing {
  background: var(--gold-dim);
  animation: audioRipple 1s ease-in-out infinite;
}
.listen-choices { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.listen-q-choice { text-align: right; font-family: var(--font-display); font-size: 14px; line-height: 1.7; }

/* ===== CONTENT PICKER ===== */
.content-picker {
  display: flex;
  gap: 8px;
  padding: 12px 16px 4px;
  flex-wrap: wrap;
}
.content-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(201,152,42,0.2);
  background: var(--bg3);
  color: var(--text2);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s;
  text-align: center;
}
.content-btn:hover {
  border-color: var(--gold-mid);
  color: var(--gold2);
}
.content-btn.active {
  background: var(--gold-dim);
  border-color: var(--gold-mid);
  color: var(--gold2);
  font-weight: 600;
}

/* ===== LTR OVERRIDES (for English and other LTR content) ===== */

/* Drawer slides from left in LTR */
[dir="ltr"] .drawer {
  right: auto;
  left: -300px;
  border-left: none;
  border-right: 1px solid var(--gold-mid);
  transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
}
[dir="ltr"] .drawer.open { left: 0; right: auto; }

/* Active section indicator bar on left in LTR */
[dir="ltr"] .section-item.active {
  background: linear-gradient(90deg, transparent 0%, var(--gold-dim) 100%);
}
[dir="ltr"] .section-item.active::before {
  right: auto;
  left: 0;
}

/* Text alignment */
[dir="ltr"] .nav-pill { text-align: left; }
[dir="ltr"] .choice-btn { text-align: left; }
[dir="ltr"] .listen-q-choice { text-align: left; }
[dir="ltr"] .section-item { text-align: left; }

/* Card answer body — allow natural LTR flow */
[dir="ltr"] .qa-answer-text { text-align: left; }
[dir="ltr"] .qa-question { text-align: left; }

/* Quiz feedback */
[dir="ltr"] .quiz-feedback { text-align: left; }

/* Build tiles answer zone */
[dir="ltr"] .build-answer { text-align: left; }
[dir="ltr"] .build-pool { justify-content: flex-start; }

/* Search input */
[dir="ltr"] #searchInput { text-align: left; }

/* Quiz select */
[dir="ltr"] .quiz-select { text-align: left; }

/* Counter pill in header */
[dir="ltr"] .view-header { flex-direction: row-reverse; }

/* Score badge */
[dir="ltr"] .quiz-score-badge { text-align: right; }

/* ===== FONT SIZE ===== */
:root {
  --font-size-base: 15px;
  --font-scale: 1;
}
/* sm=0.87, md=1, lg=1.2 — set via JS on :root */
body { font-size: calc(var(--font-size-base) * var(--font-scale)); }
.qa-question  { font-size: calc(15px * var(--font-scale)); }
.qa-answer-text { font-size: calc(15px * var(--font-scale)); }
.section-item { font-size: calc(14px * var(--font-scale)); }
.choice-btn   { font-size: calc(15px * var(--font-scale)); }
.blank-text   { font-size: calc(16px * var(--font-scale)); }
.build-tile   { font-size: calc(14px * var(--font-scale)); }
.build-placed-tile { font-size: calc(14px * var(--font-scale)); }
.about-body p { font-size: calc(14px * var(--font-scale)); }

/* ===== HIGH CONTRAST ===== */
.high-contrast {
  --bg:       #000000;
  --bg2:      #0a0a0a;
  --bg3:      #111111;
  --card:     #0d0d0d;
  --card2:    #1a1a1a;
  --gold:     #ffd700;
  --gold2:    #ffe44d;
  --gold3:    #fff0a0;
  --gold-dim: rgba(255,215,0,0.2);
  --gold-mid: rgba(255,215,0,0.5);
  --text:     #ffffff;
  --text2:    #dddddd;
  --text3:    #999999;
}

/* ===== SETTINGS OVERLAY ===== */
.settings-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
}
.settings-overlay.hidden { display: none !important; }
.settings-modal {
  background: var(--bg2);
  border: 1px solid var(--gold-mid);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px;
  padding: 0 0 env(safe-area-inset-bottom);
  animation: slideUp 0.25s cubic-bezier(0.4,0,0.2,1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--gold-mid);
  font-family: var(--font-display); font-size: 18px; color: var(--gold2);
}
.settings-close-btn {
  background: none; border: none; color: var(--text3); cursor: pointer;
  padding: 4px; border-radius: 8px; transition: color var(--transition);
}
.settings-close-btn:hover { color: var(--text); }
#settingsPanel { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 18px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.settings-label { font-size: 14px; color: var(--text2); }
.settings-btns { display: flex; gap: 8px; }
.font-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--bg3); color: var(--text2);
  cursor: pointer; transition: all var(--transition);
  font-family: var(--font-display);
}
.font-btn:nth-child(1) { font-size: 13px; }
.font-btn:nth-child(2) { font-size: 17px; }
.font-btn:nth-child(3) { font-size: 22px; }
.font-btn.active, .font-btn:hover {
  background: var(--gold-dim); border-color: var(--gold-mid); color: var(--gold2);
}
.settings-toggle {
  width: 52px; height: 28px; border-radius: 14px;
  background: var(--bg3); border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer; position: relative; transition: background var(--transition);
  flex-shrink: 0;
}
.settings-toggle.active { background: var(--gold); border-color: var(--gold); }
.toggle-knob {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text2); transition: transform var(--transition), background var(--transition);
}
.settings-toggle.active .toggle-knob {
  transform: translateX(24px); background: #0c1a12;
}
.settings-action-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--bg3); color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition);
}
.settings-action-btn:hover { background: var(--gold-dim); border-color: var(--gold-mid); color: var(--gold2); }

/* ===== CARD ACTION BUTTONS (copy + share) ===== */
.copy-btn, .share-img-btn {
  background: none; border: none; padding: 6px;
  color: var(--text3); cursor: pointer; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.copy-btn:hover, .share-img-btn:hover { color: var(--gold2); background: var(--gold-dim); }