:root {
  --ink: #1d2a3a;
  --muted: #5b6b7f;
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #dde3ee;
  --brand: #2f5bea;
  --brand-dark: #1f43b8;
  --accent: #ff9f1c;
  --ok: #1a9e5c;
  --ok-bg: #e6f7ee;
  --bad: #d83a3a;
  --bad-bg: #fdecec;
  --radius: 14px;
  font-size: 17px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--brand); }

/* ---------- top bar ---------- */
.topbar {
  background: var(--brand);
  color: #fff;
  padding: .7rem 1.2rem;
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
  font-weight: 700;
}
.topbar a { color: #fff; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.topbar .sep { opacity: .6; }
.topbar .logo { font-size: 1.1rem; }

main { max-width: 860px; margin: 0 auto; padding: 1.5rem 1.1rem 4rem; }

/* ---------- home ---------- */
.hero { padding: 1.5rem 0 1rem; }
.hero h1 { font-size: 2.1rem; margin: 0 0 .3rem; }
.hero p { color: var(--muted); margin: 0; font-size: 1.1rem; }
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.topic-card {
  display: block; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem 1.3rem; transition: transform .15s, box-shadow .15s;
  border-top: 6px solid var(--brand);
}
.topic-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(30,50,100,.12); }
.topic-card .kicker { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.topic-card h2 { margin: .2rem 0 .4rem; font-size: 1.35rem; }
.topic-card p { margin: 0; color: var(--muted); font-size: .95rem; }
.topic-card.soon { opacity: .55; pointer-events: none; border-top-color: var(--line); }

/* ---------- topic page ---------- */
.level { margin-top: 1.8rem; }
.level h2 { margin: 0 0 .2rem; font-size: 1.3rem; }
.level-desc { margin: 0 0 .8rem; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; }
.act-card {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: .8rem;
  align-items: center; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem;
  transition: transform .15s, box-shadow .15s;
}
.act-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(30,50,100,.1); }
.act-card .num {
  grid-row: span 2; width: 2.3rem; height: 2.3rem; border-radius: 50%;
  display: grid; place-items: center; background: #e8eefc; color: var(--brand); font-weight: 800;
}
.act-card .t { font-weight: 700; line-height: 1.25; }
.act-card .best { font-size: .82rem; color: var(--muted); }
.act-card.done .num { background: var(--ok); color: #fff; }
.act-card.done .best { color: var(--ok); font-weight: 700; }

/* ---------- activity page ---------- */
.act-head { margin-bottom: 1rem; }
.eyebrow { font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.act-head h1 { margin: .15rem 0 .4rem; font-size: 1.8rem; }
.instructions { margin: 0 0 .5rem; font-size: 1.05rem; }
.example { margin: 0 0 .7rem; color: var(--muted); background: var(--card); border-left: 4px solid var(--accent); padding: .45rem .8rem; border-radius: 0 8px 8px 0; }
.tip-btn { margin-top: .2rem; }
.bank {
  display: flex; flex-wrap: wrap; gap: .45rem; align-items: center;
  border: 2px dashed #9fb2e8; border-radius: 12px; padding: .6rem .8rem; margin: 0 0 .8rem; background: #fff;
}
.bank-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; color: var(--muted); margin-right: .3rem; }
.bank .word { background: #eef2fd; color: var(--brand-dark); font-weight: 700; padding: .15rem .65rem; border-radius: 999px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.3rem; }
.items { margin: 0; padding-left: 1.6rem; }
.item { padding: .75rem 0; border-bottom: 1px dashed var(--line); }
.item:last-child { border-bottom: 0; }
.item::marker { color: var(--muted); font-weight: 700; }
.line { line-height: 2.3; }
.answer-row { display: flex; align-items: center; gap: .6rem; margin-top: .4rem; flex-wrap: wrap; }
.answer-row .label { font-weight: 700; color: var(--muted); min-width: 6.5rem; }
.answer-row .gap-write { flex: 1; min-width: 240px; }

.is-passage { list-style: none; padding-left: 0; }
.passage .line { line-height: 2.5; font-size: 1.05rem; }
.gapnum {
  display: inline-grid; place-items: center; width: 1.3rem; height: 1.3rem; margin: 0 2px 0 4px;
  font-size: .7rem; font-weight: 800; border-radius: 50%; background: #e8eefc; color: var(--brand); vertical-align: middle;
}

/* gaps */
.gap { display: inline-flex; align-items: center; gap: .25rem; vertical-align: middle; }
.gap input, .gap select {
  font: inherit; color: var(--ink);
  border: 2px solid #b9c4d8; border-radius: 9px; padding: .15rem .5rem; background: #fbfcff;
  min-width: 4ch; transition: border-color .15s, background .15s; line-height: 1.4;
}
.choice { line-height: 1.4; }
.gap select { padding-right: .2rem; cursor: pointer; }
.gap-write input { width: 100%; padding: .4rem .7rem; }
.gap input:focus, .gap select:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(47,91,234,.15); }
.gap.ok input, .gap.ok select { border-color: var(--ok); background: var(--ok-bg); }
.gap.bad input, .gap.bad select { border-color: var(--bad); background: var(--bad-bg); }
.mark { font-weight: 900; width: 1.1rem; display: inline-block; }
.gap.ok .mark { color: var(--ok); }
.gap.bad .mark { color: var(--bad); }

.choices { display: inline-flex; gap: .45rem; flex-wrap: wrap; }
.choice {
  font: inherit; cursor: pointer; padding: .3rem .85rem; border-radius: 999px;
  border: 2px solid #b9c4d8; background: #fbfcff; color: var(--ink);
}
.choice:hover { border-color: var(--brand); }
.choice.picked { background: var(--brand); border-color: var(--brand); color: #fff; }
.gap.ok .choice.picked { background: var(--ok); border-color: var(--ok); }
.gap.bad .choice.picked { background: var(--bad); border-color: var(--bad); }

/* buttons */
.btn {
  font: inherit; font-weight: 800; cursor: pointer; text-decoration: none; display: inline-block;
  border-radius: 999px; padding: .6rem 1.3rem; border: 2px solid transparent;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; color: var(--brand); border-color: #c9d5f5; }
.btn-ghost:hover { border-color: var(--brand); }
.actions { display: flex; gap: .7rem; margin-top: 1.1rem; flex-wrap: wrap; }

.result { margin-top: 1rem; padding: .8rem 1.1rem; border-radius: var(--radius); display: none; font-size: 1.05rem; }
.result.show { display: block; }
.result .score { font-weight: 900; font-size: 1.3rem; margin-right: .4rem; }
.result.perfect { background: var(--ok-bg); color: #13603a; }
.result.good { background: #fff5e3; color: #7a4a00; }
.result.low { background: var(--bad-bg); color: #8a1f1f; }
.result .x { color: var(--bad); }

.pager { display: flex; justify-content: space-between; gap: .6rem; margin-top: 2rem; flex-wrap: wrap; }

.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,159,28,.55); } 50% { box-shadow: 0 0 0 8px rgba(255,159,28,0); } }

/* ---------- tip modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(20,30,50,.45);
  display: none; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.modal.show { display: flex; animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: #fff; border-radius: 18px; max-width: 520px; width: 100%; max-height: 88vh; overflow: auto;
  padding: 1.3rem 1.5rem 1.4rem; border-top: 8px solid var(--accent); box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal-title { margin: 0 0 .6rem; font-size: 1.35rem; }
.modal-body p { margin: .4rem 0; }
.modal-body table { border-collapse: collapse; margin: .5rem 0; width: 100%; }
.modal-body th, .modal-body td { border: 1px solid var(--line); padding: .3rem .6rem; text-align: left; }
.modal-body th { background: #f3f6fc; }
.modal-body .eg { color: var(--muted); font-style: italic; }
.modal-body .warn { color: var(--bad); font-weight: 700; }
.modal-box .btn { margin-top: .9rem; }

footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 2rem 1rem; }

@media (max-width: 560px) {
  :root { font-size: 16px; }
  .hero h1 { font-size: 1.7rem; }
  .act-head h1 { font-size: 1.5rem; }
  .card { padding: .8rem .9rem; }
  .answer-row .label { min-width: 0; width: 100%; }
}

/* ---------- login, user box and reports ---------- */
.topbar .userbox { margin-left: auto; display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; font-size: .92rem; }
.topbar .userbox .who { opacity: .9; }
.login { max-width: 440px; margin: 1rem auto; padding: 1.4rem 1.6rem; }
.login h1 { margin-top: 0; }
.login label { display: block; font-weight: 700; margin: .9rem 0 .3rem; }
.login input { width: 100%; box-sizing: border-box; font: inherit; font-size: 1.1rem; padding: .6rem .8rem; border: 2px solid var(--line); border-radius: 10px; }
.login input:focus { outline: none; border-color: var(--brand); }
.login #code { letter-spacing: .4em; font-weight: 800; }
.login .btn { margin-top: 1rem; margin-right: .4rem; }
.hint { color: var(--muted); font-size: .88rem; margin: .4rem 0 0; }
.msg { margin-top: .9rem; font-weight: 700; color: var(--muted); }
.msg.bad { color: var(--bad); }

main.wide { max-width: 1200px; }
.report-topic, .toolbar, .student-head { margin-bottom: 1rem; }
.report-topic h2, .card h2 small, .student-head h2 small { font-size: 1.15rem; }
.card h2 small, .report-topic h2 small { color: var(--muted); font-weight: 700; font-size: .85rem; margin-left: .4rem; }
.table-wrap { overflow-x: auto; }
table.report { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.report th, table.report td { border-bottom: 1px solid var(--line); padding: .45rem .5rem; text-align: left; vertical-align: top; }
table.report th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
table.report tr.none td { color: #a3adbb; }
table.report small { color: var(--muted); }
table.report details summary { cursor: pointer; color: var(--brand); font-weight: 700; }
.tries { margin: .4rem 0 0; padding-left: 1.4rem; }
.tries li { margin: .2rem 0; }
.pill { display: inline-block; min-width: 2.6rem; text-align: center; padding: .05rem .45rem; border-radius: 999px; font-weight: 800; font-size: .85rem; }
.pill.perfect, .cell.perfect { background: var(--ok-bg); color: #13603a; }
.pill.good, .cell.good { background: #e8eefc; color: var(--brand-dark); }
.pill.low, .cell.low { background: var(--bad-bg); color: #8a1f1f; }
table.matrix th, table.matrix td { text-align: center; padding: .35rem .3rem; border: 1px solid var(--line); }
table.matrix td.name, table.matrix th.name { text-align: left; min-width: 11rem; }
table.matrix td.name small { display: block; }
table.matrix td.cell { cursor: pointer; min-width: 2.8rem; line-height: 1.15; }
table.matrix td.cell b { display: block; }
table.matrix td.cell small { color: inherit; opacity: .75; }
table.matrix td.empty { cursor: default; }
.toolbar { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.toolbar label { font-weight: 700; display: flex; gap: .4rem; align-items: center; }
.toolbar select, .toolbar input { font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 8px; }
.student-head h2 { margin: .5rem 0; }
