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

/* =========================================================
   CSS Custom Properties (Sophisticated Dark Palette)
   ========================================================= */
:root {
  /* New sophisticated palette:
     #22223b (Dark background)
     #4a4e69 (Surface/Secondary bg)
     #9a8c98 (Tertiary/Border/Muted text)
     #c9ada7 (Accent/Highlight)
     #f2e9e4 (Primary text/Bright accent)
  */
  --bg:              #22223b;
  --surface:         rgba(74, 78, 105, 0.4); 
  --surface-solid:   #4a4e69;
  --surface2:        rgba(154, 140, 152, 0.15);
  
  --accent:          #c9ada7;
  --accent-hover:    #f2e9e4;
  --accent-soft:     rgba(201, 173, 167, 0.15);
  
  --success:         #6ba292;
  --success-soft:    rgba(107, 162, 146, 0.15);
  --danger:          #d96c75;
  --danger-soft:     rgba(217, 108, 117, 0.15);
  --warning:         #d9a05b;

  --border:          rgba(154, 140, 152, 0.25);
  --border-focus:    #c9ada7;
  
  --text:            #f2e9e4;
  --text-2:          #c9ada7;
  --text-3:          #9a8c98;

  --radius:          12px;
  --radius-lg:       20px;
  --sidebar-w:       280px;
  
  --shadow-sm:       0 4px 12px rgba(0,0,0,0.15);
  --shadow:          0 8px 24px rgba(0,0,0,0.25);
  --shadow-lg:       0 16px 48px rgba(0,0,0,0.35);
  --transition:      250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Glassmorphism */
  --glass-bg:        rgba(34, 34, 59, 0.6);
  --glass-border:    rgba(242, 233, 228, 0.08);
  --glass-shadow:    0 12px 40px rgba(0,0,0,0.4);

  --gradient-accent: linear-gradient(135deg, #9a8c98, #c9ada7);
  --gradient-hero:   linear-gradient(135deg, rgba(74,78,105,0.6) 0%, rgba(34,34,59,0.8) 100%);
}

/* =========================================================
   Animations
   ========================================================= */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(15px); }
  to   { opacity: 1; transform: none; }
}

@keyframes optionPulse {
  0%   { box-shadow: 0 0 0 0 rgba(201, 173, 167, 0.4); }
  70%  { box-shadow: 0 0 0 10px rgba(201, 173, 167, 0); }
  100% { box-shadow: 0 0 0 0 rgba(201, 173, 167, 0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(15px); }
  to   { opacity: 1; transform: none; }
}

@keyframes floatBackground1 {
  0%, 100% { transform: translate(0, 0) scale(1) rotate(0deg); }
  33% { transform: translate(15vw, 10vh) scale(1.1) rotate(45deg); }
  66% { transform: translate(-10vw, 20vh) scale(0.9) rotate(-15deg); }
}

@keyframes floatBackground2 {
  0%, 100% { transform: translate(0, 0) scale(1) rotate(0deg); }
  33% { transform: translate(-15vw, -15vh) scale(1.2) rotate(-30deg); }
  66% { transform: translate(10vw, -20vh) scale(0.8) rotate(20deg); }
}

@keyframes shimmer {
  from { background-position: -200% 0; }
  to   { background-position: 200% 0; }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  overflow-x: hidden;
  max-width: 100vw;
}

/* Margin Utilities */
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 24px; }
.mb-6 { margin-bottom: 32px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }

/* Abstract Floating Geometric Shapes Background */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
  filter: blur(80px);
  z-index: -1;
  opacity: 0.4;
  pointer-events: none;
}
body::before {
  width: 50vw;
  height: 50vw;
  max-width: 600px;
  max-height: 600px;
  background: var(--surface-solid);
  top: -10%;
  left: -10%;
  animation: floatBackground1 25s infinite ease-in-out;
}
body::after {
  width: 60vw;
  height: 60vw;
  max-width: 700px;
  max-height: 700px;
  background: #9a8c98;
  bottom: -15%;
  right: -10%;
  animation: floatBackground2 30s infinite ease-in-out;
  animation-delay: -5s;
}

.selectable { user-select: text; -webkit-user-select: text; }

