/* TOEFL trainer. One stylesheet, no build step. Light and dark follow the system setting. */
:root {
  --bg: #f4f5f8; --card: #ffffff; --ink: #1b2130; --muted: #647087; --line: #e3e6ed; --soft: #f0f2f6;
  --acc: #4450e0; --acc-ink: #ffffff; --acc-soft: #eceefe;
  --ok: #0f7a56; --ok-soft: #e2f5ec; --bad: #c0340f; --bad-soft: #fdeae4; --warn: #a85a06; --warn-soft: #fff2dc;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 6px rgba(16, 24, 40, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --serif: Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117; --card: #171b24; --ink: #e7e9f0; --muted: #98a3b8; --line: #293041; --soft: #1e2330;
    --acc: #8d95ff; --acc-ink: #0e1117; --acc-soft: #232850;
    --ok: #4ec790; --ok-soft: #11301f; --bad: #ff8d6b; --bad-soft: #3b1d13; --warn: #f3b35c; --warn-soft: #382910;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
ul, ol { margin: 0 0 .8em; padding-left: 1.3em; }
li { margin: .2em 0; }
code, kbd { font-family: var(--mono); font-size: .92em; background: var(--soft); padding: .1em .35em; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 1.1rem; padding: 4px 10px 14px; display: flex; align-items: baseline; gap: 8px; }
.brand small { font-weight: 500; color: var(--muted); font-size: .72rem; }
.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ink); font-weight: 500; }
.nav:hover { background: var(--soft); text-decoration: none; }
.nav.on { background: var(--acc-soft); color: var(--acc); }
.nav .ico { width: 22px; text-align: center; font-size: 1.05rem; }
.side .grow { flex: 1; }
.status { font-size: .8rem; color: var(--muted); padding: 8px 10px; display: flex; gap: 8px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.main { padding: 28px 32px 80px; max-width: 1080px; width: 100%; margin: 0 auto; }
@media (max-width: 880px) {
  .app { display: block; }
  .side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 20; justify-content: space-around; gap: 0; }
  .brand, .side .grow, .status, .nav.sm-hide { display: none; }
  .nav { flex-direction: column; gap: 0; font-size: .66rem; padding: 4px 6px; min-width: 0; }
  .nav .ico { font-size: 1.2rem; }
  .main { padding: 18px 14px 96px; }
  h1 { font-size: 1.4rem; }
}

/* ---------- building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 14px; }
.card.flat { box-shadow: none; }
.card.acc { border-color: var(--acc); background: var(--acc-soft); }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > .card + .card { margin-top: 0; }
@media (max-width: 880px) { .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; } .grid.c4.keep2, .grid.c3.keep2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.tiny { font-size: .76rem; }
.center { text-align: center; }
.mt { margin-top: 14px; } .mt2 { margin-top: 24px; } .mb0 { margin-bottom: 0; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.lead { color: var(--muted); margin-bottom: 18px; max-width: 70ch; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn:hover { background: var(--soft); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--acc); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--acc); padding-left: 8px; padding-right: 8px; }
.btn.sm { padding: 5px 10px; font-size: .86rem; border-radius: 8px; }
.btn.big { padding: 13px 22px; font-size: 1.05rem; }
.btn.danger { color: var(--bad); }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.acc { background: var(--acc-soft); color: var(--acc); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.tile { display: block; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--acc); text-decoration: none; }
.tile h3 { margin-bottom: 4px; }
.tile p { margin: 0; color: var(--muted); font-size: .9rem; }
.tile .meta { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }

.list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); color: inherit; }
.item:first-child { border-top: 0; }
a.item:hover { background: var(--soft); text-decoration: none; }
.item .t { font-weight: 600; }
.item .d { color: var(--muted); font-size: .86rem; }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: .8rem; color: transparent; cursor: pointer; background: transparent; padding: 0; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }

.bar { height: 8px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--acc); border-radius: 999px; }
.bar.ok > i { background: var(--ok); }

.note { border-left: 3px solid var(--acc); background: var(--acc-soft); padding: 10px 14px; border-radius: 0 10px 10px 0; margin: 0 0 .9em; }
.note.warn { border-color: var(--warn); background: var(--warn-soft); }
.note.ok { border-color: var(--ok); background: var(--ok-soft); }
.note.bad { border-color: var(--bad); background: var(--bad-soft); }
.note > :last-child { margin-bottom: 0; }

.tabs { display: flex; gap: 4px; background: var(--soft); padding: 4px; border-radius: 12px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tab { border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted); padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.tab.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

table.t { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 600; font-size: .8rem; border-top: 0; }

input.in, select.in, textarea.in { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
input.in:focus, select.in:focus, textarea.in:focus, textarea.editor:focus { outline: 2px solid var(--acc); outline-offset: 1px; }
label.f { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .92rem; z-index: 50; max-width: 90vw; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.spin { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--acc); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- stats ---------- */
.stat { text-align: left; }
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .82rem; }
.bigscore { font-size: 3rem; font-weight: 800; line-height: 1; }
.bigscore small { font-size: 1.1rem; color: var(--muted); font-weight: 600; }

