:root {
  /* UP colors: maroon (primary), forest green (complement), gold (accent only) */
  --maroon-900: #5a0b0e;
  --maroon-800: #7b1113;
  --maroon-100: #f7eaea;
  --forest-800: #014421;
  --forest-600: #0b6b3a;
  --gold: #f3aa2c;
  --gold-100: #fdf3df;
  --ink: #221615;
  --muted: #6e6462;
  --line: #ece4e1;
  --bg: #faf7f5;
  --card: #ffffff;
  --warn: #b45309;
  --warn-bg: #fff4e0;
  --red: #c62828;
  --radius: 22px;
  --tab-h: 74px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.ic { flex: none; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--maroon-800); color: #fff; border-bottom: 3px solid var(--gold);
}
.brand { display: flex; align-items: center; gap: 12px; font-size: 1.5rem; font-weight: 800; letter-spacing: .01em; }
.brand-mark { display: block; border-radius: 11px; box-shadow: 0 0 0 1.5px rgba(255,255,255,.25); }
.brand-word { display: block; width: auto; margin-top: 2px; }
.about-logo { display: block; width: 220px; max-width: 70%; height: auto; margin: 6px auto 10px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.iconbtn { display: inline-grid; place-items: center; min-width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; color: inherit; padding: 0 6px; }
.iconbtn.round { border-radius: 50%; background: rgba(255,255,255,.08); }
.iconbtn.dark { color: var(--ink); }
.iconbtn.light { background: rgba(0,0,0,.45); color: #fff; border-radius: 50%; }
.iconbtn.light.on { background: #facc15; color: #000; }
.avatar { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: #fff; color: var(--maroon-800); font-weight: 800; }

/* layout */
.view { max-width: 560px; margin: 0 auto; padding: 14px 16px 24px; outline: none; }
.section { margin: 22px 4px 10px; font-size: 1.05rem; }
.subhead { display: flex; align-items: center; gap: 6px; margin: 4px 0 12px; }
.subhead h2 { margin: 0; font-size: 1.3rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.err { color: var(--red); font-weight: 600; }
.ok { color: var(--forest-600); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 34px 12px; display: grid; gap: 14px; justify-items: center; }
.row { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; margin: 14px 4px 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

/* banner + stats */
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; margin-bottom: 12px; border-radius: 14px; background: #e8f2ec; color: var(--forest-800); font-size: .92rem; }
.banner.warn { background: var(--gold-100); color: #8a5a00; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); padding: 18px 8px; }
.stats.small { grid-template-columns: repeat(4, 1fr); }
.stats > * { padding: 0 12px; border-left: 1px solid var(--line); display: grid; gap: 4px; }
.stats > *:first-child { border-left: 0; }
.stats strong { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
.stats.small strong { font-size: 1.35rem; }
.stats span { color: var(--muted); font-size: .88rem; line-height: 1.3; }
.stats .hot { color: var(--warn); }

/* tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 18px 18px; display: grid; gap: 4px; min-height: 150px; align-content: end; }
.tile-ic { position: absolute; top: 20px; left: 18px; color: var(--maroon-800); }
.tile b { font-size: 1.15rem; }
.tile small { color: var(--muted); font-size: .9rem; }
.badge { position: absolute; top: 16px; right: 16px; min-width: 34px; height: 34px; border-radius: 17px; background: var(--maroon-800); color: #fff; box-shadow: 0 0 0 2px var(--gold); display: grid; place-items: center; font-weight: 800; font-size: .9rem; padding: 0 8px; }

/* lists */
.list { display: grid; gap: 8px; margin: 10px 0; }
.li { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.li-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.li-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-main small { color: var(--muted); }
.score { font-weight: 800; font-variant-numeric: tabular-nums; }
.roster { min-width: 30px; height: 30px; border-radius: 9px; background: var(--maroon-100); color: var(--maroon-800); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--maroon-800); border-color: var(--maroon-800); color: #fff; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: #f6d9a8; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }

/* buttons + forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 999px; border: 0; background: var(--maroon-800); color: #fff; font-weight: 700; cursor: pointer; text-align: center; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn.big { min-height: 58px; font-size: 1.1rem; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: .9rem; }
.btn.ghost { background: #fff; color: var(--maroon-800); border: 1.5px solid var(--line); }
.btn.light { background: rgba(255,255,255,.92); color: var(--ink); }
.btn.danger { background: var(--red); }
.danger-text { color: var(--red) !important; }
.form label, .card > label { display: grid; gap: 6px; margin-bottom: 12px; font-weight: 600; font-size: .92rem; }
label.inline { display: flex !important; align-items: center; gap: 10px; font-weight: 500; }
input, select, textarea { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 14px; background: #fff; font-weight: 400; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--maroon-800); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); border-color: transparent; }
.grid4 { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 8px; }
.grid4 label { font-size: .78rem; font-weight: 600; display: grid; gap: 4px; }
.grid4 input, .grid4 select { padding: 10px 8px; }
.part { border-bottom: 1px dashed var(--line); padding-bottom: 10px; margin-bottom: 12px; }
.part-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); padding: 4px; border-radius: 999px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 999px; font-weight: 600; cursor: pointer; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); color: var(--maroon-800); }
details summary { cursor: pointer; padding: 10px 0; font-weight: 600; }

/* key grid */
.keygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.krow { display: flex; align-items: center; gap: 4px; padding: 3px 4px; border-radius: 10px; }
.krow.nokey .kn { color: var(--warn); }
.krow.flag { background: var(--warn-bg); }
.kn { width: 30px; text-align: right; font-weight: 800; margin-right: 4px; font-variant-numeric: tabular-nums; }
.kn.good { color: var(--forest-600); } .kn.bad { color: var(--red); }
.bub { width: 32px; height: 32px; border-radius: 50%; border: 1.6px solid #22302a; background: #fff; font-size: .78rem; font-weight: 700; cursor: pointer; padding: 0; }
.bub.on { background: var(--maroon-800); border-color: var(--maroon-800); color: #fff; }
.bub.key { box-shadow: 0 0 0 3px #7fc79b; }
.tag { font-size: .72rem; color: var(--warn); font-weight: 700; margin-left: 4px; }

/* sheet preview */
.sheet-preview { background: #fff; border-radius: 12px; border: 1px solid var(--line); overflow: hidden; margin-bottom: 8px; }
.sheet-preview svg { display: block; width: 100%; height: auto; }
.sticky-actions { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 6px); display: flex; gap: 10px; padding: 8px 0; z-index: 5; }
.sticky-actions .btn { box-shadow: 0 6px 18px rgba(0,0,0,.12); }

/* paper review */
.paper-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.paper-head .big { font-size: 1.15rem; display: block; }
.paper-head small { color: var(--muted); }
.warnbox { background: var(--warn-bg); border-color: #f6d9a8; color: var(--warn); display: grid; gap: 10px; }
.scan-scroll { overflow: auto; max-height: 72vh; border-radius: 12px; background: #e9e4e2; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.scan-wrap { position: relative; width: 100%; }
.scan-wrap img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
.scan-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scan-wrap svg .hit { pointer-events: all; cursor: pointer; }
.ed-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.ed-tools .iconbtn { border: 1.5px solid var(--line); border-radius: 50%; width: 40px; font-size: 1.3rem; font-weight: 700; }
.ed-zoom { min-width: 48px; text-align: center; font-weight: 700; font-size: .9rem; }
.tag.blue { color: #2563eb; }
.rv-score { display: flex; align-items: center; gap: 14px; }
.rv-who { display: grid; min-width: 0; }
.rv-who b { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; }
.rv-who small { color: var(--muted); }
.rv-head { display: grid; gap: 8px; }
.rv-head .chip { white-space: normal; border-radius: 12px; }
.cam-review { position: absolute; inset: 0; z-index: 5; overflow: auto; background: var(--bg); padding: calc(12px + env(safe-area-inset-top)) 12px calc(90px + env(safe-area-inset-bottom)); }
.cam-review .scan-scroll { max-height: 62vh; }
.rv-actions { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 10px; z-index: 6; }
.rv-actions .btn { box-shadow: 0 6px 18px rgba(0,0,0,.18); }

/* reports */
.hist { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; height: 130px; align-items: end; margin-top: 12px; padding-bottom: 18px; }
.hb { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.hb i { display: block; width: 100%; background: var(--forest-600); border-radius: 5px 5px 0 0; min-height: 2px; }
.hb span { font-size: .72rem; font-weight: 700; position: absolute; bottom: calc(18px + 2px); }
.hb small { position: absolute; bottom: -18px; font-size: .68rem; color: var(--muted); }
.table-wrap { overflow-x: auto; padding: 6px; }
table.ia { border-collapse: collapse; width: 100%; font-size: .85rem; }
.ia th, .ia td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
.ia td small { display: block; color: var(--muted); font-size: .72rem; }
.ia tr.weak td { background: #fff7ed; }
.ia .dist span { font-variant-numeric: tabular-nums; }
.ia .dist .k { font-weight: 800; color: var(--forest-600); }
.prose h4 { margin: 16px 0 4px; } .prose h4:first-child { margin-top: 0; }
.prose p, .prose li { line-height: 1.5; }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; }

/* tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--maroon-800); display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; }
.tabbar a { display: grid; justify-items: center; gap: 4px; padding: 0 0 10px; color: rgba(255,255,255,.82); font-size: .82rem; font-weight: 600; }
.tabbar a.active { color: var(--gold); }
.fab-wrap { position: relative; }
.fab { display: grid; place-items: center; width: 74px; height: 74px; border-radius: 50%; background: var(--forest-800); color: #fff; border: 5px solid var(--gold); margin-top: -34px; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.tabbar a.active .fab { background: var(--forest-600); }

/* camera */
body.scanning { padding-bottom: 0; background: #000; }
body.scanning .topbar, body.scanning .tabbar { display: none; }
body.scanning .view { max-width: none; padding: 0; }
.cam { position: fixed; inset: 0; background: #000; overflow: hidden; }
.cam video, .cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-guide { position: absolute; inset: 12% 10% 18%; pointer-events: none; }
.cam-guide i { position: absolute; width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.7); }
.cam-guide i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.cam-guide i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.cam-guide i:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.cam-guide i:nth-child(4) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: calc(12px + env(safe-area-inset-top)) 14px 12px; }
.cam-count { color: #fff; background: rgba(0,0,0,.45); padding: 6px 12px; border-radius: 99px; font-size: .88rem; }
.cam-status { position: absolute; left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom)); display: flex; justify-content: center; }
.cam-result { position: absolute; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); background: #fff; border-radius: 24px; padding: 18px; display: grid; gap: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.res-name { font-size: 1.2rem; font-weight: 800; }
.res-test { color: var(--muted); font-size: .9rem; }
.res-score { font-size: 2.6rem; font-weight: 800; color: var(--maroon-800); line-height: 1.1; }
.res-score small { font-size: 1.2rem; color: var(--muted); }
.res-score span { font-size: 1rem; color: var(--muted); margin-left: 6px; }
.res-score.small { font-size: 1.7rem; text-align: right; }

/* modal + toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: grid; align-items: end; justify-items: center; padding: 12px; }
.modal-card { width: 100%; max-width: 520px; max-height: 85vh; overflow: auto; background: #fff; border-radius: 24px; padding: 20px; margin-bottom: env(safe-area-inset-bottom); }
.modal-card h3 { margin-top: 0; }
@media (min-width: 700px) { .modal { align-items: center; } }
#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #111; color: #fff; padding: 12px 18px; border-radius: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* printing */
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing { padding: 0; background: #fff; }
  body.printing #print-area { display: block; }
  #print-area .page { page-break-after: always; break-after: page; overflow: hidden; }
  #print-area .page:last-child { page-break-after: auto; break-after: auto; }
  #print-area svg { display: block; width: 100%; height: 100%; }
}
@media (max-width: 380px) {
  .grid4 { grid-template-columns: 1fr 1fr; }
  .stats strong { font-size: 1.5rem; }
}
.seg.three { grid-template-columns: repeat(3, 1fr); }
.name-crop { display: block; width: 100%; height: auto; background: #fff; border-radius: 10px; border: 1px solid #f0d9b0; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-word; }
.ia select { min-width: 132px; padding: 8px; font-size: .85rem; }

/* accounts */
body.auth .topbar, body.auth .tabbar { display: none; }
body.auth { padding-bottom: 0; }
.auth-card { max-width: 420px; margin: 6vh auto 30px; background: #fff; border: 1px solid var(--line); border-radius: 26px; padding: 26px 22px; display: grid; gap: 10px; }
.auth-mark { display: block; margin: 0 auto; border-radius: 20px; }
.auth-word { display: block; width: 150px; height: auto; margin: 2px auto 12px; }
.seg button:disabled { opacity: .4; }
.avatar { cursor: pointer; }
.avatar.dark { background: var(--maroon-800); color: #fff; width: 48px; height: 48px; flex: none; }
.acct-row { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.li.as-btn { width: 100%; text-align: left; font: inherit; cursor: pointer; }
.chips.wrap { flex-wrap: wrap; }

.cam-done { min-height: 40px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.rv-actions .btn.ghost { padding: 0 14px; }
.rv-score .res-score { white-space: nowrap; font-size: 2.2rem; }

.meter { height: 10px; border-radius: 99px; background: var(--maroon-100); overflow: hidden; margin: 6px 0 10px; }
.meter i { display: block; height: 100%; background: var(--maroon-800); }

.li > a.li-main { color: inherit; }
.li .iconbtn[data-menu] { border-radius: 50%; }
.li.selectable { cursor: pointer; }
.li.picked { border-color: var(--maroon-800); background: var(--maroon-100); }
.li input[type=checkbox] { pointer-events: none; }
.sel-bar { margin: 4px 0 0; gap: 8px; }
.btn.danger.small:disabled { opacity: .4; }

.link { color: var(--maroon-800); font-weight: 700; text-decoration: underline; }
#t-classes { margin: -4px 0 10px; }

#cam-session { text-align: center; line-height: 1.35; max-width: 62vw; overflow: hidden; text-overflow: ellipsis; }
#cam-session u { opacity: .8; font-size: .8rem; margin-left: 4px; }

.app-foot { max-width: 560px; margin: 0 auto; padding: 4px 16px 44px; text-align: center; }
body.scanning .app-foot, body.auth .app-foot { display: none; }
button.link { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; cursor: pointer; }