img { max-width: 100%; height: auto; display: block; box-sizing: border-box; }

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); text-decoration: none; }

/* =========================================================
   Glass utility class
   ========================================================= */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* =========================================================
   Layout: App shell
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 64px;
  background: rgba(34, 34, 59, 0.4);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  letter-spacing: -0.01em;
  text-transform: uppercase;
}
.app-header .logo:hover { opacity: 0.8; }
.logo-img { height: 36px; width: auto; object-fit: contain; border-radius: 8px; }

.header-spacer { flex: 1; }

.app-sidebar {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--glass-border);
  padding: 20px 0;
  overflow-y: auto;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
}

.app-main {
  padding: 32px;
  overflow-y: auto;
  min-height: calc(100vh - 64px);
  min-width: 0;
}

/* =========================================================
   Page-specific overrides
   ========================================================= */
.page-quiz .app-sidebar,
.page-math .app-sidebar { display: none; }

.page-quiz .app,
.page-math .app { grid-template-columns: 1fr; }

.page-quiz .app-main,
.page-math .app-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

.page-editor .app-sidebar { display: none; }
.page-editor .app { grid-template-columns: 1fr; }
.page-editor .app-main { padding: 0; }

/* =========================================================
   Typography
   ========================================================= */
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 12px; }
h2 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 1.1rem; font-weight: 600; }

.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.text-muted { color: var(--text-3); }
.text-faint { color: rgba(154, 140, 152, 0.6); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--text-2);
  color: var(--bg);
  box-shadow: 0 4px 12px rgba(201, 173, 167, 0.3);
}
.btn-primary:hover { 
  background: var(--text); 
  color: var(--bg) !important;
  box-shadow: 0 6px 16px rgba(242, 233, 228, 0.4); 
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
  backdrop-filter: blur(10px);
}
.btn-secondary:hover { 
  border-color: var(--accent); 
  background: var(--surface);
  transform: translateY(-2px);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px rgba(217, 108, 117, 0.3);
}
.btn-danger:hover { background: #e07a82; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(217, 108, 117, 0.4); }

.btn-sm  { padding: 6px 12px; font-size: 0.8125rem; border-radius: 8px; }
.btn-lg  { padding: 14px 28px; font-size: 1rem; border-radius: 14px; }
.btn-icon { padding: 8px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }

.btn-group { display: flex; gap: 8px; }

/* =========================================================
   Form Controls
   ========================================================= */
label { font-size: 0.85rem; font-weight: 600; color: var(--text-3); display: block; margin-bottom: 6px; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: rgba(34, 34, 59, 0.5);
  color: var(--text);
  transition: all var(--transition);
  outline: none;
  font-family: inherit;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: rgba(34, 34, 59, 0.8);
  box-shadow: 0 0 0 4px rgba(201, 173, 167, 0.15);
}

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer; flex-shrink: 0;
  border-radius: 4px;
}
.checkbox-row span { font-size: 0.9rem; font-weight: 500; color: var(--text); }

/* =========================================================
   Card
   ========================================================= */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
}
.card-sm { padding: 18px 20px; border-radius: var(--radius); }

/* =========================================================
   Badge
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge-math    { background: rgba(154, 140, 152, 0.2); color: #e2d4e1; border: 1px solid rgba(154, 140, 152, 0.3); }
.badge-general { background: rgba(74, 78, 105, 0.4); color: #c9ada7; border: 1px solid rgba(74, 78, 105, 0.5); }
.badge-success { background: var(--success-soft); color: var(--success); border: 1px solid rgba(107, 162, 146, 0.3); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); border: 1px solid rgba(217, 108, 117, 0.3); }

/* =========================================================
   Progress Bar
   ========================================================= */
.progress-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}
.progress-fill {
  height: 100%;
  background: var(--gradient-accent);
  border-radius: 999px;
  transition: width 400ms cubic-bezier(.4,0,.2,1);
  box-shadow: 0 0 10px rgba(201, 173, 167, 0.5);
}

/* =========================================================
   Navigation Dots
   ========================================================= */
.nav-dots { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; }

