/* QuizAde — styles.
   Plain, institutional look: neutral page, white panels with hairline borders, one navy accent,
   small radii, no gradients or glow. Press feedback on pointer-down; honours reduced motion,
   reduced transparency and increased contrast. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7; --panel: #ffffff; --tint: #f4f6fa;
  --ink: #111827; --soft: #5b6472; --line: #d9dde4;
  --accent: #1f2023; --accent-ink: #ffffff;
  --good: #1f7a4d; --bad: #b42318; --warn: #a15c07;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --r: .375rem; --r-lg: .5rem;
  --shadow-lg: 0 16px 48px -12px rgba(17, 24, 39, .3);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --panel: #161b22; --tint: #1b222c;
    --ink: #e8ecf2; --soft: #9aa4b2; --line: #2a323d;
    --accent: #f3f3f5; --accent-ink: #121214;
    --good: #4cc38a; --bad: #f0857a; --warn: #e0a458;
    --shadow-lg: 0 16px 48px -12px rgba(0, 0, 0, .7);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; min-height: 100dvh;
  font: 1rem/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased; font-optical-sizing: auto;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.5rem, 3.5vw, 1.875rem); letter-spacing: -.025em; font-weight: 650; line-height: 1.15; }
h2 { font-size: 1.125rem; letter-spacing: -.01em; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r); }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 1rem; height: 3.5rem; padding: 0 max(1rem, calc((100% - 76rem) / 2 + 1.5rem), env(safe-area-inset-right)) 0 max(1rem, calc((100% - 76rem) / 2 + 1.5rem), env(safe-area-inset-left)); background: color-mix(in srgb, var(--panel) 78%, transparent); -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px); border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent); }
body.auth-mode .topbar { display: none; }
.brand { display: flex; align-items: center; gap: .625rem; color: inherit; text-decoration: none; }
.mark { width: 1.875rem; height: 1.875rem; padding: .3rem; border-radius: .5rem; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); flex: none; }
.mark svg { display: block; width: 100%; height: 100%; }
.brand-name { font-weight: 600; font-size: 1.125rem; letter-spacing: -.02em; }
.brand-name b { font-weight: 700; color: var(--accent); }
.top-right { display: flex; align-items: center; gap: 1.25rem; min-width: 0; }
.quota { margin: 0; font-size: .8125rem; color: var(--soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.quota[hidden], .account[hidden] { display: none; }
.quota.low { color: var(--bad); font-weight: 600; }
.account { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.acct-avatar { width: 1.875rem; height: 1.875rem; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 600; font-size: .8125rem; background: var(--tint); color: var(--ink); border: 1px solid var(--line); }
.acct-email { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; color: var(--soft); max-width: 14rem; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: .875rem; font-weight: 600; min-height: 2.75rem; padding: 0 .25rem; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 14.5rem minmax(0, 1fr); gap: 2rem; padding: 1.5rem; max-width: 76rem; margin: 0 auto; }
.sidebar { position: sticky; top: 5rem; align-self: start; max-height: calc(100dvh - 6.5rem); display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.main { min-width: 0; padding-bottom: 4rem; outline: none; }
@media (max-width: 800px) {
  .topbar { padding: 0 1rem; }
  .acct-email, .quota { display: none; }
  .app { grid-template-columns: minmax(0, 1fr); padding: 1rem; gap: 1rem; }
  .sidebar { position: static; max-height: none; flex-direction: row; align-items: center; gap: .5rem; }
  .side-head h2 { display: none; }
  .side-head { order: 2; }
  .subjects { order: 1; flex-direction: row; overflow-x: auto; scrollbar-width: none; flex: 1; }
  .subjects::-webkit-scrollbar { display: none; }
  .subjects li { flex: none; }
  .subjects .count { display: none; }
}

/* ---------- sidebar ---------- */
.side-head { display: flex; justify-content: space-between; align-items: center; }
.side-head h2 { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); font-weight: 600; }
.icon-btn { width: 2.75rem; height: 2.75rem; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); color: var(--ink); display: grid; place-items: center; cursor: pointer; transition: scale .12s var(--ease), border-color .15s; }
.icon-btn:active { scale: .94; }
.subjects { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .125rem; flex: 1; overflow-y: auto; }
.subjects li { display: flex; align-items: center; gap: .625rem; min-height: 2.75rem; padding: .25rem .75rem; border-radius: var(--r); cursor: pointer; border-left: 3px solid transparent; transition: background-color .15s; user-select: none; -webkit-user-select: none; }
.subjects li:focus-visible { outline-offset: -2px; }
.subjects li.active { background: var(--panel); border-left-color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.subjects li:active { background: var(--tint); }
.dot { display: none; width: 1.5rem; height: 1.5rem; border-radius: var(--r); display: grid; place-items: center; flex: none; font-size: .75rem; font-weight: 650; background: var(--tint) !important; color: var(--soft); border: 1px solid var(--line); }
.subjects .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subjects .count { color: var(--soft); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.side-empty { color: var(--soft); font-size: .875rem; padding: .25rem .75rem; list-style: none; }

/* ---------- buttons / cards ---------- */
.btn { border: 1px solid var(--accent); border-radius: var(--r); min-height: 2.75rem; padding: .5rem 1.125rem; font-weight: 600; cursor: pointer; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; gap: .5rem; transition: scale .12s var(--ease), background-color .15s, opacity .2s; }
.btn.ghost { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--panel); color: var(--bad); border-color: var(--line); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn:active:not([disabled]), .icon-btn:active { scale: .97; transition-duration: .06s; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not([disabled]) { filter: brightness(1.12); }
  .btn.ghost:hover:not([disabled]), .btn.danger:hover:not([disabled]) { filter: none; background: var(--tint); }
  .icon-btn:hover { border-color: var(--soft); }
  .subjects li:not(.active):hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
  .opt:not([disabled]):hover { border-color: var(--accent); }
  .file button.x:hover { color: var(--bad); }
  .utab:not(.on):hover, .chip:hover, .oauth-btn:hover { border-color: var(--soft); }
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.25rem 1.5rem; margin-bottom: 1rem; }
.card > h3 { margin-bottom: 1rem; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 0 0 1.25rem; }
.meta { color: var(--soft); font-size: .875rem; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--soft); font-weight: 500; padding-inline: .75rem; margin-right: -.75rem; }
.btn.quiet:active:not([disabled]) { background: var(--tint); }
@media (hover: hover) and (pointer: fine) { .btn.quiet:hover:not([disabled]) { filter: none; color: var(--bad); background: var(--tint); } }
.panel { padding: 0; overflow: hidden; }
.sec { padding: 1.25rem 1.5rem; }
.sec + .sec { border-top: 1px solid var(--line); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.75rem; margin: -.5rem 0 .25rem; }
.sec-head .meta { margin: 0; }
.label { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); font-weight: 600; }
.sec > .label { margin-bottom: .75rem; }
.hint { color: var(--soft); font-size: .875rem; margin: -.25rem 0 .75rem; }
.sec .hint:last-child { margin: .75rem 0 0; }
.enter { animation: rise .4s var(--ease) both; animation-delay: calc(var(--i, 0) * 35ms); }
@keyframes rise { from { opacity: 0; translate: 0 .5rem; } to { opacity: 1; translate: 0 0; } }

