/* === Hebrew Alphabet — Minimal Serif Design System === */

:root {
  --bg: #f6f3ec;
  --bg-alt: #efeadf;
  --ink: #1a1713;
  --ink-soft: #5a524a;
  --ink-muted: #8a8178;
  --accent: #8b2e1f;
  --rule: #d8cfc0;
  --rule-soft: #e7dfd0;
  --paper: #fbf8f1;

  --serif: Helvetica, "Helvetica Neue", Arial, sans-serif;
  --display: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --hebrew: "Frank Ruhl Libre", "David Libre", "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --ui: Helvetica, "Helvetica Neue", Arial, sans-serif;

  --measure: 62ch;
  --max: 1240px;
}

[data-theme="dark"] {
  --bg: #14110d;
  --bg-alt: #1c1814;
  --ink: #f2ece0;
  --ink-soft: #b9ad9c;
  --ink-muted: #7d7265;
  --accent: #e5a07e;
  --rule: #2e2920;
  --rule-soft: #221e18;
  --paper: #1a1612;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
}

.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 48px;
}

/* Typography */
h1, h2 {
  font-family: var(--display);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}
h3, h4 {
  font-family: var(--ui);
  font-weight: 600;
  letter-spacing: 0;
  margin: 0;
  text-wrap: balance;
}

h1 { font-size: clamp(48px, 7vw, 96px); line-height: 1.0; letter-spacing: -0.03em; }
h2 { font-size: clamp(32px, 4vw, 54px); line-height: 1.1; }
h3 { font-size: 24px; line-height: 1.3; }

p { text-wrap: pretty; max-width: var(--measure); }

a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: border-color 0.2s, color 0.2s;
}
a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.hebrew {
  font-family: var(--hebrew);
  direction: rtl;
  unicode-bidi: isolate;
  font-feature-settings: "ss01";
}

.smallcaps {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-size: 13px;
}

.rule {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 0;
}

/* Top navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar__inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}
.topbar__brand {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 500;
  border: none;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.topbar__brand .hebrew { font-size: 24px; color: var(--accent); }
.topbar__nav {
  display: flex;
  gap: 28px;
  font-size: 18px;
  color: var(--ink-soft);
}
.topbar__nav a {
  border: none;
  color: var(--ink-soft);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.topbar__nav a:hover { color: var(--accent); }
.topbar__nav a.active { color: var(--ink); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  font-family: var(--serif);
  font-size: 16px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  border-radius: 0;
  transition: all 0.2s;
}
.btn:hover { background: var(--ink); color: var(--bg); }
.btn--primary {
  background: var(--ink);
  color: var(--bg);
}
.btn--primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--ghost {
  border-color: var(--rule);
  color: var(--ink-soft);
  padding: 10px 16px;
  font-size: 14px;
}
a.btn--solid-link { text-decoration: none; }
a.btn--solid-link:hover { border-color: var(--ink); }
a.btn.btn--primary.btn--solid-link:hover { border-color: var(--accent); }

/* Footer */
.footer {
  margin-top: 120px;
  padding: 40px 48px 60px;
  border-top: 1px solid var(--rule);
  color: var(--ink-muted);
  font-size: 14px;
}
.footer__inner {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 32px;
  flex-wrap: wrap;
}

/* Tweaks panel */
.tweaks {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 280px;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 20px;
  font-size: 14px;
  z-index: 100;
  display: none;
  box-shadow: 0 20px 40px -20px rgba(0,0,0,0.25);
}
.tweaks.visible { display: block; }
.tweaks h4 {
  font-family: var(--display);
  font-size: 18px;
  margin: 0 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tweaks h4 button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--ink-muted);
}
.tweak-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--rule-soft);
}
.tweak-row:first-of-type { border-top: none; }
.tweak-row label { color: var(--ink-soft); }
.tweak-row select, .tweak-row input[type="checkbox"] {
  font-family: var(--serif);
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--rule);
  padding: 4px 8px;
  color: var(--ink);
}

/* Letter grid — 8 cols × 3 rows; overlap borders via negative margins so lines are 1px everywhere */
.letter-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0;
}
.letter-cell {
  aspect-ratio: 1;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--ink);
  transition: background 0.2s, color 0.2s;
  padding: 10px 6px;
  border: 1px solid var(--rule);
  margin: 0 0 -1px -1px;
}
.letter-cell--empty { pointer-events: none; }
.letter-cell__char { font-family: var(--hebrew); font-size: 52px; line-height: 1; font-weight: 400; margin: 2px 0 4px; }
.letter-cell__name { font-size: 12px; }
@media (max-width: 900px) {
  .letter-grid { grid-template-columns: repeat(6, 1fr); }
  .letter-cell__char { font-size: 44px; }
}
.letter-cell:hover {
  background: var(--ink);
  color: var(--bg);
}
.letter-cell:hover .letter-cell__num,
.letter-cell:hover .letter-cell__name {
  color: var(--bg);
  opacity: 0.6;
}
.letter-cell__char {
  font-family: var(--hebrew);
  font-size: 68px;
  line-height: 1;
  font-weight: 400;
  margin: 4px 0 8px;
}
.letter-cell__name {
  font-size: 13px;
  font-family: var(--serif);
  color: var(--ink-soft);
  letter-spacing: 0.05em;
}
.letter-cell__num {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: oldstyle-nums;
}
.letter-cell__final {
  position: absolute;
  top: 8px;
  right: 10px;
  font-family: var(--hebrew);
  font-size: 18px;
  color: var(--ink-muted);
}

/* Utility */
.muted { color: var(--ink-muted); }
.soft { color: var(--ink-soft); }
.center { text-align: center; }
.flex { display: flex; }
.gap-16 { gap: 16px; }
.gap-32 { gap: 32px; }

.quiz-choices button {
  font: inherit;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.quiz-choices button:focus { outline: none; }
.quiz-choices button:focus-visible { outline: none; }
.quiz-choices button:hover { background: inherit; color: inherit; }
@media (hover: none) {
  .quiz-choices button:hover { background: var(--paper); color: var(--ink); }
}
.quiz-feedback {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  z-index: 40;
  padding: 16px 0;
  margin-top: 8px;
}
.quiz-feedback__inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.quiz-feedback__text {
  font-family: var(--ui);
  font-size: 18px;
  color: var(--ink);
  flex: 1;
  text-wrap: pretty;
}
.quiz-feedback__next { white-space: nowrap; flex-shrink: 0; }

@media (max-width: 640px) {
  .wrap { padding: 0 20px; }
  .topbar__inner { padding: 12px 20px; gap: 16px; flex-wrap: wrap; }
  .topbar__brand { font-size: 18px; gap: 8px; }
  .topbar__brand .hebrew { font-size: 20px; }
  .topbar__nav { gap: 16px; font-size: 14px; flex-wrap: wrap; }
  .letter-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .letter-cell__char { font-size: 52px; }
  h1 { font-size: clamp(36px, 9vw, 56px); }
  .quiz-modes { width: 100%; }
  .quiz-modes .btn { flex: 1 1 auto; font-size: 13px; padding: 8px 10px; white-space: nowrap; }
  .quiz-choices { grid-template-columns: 1fr 1fr !important; }
  .quiz-feedback__inner { padding: 0 20px; flex-direction: column; gap: 12px; align-items: stretch; }
  .quiz-feedback__text { font-size: 15px; text-align: center; }
  .quiz-feedback__next { width: 100%; }
}