.nav-dots-scroller {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 24px 0;
}
.nav-dots-scroller .nav-dots-row {
  flex: 1;
  min-width: 0;
}

.nav-dots-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}
.nav-dots-btn:hover { border-color: var(--accent); color: var(--text); }
.nav-dots-btn:disabled { opacity: 0.25; pointer-events: none; }

.nav-dots-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 5px 2px 8px;
  width: 100%;
  min-width: 0;
}
.nav-dots-row::-webkit-scrollbar { display: none; }
.nav-dot {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-3);
  transition: all var(--transition);
}
.nav-dot:hover           { border-color: var(--accent); color: var(--text); transform: translateY(-2px); }
.nav-dot.answered        { background: var(--surface-solid); border-color: var(--surface-solid); color: var(--text); }
.nav-dot.current         { background: var(--accent); border-color: var(--accent); color: var(--bg); box-shadow: 0 0 10px rgba(201, 173, 167, 0.55); transform: scale(1.1); position: relative; z-index: 1; }
.nav-dot.correct         { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.nav-dot.incorrect       { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }


/* =========================================================
   Option Items
   ========================================================= */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin: 24px 0;
}
@media(min-width: 768px) {
  .options-grid { grid-template-columns: 1fr 1fr; }
}

.option-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  -webkit-user-select: none;
  min-height: 64px;
}
.option-item .option-label-text {
  user-select: text;
  -webkit-user-select: text;
  font-size: 0.95rem;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
}
.option-label-text img {
  max-width: 100%;
  height: auto;
  max-height: 100px;
  object-fit: contain;
  display: block;
  border-radius: var(--radius);
}
.option-item:hover { 
  background: var(--surface); 
  border-color: rgba(154, 140, 152, 0.4);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.option-item.selected {
  border-color: var(--accent);
  background: rgba(201, 173, 167, 0.1);
  animation: optionPulse .4s ease;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(201, 173, 167, 0.15);
}
.option-item.correct  { border-color: var(--success); background: var(--success-soft); }
.option-item.incorrect { border-color: var(--danger); background: var(--danger-soft); }

.option-key {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface-solid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  flex-shrink: 0;
  color: var(--text-3);
  transition: all var(--transition);
}
.option-item:hover .option-key { color: var(--text); background: var(--surface-solid); }
.option-item.selected  .option-key { background: var(--accent); color: var(--bg); }
.option-item.correct   .option-key { background: var(--success); color: var(--bg); }
.option-item.incorrect .option-key { background: var(--danger); color: var(--bg); }

/* =========================================================
   Tabs
   ========================================================= */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--surface2);
  padding: 4px;
  border-radius: 12px;
  width: fit-content;
}
.tab-btn {
  padding: 8px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-3);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow-sm); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeInUp 0.3s ease; }

/* =========================================================
   Table (Editor)
   ========================================================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--glass-bg); backdrop-filter: blur(10px); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  background: rgba(34, 34, 59, 0.8);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th:hover { color: var(--text); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(154, 140, 152, 0.1); }
.td-truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =========================================================
   Modal
   ========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 26, 0.6);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeInUp .2s ease;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--glass-bg);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-sm { max-width: 460px; }

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  background: rgba(34, 34, 59, 0.8);
  backdrop-filter: blur(20px);
  z-index: 1;
}
.modal-header h2 { flex: 1; font-size: 1.25rem; margin-bottom: 0; }
.modal-body { padding: 28px; flex: 1; }
.modal-footer {
  padding: 16px 28px;
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(34, 34, 59, 0.4);
}

/* =========================================================
   Sidebar (editor only)
   ========================================================= */
.sidebar-section { padding: 0 16px; margin-bottom: 24px; }
.sidebar-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
  padding: 0 12px;
  margin-bottom: 10px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.sidebar-item:hover  { background: var(--surface2); color: var(--text); transform: translateX(4px); }
.sidebar-item.active { background: var(--surface-solid); color: var(--text); font-weight: 700; box-shadow: var(--shadow-sm); }

/* =========================================================
   Theme Toggle (Hidden if we force dark, but keeping styles)
   ========================================================= */
#theme-toggle { display: none; }

/* =========================================================
   Question Card
   ========================================================= */