/* ---------- lessons ---------- */
.prose { max-width: 74ch; }
.prose h2 { margin-top: 1.4em; }
.prose h3 { margin-top: 1.1em; }
.en { font-family: var(--serif); font-size: 1.04rem; }
.sample { background: var(--soft); border-radius: 12px; padding: 14px 16px; font-family: var(--serif); font-size: 1.04rem; white-space: pre-wrap; margin: 0 0 .9em; }
.part { display: grid; grid-template-columns: 124px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-top: 1px dashed var(--line); }
.part:first-child { border-top: 0; }
.part .k { font-size: .76rem; font-weight: 700; color: var(--acc); text-transform: uppercase; letter-spacing: .04em; padding-top: 4px; }
.part .v { font-family: var(--serif); font-size: 1.04rem; white-space: pre-wrap; }
@media (max-width: 600px) { .part { grid-template-columns: 1fr; gap: 2px; } }
.skeleton { display: grid; gap: 6px; margin: 0 0 1em; }
.skeleton > div { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; background: var(--soft); border-radius: 10px; padding: 9px 12px; }
.skeleton b.num { background: var(--acc); color: var(--acc-ink); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; }
.phrase { display: inline-block; font-family: var(--serif); background: var(--soft); border-radius: 8px; padding: 3px 9px; margin: 0 6px 6px 0; cursor: default; }
button.phrase { border: 1px solid transparent; color: inherit; font-size: 1rem; cursor: pointer; }
button.phrase:hover { border-color: var(--acc); }
.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cmp > div { border-radius: 12px; padding: 12px 14px; font-family: var(--serif); }
.cmp .no { background: var(--bad-soft); } .cmp .yes { background: var(--ok-soft); }
.cmp .cap { font: 700 .74rem var(--font); letter-spacing: .04em; text-transform: uppercase; display: block; margin-bottom: 4px; }
.cmp .no .cap { color: var(--bad); } .cmp .yes .cap { color: var(--ok); }
@media (max-width: 600px) { .cmp { grid-template-columns: 1fr; } }

/* ---------- writing workspace ---------- */
.work { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: start; }
@media (max-width: 980px) { .work { grid-template-columns: 1fr; } }
.prompt { font-family: var(--serif); font-size: 1.04rem; }
.prompt .who { font: 700 .86rem var(--font); margin: 12px 0 2px; display: flex; gap: 8px; align-items: center; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--acc-soft); color: var(--acc); display: grid; place-items: center; font: 700 .8rem var(--font); flex: none; }
.mailhead { font: .9rem var(--mono); color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 8px; }
textarea.editor { width: 100%; min-height: 320px; resize: vertical; font: 1.05rem/1.6 var(--serif); color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.timer { font: 700 1.15rem var(--mono); padding: 4px 12px; border-radius: 10px; background: var(--soft); }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--soft); color: var(--muted); border: 1px solid transparent; }
.chip.on { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
details.fold { border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--card); }
details.fold + details.fold { margin-top: 8px; }
details.fold > summary { cursor: pointer; font-weight: 600; padding: 11px 0; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "+"; color: var(--muted); font-weight: 700; }
details.fold[open] > summary::after { content: "–"; }
details.fold > .body { padding: 0 0 14px; }

