:root{
  --bg:#f3f5f8; --surface:#ffffff; --surface-2:#eef1f5; --text:#14171b; --muted:#5b6470; --border:#dbe0e6;
  --accent:#1d63d8; --accent-weak:#e5eefc; --on-accent:#ffffff;
  --ok:#17784a; --ok-weak:#e1f4e9; --bad:#c0352c; --bad-weak:#fce8e6; --gold:#a26a12; --warn-weak:#fff3dc;
  --grid:#e3e7ec;
  --radius:16px;
}
@media (prefers-color-scheme:dark){
  :root{
    --bg:#0d0f13; --surface:#16191f; --surface-2:#1f232a; --text:#e7e9ec; --muted:#98a1ac; --border:#2a2f37;
    --accent:#5c9cff; --accent-weak:#172538; --on-accent:#0a1322;
    --ok:#4cc38a; --ok-weak:#10281c; --bad:#ff6f66; --bad-weak:#33161a; --gold:#e6b450; --warn-weak:#33270f;
    --grid:#262b33;
  }
}
*{box-sizing:border-box}
html,body{margin:0}
body{background:var(--bg);color:var(--text);font:16px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;-webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent}
button{font:inherit;color:inherit}
h1,h2,h3{margin:0}
[hidden]{display:none !important}
.app{max-width:640px;margin:0 auto;padding:max(12px,env(safe-area-inset-top)) 16px max(16px,env(safe-area-inset-bottom))}
.view{display:flex;flex-direction:column;gap:12px}
.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:16px}
.muted{color:var(--muted)}
.small{font-size:13px}
.center{text-align:center}
.grow{flex:1;min-width:0}
.btn{appearance:none;border:1px solid var(--border);background:var(--surface);font-weight:600;padding:12px 16px;border-radius:12px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:48px;text-decoration:none}
.btn:active{transform:scale(.98)}
.btn.primary{background:var(--accent);border-color:var(--accent);color:var(--on-accent)}
.btn.small{min-height:34px;padding:6px 12px;font-size:13px;border-radius:9px}
.btn:disabled{opacity:.4;cursor:default;transform:none}
.btn.block{width:100%}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