.question-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 40px;
  position: relative;
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}
.question-card.fade-in { animation: fadeInUp .3s ease; }

.question-id-badge {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 0.75rem;
  color: var(--text-3);
  opacity: 0.6;
  font-family: 'SF Mono', monospace;
}

.question-text {
  font-size: 1.1rem;
  line-height: 1.8;
  font-weight: 500;
  margin-bottom: 8px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.question-text img {
  max-width: 100%;
  width: auto;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius);
  margin: 16px auto;
  cursor: zoom-in;
  transition: transform var(--transition);
  background: rgba(154, 140, 152, 0.1);
  padding: 8px;
  display: block;
  box-sizing: border-box;
}
.question-text img:hover { transform: scale(1.02); }

/* =========================================================
   Quiz fixed bar (sticky progress/actions)
   ========================================================= */
.quiz-fixed-bar {
  position: sticky;
  top: 64px;
  z-index: 90;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-sm);
}
.quiz-fixed-title {
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =========================================================
   Score Display
   ========================================================= */
.score-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}
.score-big {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 4px 20px rgba(201, 173, 167, 0.4);
}
.score-big-sm {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
}
.score-label { font-size: 1rem; font-weight: 500; color: var(--text-3); margin-top: 12px; }

.session-score-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

/* =========================================================
   Quiz timer
   ========================================================= */
.quiz-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(154, 140, 152, 0.4);
  background: var(--surface-solid);
  flex-shrink: 0;
}
.quiz-timer.warning { color: var(--bg); background: var(--warning); border-color: var(--warning); }
.quiz-timer.danger  { color: #fff; background: var(--danger); border-color: var(--danger); animation: optionPulse 1s infinite; }

/* =========================================================
   Quiz navigation row
   ========================================================= */
.quiz-nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
  flex-wrap: wrap;
}
#q-counter { font-weight: 600; font-size: 1rem; color: var(--text-3); }

/* =========================================================
   Results page
   ========================================================= */
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 24px;
}
@media(min-width: 900px) {
  .results-grid { grid-template-columns: 1fr 1fr; }
}

.type-breakdown-table td, .type-breakdown-table th { padding: 10px 14px; }

.mistake-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--surface2);
  overflow: hidden;
  transition: all var(--transition);
}
.mistake-item:hover { border-color: var(--text-3); transform: translateY(-2px); box-shadow: var(--shadow-sm); }

.mistake-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(74, 78, 105, 0.2);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  overflow: hidden;
}
.mistake-header:hover { background: rgba(74, 78, 105, 0.4); }
.mistake-body {
  padding: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.95rem;
  background: rgba(34, 34, 59, 0.4);
}
.mistake-body.hidden { display: none; }

/* =========================================================
   History bars
   ========================================================= */
.history-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-bar:last-child { border-bottom: none; }
.history-score { font-weight: 800; color: var(--accent); min-width: 48px; }
.history-meta  { color: var(--text-3); font-size: 0.8rem; font-weight: 500; }

/* =========================================================
   Index page (Dashboard)
   ========================================================= */
.index-hero {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 60px 48px;
  color: var(--text);
  margin-bottom: 48px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.index-hero::before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(135deg, rgba(201, 173, 167, 0.1) 0%, rgba(154, 140, 152, 0.05) 100%);
  pointer-events: none;
}
.index-hero h1 { font-size: 2.5rem; margin-bottom: 12px; font-weight: 800; }
.index-hero p  { color: var(--text-2); font-size: 1.1rem; font-weight: 500; max-width: 600px; }
.index-hero .hero-logo { 
  height: 64px; 
  width: auto; 
  margin-bottom: 24px; 
  border-radius: 16px; 
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.subject-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.subject-card:hover { 
  border-color: var(--accent); 
  box-shadow: 0 16px 40px rgba(0,0,0,0.3), inset 0 0 20px rgba(201, 173, 167, 0.05); 
  transform: translateY(-4px); 
}

.subject-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.subject-card-name   { font-weight: 700; font-size: 1.1rem; line-height: 1.4; }
.subject-card-meta   { font-size: 0.85rem; font-weight: 600; color: var(--text-3); margin-top: 6px; }

.subject-card-history { display: flex; gap: 8px; flex-wrap: wrap; }
.history-pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(154, 140, 152, 0.15);
  color: var(--text-2);
  border: 1px solid rgba(154, 140, 152, 0.3);
}

