/*
 * Quiz ASMEL - styles
 * Mobile-first (designed for ~360px wide phones). Colours are CSS variables,
 * redefined for dark mode, so the theme follows the phone's setting.
 */

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #d6dbe2;
  --primary: #1f5fa8;
  --primary-text: #ffffff;
  --primary-soft: #e3edf9;
  --ok: #1e7b3c;
  --ok-soft: #e1f3e6;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --warn: #8a5a00;
  --warn-soft: #fff1d1;
  --radius: 12px;
  --tap: 48px; /* minimum height of anything you can tap */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --card: #1e242d;
    --text: #e8ebef;
    --muted: #a0a9b5;
    --border: #36404c;
    --primary: #6fa8ec;
    --primary-text: #0d1622;
    --primary-soft: #1f3148;
    --ok: #6fcf8a;
    --ok-soft: #1b3325;
    --bad: #f28b82;
    --bad-soft: #3d1f1d;
    --warn: #f0c060;
    --warn-soft: #3a2f14;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--primary);
  color: var(--primary-text);
}
.topbar-home {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
}
.topbar-extra { font-weight: 700; font-variant-numeric: tabular-nums; }
.timer { padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, .18); }
.timer.low { background: var(--bad); color: #fff; }

/* ---------- Layout ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  outline: none;
}
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 19px; margin: 20px 0 8px; }
h3 { font-size: 17px; margin: 16px 0 6px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.loading { text-align: center; color: var(--muted); margin-top: 40px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  margin: 8px 0;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 40px; font-size: 15px; padding: 6px 12px; width: auto; display: inline-flex; margin: 4px 4px 4px 0; }
.btn:disabled { opacity: .5; cursor: default; }

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

/* Big home menu buttons */
.menu-btn {
  display: block;
  width: 100%;
  min-height: 64px;
  margin: 10px 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-btn strong { display: block; font-size: 18px; }
.menu-btn span { display: block; color: var(--muted); font-size: 14px; }
.menu-btn.highlight { border-color: var(--primary); background: var(--primary-soft); }

/* Segmented choice (e.g. 10 / 20 / Tutte) */
.choice { display: flex; gap: 8px; margin: 8px 0; }
.choice label { flex: 1; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  font-weight: 600;
  cursor: pointer;
}
.choice input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.choice input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Checkbox / radio list rows */
.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.check-row:last-child { border-bottom: 0; }
.check-row input { width: 22px; height: 22px; flex: none; accent-color: var(--primary); }
.check-row .grow { flex: 1; }
.check-row .count { color: var(--muted); font-size: 14px; white-space: nowrap; }

select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 80px; resize: vertical; }

/* ---------- Question ---------- */
.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.q-text { font-size: 18px; font-weight: 600; margin: 10px 0 12px; white-space: pre-line; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  background: var(--warn-soft);
  color: var(--warn);
}
.badge.demo { background: var(--primary-soft); color: var(--primary); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.subtle { background: transparent; color: var(--muted); border: 1px solid var(--border); font-weight: 600; }

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  margin: 8px 0;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.option .letter {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg);
  font-weight: 700;
  font-size: 15px;
}
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option:disabled { cursor: default; opacity: 1; }

/* ---------- Feedback ---------- */
.feedback { border-left: 5px solid var(--border); }
.feedback.is-correct { border-left-color: var(--ok); }
.feedback.is-wrong { border-left-color: var(--bad); }
.feedback.is-blank { border-left-color: var(--warn); }
.verdict { font-size: 19px; font-weight: 700; margin: 0 0 6px; }
.is-correct .verdict { color: var(--ok); }
.is-wrong .verdict { color: var(--bad); }
.is-blank .verdict { color: var(--warn); }
.source { font-size: 14px; color: var(--muted); }
.source a { color: var(--primary); }

details { margin: 10px 0; }
summary { min-height: 40px; display: flex; align-items: center; cursor: pointer; font-weight: 600; color: var(--primary); }
.why-list { margin: 6px 0; padding-left: 20px; }
.why-list li { margin: 6px 0; }

.flag-box { margin-top: 10px; }

/* "Testo della norma": verbatim text of the law under the explanation */
.evidence p { margin: 8px 0; font-size: 15px; white-space: pre-line; overflow-wrap: anywhere; }
.review-note { font-size: 15px; background: var(--bad-soft); border-radius: 8px; padding: 8px; }

/* Diagnostica table: 7 columns, allow horizontal scroll inside the card on narrow phones */
.table-scroll { overflow-x: auto; }
.diag-table { font-size: 12.5px; }
.diag-table th, .diag-table td { padding: 6px 2px; }
.diag-table td:first-child { min-width: 84px; }

/* ---------- Progress, grid, tables ---------- */
.progress { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin: 6px 0 10px; }
.progress > div { height: 100%; background: var(--primary); }

.nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin: 8px 0; }
.nav-grid button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.nav-grid button.answered { background: var(--primary-soft); border-color: var(--primary); }
.nav-grid button.current { outline: 3px solid var(--primary); outline-offset: 1px; font-weight: 700; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 8px 4px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.weak td { background: var(--bad-soft); }
tr.weak td:first-child { font-weight: 700; }

.big-score { font-size: 40px; font-weight: 800; margin: 4px 0; }
.pass { color: var(--ok); }
.fail { color: var(--bad); }

.notice { background: var(--warn-soft); color: var(--warn); border: 0; }
.notice ul { margin: 4px 0; padding-left: 20px; }

.error-item { border-bottom: 1px solid var(--border); padding: 8px 0; font-size: 15px; word-break: break-word; }
.error-item:last-child { border-bottom: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  z-index: 50;
}

.hidden { display: none !important; }

/* ---------- Home: countdown, daily session, estimate, progress per subject ---------- */
.countdown {
  margin: 0 0 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  text-align: center;
}
.menu-btn.daily { min-height: 76px; background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.menu-btn.daily strong { font-size: 20px; }
.menu-btn.daily span { color: inherit; opacity: .9; }
.menu-btn.daily.highlight { background: var(--primary); }
.menu-btn.daily.done { background: var(--ok-soft); border-color: var(--ok); color: var(--text); }
.menu-btn.daily.done strong { color: var(--ok); }
.menu-btn.daily.done span { color: var(--muted); opacity: 1; }

.estimate p { margin: 4px 0; }
.estimate-line { overflow-wrap: anywhere; }

.subject-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.subject-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.subject-row:active { transform: scale(.99); }
.subject-row.empty { cursor: default; color: var(--muted); opacity: .6; border-style: dashed; }
.subject-name { font-weight: 700; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.metric { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.metric-label { flex: none; width: 88px; color: var(--muted); }
.metric-num { flex: none; min-width: 56px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { flex: 1; min-width: 40px; height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar.ok > span { background: var(--ok); }
.subject-recent { font-size: 14px; }

.notice-info { background: var(--primary-soft); border: 0; }
.english-label { font-size: 15px; font-weight: 600; }

.field { display: block; margin: 8px 0; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type="number"], input[type="date"] {
  width: 100%;
  min-height: var(--tap);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
}