/* ---------- Header ---------- */
.topbar{display:flex;align-items:center;gap:10px}
.brand{display:flex;align-items:center;gap:12px;min-width:0}
.topbar .brand{flex:1}
.logo{width:42px;height:42px;border-radius:12px;background:var(--accent);color:#fff;display:grid;place-items:center;font-weight:800;flex:none;font-size:15px}
.brand h1,.h1{font-size:19px;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.brand p{margin:2px 0 0;font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-chip{flex:none;border:1px solid var(--border);background:var(--surface);border-radius:99px;padding:6px 12px 6px 6px;display:flex;align-items:center;gap:8px;cursor:pointer;font-size:14px;font-weight:600;max-width:46%}
.user-chip .av{width:28px;height:28px;border-radius:50%;background:var(--accent-weak);color:var(--accent);display:grid;place-items:center;font-size:13px;font-weight:800;flex:none}
.user-chip span:last-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.icon-btn{width:40px;height:40px;border-radius:10px;border:1px solid var(--border);background:var(--surface);display:grid;place-items:center;cursor:pointer;flex:none;font-size:18px;line-height:1}
.foot{text-align:center;font-size:11px;color:var(--muted);margin:8px 0 0;line-height:1.6}
.foot a{color:var(--accent);font-weight:600}

/* ---------- Auth ---------- */
#v-auth{min-height:calc(100dvh - 40px);justify-content:center}
.auth{display:flex;flex-direction:column;gap:12px}
.auth p{margin:0}
.seg,.tabs{display:grid;grid-auto-flow:column;grid-auto-columns:1fr;background:var(--surface-2);border-radius:12px;padding:4px;gap:4px}
.seg button,.tabs button{border:0;background:none;padding:9px;border-radius:9px;font-weight:600;cursor:pointer;color:var(--muted)}
.seg button.on,.tabs button.on{background:var(--surface);color:var(--text);box-shadow:0 1px 2px rgba(0,0,0,.12)}
.field{display:flex;flex-direction:column;gap:5px;font-size:13px;font-weight:600;color:var(--muted)}
input[type=text],input[type=password],.field input,.modal input{width:100%;padding:12px;border-radius:12px;border:1.5px solid var(--border);background:var(--surface);color:var(--text);font:inherit;font-size:17px}
.field input:focus,.modal input:focus{outline:none;border-color:var(--accent)}
.err{color:var(--bad);font-size:13px;min-height:18px}
.check{display:flex;align-items:center;gap:8px;font-size:14px;cursor:pointer}
.check input{width:18px;height:18px;accent-color:var(--accent)}

/* ---------- Home ---------- */
.app:has(#v-home:not([hidden])){max-width:1080px}
.sec-title{font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin:4px 0 0;font-weight:700}
.hstats{display:flex;gap:8px;margin-left:auto}
.hstat{display:flex;align-items:baseline;gap:5px;background:var(--surface);border:1px solid var(--border);border-radius:99px;padding:6px 12px;font-size:13px;color:var(--muted);white-space:nowrap}
.hstat b{color:var(--text);font-size:15px;font-variant-numeric:tabular-nums}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chip{font-size:12.5px;padding:3px 9px;border-radius:99px;background:var(--surface-2);color:var(--muted);white-space:nowrap}
.chip b{color:var(--text)}

.exam-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:12px}
.exam-card{--ex:var(--accent);position:relative;display:flex;flex-direction:column;gap:12px;text-align:left;width:100%;cursor:pointer;
  background:var(--surface);border:1px solid var(--border);border-top:4px solid var(--ex);border-radius:var(--radius);padding:16px;transition:border-color .15s,transform .15s,box-shadow .15s}
@media (hover:hover){.exam-card:hover{transform:translateY(-2px);box-shadow:0 6px 20px rgba(0,0,0,.12)}}
.exam-card .logo{width:46px;height:46px;font-size:15px;background:var(--ex)}
.exam-card .txt{display:flex;flex-direction:column;gap:4px;min-width:0}
.exam-card h3{font-size:17px;line-height:1.25}
.exam-card p{margin:0;font-size:13px;color:var(--muted)}
.exam-card .meta-m{display:none;font-size:12.5px;color:var(--muted)}
.badge{position:absolute;top:14px;right:14px;font-size:12px;font-weight:700;padding:4px 10px;border-radius:99px;white-space:nowrap}
.badge.yes{background:var(--ok);color:var(--surface)}
.badge.no{background:var(--surface-2);color:var(--muted)}
.tile-stats{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-top:auto}
.ts{background:var(--surface-2);border-radius:10px;padding:8px 10px;min-width:0}
.ts b{display:block;font-size:17px;font-variant-numeric:tabular-nums;line-height:1.2}
.ts span{font-size:11.5px;color:var(--muted)}
.tile-foot{display:flex;justify-content:space-between;align-items:center;gap:8px}
.exam-card .start{font-weight:700;font-size:14px;color:var(--accent)}
/* passed: green frame + soft green tint */
.exam-card.passed{border-color:var(--ok);border-top-color:var(--ok);background:linear-gradient(180deg,var(--ok-weak),var(--surface) 70%)}
.exam-card.passed .ts{background:var(--surface)}
.exam-card.passed .ts:nth-child(2) b{color:var(--ok)}

/* Phone: slim rows – logo, title, attempts/best, badge */
@media (max-width:600px){
  .topbar .brand p{display:none}
  .topbar:has(.hstats){flex-wrap:wrap}
  .hstats{order:3;width:100%;gap:6px;margin-left:0}
  .hstat{flex:1;justify-content:center}
  .hstat{padding:4px 8px;font-size:11.5px}
  .hstat b{font-size:13px}
  .topbar .user-chip span:last-child{display:none}
  .topbar .user-chip{padding:4px}
  .exam-list{grid-template-columns:1fr;gap:8px}
  .exam-card{display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:12px;padding:12px 14px;border-top:1px solid var(--border);border-left:4px solid var(--ex)}
  .exam-card.passed{border-color:var(--ok);border-left-color:var(--ok)}
  .exam-card .logo{width:40px;height:40px;font-size:13px}
  .exam-card h3{font-size:15.5px;padding-right:0}
  .exam-card p,.tile-stats,.tile-foot{display:none}
  .exam-card .meta-m{display:block}
  .badge{position:static;grid-column:3;grid-row:1;font-size:11px;padding:3px 8px}
  .badge.no{display:none}
}
/* ---------- Exam ---------- */
.hero{display:flex;flex-direction:column;gap:12px;padding:18px 16px}
.hero .chips{justify-content:center}
.hero p{margin:-4px 0 0}
.play{width:100%;font-size:20px;min-height:60px;border-radius:14px}
.more{border-top:1px solid var(--border);padding-top:10px}
.more summary{cursor:pointer;font-weight:600;font-size:14px;color:var(--accent);list-style:none;text-align:center}
.more summary::-webkit-details-marker{display:none}
.more summary::after{content:" ▾"}
.more[open] summary::after{content:" ▴"}
.more[open]{display:flex;flex-direction:column;gap:10px}
.more p{margin:0}

.lb{list-style:none;margin:0;padding:0}
.lb li{display:grid;grid-template-columns:30px 1fr auto auto;gap:10px;align-items:center;padding:9px 8px;border-radius:10px;font-size:15px}
.lb li:nth-child(odd){background:var(--surface-2)}
.lb li.me{outline:2px solid var(--accent);outline-offset:-2px}
.rank{font-weight:700;color:var(--muted);text-align:center;font-variant-numeric:tabular-nums}
.lb li:nth-child(-n+3) .rank{color:var(--gold)}
.hname{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.hname small{display:block;color:var(--muted);font-size:12px}
.hscore{font-weight:700;font-variant-numeric:tabular-nums;text-align:right}
.hscore small{display:block;font-weight:400;color:var(--muted);font-size:12px}
.pill{font-size:11px;font-weight:700;padding:2px 7px;border-radius:99px;text-transform:uppercase;letter-spacing:.03em}
.pill.ok{background:var(--ok-weak);color:var(--ok)}
.pill.bad{background:var(--bad-weak);color:var(--bad)}
.empty{padding:16px;text-align:center;color:var(--muted);font-size:14px}

.tiles{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.tile{background:var(--surface);border:1px solid var(--border);border-radius:14px;padding:12px}
.tile b{display:block;font-size:22px;line-height:1.15;font-variant-numeric:tabular-nums}
.tile span{font-size:12px;color:var(--muted)}
.sec{display:flex;flex-direction:column;gap:10px}
.sec h3{font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);display:flex;justify-content:space-between;align-items:center}
.stats{display:flex;flex-direction:column;gap:12px}
.fold summary{cursor:pointer;list-style:none;font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);font-weight:700;display:flex;justify-content:space-between}
.fold summary::-webkit-details-marker{display:none}
.fold summary::after{content:"▾";transition:transform .2s}
.fold[open] summary::after{transform:rotate(180deg)}
.fold:not([open]){gap:0}

.chart{width:100%;height:auto;display:block;overflow:visible}
.chart .gridline{stroke:var(--grid);stroke-width:1}
.chart .passline{stroke:var(--ok);stroke-width:1.5;stroke-dasharray:4 4}
.chart .line{fill:none;stroke:var(--accent);stroke-width:2;stroke-linejoin:round;stroke-linecap:round}
.chart .dot{fill:var(--accent);stroke:var(--surface);stroke-width:2}
.chart .dot.hit{fill:transparent;stroke:none;cursor:pointer}
.chart text{fill:var(--muted);font-size:11px}
.chart .passlabel{fill:var(--ok);font-weight:600}
.tip{position:fixed;z-index:30;pointer-events:none;background:var(--text);color:var(--bg);font-size:12.5px;padding:6px 9px;border-radius:8px;white-space:nowrap;transform:translate(-50%,calc(-100% - 10px))}

.arow{display:grid;grid-template-columns:minmax(0,1fr) 46px auto;gap:10px;align-items:center;font-size:14px}
.arow .name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.arow .meter{grid-column:1/3;height:8px;border-radius:99px;background:var(--surface-2);overflow:hidden;margin-top:-6px}
.arow .meter i{display:block;height:100%;border-radius:99px;background:var(--accent)}
.arow .val{text-align:right;font-weight:700;font-variant-numeric:tabular-nums}
.arow .val small{font-weight:400;color:var(--muted)}
.arow .btn{grid-row:1/3;grid-column:3}
.missed{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:8px}
.missed li{font-size:14px;padding:10px 12px;border-radius:10px;background:var(--surface-2)}
.missed li small{display:block;color:var(--muted);font-size:12px;margin-top:3px}

/* ---------- Quiz ---------- */
.view.quiz{height:calc(100dvh - max(12px,env(safe-area-inset-top)) - max(16px,env(safe-area-inset-bottom)))}
.qtop{display:flex;align-items:center;gap:10px}
.progress{flex:1}
.progress .row{display:flex;justify-content:space-between;align-items:center;font-size:13px;color:var(--muted);margin-bottom:5px;font-variant-numeric:tabular-nums}
.progress .row b{color:var(--text)}
.score{display:flex;align-items:center;gap:6px}
.pct{min-width:46px;text-align:center;font-weight:700;font-size:13px;padding:1px 8px;border-radius:99px;background:var(--surface-2);color:var(--muted);transition:background .2s,color .2s}
.pct.ok{background:var(--ok-weak);color:var(--ok)}
.timer{font-weight:700;font-size:14px;padding:1px 9px;border-radius:99px;background:var(--surface-2);color:var(--text)}
.timer.low{background:var(--bad-weak);color:var(--bad)}
.bar{height:6px;border-radius:99px;background:var(--surface-2);overflow:hidden}
.bar i{display:block;height:100%;background:var(--accent);width:0;transition:width .25s}
.qbody{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding-bottom:2px}
.area{align-self:flex-start;font-size:12px;font-weight:600;padding:3px 9px;border-radius:99px;background:var(--accent-weak);color:var(--accent)}
.qtext{font-size:clamp(17px,4.6vw,20px);font-weight:650;line-height:1.35;margin:0}
.opts{display:flex;flex-direction:column;gap:8px}
.opt{display:flex;gap:10px;align-items:flex-start;text-align:left;width:100%;padding:11px 12px;border:1.5px solid var(--border);border-radius:12px;background:var(--surface);cursor:pointer;font-size:15px;line-height:1.35}
.opt .key{flex:none;width:24px;height:24px;border-radius:7px;display:grid;place-items:center;font-size:12px;font-weight:700;background:var(--surface-2);color:var(--muted)}
@media (hover:hover){.opt:not(:disabled):hover{border-color:var(--accent)}}
.opt:disabled{cursor:default}
.opt.sel{border-color:var(--accent);background:var(--accent-weak)}
.opt.sel .key{background:var(--accent);color:var(--on-accent)}
.opt.right{border-color:var(--ok);background:var(--ok-weak)}
.opt.right .key{background:var(--ok);color:var(--surface)}
.opt.wrong{border-color:var(--bad);background:var(--bad-weak)}
.opt.wrong .key{background:var(--bad);color:var(--surface)}
.opt.gone{display:none}
.opt.busy{opacity:.6}
.fb{border-radius:12px;padding:12px 14px;font-size:14.5px;line-height:1.45;animation:pop .2s ease-out}
.fb.ok{background:var(--ok-weak)}
.fb.bad{background:var(--bad-weak)}
.fb b{display:block;font-size:16px;margin-bottom:3px}
.fb.ok b{color:var(--ok)}
.fb.bad b{color:var(--bad)}
.fb .ans{display:block;font-weight:600;margin-bottom:4px}
@keyframes pop{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
.qnav{display:flex;gap:8px}
.qnav .btn{flex:1}
.next{width:100%;font-size:17px}
#b-flag.on{background:var(--warn-weak);border-color:var(--gold);color:var(--gold)}
.grid{display:grid;grid-template-columns:repeat(10,1fr);gap:4px}
.gridbtn{display:none;border:1px solid var(--border);background:var(--surface);border-radius:99px;font-size:12.5px;font-weight:600;padding:2px 10px;cursor:pointer;color:var(--accent)}
@media (max-width:600px){
  .gridbtn:not([hidden]){display:inline-block}
  #v-quiz:not(.show-grid) .grid{display:none}
  #v-quiz.show-grid .qtop{order:-2}
  #v-quiz.show-grid .grid{order:-1}
}
.grid button{border:1px solid var(--border);background:var(--surface);border-radius:6px;font-size:11px;padding:4px 0;cursor:pointer;font-variant-numeric:tabular-nums}
.grid button.ans{background:var(--accent-weak);color:var(--accent);border-color:transparent}
.grid button.flag{background:var(--warn-weak);color:var(--gold);border-color:var(--gold)}
.grid button.cur{outline:2px solid var(--accent);outline-offset:-1px}

/* ---------- Result ---------- */
.result{display:flex;flex-direction:column;align-items:center;text-align:center;gap:6px;padding-top:10px}
.ring{--p:0;width:150px;height:150px;border-radius:50%;background:conic-gradient(var(--c,var(--accent)) calc(var(--p)*1%),var(--surface-2) 0);display:grid;place-items:center;margin-bottom:10px}
.ring>div{width:120px;height:120px;border-radius:50%;background:var(--bg);display:grid;place-items:center}
.ring b{font-size:34px;line-height:1}
.ring span{font-size:13px;color:var(--muted)}
.verdict{font-size:28px;font-weight:800;margin:0}
.verdict.ok{color:var(--ok)}
.verdict.bad{color:var(--bad)}
.rlines{font-size:15px;color:var(--muted);margin:0}
.rbtns{display:flex;flex-direction:column;gap:8px;width:100%}
#r-areas{display:flex;flex-direction:column;gap:10px}

/* ---------- Review ---------- */
.review{display:flex;flex-direction:column;gap:10px}
.rv{display:flex;flex-direction:column;gap:8px}
.rv .head{display:flex;justify-content:space-between;gap:8px;align-items:center}
.rv .qtext{font-size:16px}
.rv .opt{cursor:default}
.rv .expl{font-size:14px;color:var(--muted);margin:0}

/* ---------- Menu / modal / toast ---------- */
.menu{position:fixed;z-index:20;background:var(--surface);border:1px solid var(--border);border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,.18);min-width:180px;padding:6px;display:flex;flex-direction:column}
.menu-head{padding:8px 10px;font-size:13px;color:var(--muted);border-bottom:1px solid var(--border);margin-bottom:4px}
.menu button{border:0;background:none;text-align:left;padding:10px;border-radius:8px;cursor:pointer;font-size:15px}
.menu button:hover{background:var(--surface-2)}
.modal{position:fixed;inset:0;background:rgba(0,0,0,.5);display:flex;align-items:center;justify-content:center;padding:16px;z-index:25}
.modal .card{width:100%;max-width:400px}
.modal h2{margin:0 0 6px;font-size:20px}
.modal p{margin:0 0 14px;color:var(--muted);font-size:14px}
.mbtns{display:flex;gap:8px;margin-top:14px}
.mbtns .btn{flex:1}
.toast{position:fixed;left:50%;bottom:max(20px,env(safe-area-inset-bottom));transform:translateX(-50%);background:var(--text);color:var(--bg);padding:10px 16px;border-radius:12px;font-size:14px;z-index:40;max-width:calc(100% - 32px)}

@media (max-height:700px){ .view.quiz{gap:9px} .qbody{gap:8px} .qtext{font-size:16.5px} .opt{padding:9px 11px;font-size:14px} .fb{padding:10px 12px;font-size:13.5px} .fb b{font-size:15px} .btn{min-height:44px} }
@media (max-width:400px){ .tiles{grid-template-columns:repeat(2,1fr)} .grid{grid-template-columns:repeat(8,1fr)} }

/* ---------- Main-page top 3 ---------- */
.top3{margin-bottom:16px;padding:14px 16px}
.top3 .sec-title{margin-top:0}
.top3 p{margin:8px 0 0}
.podium{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
.podium li{background:var(--surface-2);border-radius:12px;padding:10px;display:flex;flex-direction:column;align-items:center;text-align:center;gap:2px;min-width:0}
.podium li.me{outline:2px solid var(--accent);outline-offset:-2px}
.podium .medal{font-size:22px;line-height:1}
.podium .pn{font-weight:700;font-size:14px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.podium .pt{font-size:12.5px;color:var(--muted)}
.podium .pt b{color:var(--text);font-size:15px}
.podium .empty{grid-column:1/-1;padding:6px}
@media (max-width:600px){ .top3{padding:12px} .podium li{padding:8px 6px} .podium .medal{font-size:18px} }
