/* Chidon Quiz: calm, mobile-first styling.
   The quiz screen is the one bold element (a deep navy "stage" card);
   everything around it stays on a quiet, light page. */

:root {
  /* Base palette */
  --navy: #14185a;          /* header, primary buttons, quiz stage edge */
  --stage: #1d2378;         /* quiz card */
  --stage-raised: #2a3194;  /* option rows on the stage */
  --stage-line: #4049ad;
  --sky: #cfe0ff;           /* question text on the stage */
  --sky-dim: #9fb6ec;
  --gold: #f4b63a;          /* selected answer, primary action on the stage */
  --gold-deep: #c98a0c;
  --page: #eef2fb;
  --surface: #ffffff;
  --text: #1b1f3b;
  --muted: #535a7c;
  --line: #d3d9ea;
  --focus: #f4b63a;

  /* Results (spec) */
  --correct: #2e9e4f;
  --correct-bg: #e3f6e8;
  --correct-text: #1d6b34;
  --wrong: #d64545;
  --wrong-bg: #fde4e4;
  --wrong-text: #a12a2a;

  /* Progress levels (spec) */
  --level-green: #bfe8c6;
  --level-yellow: #ffe7a8;
  --level-red: #f7c1c1;
  --level-none: #eee;
  --level-green-edge: #2e9e4f;
  --level-yellow-edge: #d39b0f;
  --level-red-edge: #d64545;
  --level-none-edge: #c6cbd8;

  --radius-lg: 22px;
  --radius: 14px;
  --radius-sm: 10px;
  --pill: 999px;
  --tap: 48px;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Noto Sans Hebrew", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--page);
  overflow-wrap: break-word;
}

bdi[lang="he"] {
  font-family: "Noto Sans Hebrew", system-ui, sans-serif;
  font-size: 1.12em;
  line-height: 1.3;
}

