/* ============ Base ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e6eb;
  --border-strong: #ccd1d8;
  --ink: #1a2330;
  --muted: #5b6675;
  --faint: #9099a6;
  --accent: #2e6bb0;
  --accent-strong: #25578e;
  --accent-tint: #ecf2f9;
  --green: #1c7c4a;
  --green-bg: #e9f5ee;
  --green-border: #b9dcc8;
  --red: #bb3a30;
  --red-bg: #fbeeed;
  --red-border: #eed1cd;
  --amber: #946614;
  --amber-bg: #faf3e2;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(26, 35, 48, .05), 0 4px 14px rgba(26, 35, 48, .05);
  --code-bg: #161c26;
  --code-text: #d5deeb;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
}

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

.hidden { display: none !important; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

svg.icon {
  width: 20px; height: 20px; flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}
svg.icon-sm { width: 16px; height: 16px; }
svg.icon-lg { width: 24px; height: 24px; }

code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  color: #33506e;
  word-break: break-word;
}

.screen { animation: rise .22s ease both; }

/* ============ Masthead ============ */
.masthead {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
  padding: 26px 2px 20px;
}
.brand-mark {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  background: var(--ink);
  border-radius: 12px;
  color: #fff;
}
.brand-mark svg.icon { width: 24px; height: 24px; stroke-width: 2; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 12.5px; color: var(--muted); }

/* ============ Tile-uri iconițe ============ */
.tile {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: color-mix(in srgb, var(--tc, var(--accent)) 10%, white);
  color: var(--tc, var(--accent));
}
.tile-accent { background: var(--accent-tint); color: var(--accent); }

