/* ===================================================================
   Psychome — Design System v2
   "Sapphire Scholar" — Modern Hebrew Academic
=================================================================== */

:root {
  /* Colors — Primary palette */
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-soft: #f5f5f4;
  --primary: #1e3a8a;
  --primary-hover: #1e40af;
  --primary-light: #eef2ff;
  --primary-50: #f8faff;
  --accent: #f59e0b;
  --accent-soft: #fef3c7;
  --accent-hover: #d97706;

  /* Colors — Status */
  --correct: #15803d;
  --correct-bg: #dcfce7;
  --correct-border: #86efac;
  --wrong: #b91c1c;
  --wrong-bg: #fee2e2;
  --wrong-border: #fca5a5;

  /* Text */
  --text: #1c1917;
  --text-soft: #292524;
  --text-muted: #57534e;
  --text-subtle: #a8a29e;

  /* Borders & dividers */
  --border: #e7e5e4;
  --border-soft: #f0eeec;
  --divider: #d6d3d1;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-sm: 0 2px 8px rgba(28, 25, 23, 0.06);
  --shadow-md: 0 8px 24px rgba(28, 25, 23, 0.08);
  --shadow-lg: 0 20px 48px rgba(28, 25, 23, 0.12);
  --shadow-primary: 0 8px 24px rgba(30, 58, 138, 0.18);

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration: 220ms;
  --duration-slow: 350ms;
}

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

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  min-height: 100vh;
  font-feature-settings: 'ss01', 'cv01';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--accent-soft); color: var(--text); }

h1, h2, h3, h4 {
  font-family: 'Rubik', 'Heebo', sans-serif;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin: 0;
}

h1 { font-size: clamp(28px, 4vw, 42px); }
h2 { font-size: clamp(22px, 3vw, 30px); margin-bottom: var(--space-4); }
h3 { font-size: 19px; }

p { margin: var(--space-3) 0; }
a { color: var(--primary); text-decoration: none; transition: color var(--duration) var(--ease); }
a:hover { color: var(--primary-hover); }

/* ===================================================================
   Top Bar
=================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(250, 250, 249, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  min-height: 60px;
}

.topbar .logo {
  font-family: 'Rubik', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.nav-btn {
  width: 42px; height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 19px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--duration) var(--ease);
  box-shadow: var(--shadow-xs);
}
.nav-btn:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ===================================================================
   Layout & Screens
=================================================================== */
main#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-16);
}

.screen { animation: fadeIn 0.4s var(--ease-out); }
.screen.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   Home — Hero & Domain Grid
=================================================================== */
#screen-home h2 {
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: var(--space-6) 0 var(--space-2);
  text-align: center;
}
#screen-home h2::after {
  content: '';
  display: block;
  width: 60px; height: 3px;
  background: var(--accent);
  margin: var(--space-4) auto var(--space-8);
  border-radius: 2px;
}

.domain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}

.domain-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6) var(--space-5);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  gap: var(--space-3);
  position: relative;
  overflow: hidden;
  transition: transform var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease),
              border-color var(--duration) var(--ease);
  font-family: inherit;
  color: var(--text);
}

.domain-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0; left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.domain-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-light);
}
.domain-card:hover::before { opacity: 1; }
.domain-card:active { transform: translateY(-1px); }

.domain-card .icon {
  font-size: 42px;
  width: 72px; height: 72px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-light);
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  transition: transform var(--duration) var(--ease);
}
.domain-card:hover .icon { transform: scale(1.08) rotate(-2deg); }

.domain-card .name {
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  font-size: 19px;
  color: var(--text);
}

.domain-card .meta {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===================================================================
   Breadcrumb
=================================================================== */
.breadcrumb {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: var(--space-5);
  display: flex; gap: var(--space-2); flex-wrap: wrap;
}
.breadcrumb a {
  color: var(--text-muted);
  font-weight: 500;
}
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span {
  color: var(--text);
  font-weight: 600;
}

/* ===================================================================
   Settings / Forms (fieldsets)
=================================================================== */
fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-xs);
}

legend {
  font-weight: 700;
  color: var(--primary);
  padding: 0 var(--space-2);
  font-size: 15px;
  background: var(--surface);
}

label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-end: var(--space-5);
  margin-block: var(--space-1);
  cursor: pointer;
  font-size: 15px;
}

input[type="radio"], input[type="checkbox"] {
  accent-color: var(--primary);
  width: 18px; height: 18px;
  cursor: pointer;
}

input[type="number"], select, input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: 15px;
  min-width: 80px;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
input[type="number"]:focus, select:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===================================================================
   Buttons
=================================================================== */
.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-6);
  font-family: 'Rubik', sans-serif;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  border: none;
  transition: all var(--duration) var(--ease);
  min-height: 44px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-primary);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled {
  background: var(--surface-soft);
  color: var(--text-subtle);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-50);
}

.btn-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

/* ===================================================================
   Question Screen
=================================================================== */
.qheader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.progress, .timer {
  font-family: 'Rubik', monospace;
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
}