/* ---------- welcome ---------- */
body.empty .sidebar { display: none; }
body.empty .app { grid-template-columns: minmax(0, 1fr); min-height: calc(100dvh - 3.5rem); align-items: center; }
body.empty .main { padding: 0; }
.welcome { text-align: center; padding: 2rem 1rem; max-width: 32rem; margin: 0 auto; }
.welcome .mark { width: 3.25rem; height: 3.25rem; padding: .6rem; margin: 0 auto 1.25rem; border-radius: .75rem; }
.welcome h1 { margin-bottom: .625rem; }
.welcome > p { color: var(--soft); margin-bottom: 1.5rem; }
.steps { list-style: none; counter-reset: s; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 2.5rem 0 0; padding: 1.5rem 0 0; border-top: 1px solid var(--line); text-align: left; }
.steps li { counter-increment: s; display: grid; gap: .25rem; align-content: start; }
.steps li::before { content: counter(s); font-size: .75rem; font-weight: 600; color: var(--soft); letter-spacing: .08em; }
.steps strong { font-size: .9375rem; font-weight: 600; }
.steps span { color: var(--soft); font-size: .875rem; line-height: 1.45; }
@media (max-width: 560px) { .steps { grid-template-columns: 1fr; } }

/* ---------- drop zone / files ---------- */
.drop { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 1rem 1.125rem; border: 1.5px dashed var(--line); border-radius: var(--r-lg); background: var(--tint); cursor: pointer; transition: border-color .15s, background-color .15s; }
.drop > svg { color: var(--soft); flex: none; }
.drop-text { flex: 1 1 14rem; display: grid; gap: .125rem; min-width: 0; }
.drop-text strong { font-weight: 600; font-size: .9375rem; }
.drop-text span { color: var(--soft); font-size: .8125rem; }
.drop-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.drop-actions .btn { min-height: 2.75rem; font-size: .9375rem; }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--tint)); }
.files { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: .5rem; }
.files:empty { display: none; }
.file { display: flex; align-items: center; gap: .75rem; padding: .5rem .625rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.file img, .file .ph { width: 2.5rem; height: 2.5rem; border-radius: var(--r); object-fit: cover; flex: none; }
.file .ph { display: grid; place-items: center; font-size: .6875rem; font-weight: 700; letter-spacing: .04em; color: var(--soft); background: var(--tint); border: 1px solid var(--line); }
.file .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9375rem; }
.file .sz { color: var(--soft); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.file button.x { width: 2.75rem; height: 2.75rem; display: grid; place-items: center; border: 0; background: none; color: var(--soft); cursor: pointer; border-radius: var(--r); transition: color .15s; }
.file button.x:active { color: var(--bad); }

/* ---------- generate ---------- */
.gen-row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
.stepper button { width: 2.75rem; height: 2.75rem; border: 0; background: none; font-size: 1.25rem; cursor: pointer; color: var(--soft); border-radius: var(--r); }
.stepper button:active { color: var(--accent); background: var(--tint); }
.stepper output { min-width: 5.5rem; text-align: center; font-weight: 600; font-size: .9375rem; font-variant-numeric: tabular-nums; }
.status { color: var(--soft); font-size: .9375rem; margin-top: .75rem; font-variant-numeric: tabular-nums; }
.err { color: var(--bad); font-size: .9375rem; margin-top: .5rem; }
.err:empty { display: none; }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -.2rem; margin-right: .5rem; }
@keyframes spin { to { rotate: 360deg; } }