/* ---------- review ---------- */
.answer { font-family: var(--serif); font-size: 1.06rem; white-space: pre-wrap; line-height: 1.75; }
mark.err { background: var(--bad-soft); color: inherit; border-bottom: 2px solid var(--bad); cursor: pointer; border-radius: 3px; padding: 0 1px; }
mark.err.sel { background: var(--bad); color: #fff; }
mark.up { background: var(--warn-soft); color: inherit; border-bottom: 2px dotted var(--warn); border-radius: 3px; }
.fix { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 10px 0; border-top: 1px solid var(--line); }
.fix:first-child { border-top: 0; }
.fix.sel { background: var(--bad-soft); margin: 0 -10px; padding: 10px; border-radius: 10px; border-top-color: transparent; }
.fix .q { font-family: var(--serif); }
.fix .q s { color: var(--bad); text-decoration-thickness: 1.5px; }
.fix .q b { color: var(--ok); font-weight: 600; }
.crit { display: grid; grid-template-columns: 150px 86px minmax(0, 1fr); gap: 10px; align-items: start; padding: 8px 0; border-top: 1px solid var(--line); font-size: .93rem; }
.crit:first-child { border-top: 0; }
.pips { display: flex; gap: 3px; padding-top: 6px; }
.pips i { width: 13px; height: 8px; border-radius: 3px; background: var(--soft); }
.pips i.on { background: var(--acc); }
@media (max-width: 700px) { .crit { grid-template-columns: 1fr 86px; } .crit > :last-child { grid-column: 1 / -1; } }
.checks .ck { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; padding: 6px 0; font-size: .94rem; }
.ck .i { font-weight: 800; }
.ck.ok .i { color: var(--ok); } .ck.bad .i { color: var(--bad); } .ck.warn .i { color: var(--warn); }
.ck .d { color: var(--muted); font-size: .86rem; }

/* ---------- quiz ---------- */
.q { font-size: 1.06rem; font-weight: 600; margin-bottom: 12px; white-space: pre-wrap; }
.opts { display: grid; gap: 8px; }
.opt { text-align: left; font: inherit; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 14px; cursor: pointer; display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 8px; align-items: start; }
.opt:hover:not(:disabled) { border-color: var(--acc); }
.opt .l { font-weight: 700; color: var(--muted); }
.opt.pick { border-color: var(--acc); background: var(--acc-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.explain { margin-top: 12px; }
.passage { font-family: var(--serif); font-size: 1.06rem; line-height: 1.75; white-space: pre-wrap; }
.passage.doc { background: var(--soft); border-radius: 12px; padding: 14px 16px; }
.bubble { max-width: 82%; background: var(--soft); border-radius: 14px 14px 14px 4px; padding: 8px 12px; margin: 6px 0; font-family: var(--serif); }
.bubble.me { margin-left: auto; background: var(--acc-soft); border-radius: 14px 14px 4px 14px; }
.bubble .n { font: 700 .74rem var(--font); color: var(--muted); display: block; }
.ctw { font-family: var(--serif); font-size: 1.12rem; line-height: 2.3; }
.ctw .w { white-space: nowrap; }
.ctw input { font: inherit; font-family: var(--mono); font-size: 1rem; letter-spacing: .12em; border: 0; border-bottom: 2px solid var(--acc); background: var(--acc-soft); color: var(--ink); padding: 1px 3px; margin-left: 1px; border-radius: 4px 4px 0 0; }
.ctw input.right { border-color: var(--ok); background: var(--ok-soft); }
.ctw input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.ctw .fixd { color: var(--ok); font-weight: 600; font-size: .9rem; margin-left: 4px; }

/* ---------- build a sentence ---------- */
.bas .ctx { font-family: var(--serif); font-size: 1.15rem; margin-bottom: 14px; }
.bas .line { font-family: var(--serif); font-size: 1.15rem; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 48px; }
.slot { min-width: 64px; min-height: 40px; border: 2px dashed var(--line); border-radius: 10px; display: inline-grid; place-items: center; padding: 0 4px; }
.slot.full { border-style: solid; border-color: transparent; padding: 0; }
.slot.right .chunk { background: var(--ok-soft); border-color: var(--ok); }
.slot.wrong .chunk { background: var(--bad-soft); border-color: var(--bad); }
.chunk { font: 1.08rem var(--serif); color: var(--ink); background: var(--card); border: 1.5px solid var(--acc); border-radius: 10px; padding: 7px 12px; cursor: pointer; user-select: none; }
.chunk:hover { background: var(--acc-soft); }
.chunk.used { visibility: hidden; }
.bank { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding: 14px; background: var(--soft); border-radius: 12px; min-height: 68px; }

/* ---------- audio / speaking ---------- */
.player { display: flex; gap: 12px; align-items: center; background: var(--soft); border-radius: 12px; padding: 12px 14px; }
.wave { flex: 1; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.wave > i { display: block; height: 100%; width: 0; background: var(--acc); }
.playing .wave > i { width: 40%; animation: slide 1.2s ease-in-out infinite alternate; }
@keyframes slide { from { margin-left: 0; } to { margin-left: 60%; } }
.rec { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--bad); }
.rec::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.heard .miss { color: var(--bad); text-decoration: line-through; }
.heard .add { color: var(--warn); }
.heard .hit { color: var(--ok); }

/* ---------- flashcards ---------- */
.flash { min-height: 250px; display: grid; place-items: center; text-align: center; padding: 28px 20px; }
.flash .ru { font-size: 1.35rem; font-weight: 600; }
.flash .term { font: 600 1.5rem var(--serif); margin-top: 14px; }
.flash .ex { font-family: var(--serif); color: var(--muted); margin-top: 8px; }
.grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grade .btn { justify-content: center; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font: 11px var(--font); }
.chart .axis { stroke: var(--line); }
.chart .ln { fill: none; stroke: var(--acc); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--card); stroke: var(--acc); stroke-width: 2.5; }
.chart .goal { stroke: var(--ok); stroke-dasharray: 5 5; }