.timer {
  background: var(--accent-soft);
  color: var(--accent-hover);
}
.timer.urgent {
  background: var(--wrong-bg);
  color: var(--wrong);
  animation: pulse 1s infinite;
}
.timer.hidden { display: none; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.passage {
  background: var(--primary-50);
  border-inline-start: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: var(--space-5);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: var(--space-4);
  white-space: pre-wrap;
  color: var(--text-soft);
}
.passage.hidden { display: none; }
.passage.ltr { direction: ltr; text-align: left; font-family: 'Heebo', sans-serif; }

.qstem {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  font-size: 18px;
  line-height: 1.7;
  margin-bottom: var(--space-5);
  white-space: pre-wrap;
  box-shadow: var(--shadow-xs);
  font-weight: 500;
}
.qstem.ltr { direction: ltr; text-align: left; }

/* Options */
.options {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.options.ltr li { direction: ltr; text-align: left; }

.options li {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: 16px;
  font-weight: 500;
  transition: all var(--duration) var(--ease);
  position: relative;
}

.options li:hover:not(.correct):not(.wrong) {
  border-color: var(--primary);
  background: var(--primary-50);
  transform: translateX(-2px);
}
[dir="ltr"] .options li:hover:not(.correct):not(.wrong),
.options.ltr li:hover:not(.correct):not(.wrong) {
  transform: translateX(2px);
}

.options li.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.options li .marker {
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--surface-soft);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  transition: all var(--duration) var(--ease);
}

.options li:hover .marker { background: var(--primary); color: #fff; }
.options li.selected .marker { background: var(--primary); color: #fff; }

.options li.correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
  color: var(--correct);
}
.options li.correct .marker { background: var(--correct); color: #fff; }

.options li.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
  color: var(--wrong);
}
.options li.wrong .marker { background: var(--wrong); color: #fff; }

.opt-text { flex: 1; }

/* Feedback */
.feedback {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-top: var(--space-4);
  box-shadow: var(--shadow-sm);
  animation: slideUp 0.3s var(--ease-out);
}
.feedback.hidden { display: none; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.feedback.correct { border-color: var(--correct-border); background: var(--correct-bg); }
.feedback.wrong { border-color: var(--wrong-border); background: var(--wrong-bg); }

.feedback .result {
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  font-size: 18px;
  margin-bottom: var(--space-3);
}
.feedback.correct .result { color: var(--correct); }
.feedback.wrong .result { color: var(--wrong); }

.feedback .explanation {
  color: var(--text-soft);
  line-height: 1.7;
  font-size: 15px;
}

/* ===================================================================
   Score / Summary
=================================================================== */
.score {
  text-align: center;
  font-family: 'Rubik', sans-serif;
  font-weight: 800;
  font-size: 56px;
  color: var(--primary);
  letter-spacing: -0.02em;
  margin: var(--space-6) 0;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: var(--space-5) 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.breakdown th, .breakdown td {
  padding: var(--space-3) var(--space-4);
  text-align: center;
  border-bottom: 1px solid var(--border-soft);
}
.breakdown th {
  background: var(--surface-soft);
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.breakdown td { font-variant-numeric: tabular-nums; font-weight: 500; }
.breakdown tr:last-child td { border-bottom: none; }
.breakdown tr:hover td { background: var(--primary-50); }

/* ===================================================================
   Stats screen
=================================================================== */
#screen-stats h2, #screen-summary h2 {
  text-align: center;
  margin-bottom: var(--space-6);
}

/* ===================================================================
   Games (English + Hebrew shared cards)
=================================================================== */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6) var(--space-4);
  cursor: pointer;
  text-align: center;
  display: flex; flex-direction: column; gap: var(--space-2);
  transition: all var(--duration) var(--ease);
  font-family: inherit;
  color: var(--text);
  position: relative;
  overflow: hidden;
}
.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-soft), transparent 50%);
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
  pointer-events: none;
}
.game-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}
.game-card:hover::before { opacity: 1; }

.game-icon { font-size: 36px; }
.game-name {
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  font-size: 17px;
}
.game-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.game-error { color: var(--wrong); padding: var(--space-4); }

/* ===================================================================
   Flashcards
=================================================================== */
#screen-flashcards form {
  background: var(--surface);
  padding: var(--space-6);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.fc-bucket-table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-3) 0;
  font-size: 14px;
}
.fc-bucket-table .ltr-cell { direction: ltr; text-align: left; }
.ltr-text { direction: ltr; unicode-bidi: embed; }

/* ===================================================================
   Mock Exam Runtime
=================================================================== */
#screen-mock-run .qheader {
  position: sticky;
  top: 60px;
  background: rgba(250, 250, 249, 0.95);
  backdrop-filter: blur(8px);
  padding: var(--space-3) 0;
  margin: 0 calc(var(--space-5) * -1) var(--space-4);
  padding-inline: var(--space-5);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}
#mock-section-label {
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  color: var(--accent-hover);
  margin: var(--space-3) 0 var(--space-4);
  font-size: 15px;
  padding: var(--space-2) var(--space-4);
  background: var(--accent-soft);
  border-radius: var(--radius-full);
  display: inline-block;
}

/* ===================================================================
   Mobile responsive
=================================================================== */
@media (max-width: 640px) {
  html, body { font-size: 15px; }
  main#app { padding: var(--space-4) var(--space-3) var(--space-12); }
  .topbar { padding: var(--space-3); }
  .topbar .logo { font-size: 18px; }
  .domain-card { padding: var(--space-5) var(--space-4); }
  .domain-card .icon { font-size: 36px; width: 60px; height: 60px; }
  .qstem { padding: var(--space-4); font-size: 16px; }
  .options li { padding: var(--space-3) var(--space-4); font-size: 15px; }
  .score { font-size: 44px; }
  fieldset { padding: var(--space-4); }
  label { display: flex; margin-inline-end: 0; margin-block: var(--space-2); }
  .btn-primary, .btn-secondary { padding: var(--space-3) var(--space-5); font-size: 14px; }
  .breadcrumb { font-size: 13px; }
}

/* ===================================================================
   Utility
=================================================================== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }

/* Smooth scroll */
html { scroll-behavior: smooth; }

/* Focus visible (accessibility) */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}