a { color: #2b3aa8; text-underline-offset: .18em; }
a:hover { color: var(--navy); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1, h2 { line-height: 1.2; color: var(--navy); }
h1 { font-size: clamp(1.6rem, 6vw, 2.1rem); font-weight: 800; margin: .4rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; font-weight: 700; margin: 1.6rem 0 .6rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem .9rem;
  padding: .5rem 16px;
  background: var(--navy);
  color: #fff;
}
.site-name { color: inherit; text-decoration: none; font-weight: 800; font-size: 1.1rem; margin-inline-end: auto; letter-spacing: .01em; }
.site-name::before {
  content: ""; display: inline-block; width: .7em; height: .7em; margin-inline-end: .45em;
  border-radius: 50%; background: var(--gold); vertical-align: .02em;
}
.site-header a {
  color: var(--sky);
  display: inline-flex; align-items: center; min-height: 44px;
  text-decoration: none; font-weight: 600;
}
.site-header a:hover { color: #fff; text-decoration: underline; }
.current-child {
  padding: .15rem .7rem; border-radius: var(--pill);
  background: rgba(255, 255, 255, .12); font-weight: 700;
}
.logout { margin: 0; }
.site-header .logout button {
  min-height: 44px; padding: .3rem .9rem; font: inherit; font-weight: 600; font-size: .95rem;
  color: var(--sky); background: transparent;
  border: 2px solid rgba(207, 224, 255, .35); border-radius: var(--pill); cursor: pointer;
}
.site-header .logout button:hover { color: #fff; border-color: var(--sky); }

/* ---------- Page body ---------- */

main {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1rem 16px 3rem;
}
main:has(.progress-grid) { max-width: 64rem; }

p { margin: .6rem 0; }

/* ---------- Forms ---------- */

main form { margin: 1rem 0; }
main form label:not(.color-choice) {
  display: grid;
  gap: .35rem;
  margin: 0 0 1rem;
  font-weight: 600;
}
input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%;
  min-height: var(--tap);
  padding: .55rem .85rem;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
}
input:focus, select:focus { border-color: #5a6cd8; }

fieldset { border: 0; padding: 0; margin: 0 0 1.2rem; }
legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }

main button, .button {
  min-height: var(--tap);
  padding: .6rem 1.4rem;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--navy);
  border: 2px solid var(--navy);
  border-radius: var(--pill);
  cursor: pointer;
}
main button:hover { background: #262c86; border-color: #262c86; }
main form > button[type="submit"] { width: 100%; }
@media (min-width: 560px) { main form > button[type="submit"] { width: auto; } }

.error {
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--wrong-bg);
  color: var(--wrong-text);
  border-inline-start: 6px solid var(--wrong);
  font-weight: 600;
}

/* Child form: color swatches and remove */
.color-choice {
  position: relative;
  display: inline-block;
  width: 44px; height: 44px;
  margin: 0 .4rem .4rem 0;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--line);
  cursor: pointer;
}
.color-choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.color-choice:has(input:checked) { box-shadow: 0 0 0 3px var(--navy); }
.color-choice:has(input:checked)::after {
  content: "✓"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-weight: 800; text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
.color-choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 3px; }

.remove-child { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
main .remove-child button {
  color: var(--wrong-text);
  background: transparent;
  border-color: var(--wrong);
}
main .remove-child button:hover { background: var(--wrong-bg); }

/* ---------- Profiles ---------- */

.profile-grid {
  list-style: none; padding: 0; margin: 1rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: .9rem;
}
.profile-grid form { margin: 0; height: 100%; }
main .profile-tile {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start;
  gap: .15rem;
  width: 100%; height: 100%; min-height: 8.5rem;
  padding: 1rem;
  text-align: start;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line);
  border-top: 14px solid var(--child, var(--navy));
  border-radius: var(--radius);
  text-decoration: none;
}
main .profile-tile:hover { background: var(--surface); border-color: var(--navy); border-top-color: var(--child, var(--navy)); }
.profile-name { font-size: 1.3rem; font-weight: 800; color: var(--navy); }
.profile-book { font-size: .9rem; font-weight: 400; color: var(--muted); }
main .profile-tile.profile-add {
  align-items: center; justify-content: center;
  border: 2px dashed var(--sky-dim);
  font-weight: 700; color: var(--navy);
}
main .profile-tile.profile-add:hover { border-color: var(--navy); }
.profile-add::before { content: "+"; font-size: 2rem; line-height: 1; font-weight: 400; }
.manage-links { color: var(--muted); font-size: .95rem; }
.manage-links a { display: inline-block; padding: .55rem 0; }

/* ---------- Score buttons (units, needs work, history) ---------- */

.unit-list { list-style: none; padding: 0; margin: 0; }
.unit {
  margin: 0 0 .9rem;
  padding: .9rem 1rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.unit h2 { margin: 0 0 .7rem; font-size: 1.1rem; }
.track-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
@media (min-width: 560px) { .track-buttons { grid-template-columns: repeat(4, 1fr); } }

.track-button {
  display: inline-flex; align-items: center; justify-content: space-between; gap: .5rem;
  min-height: var(--tap);
  padding: .5rem .85rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
}
a.track-button:hover { color: var(--text); border-color: var(--navy); }
.score {
  font-size: .85rem; font-weight: 700;
  padding: .05rem .5rem; border-radius: var(--pill);
  background: rgba(255, 255, 255, .7);
}

.not-tried { background: var(--level-none); border-color: var(--level-none-edge); }
.green { background: var(--level-green); border-color: var(--level-green-edge); }
.yellow { background: var(--level-yellow); border-color: var(--level-yellow-edge); }
.red { background: var(--level-red); border-color: var(--level-red-edge); }

.track-soon {
  font-weight: 400; font-size: .9rem;
  color: var(--muted); background: #f6f7fb;
  border-style: dashed; border-color: var(--line);
}
.coming-soon { color: var(--muted); margin: 0; font-size: .9rem; }
.unit:has(.coming-soon) {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  margin-bottom: .4rem; padding: .55rem 1rem;
  background: transparent; border-style: dashed;
}
.unit:has(.coming-soon) h2 { margin: 0; font-size: 1rem; color: var(--muted); }

/* ---------- Quiz ---------- */

.quiz-heading { color: var(--muted); font-weight: 600; }
.quiz-heading a { margin-inline-end: .6rem; font-weight: 700; display: inline-block; padding: .55rem 0; }

#quiz {
  margin: .5rem -4px 0;
  padding: 1.4rem 1rem 1.2rem;
  color: #fff;
  background: var(--stage);
  border: 2px solid var(--navy);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 40px -18px rgba(20, 24, 90, .55);
}
@media (min-width: 560px) { #quiz { margin: .5rem 0 0; padding: 2rem 2rem 1.5rem; } }
#quiz noscript { display: block; color: var(--sky); text-align: center; }

.quiz-progress {
  margin: 0 0 1rem;
  text-align: center;
  font-size: .95rem; font-weight: 600;
  color: var(--sky-dim);
}
.quiz-prompt {
  margin: 0 auto 1.4rem;
  max-width: 34rem;
  text-align: center;
  font-size: clamp(1.3rem, 5vw, 1.75rem);
  font-weight: 700;
  line-height: 1.35;
  color: var(--sky);
}
.quiz-prompt p { margin: 0 0 .5rem; }

.quiz-options { display: grid; gap: .7rem; }
#quiz .quiz-option {
  display: block; width: 100%;
  min-height: 56px;
  margin: 0;
  padding: .85rem 1.1rem;
  text-align: start;
  font: inherit; font-size: 1.15rem; font-weight: 600; line-height: 1.4;
  color: #fff;
  background: var(--stage-raised);
  border: 2px solid var(--stage-line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
#quiz .quiz-option:hover { background: #343ca6; border-color: var(--sky-dim); }
#quiz .quiz-option.selected {
  color: var(--navy);
  background: var(--gold);
  border-color: #ffd67a;
}

.quiz-nav { display: flex; justify-content: space-between; gap: .75rem; margin-top: 1.4rem; }
#quiz .quiz-nav button { flex: 1 1 0; max-width: 12rem; min-height: var(--tap); padding: .6rem 1.2rem; }
#quiz-back { color: var(--sky); background: transparent; border-color: var(--stage-line); }
#quiz-back:hover { background: rgba(255, 255, 255, .06); border-color: var(--sky-dim); }
#quiz-next { color: var(--navy); background: var(--gold); border-color: var(--gold); }
#quiz-next:hover { background: #ffc85a; border-color: #ffc85a; }
#quiz .quiz-nav button:disabled { opacity: .35; cursor: default; }
#quiz .error { margin: 1rem 0 0; }

@media (prefers-reduced-motion: reduce) {
  #quiz .quiz-option { transition: none; }
}

/* ---------- Results ---------- */

.results-head {
  margin: .5rem 0 1.2rem;
  padding: 1.4rem 1.2rem;
  text-align: center;
  color: #fff;
  background: var(--stage);
  border-radius: var(--radius-lg);
}
.results-head h1 { margin: 0 0 .3rem; color: #fff; }
.results-head p { margin: 0; color: var(--sky); }

.review-question {
  margin: 0 0 1rem;
  padding: 1rem 1rem .6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.review-question h2 { margin: 0 0 .4rem; font-size: 1rem; color: var(--muted); }
.review-prompt { font-size: 1.15rem; font-weight: 600; margin-bottom: .6rem; }
.review-options { list-style: none; padding: 0; margin: 0; }
.opt {
  margin: .5rem 0;
  padding: .7rem 1rem;
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfe;
}
.opt.correct { background: var(--correct-bg); border-color: var(--correct); color: var(--correct-text); }
.opt.chosen-wrong { background: var(--wrong-bg); border-color: var(--wrong); color: var(--wrong-text); }
.opt-label { display: inline-block; margin-inline-start: .4rem; font-size: .9rem; }
.opt.correct .opt-label::before { content: "✓ "; color: var(--correct); }
.opt.chosen-wrong .opt-label::before { content: "✗ "; color: var(--wrong); }
.not-answered { color: var(--wrong-text); font-weight: 700; margin: .2rem 0; }

.result-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.5rem; }
.result-actions .track-button { flex: 1 1 10rem; justify-content: center; }
.track-button.primary { justify-content: center; color: #fff; background: var(--navy); border-color: var(--navy); }
a.track-button.primary:hover { color: #fff; background: #262c86; }

/* ---------- Progress ---------- */

.progress-summary { color: var(--muted); font-weight: 600; }

.needs-work ul, .history-list { list-style: none; padding: 0; margin: 0; }
.needs-work li, .history-list li { margin: .45rem 0; }
.needs-work .track-button, .history-list .track-button { width: 100%; }

.progress-scroll {
  max-width: 100%;
  overflow-x: auto;
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}
.progress-grid { border-collapse: separate; border-spacing: .35rem; min-width: 26rem; width: 100%; }
.progress-grid thead th { font-size: .9rem; color: var(--muted); font-weight: 700; text-align: center; padding: .3rem 0; }
.progress-grid thead th:first-child { text-align: start; }
.progress-grid th[scope="row"] {
  position: sticky; left: 0; z-index: 1;
  min-width: 7rem; max-width: 12rem;
  padding: .2rem .5rem .2rem .4rem;
  text-align: start; font-weight: 800; color: var(--navy);
  background: var(--surface);
}
.unit-title { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; line-height: 1.3; }
.cell {
  display: flex; align-items: center; justify-content: center;
  min-width: 52px; min-height: 44px;
  padding: .3rem .5rem;
  font-weight: 700; font-size: .95rem;
  color: var(--text);
  text-decoration: none;
  border-width: 2px;
  border-style: solid;
  border-radius: var(--radius-sm);
}
a.cell:hover { color: var(--text); outline: 2px solid var(--navy); outline-offset: 1px; }
span.cell { color: var(--muted); }

input[readonly] { color: var(--muted, #666); background: transparent; border-style: dashed; }