.subject-card-actions { display: flex; gap: 12px; margin-top: auto; }
.subject-card-actions .btn { flex: 1; }

.settings-drawer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 400ms cubic-bezier(0.4, 0, 0.2, 1), padding 400ms ease, opacity 400ms ease;
  opacity: 0;
}
.settings-drawer.open { max-height: 600px; padding-top: 12px; opacity: 1; }
.settings-drawer .form-row { margin-bottom: 12px; }

/* =========================================================
   History section on index
   ========================================================= */
.history-section { margin-top: 60px; }
.history-section h2 { margin-bottom: 24px; }

.history-subject-group { margin-bottom: 28px; }
.history-subject-label { 
  font-size: 0.85rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-2); margin-bottom: 12px; 
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  margin-bottom: 8px;
  transition: all var(--transition);
}
.history-entry:hover { 
  background: rgba(154, 140, 152, 0.2); 
  border-color: var(--accent); 
  transform: translateX(6px); 
}
.history-entry-score { font-weight: 800; color: var(--accent); min-width: 80px; font-size: 1.1rem; }
.history-entry-meta  { color: var(--text-3); font-size: 0.85rem; font-weight: 500; flex: 1; }
.history-entry-badge { flex-shrink: 0; }

/* =========================================================
   Editor toolbar (data-grid layout)
   ========================================================= */
.editor-toolbar {
  position: sticky;
  top: 64px;
  z-index: 90;
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  background: rgba(34, 34, 59, 0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  min-height: 64px;
}
.editor-toolbar .toolbar-spacer { flex: 1; min-width: 16px; }

.editor-table-wrap {
  height: calc(100vh - 64px - 64px);
  overflow-y: auto;
}
.editor-content { padding: 24px 32px; }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.toolbar-spacer { flex: 1; }

.drop-zone {
  border: 2px dashed rgba(154, 140, 152, 0.5);
  border-radius: var(--radius-lg);
  padding: 60px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-3);
  font-weight: 600;
  font-size: 1.1rem;
  background: rgba(34, 34, 59, 0.3);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(201, 173, 167, 0.1);
  color: var(--text);
  transform: scale(1.01);
}

.prompt-block {
  background: rgba(11, 11, 26, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text-2);
  user-select: none;
  -webkit-user-select: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.prompt-copy-btn { width: 100%; margin-top: 12px; }

details.prompt-details summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-3);
  padding: 8px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.prompt-details summary::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border: 6px solid transparent;
  border-left-color: currentColor;
  transition: transform 200ms ease;
}
details.prompt-details[open] summary::before { transform: rotate(90deg); }

.help-steps { display: flex; flex-direction: column; }
.help-step {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
}
.step-num {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.step-body h3 { font-size: 1.05rem; margin-bottom: 6px; color: var(--text); }
.step-body p  { font-size: 0.95rem; color: var(--text-3); }

.type-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.type-chip {
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid rgba(154, 140, 152, 0.4);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface2);
  color: var(--text-3);
}
.type-chip.on { background: var(--accent); border-color: var(--accent); color: var(--bg); box-shadow: 0 4px 12px rgba(201, 173, 167, 0.3); }
.type-chip:hover:not(.on) { border-color: var(--accent); color: var(--text); }

.preview-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  background: rgba(34, 34, 59, 0.6);
}
.preview-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.preview-option {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(154, 140, 152, 0.3);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(74, 78, 105, 0.2);
}
.preview-option.correct-opt { border-color: var(--success); background: var(--success-soft); }

.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.preview-pane {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 24px;
  font-size: 0.95rem;
  min-height: 160px;
  border: 1px solid var(--border);
}

/* =========================================================
   Divider & Spacing helpers
   ========================================================= */