/* ============ Card practică mixtă ============ */
.mixed-card {
  display: flex; align-items: center; gap: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.mixed-card:hover { border-color: var(--accent); }
.mixed-card:active { border-color: var(--accent-strong); }

.mixed-text { flex: 1; min-width: 0; }
.mixed-text h2 { font-size: 15.5px; font-weight: 650; letter-spacing: -.01em; }
.mixed-text p { color: var(--muted); font-size: 13px; margin-top: 1px; }

.btn-ghost {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 38px;
  transition: border-color .15s ease, color .15s ease;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ============ Listă capitole ============ */
.section-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.1px;
  color: var(--faint);
}
.masthead + .mixed-card + .section-label { margin: 22px 2px 9px; }
.section-label.mt { margin: 20px 2px 9px; }

.chapters { display: grid; grid-template-columns: 1fr; gap: 8px; }

.chapter-card {
  display: flex; align-items: center; gap: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.chapter-card:hover { border-color: color-mix(in srgb, var(--tc, var(--accent)) 55%, var(--border)); }

.chapter-info { flex: 1; min-width: 0; }
.chapter-name { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.chapter-desc {
  color: var(--muted); font-size: 12.5px; margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chapter-stats { text-align: right; flex: none; display: flex; flex-direction: column; gap: 1px; }
.chapter-pct { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chapter-count { color: var(--faint); font-size: 11px; }

.chapter-arrow { color: var(--faint); display: grid; place-items: center; }

.home-footer {
  margin-top: 28px;
  text-align: center;
  color: var(--faint);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.total-stats { font-size: 12.5px; }

.link-btn {
  color: var(--faint);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px 10px;
  min-height: 34px;
}
.link-btn:hover { color: var(--red); }

/* ============ Ecran Quiz ============ */
.quiz-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  margin: 0 -6px;
  padding-left: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 1px 2px rgba(26, 35, 48, .04);
  transition: border-color .15s ease, color .15s ease;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--ink); }

.quiz-topic {
  flex: 1; min-width: 0;
  font-weight: 650; font-size: 15px; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.quiz-chips { display: flex; gap: 6px; flex: none; }
.chip {
  font-size: 12.5px; font-weight: 650;
  font-variant-numeric: tabular-nums;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip-score { color: var(--muted); }
.chip-streak { color: var(--amber); background: var(--amber-bg); border-color: transparent; }
.chip-streak svg.icon { width: 14px; height: 14px; }
.chip-streak.cold { color: var(--faint); background: var(--surface); border-color: var(--border); }

.quiz-meta {
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 12.5px; font-weight: 550;
  margin: 8px 2px 7px;
  font-variant-numeric: tabular-nums;
}

.accuracy-bar {
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 16px;
}
.accuracy-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .3s ease;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  animation: rise .22s ease both;
}

.q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.level-chip {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .7px;
  padding: 4px 9px;
  border-radius: 6px;
}
.level-chip.l1 { color: var(--green); background: var(--green-bg); }
.level-chip.l2 { color: var(--amber); background: var(--amber-bg); }
.level-chip.l3 { color: var(--red); background: var(--red-bg); }

.topic-chip {
  font-size: 11.5px; font-weight: 600;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 5px;
}
.topic-chip svg.icon { width: 13px; height: 13px; }

.question-text { font-size: 17px; font-weight: 600; line-height: 1.45; letter-spacing: -.01em; margin-bottom: 14px; }

.code {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin: 0 0 14px;
  overflow-x: auto;
  white-space: pre;
}
.code:empty { display: none; }

.tk-str { color: #98c379; }
.tk-num { color: #d19a66; }
.tk-kw { color: #c678dd; }
.tk-fn { color: #61afef; }

.options { display: grid; gap: 8px; }

.option {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 10px 13px;
  text-align: left;
  font-size: 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .13s ease, background .13s ease;
}
.option:hover { border-color: var(--accent); background: var(--accent-tint); }

.option-letter {
  width: 27px; height: 27px; flex: none;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700;
  font-family: var(--mono);
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.option-text { flex: 1; min-width: 0; word-break: break-word; }
.option-text code { background: none; border: none; padding: 0; color: inherit; font-size: .95em; }

.options.answered .option { cursor: default; }
.options.answered .option:not(.correct):not(.wrong) { opacity: .45; }
.options.answered .option:hover { border-color: var(--border); background: var(--surface); }

.option.correct {
  background: var(--green-bg);
  border-color: var(--green-border);
}
.option.correct .option-letter {
  background: var(--green); border-color: var(--green); color: #fff;
}
.option.wrong {
  background: var(--red-bg);
  border-color: var(--red-border);
}
.option.wrong .option-letter {
  background: var(--red); border-color: var(--red); color: #fff;
}

.feedback {
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  animation: rise .2s ease both;
}
.feedback.ok { border-left-color: var(--green); }
.feedback.no { border-left-color: var(--red); }

.feedback-title {
  font-size: 14.5px; font-weight: 650; margin-bottom: 7px;
  display: flex; align-items: flex-start; gap: 7px;
}
.feedback-title svg.icon { width: 17px; height: 17px; margin-top: 2px; }
.feedback.ok .feedback-title { color: var(--green); }
.feedback.no .feedback-title { color: var(--red); }

.explanation {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 14px;
}

/* ============ Butoane ============ */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 12px 22px;
  font-size: 15px; font-weight: 650;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(37, 87, 142, .25);
  transition: background .15s ease;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:disabled { background: var(--border-strong); cursor: not-allowed; box-shadow: none; }
.btn-block { width: 100%; }

/* ============ Modal filtre ============ */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: end center;
  background: rgba(26, 35, 48, .45);
  animation: fade .15s ease both;
}
.modal-box {
  width: 100%; max-width: 520px;
  max-height: min(86dvh, 720px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(26, 35, 48, .2);
  animation: up .2s ease both;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px 11px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.modal-body { padding: 13px 16px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; }

.filter-row-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 9px;
}
.filter-actions { display: flex; gap: 2px; }

.filter-topics { display: grid; gap: 6px; }

.filter-topic {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: border-color .13s ease, background .13s ease;
}
.filter-topic:hover { border-color: var(--border-strong); }
.filter-topic.on { border-color: var(--accent); background: var(--accent-tint); }

.filter-topic .box {
  width: 20px; height: 20px; flex: none;
  display: grid; place-items: center;
  border-radius: 5px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: transparent;
  transition: all .13s ease;
}
.filter-topic.on .box {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.filter-topic .box svg.icon { width: 13px; height: 13px; stroke-width: 3; }
.filter-topic .ft-name { font-weight: 600; font-size: 14px; }

.seg {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: 9px;
}
.seg button {
  min-height: 42px;
  font-size: 13.5px; font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all .13s ease;
}
.seg button:hover { border-color: var(--border-strong); }
.seg button.active {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.filter-hint { color: var(--faint); font-size: 12px; margin: 13px 2px 12px; text-align: center; }
.filter-hint.warn { color: var(--red); font-weight: 600; }

#btn-apply-filters { margin-top: auto; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(90vw, 420px);
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  padding: 11px 18px;
  border-radius: 9px;
  box-shadow: 0 8px 24px rgba(26, 35, 48, .3);
  text-align: center;
  animation: rise .18s ease both;
}

/* ============ Animații ============ */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes up { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.option.wrong { animation: shake .25s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============ Desktop ≥680px ============ */
@media (min-width: 680px) {
  #app { padding: 0 24px 48px; }

  .masthead { padding: 40px 2px 24px; gap: 12px; }
  .brand-mark { width: 52px; height: 52px; border-radius: 14px; }
  .brand-mark svg.icon { width: 27px; height: 27px; }
  .brand-name { font-size: 22px; }
  .brand-sub { font-size: 13.5px; }

  .chapters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

  .question-text { font-size: 18.5px; }
  .question-card { padding: 22px 20px; }

  .modal { place-items: center; padding: 20px; }
  .modal-box { border-radius: 16px; }
}

/* ============ Ecrane foarte înguste ============ */
@media (max-width: 355px) {
  .mixed-card { flex-wrap: wrap; }
  .btn-ghost { margin-left: auto; }
  .quiz-topic { font-size: 13.5px; }
}
