:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1b2330; --muted: #667085; --line: #e3e6ea;
  --brand: #1f3a5f; --brand-ink: #fff; --head: #1f3a5f; --head-ink: #fff; --accent: #c2410c;
  --right: #15803d; --right-bg: #e8f6ec; --wrong: #b42318; --wrong-bg: #fdecea; --unseen: #d0d5dd;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --card: #18202b; --ink: #e6e9ee; --muted: #98a2b3; --line: #2a3441;
    --brand: #8fb3e6; --brand-ink: #0f141b; --head: #16263b; --head-ink: #e6e9ee; --accent: #fb923c;
    --right: #4ade80; --right-bg: #12301f; --wrong: #f87171; --wrong-bg: #3a1717; --unseen: #3a4553;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.4rem; line-height: 1.25; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.err { color: var(--wrong); }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .75rem;
  padding: .55rem max(16px, env(safe-area-inset-left)); padding-top: max(.55rem, env(safe-area-inset-top));
  background: var(--head); color: var(--head-ink); }
.top a { color: inherit; text-decoration: none; }
.brand { font-weight: 700; letter-spacing: .02em; }
.top nav { display: flex; gap: .25rem; margin-left: auto; }
.top nav a { padding: .35rem .6rem; border-radius: 8px; opacity: .8; font-size: .95rem; }
.top nav a.on { opacity: 1; background: rgba(255,255,255,.18); }
.logout button { display: grid; background: none; border: 0; color: inherit; cursor: pointer; padding: .35rem; opacity: .8; }

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

/* cards & buttons */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 0 0 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: .55rem 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.accent { border-color: var(--accent); color: var(--accent); }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn.wide { display: flex; width: 100%; margin-bottom: 16px; }
.btn[aria-disabled="true"] { opacity: .55; }
.pill { background: var(--bg); border-radius: 99px; padding: 0 .5rem; font-size: .8rem; color: var(--muted); }
.link { background: none; border: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.danger { color: var(--wrong); }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-bottom: .6rem; }
.quick.center { display: flex; justify-content: center; flex-wrap: wrap; }

/* home */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stats b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stats small { font-size: .9rem; color: var(--muted); font-weight: 400; }
.stats span { font-size: .8rem; color: var(--muted); }
.doms { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.dom { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); }
.dom:hover { border-color: var(--brand); }
.dom-h { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.dom-n { font-size: .85rem; color: var(--muted); margin: .15rem 0 .5rem; min-height: 2.5em; }
.bar { display: flex; height: 8px; border-radius: 99px; background: var(--unseen); overflow: hidden; }
.bar .r { background: var(--right); } .bar .w { background: var(--wrong); }
.key { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; background: var(--unseen); margin: 0 .25rem 0 .5rem; vertical-align: -1px; }
.key.r { background: var(--right); margin-left: 0; } .key.w { background: var(--wrong); }

/* question */
.qhead { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.qhead .tag { margin-left: auto; }
.tag { font-size: .78rem; font-weight: 600; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: .1rem .55rem; white-space: nowrap; }
.flag { background: none; border: 1px solid var(--line); border-radius: 8px; width: 40px; height: 36px; font-size: 1.05rem; color: var(--muted); cursor: pointer; }
.flag.on { color: var(--accent); border-color: var(--accent); }
.progress { height: 4px; background: var(--line); border-radius: 99px; margin-bottom: 14px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--brand); }
.scenario { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: .93rem; }
.scenario summary { cursor: pointer; font-weight: 700; }
.scenario p { margin: .6rem 0 0; }
.qtext { font-size: 1.12rem; line-height: 1.45; font-weight: 600; margin: .2rem 0 1rem; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; gap: .75rem; align-items: flex-start; width: 100%; text-align: left; font: inherit; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; min-height: 52px; }
.opt:hover:not(:disabled) { border-color: var(--brand); }
.opt:disabled { cursor: default; }
.opt .letter { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .85rem; background: var(--bg); }
.opt.right { border-color: var(--right); background: var(--right-bg); }
.opt.right .letter { background: var(--right); color: #fff; }
.opt.wrong { border-color: var(--wrong); background: var(--wrong-bg); }
.opt.wrong .letter { background: var(--wrong); color: #fff; }
.opt:disabled:not(.right):not(.wrong) { opacity: .6; }
.feedback { margin-top: 14px; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.feedback.ok { border-left: 4px solid var(--right); } .feedback.ko { border-left: 4px solid var(--wrong); }
.feedback.ok > b { color: var(--right); } .feedback.ko > b { color: var(--wrong); }
.feedback p { margin: .5rem 0 0; }
.actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.big { font-size: 2.2rem; font-weight: 700; margin: .3rem 0; }
.big small { font-size: 1rem; color: var(--muted); font-weight: 400; }

/* wide screens: long scenario in a sticky column beside the question */
@media (min-width: 1000px) {
  main#app.wide { max-width: 1240px; }
  .wide .qgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
  .wide .scenario { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow-y: auto; margin: 0; }
  .wide .qgrid:has(.scenario:not([open])) { grid-template-columns: 1fr; }
  .wide .scenario:not([open]) { position: static; }
}

/* lists */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; padding: .3rem .75rem; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font-size: .88rem; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.qlist { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.qlist li + li { border-top: 1px solid var(--line); }
.qlist a { display: flex; align-items: center; gap: .6rem; padding: 10px 12px; color: var(--ink); text-decoration: none; }
.qlist a:hover { background: var(--bg); }
.qlist .num { flex: none; width: 1.8rem; font-weight: 700; color: var(--muted); font-size: .9rem; }
.qlist .qt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .93rem; }
.qlist .fl { color: var(--accent); }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--unseen); }
.dot.right { background: var(--right); } .dot.wrong { background: var(--wrong); }

/* study */
.crumbs { font-size: .88rem; color: var(--muted); margin: 0 0 .3rem; }
.chap { display: flex; gap: .7rem; align-items: center; padding: 10px 4px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.chap:hover { color: var(--brand); }
.num { font-weight: 700; color: var(--brand); }
.chap .num { width: 1.6rem; text-align: center; }
.summary p { margin: .4rem 0 0; }
.sec { background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.sec summary { cursor: pointer; padding: 12px 14px; font-weight: 600; }
.sec ul { margin: 0; padding: 0 16px 12px 34px; }
.sec li { margin: .35rem 0; }
.terms dt { font-weight: 700; margin-top: .8rem; }
.terms dd { margin: .15rem 0 0; }
input[type=search], input[type=password] { width: 100%; font: inherit; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
#gl { margin-top: 8px; }

/* login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.card form { display: grid; gap: .7rem; }
.card label { font-weight: 600; font-size: .9rem; }

@media (max-width: 520px) {
  .top nav a { padding: .35rem .45rem; font-size: .9rem; }
  .brand { font-size: .95rem; }
  .actions .btn { flex: 1; }
  .qtext { font-size: 1.05rem; }
}
