:root {
  --pri: #2b6584;
  --pri-d: #1f4e66;
  --pri-l: #e3f3f8;
  --link: #2a5aa8;
  --bg: #ffffff;
  --soft: #f6f6f7;
  --line: #e4e4e7;
  --text: #16181d;
  --muted: #6b6f78;
  --ok: #2e9d57;
  --ok-l: #e5f5ea;
  --bad: #d64538;
  --bad-l: #fde9e6;
  --crit: #c0392b;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; touch-action: manipulation; }
input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }
b, strong { font-weight: 700; }

/* ---------- Lock ---------- */
.lock { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; color: #fff;
  background: radial-gradient(120% 70% at 50% 0%, #3a7ca5 0%, #1f4e66 55%, #12303f 100%); }
.lock-logo img { width: 86px; height: 86px; border-radius: 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.lock-brand { margin-top: 16px; font-size: 13px; letter-spacing: .18em; text-transform: uppercase; color: #f2c94c; font-weight: 700; }
.lock-title { font-size: 22px; font-weight: 700; margin-top: 6px; }
.lock-sub { color: rgba(255, 255, 255, .7); font-size: 14px; min-height: 20px; margin-top: 4px; text-align: center; }
.dots { display: flex; gap: 20px; margin: 28px 0 10px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #f2c94c; transition: background-color .15s, transform .15s var(--ease); }
.dots i.on { background: #f2c94c; transform: scale(1.15); }
.dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.lock-err { color: #ffb4a8; font-size: 14px; min-height: 20px; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 74px); gap: 16px 26px; margin-top: 18px; }
.keypad button { width: 74px; height: 74px; border-radius: 50%; font-size: 28px; font-weight: 500; color: #fff; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
  touch-action: none; user-select: none; -webkit-user-select: none; transition: transform .25s var(--ease), background-color .3s; }
.keypad button.pressed { background: rgba(242, 201, 76, .4); transform: scale(.9); transition: none; }
.keypad button.ghost { background: none; border: 0; font-size: 22px; color: rgba(255, 255, 255, .75); }

/* ---------- Layout ---------- */
#view { max-width: 680px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.enter { animation: enter .28s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateX(14px); } }
.hdr { position: sticky; top: 0; z-index: 5; background: var(--bg); display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 10px) 14px 10px; }
.hdr.shade { box-shadow: 0 1px 0 var(--line); }
.hdr h1 { margin: 0; font-size: 19px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr .sub { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.cbtn { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); box-shadow: 0 3px 10px rgba(0, 0, 0, .06); transition: transform .15s; }
.cbtn:active { transform: scale(.92); }
.cbtn svg { width: 24px; height: 24px; }
.cbtn.pri { background: #4a86c5; border-color: #4a86c5; color: #fff; box-shadow: 0 4px 14px rgba(74, 134, 197, .45); }
.cbtn.dim { opacity: .45; pointer-events: none; }
.pill { height: 46px; padding: 0 18px; border-radius: 23px; border: 1px solid var(--line); background: #fff; color: var(--link); font-size: 17px; font-weight: 500; white-space: nowrap; }
.pill.red { color: #fff; background: var(--bad); border-color: var(--bad); font-weight: 700; }
.body { padding: 4px 18px calc(28px + var(--safe-b)); flex: 1; }

/* ---------- Home ---------- */
.prog { border: 1.5px solid var(--line); border-radius: 20px; padding: 18px 18px 16px; margin: 8px 0 22px; width: 100%; text-align: left; display: block; }
.prog .top { display: flex; align-items: center; gap: 10px; }
.prog .top .t { flex: 1; font-size: 19px; font-weight: 600; }
.prog .top .n { color: var(--link); font-size: 18px; font-weight: 700; }
.prog .go { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--pri-l); color: var(--pri-d); }
.prog .go svg { width: 18px; height: 18px; }
.bar { height: 12px; border-radius: 6px; background: #e3e3e6; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; transition: width .4s var(--ease); }
.bar .g { background: var(--ok); }
.bar .r { background: var(--bad); }
.prog .mid { display: flex; align-items: center; gap: 14px; margin: 14px 0 8px; }
.prog .mid .bar { flex: 1; }
.prog .mid .pc { color: var(--muted); font-weight: 600; min-width: 42px; text-align: right; }
.prog .hint { color: var(--muted); font-size: 14.5px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { border-radius: 22px; padding: 22px 8px 18px; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 124px; justify-content: center; transition: transform .15s var(--ease), filter .15s; }
.tile:active { transform: scale(.96); filter: brightness(.95); }
.tile svg { width: 46px; height: 46px; }
.tile span { font-size: 18px; text-align: center; line-height: 1.2; }
.tile .badge { font-size: 12.5px; background: rgba(255, 255, 255, .25); padding: 2px 9px; border-radius: 10px; margin-top: -4px; }
.foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 22px; }

/* ---------- Exam intro ---------- */
.sec-t { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; margin: 16px 2px 10px; }
.info { background: var(--soft); border-radius: 18px; padding: 0 18px; }
.info .row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--line); font-size: 16.5px; gap: 10px; }
.info .row:last-child { border-bottom: 0; }
.info .row b { color: var(--link); text-transform: uppercase; white-space: nowrap; }
.opt { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; border: 1.5px solid var(--line); background: var(--soft); border-radius: 18px; padding: 14px 18px; margin-bottom: 12px; }
.opt .t { font-weight: 700; font-size: 17px; }
.opt .s { color: var(--muted); font-size: 14.5px; }
.opt .tx { flex: 1; }
.radio { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #8b8f97; flex-shrink: 0; display: grid; place-items: center; }
.opt.on { background: var(--pri-l); border-color: var(--pri); }
.opt.on .t { color: var(--pri-d); }
.opt.on .radio { border-color: var(--pri-d); }
.opt.on .radio::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--pri-d); }
.bigbtn { display: block; width: 100%; padding: 17px; border-radius: 30px; background: var(--pri); color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .03em; text-transform: uppercase; box-shadow: 0 6px 16px rgba(31, 78, 102, .28); transition: transform .15s; }
.bigbtn:active { transform: scale(.98); }
.bigbtn.sec { background: var(--soft); color: var(--text); box-shadow: none; border: 1px solid var(--line); }
.stick-b { position: sticky; bottom: 0; padding: 12px 18px calc(14px + var(--safe-b)); background: linear-gradient(transparent, #fff 30%); }

/* ---------- Sets ---------- */
.sets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.set { aspect-ratio: 1; border-radius: 16px; background: #ebebec; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; transition: transform .15s; }
.set:active { transform: scale(.95); }
.set .l { color: var(--muted); font-size: 15px; }
.set .n { font-size: 44px; font-weight: 700; line-height: 1.05; }
.set .s { font-size: 12.5px; font-weight: 600; min-height: 17px; }
.set.pass { background: var(--ok-l); }
.set.pass .s { color: var(--ok); }
.set.fail { background: var(--bad-l); }
.set.fail .s { color: var(--bad); }

/* ---------- Question view ---------- */
.qtabs { display: flex; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); position: sticky; top: calc(var(--safe-t) + 68px); background: #fff; z-index: 4; }
.qtabs::-webkit-scrollbar { display: none; }
.qtabs button { flex: 0 0 auto; padding: 12px 18px 11px; font-size: 17px; color: #7c8088; border-bottom: 3px solid transparent; white-space: nowrap; position: relative; }
.qtabs button.on { color: #4a86c5; border-bottom-color: #4a86c5; }
.qtabs button.ok { color: var(--ok); }
.qtabs button.bad { color: var(--bad); }
.qtabs button.done::after { content: ""; position: absolute; top: 9px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.qtabs button.on.done::after { display: none; }
.qbox { flex: 1; padding-bottom: calc(100px + var(--safe-b)); }
.qtext { padding: 14px 18px; font-size: 17.5px; font-weight: 700; border-bottom: 1px solid var(--line); line-height: 1.4; }
.qtext.crit { color: var(--crit); }
.qtext .tag { display: inline-block; font-size: 11.5px; font-weight: 700; color: #fff; background: var(--crit); border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.qimg { padding: 12px 18px 4px; }
.qimg img { width: 100%; max-width: 520px; display: block; margin: 0 auto; border-radius: 10px; }
.ans { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 17px; line-height: 1.45; transition: background-color .2s; }
.ans .radio { width: 24px; height: 24px; }
.ans.sel { background: #eef4fb; }
.ans.sel .radio { border-color: #4a86c5; }
.ans.sel .radio::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: #4a86c5; }
.ans.right { background: var(--ok-l); }
.ans.right .radio { border-color: var(--ok); background: var(--ok); }
.ans.right .radio::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 700; width: auto; height: auto; background: none; }
.ans.wrong { background: var(--bad-l); }
.ans.wrong .radio { border-color: var(--bad); background: var(--bad); }
.ans.wrong .radio::after { content: "✕"; color: #fff; font-size: 13px; font-weight: 700; width: auto; height: auto; background: none; }
.ans[disabled] { cursor: default; }
.expl { margin: 14px 18px; border-radius: 16px; padding: 14px 16px; background: #fff8e1; border: 1px solid #f1e0a6; font-size: 15.5px; }
.expl .h { font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.expl .h svg { width: 18px; height: 18px; }
.expl.ok { background: var(--ok-l); border-color: #bfe3cb; }
.expl.bad { background: var(--bad-l); border-color: #f4c3bc; }
.empty { flex: 1; display: flex; align-items: center; padding: 24px; font-size: 18px; }
.botbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); width: min(100%, 680px); padding: 0 16px; display: flex; justify-content: space-between; pointer-events: none; z-index: 6; }
.botbar .grp { pointer-events: auto; display: flex; background: #fff; border: 1px solid var(--line); border-radius: 32px; box-shadow: 0 6px 20px rgba(0, 0, 0, .08); }
.botbar .grp button { width: 62px; height: 60px; display: grid; place-items: center; }
.botbar .grp button svg { width: 28px; height: 28px; }
.botbar .grp button:disabled { opacity: .3; }
.botbar .grp button.on { color: #4a86c5; }
.timer { font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }

/* ---------- Grid sheet ---------- */
.qgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.qgrid button { aspect-ratio: 1; border-radius: 12px; background: var(--soft); border: 1px solid var(--line); font-weight: 600; font-size: 15px; position: relative; }
.qgrid button.cur { border: 2px solid #4a86c5; }
.qgrid button.done { background: #e3ecf8; }
.qgrid button.ok { background: var(--ok-l); color: var(--ok); border-color: #bfe3cb; }
.qgrid button.bad { background: var(--bad-l); color: var(--bad); border-color: #f4c3bc; }
.qgrid button.crit::after { content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--crit); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 12px 2px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 5px; }

/* ---------- Result ---------- */
.res { text-align: center; padding: 18px 0 8px; }
.res .ring { width: 150px; height: 150px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; }
.res .ring div { width: 122px; height: 122px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 38px; font-weight: 800; }
.res .ring small { display: block; font-size: 14px; color: var(--muted); font-weight: 600; margin-top: -10px; }
.res .verdict { font-size: 26px; font-weight: 800; margin-top: 14px; }
.res .verdict.ok { color: var(--ok); }
.res .verdict.bad { color: var(--bad); }
.res .why { color: var(--muted); margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.stats div { background: var(--soft); border-radius: 14px; padding: 12px 6px; text-align: center; }
.stats b { display: block; font-size: 22px; }
.stats span { font-size: 13px; color: var(--muted); }

/* ---------- Chapter list ---------- */
.search { position: sticky; top: calc(var(--safe-t) + 68px); z-index: 4; background: #fff; padding: 6px 0 12px; }
.search label { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 30px; padding: 0 18px; height: 54px; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .03); }
.search svg { width: 24px; height: 24px; flex-shrink: 0; }
.search input { flex: 1; border: 0; outline: none; font-size: 18px; background: none; min-width: 0; }
.chap { display: block; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px; margin-bottom: 14px; box-shadow: 0 2px 8px rgba(0, 0, 0, .03); transition: transform .15s; }
.chap:active { transform: scale(.98); }
.chap .t { font-weight: 700; font-size: 17.5px; line-height: 1.3; }
.chap .m { display: flex; justify-content: space-between; color: var(--muted); font-size: 15px; margin: 4px 0 12px; gap: 10px; }
.chap .f { color: var(--muted); font-size: 14px; margin-top: 10px; }
.sres { display: block; width: 100%; text-align: left; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.sres .n { color: var(--link); font-weight: 700; font-size: 14px; }
.sres mark { background: #fff1a8; border-radius: 3px; }

/* ---------- Signs ---------- */
.stabs { display: flex; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); position: sticky; top: calc(var(--safe-t) + 68px); background: #fff; z-index: 4; }
.stabs::-webkit-scrollbar { display: none; }
.stabs button { flex: 0 0 auto; padding: 12px 16px; font-size: 17px; color: #7c8088; border-bottom: 3px solid transparent; white-space: nowrap; }
.stabs button.on { color: #4a86c5; border-bottom-color: #4a86c5; }
.sign { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.sign .im { width: 92px; height: 92px; flex-shrink: 0; display: grid; place-items: center; }
.sign .im img { max-width: 100%; max-height: 100%; }
.sign .ph { width: 80px; height: 80px; border-radius: 14px; background: var(--soft); display: grid; place-items: center; font-weight: 700; color: var(--muted); font-size: 14px; }
.sign .c { color: #3f6fae; font-weight: 700; font-size: 19px; }
.sign .nm { font-size: 17px; margin-top: 2px; }
.sign-big { text-align: center; }
.sign-big img { width: 200px; height: 200px; object-fit: contain; }

/* ---------- Tips ---------- */
.tsec { margin: 0 -18px 12px; }
.tsec .th { display: flex; align-items: center; gap: 10px; padding: 14px 18px; background: var(--soft); width: 100%; text-align: left; }
.tsec .th .t { font-weight: 700; font-size: 18px; }
.tsec .th .s { color: var(--muted); font-size: 14.5px; }
.tsec .th .tx { flex: 1; }
.tsec .th .tg { border: 1.5px solid var(--pri); color: var(--pri); border-radius: 10px; padding: 3px 12px; font-size: 15px; white-space: nowrap; }
.tcard { margin: 0 14px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.tcard .hh { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.tcard .hh b { font-size: 18px; }
.mark { background: #e3edfb; color: #2a5aa8; border-radius: 12px; padding: 7px 14px; font-size: 14.5px; white-space: nowrap; }
.mark.on { background: var(--ok-l); color: var(--ok); font-weight: 600; }
.tcard ul { margin: 0; padding: 0; list-style: none; }
.tcard li { padding: 5px 0; font-size: 16.5px; line-height: 1.55; }
.tcard li::before { content: "•"; color: var(--muted); margin-right: 8px; }
.tsearch { position: sticky; bottom: 0; padding: 10px 18px calc(12px + var(--safe-b)); background: linear-gradient(transparent, #fff 35%); }
.tsearch label { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 30px; padding: 0 20px; height: 56px; background: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .06); }
.tsearch svg { width: 24px; height: 24px; flex-shrink: 0; }
.tsearch input { flex: 1; border: 0; outline: none; font-size: 18px; background: none; min-width: 0; }
.toc button { display: block; width: 100%; text-align: left; padding: 13px 4px; border-bottom: 1px solid var(--line); font-size: 16.5px; }
.toc button .ck { color: var(--ok); font-weight: 700; float: right; }

/* ---------- Settings / sheet ---------- */
.card { background: var(--soft); border-radius: 18px; padding: 4px 16px; margin-bottom: 16px; }
.li { display: flex; align-items: center; gap: 12px; padding: 13px 0; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .ico { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: var(--pri); flex-shrink: 0; }
.li .ico svg { width: 19px; height: 19px; }
.li .lbl { flex: 1; font-size: 16px; font-weight: 500; }
.li .v { color: var(--muted); font-size: 14px; }
.li .chev svg { width: 16px; height: 16px; color: #b5b8bf; }
.li.danger .ico { background: var(--bad); }
.li.danger .lbl { color: var(--bad); }
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10, 20, 30, .42); animation: fadeIn .22s ease-out; }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto; -webkit-overflow-scrolling: touch; background: #fff; border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(22px + var(--safe-b)); animation: up .3s var(--ease); max-width: 680px; margin: 0 auto; }
.sheet.closing .sheet-bg { animation: fadeOut .2s forwards; }
.sheet.closing .sheet-body { animation: down .2s forwards ease-in; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #d6d6da; margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 16px; font-size: 19px; text-align: center; }
.sheet p { margin: 0 0 14px; color: var(--muted); text-align: center; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 5px 2px; }
.field input, .field select { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fff; outline: none; font-size: 16px; -webkit-appearance: none; appearance: none; }
.field input:focus, .field select:focus { border-color: var(--pri); box-shadow: 0 0 0 3px rgba(43, 101, 132, .15); }
.btns { display: flex; gap: 10px; margin-top: 16px; }
.btn { flex: 1; padding: 14px; border-radius: 15px; font-weight: 700; font-size: 16px; color: #fff; background: var(--pri); }
.btn.sec { background: #ececef; color: var(--text); }
.btn.danger { background: var(--bad); color: #fff; }
.toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%) translateY(16px); background: #1d2430; color: #fff; padding: 10px 18px; border-radius: 14px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s var(--ease); z-index: 60; max-width: calc(100% - 40px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