/* ---------- test ---------- */
.test-bar { position: sticky; top: 4rem; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .625rem 1rem; margin-bottom: 1rem; border-radius: var(--r-lg); background: color-mix(in srgb, var(--panel) 82%, transparent); -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px); border: 1px solid var(--line); }
.test-bar .label { font-weight: 600; font-size: .9375rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.track { flex: 1; height: .375rem; border-radius: 999px; background: var(--line); overflow: hidden; }
.fill { height: 100%; width: 100%; border-radius: inherit; background: var(--accent); transform-origin: left; scale: 0 1; transition: scale .4s var(--ease); }
.q { padding: 1.25rem 1.5rem; margin-bottom: 1rem; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); }
.q .n { color: var(--soft); font-weight: 600; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .375rem; }
.q .prompt { font-size: 1.0625rem; font-weight: 600; line-height: 1.4; margin-bottom: 1rem; }
.opt { display: flex; gap: .75rem; align-items: baseline; width: 100%; text-align: left; min-height: 2.75rem; padding: .625rem .875rem; margin-bottom: .5rem; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); cursor: pointer; transition: border-color .15s, background-color .15s; }
.opt .k { color: var(--soft); font-weight: 650; font-size: .875rem; flex: none; width: 1rem; }
.opt:active:not([disabled]) { background: var(--tint); }
.opt[disabled] { cursor: default; }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 11%, var(--panel)); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--panel)); }
.opt.dim { opacity: .55; }
.opt[disabled]:not(.right):not(.wrong):not(.dim) { cursor: progress; }
.explain { display: grid; grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows .3s var(--ease), visibility 0s .3s; }
.explain.open { grid-template-rows: 1fr; visibility: visible; transition-delay: 0s; }
.explain > div { overflow: hidden; min-height: 0; }
.explain p { padding-top: .75rem; color: var(--soft); font-size: .9375rem; }
.fig { margin: .75rem 0 1rem; padding: .5rem; background: #fff; border: 1px solid var(--line); border-radius: var(--r); }
.fig img { display: block; width: 100%; max-height: 22rem; object-fit: contain; }
.result { text-align: center; padding: 1.75rem 1.5rem; }
.result .big { font-size: 3rem; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.result p { color: var(--soft); margin: .25rem 0 1.25rem; }
.pill { display: inline-flex; align-items: center; gap: .5rem; flex: none; padding: .25rem .625rem; border-radius: var(--r); font-size: .8125rem; color: var(--soft); background: var(--tint); border: 1px solid var(--line); }
.pill .spinner { width: .75rem; height: .75rem; margin: 0; }

/* ---------- forms / dialogs ---------- */
input[type=text], input[type=email], input[type=password], textarea.short, .chat-in { font: inherit; padding: .625rem .875rem; min-height: 2.75rem; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); color: var(--ink); width: 100%; }
textarea.short { min-height: 5.5rem; resize: vertical; margin-bottom: .75rem; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field { display: grid; gap: .375rem; margin: 1rem 0 .25rem; font-weight: 600; font-size: .875rem; }
dialog { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); color: var(--ink); max-width: 26rem; width: calc(100% - 2rem); padding: 1.5rem; box-shadow: var(--shadow-lg); }
dialog { opacity: 0; translate: 0 .75rem; transition: opacity .2s var(--ease), translate .3s var(--ease), overlay .3s allow-discrete, display .3s allow-discrete; }
dialog[open] { opacity: 1; translate: 0 0; }
@starting-style { dialog[open] { opacity: 0; translate: 0 .75rem; } }
dialog::backdrop { background: rgba(8, 12, 22, 0); transition: background-color .3s var(--ease), overlay .3s allow-discrete, display .3s allow-discrete; }
dialog[open]::backdrop { background: rgba(8, 12, 22, .5); }
@starting-style { dialog[open]::backdrop { background: rgba(8, 12, 22, 0); } }
dialog .row { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
dialog h2 { margin-bottom: .25rem; }

/* ---------- camera ---------- */
dialog.camera { max-width: 40rem; padding: 0; overflow: hidden; background: #000; border-color: #000; }
.cam-stage { position: relative; aspect-ratio: 4 / 3; background: #000; display: grid; place-items: center; }
.cam-stage video { width: 100%; height: 100%; object-fit: contain; }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 1.5rem; text-align: center; color: #e8ecf2; font-size: .9375rem; }
.cam-msg[hidden] { display: none; }
.cam-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .875rem 1rem; background: #0b0d11; }
.cam-bar .btn.ghost { background: transparent; color: #e8ecf2; border-color: #3a414d; }
.cam-bar .btn { min-width: 5.5rem; }
.shutter { width: 3.75rem; height: 3.75rem; border-radius: 50%; border: 3px solid #fff; background: transparent; padding: 0; cursor: pointer; position: relative; }
.shutter::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: #fff; transition: scale .08s; }
.shutter:active::after { scale: .88; }
.shutter[disabled] { opacity: .4; }

/* ---------- toast (undo) ---------- */
.toast { position: fixed; left: 50%; bottom: max(1.25rem, env(safe-area-inset-bottom)); translate: -50% 1rem; opacity: 0; pointer-events: none; z-index: 60; display: flex; align-items: center; gap: 1rem; padding: .5rem .5rem .5rem 1rem; border-radius: var(--r-lg); background: var(--ink); color: var(--bg); font-size: .9375rem; box-shadow: var(--shadow-lg); transition: opacity .25s var(--ease), translate .3s var(--ease); max-width: calc(100% - 2rem); }
.toast.show { opacity: 1; translate: -50% 0; pointer-events: auto; }
.toast button { border: 0; background: color-mix(in srgb, var(--bg) 20%, transparent); color: inherit; font-weight: 600; border-radius: var(--r); min-height: 2.75rem; padding: 0 1rem; cursor: pointer; }
.toast button:empty { display: none; }

/* ---------- accounts ---------- */
body.auth-mode .app { display: none; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.auth[hidden] { display: none; }
.auth-card { width: min(100%, 25rem); padding: 2rem 1.75rem 1.5rem; border-radius: var(--r-lg); background: var(--panel); border: 1px solid var(--line); }
.auth-card .mark { width: 2.75rem; height: 2.75rem; padding: .5rem; margin-bottom: 1.25rem; border-radius: .625rem; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: .375rem; }
.oauth { display: grid; gap: .625rem; margin: 1.5rem 0 .25rem; }
.oauth-btn { display: flex; align-items: center; justify-content: center; gap: .625rem; min-height: 2.75rem; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 600; cursor: pointer; }
.oauth-btn[hidden] { display: none; }
.oauth-btn:active { background: var(--tint); }
.or { display: flex; align-items: center; gap: .75rem; color: var(--soft); font-size: .8125rem; margin: 1rem 0 .25rem; }
.or[hidden] { display: none; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.check { display: flex; align-items: center; gap: .625rem; margin: 1rem 0 .5rem; min-height: 2.75rem; font-size: .9375rem; cursor: pointer; }
.check input { width: 1.125rem; height: 1.125rem; accent-color: var(--accent); }
.wide-btn { width: 100%; }
.auth-foot { text-align: center; margin-top: 1.25rem; font-size: .9375rem; }
.text-btn { background: none; border: 0; padding: .25rem; color: var(--accent); font-weight: 600; cursor: pointer; font-size: inherit; }

/* ---------- grading ---------- */
.grade { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.grade-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.grade-row .btn { min-height: 2.75rem; padding: .375rem 1rem; font-size: .9375rem; }
.gchips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .625rem; }
.gchips:empty { display: none; }
.gchip { display: inline-flex; align-items: center; gap: .375rem; max-width: 100%; padding: .125rem .125rem .125rem .625rem; border-radius: var(--r); background: var(--tint); border: 1px solid var(--line); font-size: .8125rem; }
.gchip button { width: 2rem; height: 2rem; border: 0; border-radius: var(--r); background: none; color: var(--soft); cursor: pointer; font-size: 1rem; line-height: 1; }
.grade-head { display: flex; align-items: center; gap: 1rem; padding: 1rem; margin-top: .875rem; border-radius: var(--r); border: 1px solid var(--line); }
.grade-head p { color: var(--soft); font-size: .9375rem; margin-top: .125rem; }
.grade-score { min-width: 3.5rem; height: 3.5rem; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; flex: none; color: #fff; }
.tone-good { border-color: var(--good); } .tone-good .grade-score { background: var(--good); }
.tone-mid { border-color: var(--warn); } .tone-mid .grade-score { background: var(--warn); }
.tone-bad { border-color: var(--bad); } .tone-bad .grade-score { background: var(--bad); }
.tone-neutral .grade-score { background: var(--soft); }
.grade-group { margin-top: 1rem; }
.grade-group h4 { margin: 0 0 .375rem; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
.gr-right h4 { color: var(--good); } .gr-wrong h4 { color: var(--bad); }
.grade-group ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .375rem; }
.grade-group li { position: relative; padding-left: 1.5rem; font-size: .9375rem; }
.grade-group li::before { position: absolute; left: 0; top: 0; font-weight: 700; }
.gr-right li::before { content: "✓"; color: var(--good); } .gr-wrong li::before { content: "✗"; color: var(--bad); }

/* ---------- chat ---------- */
.chat-log { display: flex; flex-direction: column; gap: .5rem; max-height: 22rem; overflow-y: auto; padding: .25rem 0 .75rem; }
.chat-log[hidden], .chips[hidden] { display: none; }
.bubble { max-width: 85%; padding: .5rem .75rem; border-radius: var(--r-lg); font-size: .9375rem; line-height: 1.45; animation: rise .3s var(--ease) both; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.bubble.assistant { align-self: flex-start; background: var(--tint); border: 1px solid var(--line); }
.bubble.typing { color: var(--soft); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .875rem; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); min-height: 2.75rem; padding: 0 .75rem; cursor: pointer; font-size: .875rem; }
.chip:active { background: var(--tint); }
.chat-form { display: flex; gap: .5rem; }
.chat-in { flex: 1; min-width: 0; }

/* ---------- units + final exam ---------- */
.units { display: flex; gap: .25rem; overflow-x: auto; margin: 0 0 1rem; border-bottom: 1px solid var(--line); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.units::-webkit-scrollbar { display: none; }
.utab { flex: none; display: inline-flex; align-items: center; gap: .4rem; min-height: 2.75rem; padding: 0 .875rem; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--soft); font: inherit; font-size: .9375rem; font-weight: 500; cursor: pointer; transition: color .15s, border-color .15s; }
.utab:active { background: var(--tint); }
.utab.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.utab.add { color: var(--accent); }
.utab.final { margin-left: auto; }
.utab .dotmark { width: .375rem; height: .375rem; border-radius: 50%; background: var(--good); }
input.unit-name { width: 100%; min-height: 3rem; padding: 0 .75rem; margin-left: -.75rem; width: calc(100% + 1.5rem); border: 1px solid transparent; border-radius: var(--r); background: transparent; color: var(--ink); font: inherit; font-size: 1.25rem; font-weight: 600; letter-spacing: -.015em; transition: background-color .15s, border-color .15s; }
input.unit-name:hover { background: var(--tint); }
input.unit-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; background: var(--panel); }
.final-units { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.final-units li { display: flex; align-items: center; gap: .75rem; min-height: 2.75rem; padding: 0 .875rem; border-radius: var(--r); border: 1px solid var(--line); }
.final-units .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.final-units .sz { color: var(--soft); font-size: .875rem; }
.final-units .sz.none { color: var(--bad); }
.final-units .link { border: 0; background: none; color: var(--accent); font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer; min-height: 2.75rem; padding: 0 .25rem; }

/* ---------- accessibility media ---------- */
@media (prefers-reduced-motion: reduce) {
  .enter, .bubble { animation: fade .2s ease both; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
  .fill, .explain, .toast { transition-duration: .01ms !important; }
  .spinner { animation-duration: 1.6s; }
}
@media (prefers-contrast: more) {
  :root { --soft: #2f3744; --line: #6b7380; }
  .opt, .card, .q, .file, input, textarea { border-width: 2px; }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) { :root { --soft: #d3d9e2; --line: #8b94a3; } }
.cam-stage video.flash { opacity: .35; }
.cam-stage video { transition: opacity .12s; }

/* dialogs and the toast respect the keyboard-free safe areas; the toast also yields to reduced transparency by being opaque already */
@media (max-width: 800px) { .test-bar { top: 3.75rem; } .cam-bar { padding-bottom: max(.875rem, env(safe-area-inset-bottom)); } }

@media (prefers-reduced-transparency: reduce) {
  .topbar, .test-bar { background: var(--panel); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-reduced-motion: reduce) { dialog, dialog::backdrop { transition-duration: .01ms; } }
.legal-note { margin: 1rem 0 0; font-size: .8125rem; color: var(--soft); text-align: center; line-height: 1.5; }
.legal-note a { color: var(--soft); }

/* ---- your tests: switch between tests you made and see their scores ---- */
.tests-card { padding-block: 1rem; }
.tests-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.tests-head h3 { margin: 0; }
.tests-head .btn { min-height: 2.25rem; font-size: .875rem; }
.tests { display: flex; gap: .5rem; overflow-x: auto; padding: .75rem 0 .25rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tests::-webkit-scrollbar { display: none; }
.tchip { flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: .125rem; min-width: 5.5rem; padding: .625rem .875rem; border: 1px solid var(--line); border-radius: .75rem; background: transparent; color: var(--ink); font: inherit; cursor: pointer; text-align: left; transition: border-color .15s, background-color .15s, transform .1s; }
.tchip:active { transform: scale(.97); }
.tchip.on { border-color: var(--accent); background: var(--tint); }
@media (hover: hover) and (pointer: fine) { .tchip:not(.on):hover { border-color: var(--soft); } }
.tchip .tn { font-size: .9375rem; font-weight: 600; }
.tchip .ts { font-size: .8125rem; color: var(--soft); font-variant-numeric: tabular-nums; }
.tchip .ts.good { color: var(--good, #1f9d55); font-weight: 600; }
.tchip .ts.mid { color: var(--warn, #b7791f); font-weight: 600; }
.tchip .ts.bad { color: var(--bad, #c0392b); font-weight: 600; }
.tests-info { margin: .5rem 0 0; font-size: .875rem; font-variant-numeric: tabular-nums; }

/* ---- cleaner pass: fewer boxes, calmer controls ---- */
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.25rem; padding: 0 1.5rem; cursor: pointer; list-style: none; font-weight: 600; font-size: .9375rem; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: ""; width: .5rem; height: .5rem; margin-left: .25rem; border-right: 1.5px solid var(--soft); border-bottom: 1.5px solid var(--soft); rotate: 45deg; translate: 0 -.1rem; transition: rotate .2s; flex: none; }
.fold[open] > summary::after { rotate: 225deg; translate: 0 .1rem; }
.fold > summary .meta { margin: 0 0 0 auto; font-weight: 400; font-size: .8125rem; }
.fold[open] > summary { border-bottom: 1px solid var(--line); }
.panel > .fold + .sec { border-top: 1px solid var(--line); }
.drop { padding: .75rem 1rem; border-width: 1px; }
.drop-text span { display: none; }
.drop-actions .btn { min-height: 2.5rem; font-size: .875rem; }
.grade-row .btn { min-height: 2.5rem; padding: .25rem .875rem; font-size: .875rem; }
.q { padding: 1.125rem 1.375rem; }
.q + .q { margin-top: -.25rem; }
.chat > h3 { font-size: 1rem; }
.chat .muted { font-size: .875rem; }

/* ---- clearer grading + tutor chat under missed questions ---- */
.grade-next { margin: .75rem 0 0; font-size: .9375rem; color: var(--soft); }
.grade-next strong { color: var(--ink); font-weight: 600; }
.tutor { margin-top: .875rem; }
.tutor[hidden], .tutor-panel[hidden] { display: none; }
.tutor > .btn { min-height: 2.5rem; font-size: .875rem; }
.tutor-panel { margin-top: .75rem; padding: .875rem; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--tint); }
.tutor-panel .chat-log { max-height: 20rem; }
.tutor-panel .bubble.assistant { background: var(--panel); white-space: pre-wrap; }

/* =====================================================================
   Theme v3: bright, friendly study-app look (rounded tiles, soft shadows, one vivid blue,
   chunky buttons, springy answer feedback). Overrides the earlier tokens and components.
   ===================================================================== */
:root {
  --bg: #f7f7f8; --panel: #ffffff; --tint: #f1f1f3;
  --ink: #1f2023; --soft: #5f6168; --line: #e2e2e6;
  --accent: #1f2023; --accent-ink: #ffffff; --accent-soft: #eeeef1;
  --good: #0d8a5e; --bad: #d23f2a; --warn: #a15c07;
  --good-soft: #dff6ec; --bad-soft: #fde8e4;
  --r: .75rem; --r-lg: 1rem;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px -6px rgba(0, 0, 0, .09);
  --spring: cubic-bezier(.34, 1.45, .5, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214; --panel: #1c1c1f; --tint: #26262a;
    --ink: #f3f3f5; --soft: #a2a3ab; --line: #2f2f34;
    --accent: #f3f3f5; --accent-ink: #121214; --accent-soft: #2a2a2f;
    --good: #4cd6a0; --bad: #ff8f7c; --warn: #f0b45f;
    --good-soft: #17352b; --bad-soft: #3b2227;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -8px rgba(0, 0, 0, .5);
  }
}
body { font-family: "Hanken Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-feature-settings: normal; background: var(--bg); }
h1 { font-weight: 800; letter-spacing: -.03em; }
h2, h3 { font-weight: 700; }
button, input, textarea { font-family: inherit; }
.topbar { background: var(--panel); -webkit-backdrop-filter: none; backdrop-filter: none; border-bottom: 0; box-shadow: 0 1px 0 var(--line), 0 4px 16px -8px rgba(0, 0, 0, .12); height: 3.75rem; }
.brand-name { font-weight: 800; font-size: 1.25rem; letter-spacing: -.03em; }
.mark { border-radius: .625rem; background: var(--accent); }
.acct-avatar { background: var(--accent-soft); color: var(--accent); border: 0; font-weight: 700; }
.link-btn { font-weight: 700; }

/* sidebar */
.subjects li { border-left: 0; border-radius: var(--r); min-height: 3rem; font-weight: 600; transition: background-color .2s, color .2s, transform .15s var(--ease); }
.subjects li.active { background: var(--accent-soft); color: var(--accent); box-shadow: none; font-weight: 700; }
.subjects li.active .count { color: var(--accent); }
.dot { background: var(--panel) !important; border: 0; box-shadow: var(--card-shadow); border-radius: .5rem; color: var(--accent); font-weight: 800; }
.icon-btn { border: 0; background: var(--panel); box-shadow: var(--card-shadow); border-radius: var(--r); transition: transform .2s var(--spring), box-shadow .2s; }
.side-head h2 { font-weight: 700; }

/* cards */
.card, .q, .panel, .tests-card { border: 0; box-shadow: var(--card-shadow); border-radius: var(--r-lg); }
@media (prefers-color-scheme: dark) { .card, .q, .panel, .tests-card { border: 1px solid var(--line); } }
.card, .q { transition: box-shadow .25s, transform .25s var(--ease); }
.sec + .sec, .fold[open] > summary, .panel > .fold + .sec { border-top-color: var(--line); }
.fold > summary { font-weight: 700; min-height: 3.5rem; }

/* buttons */
.btn { min-height: 3rem; border-radius: var(--r); font-weight: 700; padding: .5rem 1.375rem; border: 2px solid var(--accent); letter-spacing: -.005em; transition: transform .2s var(--spring), box-shadow .2s, background-color .2s, border-color .2s, filter .2s; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.quiet { border-color: transparent; font-weight: 600; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not([disabled]):not(.ghost):not(.quiet) { filter: none; transform: translateY(-1px); box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--accent) 70%, transparent); background: color-mix(in srgb, var(--accent) 90%, #000); border-color: color-mix(in srgb, var(--accent) 90%, #000); }
  .btn.ghost:hover:not([disabled]) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
  .subjects li:not(.active):hover { background: var(--tint); }
  .icon-btn:hover { transform: translateY(-1px); box-shadow: var(--card-shadow), 0 0 0 2px var(--accent); }
}
.btn:active:not([disabled]) { transform: scale(.97); box-shadow: none; }
.stepper { border: 2px solid var(--line); background: var(--panel); border-radius: var(--r); }
.stepper button { color: var(--accent); font-weight: 700; }
.stepper output { font-weight: 700; }
.gen-row { gap: 1rem; }

/* inputs */
input[type=text], input[type=email], input[type=password], textarea.short, .chat-in { border: 2px solid var(--line); border-radius: var(--r); background: var(--panel); transition: border-color .2s, box-shadow .2s; }
input[type=text]:focus, input[type=email]:focus, input[type=password]:focus, textarea.short:focus, .chat-in:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
input.unit-name { border: 2px solid transparent; font-weight: 700; font-size: 1.125rem; }
input.unit-name:hover { border-color: var(--line); }

/* unit + test tabs */
.units { border-bottom: 0; gap: .5rem; margin-bottom: 1.25rem; padding-bottom: .25rem; }
.utab { border: 0; margin: 0; border-radius: 999px; min-height: 2.5rem; padding: 0 1.125rem; font-weight: 700; color: var(--soft); background: transparent; transition: background-color .2s, color .2s, transform .2s var(--spring); }
.utab.on { background: var(--accent); color: var(--accent-ink); border: 0; }
.utab.on .dotmark { background: var(--accent-ink); }
.utab.add { color: var(--accent); background: var(--accent-soft); }
.utab:not(.on):hover { background: var(--tint); color: var(--ink); }
.utab:active { transform: scale(.96); background: var(--tint); }
.utab.on:active { background: var(--accent); }
.tests-head h3 { font-weight: 700; }
.tchip { border: 2px solid var(--line); border-radius: var(--r-lg); min-width: 6rem; transition: border-color .2s, background-color .2s, transform .2s var(--spring); }
.tchip.on { border-color: var(--accent); background: var(--accent-soft); }
.tchip .tn { font-weight: 800; }

/* drop zone */
.drop { border: 2px dashed color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); border-radius: var(--r-lg); transition: border-color .2s, background-color .2s, transform .2s var(--spring); }
.drop.over { border-color: var(--accent); transform: scale(1.01); }
.drop > svg { color: var(--accent); }
.file { border-radius: var(--r); }

/* test */
.test-bar { border: 0; border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--card-shadow); -webkit-backdrop-filter: none; backdrop-filter: none; padding: .75rem 1.125rem; }
.test-bar .label { font-weight: 800; }
.track { height: .625rem; background: var(--accent-soft); }
.fill { background: var(--accent); transition: scale .5s var(--spring); }
.q { padding: 1.5rem 1.75rem; margin-bottom: 1.25rem; }
.q .n { font-weight: 800; color: var(--accent); letter-spacing: .1em; }
.q .prompt { font-size: 1.1875rem; font-weight: 700; line-height: 1.4; letter-spacing: -.01em; margin-bottom: 1.25rem; }
.opt { border: 2px solid var(--line); border-radius: var(--r); padding: .875rem 1.125rem; margin-bottom: .625rem; font-weight: 500; align-items: center; transition: border-color .2s, background-color .2s, transform .2s var(--spring), box-shadow .2s, opacity .3s; }
.opt .k { display: grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 50%; background: var(--tint); color: var(--soft); font-weight: 800; font-size: .8125rem; transition: background-color .2s, color .2s; }
@media (hover: hover) and (pointer: fine) { .opt:not([disabled]):hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); } .opt:not([disabled]):hover .k { background: var(--accent); color: var(--accent-ink); } }
.opt:active:not([disabled]) { transform: scale(.985); }
.opt.right { border-color: var(--good); background: var(--good-soft); animation: pop .4s var(--spring); }
.opt.right .k { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .4s var(--ease); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt.dim { opacity: .5; }
@keyframes pop { 0% { transform: scale(.97); } 60% { transform: scale(1.015); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { translate: 0; } 20% { translate: -6px; } 40% { translate: 5px; } 60% { translate: -3px; } 80% { translate: 2px; } }
.explain p { background: var(--tint); border-radius: var(--r); padding: .875rem 1rem; margin-top: .75rem; color: var(--ink); }
.result { padding: 2.25rem 1.5rem; }
.result .big { font-size: 3.75rem; font-weight: 800; color: var(--accent); }
.fig { border: 0; border-radius: var(--r); box-shadow: inset 0 0 0 2px var(--line); }
.pill { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; border-radius: 999px; }
.chip { border: 2px solid var(--line); border-radius: 999px; font-weight: 600; transition: border-color .2s, background-color .2s, transform .2s var(--spring); }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip:active { transform: scale(.96); }
.bubble { border-radius: 1.125rem; }
.bubble.assistant { border: 0; background: var(--tint); }
.tutor-panel { border: 0; background: var(--accent-soft); }
.tutor-panel .bubble.assistant { background: var(--panel); }
.grade-head { border-radius: var(--r-lg); }
.dotmark { background: var(--good); }
@media (prefers-reduced-motion: reduce) { .opt.right, .opt.wrong { animation: none; } .btn, .opt, .utab, .tchip, .icon-btn { transition-duration: .01s; } }