.divider { height: 1px; background: var(--border); margin: 24px 0; }
.mt-2  { margin-top: 8px; }
.mt-3  { margin-top: 12px; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-2  { margin-bottom: 8px; }
.mb-3  { margin-bottom: 12px; }
.mb-4  { margin-bottom: 16px; }
.flex  { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* =========================================================
   Empty state
   ========================================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  text-align: center;
  color: var(--text-3);
  gap: 16px;
}
.empty-state svg { opacity: 0.5; color: var(--accent); }
.empty-state p   { font-size: 1rem; font-weight: 500; }

/* =========================================================
   Toast / Notification
   ========================================================= */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.toast {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn 300ms cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 360px;
  color: var(--text);
}
.toast.success { border-left: 4px solid var(--success); }
.toast.danger  { border-left: 4px solid var(--danger); }

/* =========================================================
   Image zoom overlay
   ========================================================= */
.img-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 26, 0.9);
  backdrop-filter: blur(8px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 24px;
  animation: fadeInUp .2s ease;
}
.img-overlay.hidden { display: none; }
.img-overlay img {
  max-width: 100%;
  width: auto;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  touch-action: pinch-zoom;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  display: block;
}

/* =========================================================
   Bottom nav
   ========================================================= */
.bottom-nav { display: none; }

/* =========================================================
   Responsive: Mobile / Tablet
   ========================================================= */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }
  .app-sidebar {
    position: static;
    height: auto;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    transition: max-height 350ms ease, padding 350ms ease;
  }
  .app-sidebar.open { max-height: 80vh; padding: 16px 0; overflow-y: auto; }
  .app-main { padding: 20px; max-width: 100vw; box-sizing: border-box; }

  .page-quiz .app-main, .page-math .app-main { padding: 0 16px 40px; max-width: 100vw; overflow-x: hidden; }

  .options-grid, .results-grid, .edit-grid, .preview-options, .form-grid, .subject-grid { grid-template-columns: 1fr; }

  .btn { min-height: 44px; }
  .option-item { min-height: 52px; padding: 12px 16px; }
  
  .question-card { padding: 20px; width: 100%; box-sizing: border-box; }
  .score-big { font-size: 3rem; }
  h1 { font-size: 1.6rem; }

  .index-hero { padding: 40px 24px; border-radius: 20px; }
  .index-hero h1 { font-size: 1.8rem; }

  .subject-card-actions { flex-direction: row; }
  .history-entry { flex-wrap: wrap; gap: 8px; }
  .history-entry-meta { order: 3; width: 100%; }

  .quiz-fixed-bar { padding: 10px 16px; gap: 12px; font-size: 0.9rem; }

  .editor-toolbar { flex-wrap: wrap; gap: 8px; }
  .nav-dots-btn { display: none; }
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 200;
    background: rgba(34, 34, 59, 0.85);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    padding: 8px 0 max(12px, env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: center;
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-3);
    text-decoration: none;
    padding: 6px 16px;
    border-radius: 12px;
    transition: all var(--transition);
  }
  .bottom-nav-item:hover, .bottom-nav-item.active { color: var(--accent); background: rgba(201, 173, 167, 0.1); }
  body:has(.bottom-nav) main { padding-bottom: 80px; }
}

@media (max-width: 480px) {
  .modal { max-width: 100%; border-radius: 0; }
  .app-header { padding: 0 16px; }

  .page-quiz .app-main, .page-math .app-main { padding: 0 10px 40px; }
  .question-card { padding: 14px 14px 18px; }
  .question-text img { max-height: 200px; }
  .quiz-fixed-bar { padding: 8px 10px; gap: 8px; }
  .quiz-fixed-title { font-size: 0.875rem; }
  #btn-finish-top { padding: 5px 10px; font-size: 0.78rem; }
}

/* =========================================================
   KaTeX overrides
   ========================================================= */
.katex { font-size: 1.1em; color: var(--text); max-width: 100%; overflow-x: auto; display: inline-block; }
.katex-display { margin: 16px 0; overflow-x: auto; overflow-y: hidden; padding: 8px 0; max-width: 100%; }
.katex-html { max-width: 100%; overflow-x: auto; }

/* =========================================================
   Scrollbar styling
   ========================================================= */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(154, 140, 152, 0.3); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(154, 140, 152, 0.6); }
