:root{
 --bg:#f4f6f8;--surface:#fff;--surface2:#f8fafc;--ink:#17212b;--muted:#667085;
 --line:#dfe5ec;--brand:#5754d9;--brand2:#7c5cff;--soft:#eeefff;--yellow:#fff1a8;
 --green:#16834b;--red:#d94141;--focus:#1d4ed8;--radius:18px;
 --font:Atkinson Hyperlegible,Arial,sans-serif;--size:18px;--spacing:1.65;
}
*{box-sizing:border-box}html{font-size:16px}body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--font);font-size:var(--size);line-height:var(--spacing)}
button,input,textarea,select{font:inherit}button{cursor:pointer}button:focus,input:focus,textarea:focus,select:focus{outline:3px solid #b8c5ff;outline-offset:2px}
.app{display:flex;min-height:100vh}.side{width:255px;background:#121826;color:#fff;padding:20px 14px;display:flex;flex-direction:column;position:sticky;top:0;height:100vh}
.logo{font-weight:700;font-size:27px;padding:8px 12px 28px}.logo span{color:#aeb0ff}
.nav button{width:100%;background:none;border:0;color:#cbd5e1;text-align:left;padding:12px 14px;border-radius:12px;margin:2px 0}.nav button:hover,.nav button.active{background:#282f43;color:#fff}
.side{overflow-y:auto}.bottom{margin-top:auto;padding:12px 4px 4px}
.privacy{display:flex;flex-direction:column;gap:4px;border:1px solid #334155;border-radius:12px;padding:10px 12px;color:#9ca8bb;font-size:13px;line-height:1.45}.privacy b{color:#e2e8f0}
@media(max-width:900px){.privacy{display:none}}
main{flex:1;max-width:1500px;margin:auto;padding:28px 34px}.page{display:none}.page.active{display:block}
.top{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-bottom:22px}h1{font-size:32px;line-height:1.1;margin:0}h2{font-size:20px;line-height:1.2;margin:0 0 14px}.sub{color:var(--muted);margin-top:6px}
.actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.btn{border:1px solid var(--line);background:var(--surface);color:var(--ink);padding:10px 15px;border-radius:11px}.primary{background:var(--brand);border-color:var(--brand);color:white}.danger{background:var(--red);border-color:var(--red);color:white}.ghost{background:transparent}
.grid{display:grid;grid-template-columns:minmax(0,1.35fr) minmax(300px,.65fr);gap:20px}.card{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:22px;box-shadow:0 8px 25px #17212b0a}
.hero{background:linear-gradient(135deg,#171c32,#34365d);color:white;border:0}.hero .sub{color:#d8dcff}
.featuregrid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px;margin-top:18px}.feature{background:#ffffff14;border:1px solid #ffffff22;padding:15px;border-radius:14px}
.note{background:var(--surface2);border:1px solid var(--line);border-radius:14px;padding:16px;margin:12px 0}.note strong{display:block;margin-bottom:5px}.key{background:var(--yellow);padding:1px 4px;border-radius:4px}.tag{display:inline-block;background:var(--soft);color:#4b46b7;padding:4px 9px;border-radius:999px;font-size:13px;margin:2px}
.btn:disabled{opacity:.4;cursor:not-allowed;filter:grayscale(1);box-shadow:none}
html.m-portrait .rec-controls #recordBtn{flex-basis:100%}
.toolbar{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:15px}.toolbar .btn{padding:8px 11px}
textarea,input[type=text],select{width:100%;border:1px solid var(--line);border-radius:12px;padding:12px;background:var(--surface);color:var(--ink)}
.field{display:block;font-weight:700;margin-bottom:14px}.field input,.field select{display:block;margin-top:6px;font-weight:400}
.field input[type=password]{display:block;width:100%;margin-top:6px;border:1px solid var(--line);border-radius:12px;padding:12px;background:var(--surface);color:var(--ink);font-weight:400}
html.dark .field input[type=password]{background:var(--surface2)}html.hc .field input[type=password]{border:2px solid var(--line)}html.m-portrait .field input[type=password]{font-size:max(16px,1em)}
.acct-actions{align-items:center;margin-top:6px}.acct-spacer{flex:1}
.acct-switch{text-align:center;margin:14px 0 0}.acct-switch a{color:var(--brand);font-weight:700}
html.m-portrait .acct-actions .btn{flex:1 1 auto}html.m-portrait .acct-spacer{display:none}
.acct-row{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;padding:10px 0}
.acct-email{border-bottom:1px solid var(--line);padding-bottom:6px}
.badge{display:inline-block;font-size:12px;font-weight:700;padding:1px 8px;border-radius:999px;margin-left:4px}
.badge.warn{background:#fff1d6;color:#8a5300}.badge.good{background:#e3f6ea;color:#17663d}
html.dark .badge.warn{background:#3d2e10;color:#ffd58a}html.dark .badge.good{background:#16301f;color:#8fe0b0}html.hc .badge{background:var(--surface);color:var(--ink);border:2px solid var(--line)}
.thumbs{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0 6px}.thumbs:empty{display:none}
.thumb{position:relative;width:96px;height:96px;border-radius:12px;overflow:hidden;border:1px solid var(--line);background:var(--surface2)}
.thumb img{width:100%;height:100%;object-fit:cover;display:block}
.thumb-n{position:absolute;left:6px;bottom:6px;background:#000a;color:#fff;font-size:12px;font-weight:700;border-radius:999px;padding:0 7px}
.thumb-x{position:absolute;top:4px;right:4px;width:28px;height:28px;border:0;border-radius:50%;background:#000b;color:#fff;font-size:14px;line-height:1}
.photo-row{display:flex;flex-wrap:wrap;gap:10px;margin-top:6px}.photo-row img{max-width:220px;max-height:220px;border-radius:10px;border:1px solid var(--line);display:block}
html.m-portrait .photo-row img{max-width:100%}
.check{display:flex;align-items:center;gap:10px;margin:0 0 16px;font-weight:700;cursor:pointer}.check input{width:22px;height:22px;flex:0 0 auto;accent-color:var(--brand)}
.field textarea{display:block;margin-top:6px;font-weight:400}
.note-preview{margin-top:6px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
textarea{min-height:180px;resize:vertical}.status{padding:12px;border-radius:12px;background:#f2f4f8;color:#475467}.status.live{background:#fff0f0;color:#9b2525}.status.ok{background:#ebf8f1;color:#17663d}
.wave{height:62px;display:flex;align-items:center;gap:4px;margin:12px 0}.wave i{width:5px;background:#7773df;border-radius:4px;animation:pulse 1s infinite ease-in-out}.wave i:nth-child(2n){animation-delay:.1s}.wave i:nth-child(3n){animation-delay:.2s}@keyframes pulse{50%{height:8px}0%,100%{height:35px}}
#timer{font-size:28px;font-weight:700}.upload{border:2px dashed #c9d0dc;border-radius:16px;padding:26px;text-align:center;background:#fafbfc}.upload input{display:none}.upload label{display:inline-block}
.fileitem{display:flex;justify-content:space-between;align-items:center;padding:12px;border:1px solid var(--line);border-radius:12px;margin-top:8px}.fileitem span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.controls{display:flex;gap:8px;flex-wrap:wrap}.setting{display:flex;justify-content:space-between;gap:20px;align-items:center;padding:15px 0;border-bottom:1px solid var(--line)}
.switch{flex:0 0 52px;width:52px;min-width:52px;height:29px;padding:0;border:0;border-radius:20px;background:#cbd5e1;position:relative}.setting>div{min-width:0}.switch:after{content:"";position:absolute;width:23px;height:23px;border-radius:50%;background:#fff;top:3px;left:3px;transition:.2s}.switch.on{background:var(--brand)}.switch.on:after{left:26px}
.big{font-size:26px}.small{font-size:14px}.muted{color:var(--muted)}.hidden{display:none!important}
.bio-b{font-weight:700}
html.no-tts [onclick^="speak"],html.no-tts .tts-only{display:none!important}
html:not(.is-mobile) .mobile-only{display:none!important}
.ruler{position:fixed;left:0;right:0;top:0;transform:translateY(40vh);will-change:transform;height:calc(var(--size) * var(--spacing) * 1.9);background:#fff3a826;border-top:2px solid var(--brand);border-bottom:2px solid var(--brand);box-shadow:0 0 0 100vmax #0f141c73;pointer-events:none;display:none;z-index:35}.ruler.on{display:block}
.diagram{display:flex;align-items:center;justify-content:center;gap:10px;flex-wrap:wrap;padding:25px}.node{padding:14px 18px;background:#eef0ff;border:1px solid #cdd0ff;border-radius:14px;font-weight:700}.arrow{font-size:25px;color:var(--brand)}
.toast{position:fixed;bottom:22px;right:22px;background:#121826;color:#fff;padding:13px 17px;border-radius:12px;z-index:50;max-width:380px;box-shadow:0 10px 30px #0000003d;pointer-events:none;
 opacity:0;visibility:hidden;transform:translate(18px,18px) scale(.96);transition:opacity .16s ease-in,transform .16s ease-in,visibility 0s linear .16s}
/* Pops in from the bottom right with a slight overshoot, fades out quickly. Reduce motion makes both instant. */
.toast.show{opacity:1;visibility:visible;transform:none;transition:opacity .2s ease-out,transform .32s cubic-bezier(.2,.9,.3,1.25),visibility 0s}
.modal{position:fixed;inset:0;background:#10182877;display:none;align-items:center;justify-content:center;padding:20px;z-index:40}.modal.show{display:flex}.modalbox{background:#fff;border-radius:20px;padding:25px;max-width:560px;width:100%;max-height:85vh;overflow:auto}
/* Tab switch animation: page fades in, then its blocks rise in with a short stagger */
.page.active{animation:pageIn .22s ease-out both}
.page.active>.top,.page.active>.card,.page.active>.grid>.card{animation:riseIn .32s cubic-bezier(.2,.7,.3,1) both}
.page.active>.card,.page.active>.grid>.card:first-child{animation-delay:.04s}
.page.active>.grid>.card:nth-child(2),.page.active>.card~.card,.page.active>.card~.grid>.card{animation-delay:.09s}
.page.active>.grid~.card{animation-delay:.14s}
#noteList .note{animation:riseIn .25s cubic-bezier(.2,.7,.3,1) both}
#noteList .note.removing{animation:noteOut .22s ease-in forwards;pointer-events:none}
@keyframes noteOut{to{opacity:0;transform:translateX(28px) scale(.98)}}
/* AI */
.spinner{display:inline-block;width:1em;height:1em;border:3px solid currentColor;border-right-color:transparent;border-radius:50%;vertical-align:-2px;margin-right:4px;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.ai-loading{display:flex;align-items:center;gap:6px}
.ai-pill{position:fixed;left:22px;bottom:22px;z-index:45;display:flex;align-items:center;gap:6px;max-width:calc(100% - 44px);padding:8px 14px;border-radius:999px;background:var(--surface);color:var(--ink);border:1px solid var(--line);box-shadow:0 6px 20px #0000002e;font-size:13px;
 opacity:0;visibility:hidden;transform:translateY(10px);transition:opacity .2s,transform .2s,visibility 0s linear .2s;pointer-events:none}
.ai-pill.show{opacity:1;visibility:visible;transform:none;transition:opacity .2s,transform .2s,visibility 0s}
html.m-portrait .ai-pill{left:16px;bottom:calc(84px + env(safe-area-inset-bottom))}
html.m-portrait .toast.show~.ai-pill{bottom:calc(140px + env(safe-area-inset-bottom))}
#apiKeyInput{display:block;width:100%;margin-top:6px;border:1px solid var(--line);border-radius:12px;padding:12px;background:var(--surface);color:var(--ink);font-family:ui-monospace,Consolas,monospace;font-weight:400}
html.dark #apiKeyInput{background:var(--surface2)}html.hc #apiKeyInput{border:2px solid var(--line)}html.m-portrait #apiKeyInput{font-size:16px}
.providers{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:14px}
@media(max-width:700px){.providers{grid-template-columns:repeat(2,1fr)}}html.m-portrait .providers{grid-template-columns:repeat(2,1fr)}
.provider{display:flex;flex-direction:column;align-items:center;gap:2px;padding:12px 8px;border:2px solid var(--line);border-radius:14px;background:var(--surface);color:var(--ink)}
.provider span{font-size:13px;color:var(--muted)}.provider[aria-checked="true"]{border-color:var(--brand);background:var(--soft);box-shadow:0 0 0 1px var(--brand)}
.engines{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:6px;font-weight:400}
.engine{display:flex;flex-direction:column;align-items:flex-start;gap:4px;text-align:left;padding:12px;border:2px solid var(--line);border-radius:14px;background:var(--surface);color:var(--ink)}
.engine span{font-size:13px;line-height:1.4;color:var(--muted)}.engine[aria-checked="true"]{border-color:var(--brand);background:var(--soft);box-shadow:0 0 0 1px var(--brand)}
html.m-portrait .engines{grid-template-columns:1fr}.engine:disabled{opacity:.5;cursor:not-allowed}
.presets{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}
@media(max-width:1250px){.presets{grid-template-columns:repeat(2,1fr)}}
.preset{display:flex;flex-direction:column;gap:6px;text-align:left;padding:14px;border:2px solid var(--line);border-radius:14px;background:var(--surface);color:var(--ink)}
.preset:hover{border-color:var(--brand)}.preset[aria-pressed="true"]{border-color:var(--brand);background:var(--soft)}
.preset-top{display:flex;align-items:center;gap:8px}.preset-icon{font-size:22px;line-height:1}
.preset-on{margin-left:auto;font-size:12px;font-weight:700;color:var(--brand);background:var(--surface);border:1px solid var(--brand);padding:1px 8px;border-radius:999px}
.preset-desc{font-size:13px;line-height:1.45;color:var(--muted)}
.preset-status{margin-top:12px;display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
@media(max-width:900px){.presets{grid-template-columns:1fr}}
.preset:focus,html.hc .preset:focus{outline:none}.preset:focus-visible{outline:3px dashed var(--focus);outline-offset:3px}
/* Choice cards show selection with their own border, so drop the click focus ring; keep a clear ring for keyboard users. */
.provider:focus,.engine:focus,html.hc .provider:focus,html.hc .engine:focus{outline:none}
.provider:focus-visible,.engine:focus-visible{outline:3px dashed var(--focus);outline-offset:3px}
.interim{min-height:1.6em;margin:6px 0 10px;color:var(--muted);font-style:italic}
.vocab{padding:6px 0;border-bottom:1px dashed var(--line)}.vocab:last-child{border-bottom:0}
mark.key{color:inherit}
#aiResult.airy .note{line-height:calc(var(--spacing) + .4)}#aiResult.airy p,#aiResult.airy li{margin:.9em 0}
.ai-steps{padding-left:1.4em;margin:6px 0}.ai-steps li{margin:8px 0}
.node small{display:block;font-weight:400;margin-top:4px}.diagram.flow .node{max-width:200px;text-align:center}
.diagram.map{flex-direction:column}.branches{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;width:100%}
.node.hub{background:var(--brand);border-color:var(--brand);color:#fff;font-size:1.1em}html.hc .node.hub{color:var(--hc-on-brand)}
.quiz-explain{margin-top:6px;color:var(--ink)}
/* Quiz */
.quiz-head{display:flex;justify-content:space-between;align-items:baseline;gap:10px;flex-wrap:wrap}
.quiz-progress{height:8px;background:var(--surface2);border:1px solid var(--line);border-radius:99px;overflow:hidden;margin:10px 0 14px}.quiz-progress i{display:block;height:100%;background:var(--brand);transition:width .3s}
.quiz-q{margin:0 0 8px;font-weight:700}
.quiz-sentence{font-size:1.1em;background:var(--surface2);border:1px solid var(--line);border-radius:14px;padding:14px 16px;margin:0}
.quiz-opts{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin:14px 0}
.quiz-opt{text-align:left;padding:13px 14px;font-weight:700;display:flex;align-items:center;gap:10px}.quiz-opt:disabled{opacity:1;filter:none;cursor:default;color:var(--ink)}
.quiz-opt .num{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:1.7em;height:1.7em;border-radius:50%;background:var(--soft);color:var(--brand);font-size:.8em}
.quiz-opt.right{background:#e7f6ee;border:2px solid var(--green);color:#0f5132}.quiz-opt.wrong{background:#fdecec;border:2px solid var(--red);color:#842029}
html.dark .quiz-opt.right{background:#16301f;color:#8fe0b0}html.dark .quiz-opt.wrong{background:#3a1b1e;color:#ffb3b3}
html.hc .quiz-opt.right,html.hc .quiz-opt.wrong{background:var(--surface);color:var(--ink);border-width:4px}
.quiz-score{font-size:46px;font-weight:700;text-align:center;margin:10px 0 4px;color:var(--brand)}
html.m-portrait .quiz-opts{grid-template-columns:1fr}
#noteList .controls{margin-top:10px}.btn.del{color:var(--red)}.btn.del:hover{border-color:var(--red)}
html.m-portrait #noteList .controls .btn.del{flex:0 0 auto}
@keyframes pageIn{from{opacity:0}to{opacity:1}}
@keyframes riseIn{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
.nav button{transition:background .18s,color .18s,transform .12s}.nav button:active{transform:scale(.94)}
body,.card,.note,.btn,.status,textarea,input[type=text]{transition:background-color .25s,border-color .25s,color .25s}
/* Reduce motion (Settings setting; defaults to the OS preference) */
html.reduce-motion *,html.reduce-motion *::before,html.reduce-motion *::after{animation:none!important;transition:none!important;scroll-behavior:auto!important}

/* ===== Dark mode (Settings setting; defaults to the OS preference) ===== */
html.dark{--bg:#0f141c;--surface:#171e29;--surface2:#1d2531;--ink:#e6ebf2;--muted:#9aa6b8;--line:#2b3442;--soft:#2a2b55;--yellow:#5c4f12;--green:#4ade80;--red:#e05252;color-scheme:dark}
html.dark .side{border-right:1px solid var(--line)}
html.dark .card{box-shadow:none}
html.dark .hero{background:linear-gradient(135deg,#1c2142,#2e3160);border:1px solid #3a3f70}
html.dark .tag{color:#c9c7ff}html.dark .key{color:#fff6cc}
html.dark textarea,html.dark input[type=text],html.dark select{background:var(--surface2)}
html.dark .status{background:#202938;color:#b8c2d1}html.dark .status.live{background:#3a1b1e;color:#ffb3b3}html.dark .status.ok{background:#16301f;color:#8fe0b0}
html.dark .upload{background:var(--surface2);border-color:#3a4556}
html.dark .modal{background:#000000a0}html.dark .modalbox{background:var(--surface);border:1px solid var(--line)}
html.dark .node{background:#24264a;border-color:#3d4080;color:var(--ink)}
html.dark .switch{background:#3a4556}
html.dark .ruler{background:#ffe27a1a;box-shadow:0 0 0 100vmax #000000a6}
html.dark .toast{background:#e6ebf2;color:#121826}

/* ===== Light mode: the sidebar, mobile bars and welcome banner are light too ===== */
html:not(.dark):not(.hc) .side,html:not(.dark):not(.hc) .mbar{background:var(--surface);color:var(--ink)}
html:not(.dark):not(.hc) .side{border-right:1px solid var(--line)}
html:not(.dark):not(.hc).m-portrait .side{border-top:1px solid var(--line);border-right:0;box-shadow:0 -4px 16px #17212b0f}
html:not(.dark):not(.hc).m-portrait .mbar{border-bottom:1px solid var(--line)}
html:not(.dark):not(.hc) .logo span,html:not(.dark):not(.hc) .mlogo span{color:var(--brand)}
html:not(.dark):not(.hc) .nav button{color:#475467}
html:not(.dark):not(.hc) .nav button:hover{background:var(--surface2);color:var(--ink)}
html:not(.dark):not(.hc) .nav button.active{background:var(--soft);color:#3f3bb8}
html:not(.dark):not(.hc) .privacy{border-color:var(--line);color:var(--muted)}html:not(.dark):not(.hc) .privacy b{color:var(--ink)}
html:not(.dark):not(.hc) .mpriv{background:var(--soft);color:#3f3bb8}
html:not(.dark):not(.hc) .hero{background:linear-gradient(135deg,#eeefff,#e3e6ff);color:var(--ink);border:1px solid #d6d9fb}
html:not(.dark):not(.hc) .hero .sub{color:#4a4f73}
html:not(.dark):not(.hc) .feature{background:#ffffffb3;border-color:#d6d9fb}

/* ===== High contrast (Settings setting). Light: black on white. Combined with dark: white/yellow on black. ===== */
html.hc{--bg:#fff;--surface:#fff;--surface2:#fff;--ink:#000;--muted:#000;--line:#000;--brand:#1f0fb8;--soft:#fff;--yellow:#ffe14d;--green:#005c2a;--red:#b00000;--hc-on-brand:#fff;--hc-focus:#000}
html.hc.dark{--bg:#000;--surface:#000;--surface2:#000;--ink:#fff;--muted:#fff;--line:#fff;--brand:#ffd600;--soft:#000;--yellow:#ffd600;--green:#5dff9b;--red:#ff6b6b;--hc-on-brand:#000;--hc-focus:#ffd600}
html.hc .card,html.hc .note,html.hc .btn,html.hc textarea,html.hc input[type=text],html.hc select,html.hc .fileitem,html.hc .modalbox,html.hc .status{border:2px solid var(--line)}
html.hc .card{box-shadow:none}
html.hc .primary,html.hc .danger{color:var(--hc-on-brand)}
html.hc .danger{background:var(--red);border-color:var(--red)}
html.hc .hero{background:#000;color:#fff;border:2px solid var(--line)}html.hc .hero .sub{color:#fff}html.hc .feature{background:#000;border:2px solid #fff}
html.hc .side,html.hc .mbar,html.hc .toast{background:#000;color:#fff}html.hc .side{border-right:2px solid var(--line)}
html.hc .nav button{color:#fff}html.hc .nav button:hover,html.hc .nav button.active{background:#fff;color:#000}
html.hc.dark .nav button:hover,html.hc.dark .nav button.active{background:#ffd600;color:#000}
html.hc .logo span,html.hc .mlogo span{color:#fff}html.hc .privacy{color:#fff;border-color:#fff}
html.hc .tag{background:var(--surface);color:var(--ink);border:2px solid var(--line);font-weight:700}
html.hc .status,html.hc .status.live,html.hc .status.ok{background:var(--surface);color:var(--ink)}
html.hc .key{background:var(--yellow);color:#000}
html.hc .upload{background:var(--surface);border:3px dashed var(--line)}
html.hc .node{background:var(--surface);color:var(--ink);border:2px solid var(--line)}
html.hc .switch{background:var(--surface);border:2px solid var(--line)}html.hc .switch:after{background:var(--ink);top:2px;left:2px}
html.hc .switch.on{background:var(--brand);border-color:var(--brand)}html.hc .switch.on:after{background:var(--hc-on-brand);left:25px}
html.hc .modal{background:#000000cc}
html.hc .ruler{background:transparent;border-width:3px;border-color:var(--hc-focus);box-shadow:0 0 0 100vmax #000000b3}
html.hc a{color:var(--ink)}
html.hc button:focus,html.hc input:focus,html.hc textarea:focus{outline:4px solid var(--hc-focus);outline-offset:3px}

/* ===== Background tint (Settings). Light and dark variants; high contrast + dark stays pure black. ===== */
html[data-tint="cream"]{--bg:#f6efdc;--surface:#fdf6e3;--surface2:#f9f0d9;--line:#e3d8bc}
html[data-tint="blue"]{--bg:#e3edf7;--surface:#eef5fc;--surface2:#e7f0f9;--line:#cbd9ea}
html[data-tint="mint"]{--bg:#e0f2e9;--surface:#ecf8f1;--surface2:#e4f3ea;--line:#c6e0d1}
html[data-tint="peach"]{--bg:#f9e6da;--surface:#fdf0e8;--surface2:#f9e8dd;--line:#e9cfbe}
html[data-tint="grey"]{--bg:#e5e6e8;--surface:#f0f1f2;--surface2:#e9eaec;--line:#d1d4d9}
html.dark[data-tint="cream"]{--bg:#17140d;--surface:#211d14;--surface2:#29241a;--line:#3a3426}
html.dark[data-tint="blue"]{--bg:#0e1520;--surface:#152030;--surface2:#1b283a;--line:#2a3a50}
html.dark[data-tint="mint"]{--bg:#0d1813;--surface:#14231b;--surface2:#1a2c22;--line:#2a4134}
html.dark[data-tint="peach"]{--bg:#1a120e;--surface:#261a14;--surface2:#2f211a;--line:#443128}
html.dark[data-tint="grey"]{--bg:#141414;--surface:#1e1e1e;--surface2:#262626;--line:#383838}
html.hc[data-tint]:not(.dark){--line:#000}
html.hc.dark[data-tint]{--bg:#000;--surface:#000;--surface2:#000;--line:#fff}
html[data-tint] .upload{background:var(--surface2)}html[data-tint] .modalbox{background:var(--surface)}
.font-setting{padding:15px 0;border-bottom:1px solid var(--line)}
.font-choices{display:grid;grid-template-columns:repeat(auto-fill,minmax(170px,1fr));gap:8px;margin:12px 0}
.font-choice{display:flex;flex-direction:column;align-items:flex-start;gap:3px;text-align:left;padding:10px 12px;border:2px solid var(--line);border-radius:12px;background:var(--surface);color:var(--ink);letter-spacing:normal}
.font-sample{font-size:1.1em;font-weight:700;line-height:1.3}.font-choice small{color:var(--muted);font-size:12px;line-height:1.35}
.font-choice[aria-checked="true"]{border-color:var(--brand);background:var(--soft);box-shadow:0 0 0 1px var(--brand)}
.font-choice:focus,html.hc .font-choice:focus{outline:none}.font-choice:focus-visible{outline:3px dashed var(--focus);outline-offset:3px}
.font-choice-wrap{position:relative;display:flex}.font-choice-wrap .font-choice{flex:1;padding-right:34px}
.font-x{position:absolute;top:6px;right:6px;width:26px;height:26px;border-radius:50%;border:1px solid var(--line);background:var(--surface);color:var(--muted);font-size:12px;line-height:1}.font-x:hover{color:var(--red);border-color:var(--red)}
.font-more{border-top:1px dashed var(--line);padding-top:12px}.font-more .field{margin-bottom:10px}#fontStatus{margin-top:10px}
.tints{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0 18px}
.tint{display:flex;flex-direction:column;align-items:center;gap:4px;background:none;border:0;padding:4px 2px;min-width:58px;color:var(--ink);font-size:13px;line-height:1.2}
.tint i{width:40px;height:40px;border-radius:50%;background:var(--sw);border:2px solid var(--line);transition:transform .15s}
.tint[aria-checked="true"] i{outline:3px solid var(--brand);outline-offset:2px;transform:scale(1.06)}
.tint:focus,html.hc .tint:focus{outline:none}.tint:focus-visible i{outline:3px dashed var(--focus);outline-offset:2px}.tint[aria-checked="true"]{font-weight:700}
html.m-portrait .tint{min-width:0;flex:1 1 30%}
.nav .ic{display:inline-block;width:1.7em}.nav .sh,.mbar{display:none}
@media(max-width:900px){.side{width:78px}.logo{font-size:0}.logo:after{content:'N';font-size:28px}.nav button{font-size:0;text-align:center}.nav .ic{font-size:20px}.grid{grid-template-columns:1fr}.featuregrid{grid-template-columns:1fr}.top{align-items:flex-start;flex-direction:column}main{padding:20px}}

/* ===== Mobile device: landscape keeps the rail, but trims it to fit short screens ===== */
html.is-mobile:not(.m-portrait) .bottom{display:none}

/* ===== Mobile device in portrait (html.m-portrait is set by detectDevice()) ===== */
html.m-portrait .app{display:block}
html.m-portrait .mbar{display:flex;position:sticky;top:0;z-index:25;align-items:center;justify-content:space-between;background:#121826;color:#fff;padding:calc(10px + env(safe-area-inset-top)) 16px 10px}
html.m-portrait .mlogo{font-weight:700;font-size:22px}html.m-portrait .mlogo span{color:#aeb0ff}
html.m-portrait .mpriv{background:#282f43;border:0;color:#fff;border-radius:999px;padding:6px 12px;font-size:14px;min-height:36px}
/* Sidebar becomes a bottom tab bar */
html.m-portrait .side{position:fixed;top:auto;bottom:0;left:0;right:0;width:auto;height:auto;padding:6px 6px calc(6px + env(safe-area-inset-bottom));z-index:30;flex-direction:row;border-top:1px solid #283044}
html.m-portrait .logo,html.m-portrait .bottom{display:none}
html.m-portrait .nav{display:grid;grid-template-columns:repeat(6,1fr);gap:2px;width:100%}
html.m-portrait .nav button{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;padding:7px 2px;margin:0;min-height:56px;font-size:11px;line-height:1.15;text-align:center;border-radius:10px}
html.m-portrait .nav .ic{width:auto;font-size:20px;line-height:1}html.m-portrait .nav .lb{display:none}html.m-portrait .nav .sh{display:block}
/* Content: single column, room for the tab bar */
html.m-portrait main{max-width:none;padding:16px 16px calc(96px + env(safe-area-inset-bottom))}
html.m-portrait .top{flex-direction:column;align-items:stretch;gap:12px;margin-bottom:16px}
html.m-portrait h1{font-size:26px}html.m-portrait h2{font-size:19px}html.m-portrait .big{font-size:21px}
html.m-portrait .top .actions .btn{flex:1}
html.m-portrait .grid{grid-template-columns:1fr;gap:14px}
html.m-portrait .card{padding:16px;border-radius:16px}
html.m-portrait .featuregrid{grid-template-columns:1fr;gap:10px}
html.m-portrait .btn{min-height:46px;padding:11px 14px}
html.m-portrait .controls .btn{flex:1 1 calc(50% - 8px)}
html.m-portrait #ai .toolbar{display:grid;grid-template-columns:1fr 1fr;gap:8px}
html.m-portrait #notes .toolbar input{order:-1;flex:1 1 100%;max-width:none!important}
html.m-portrait textarea,html.m-portrait input[type=text],html.m-portrait select{font-size:max(16px,1em)}
html.m-portrait textarea{min-height:150px}
html.m-portrait #access label{display:block}html.m-portrait #access input[type=range]{display:block;width:100%;height:32px;margin-top:6px}
html.m-portrait #access br{display:none}html.m-portrait #access label+label{margin-top:16px}
html.m-portrait .setting{padding:13px 0}html.m-portrait .switch{flex:0 0 52px}
html.m-portrait .upload{padding:20px 14px}
html.m-portrait #timer{font-size:34px}
/* Modal becomes a bottom sheet, toast sits above the tab bar */
html.m-portrait .modal{align-items:flex-end;padding:0}
html.m-portrait .modalbox{max-width:none;border-radius:22px 22px 0 0;max-height:88vh;padding:20px 16px calc(20px + env(safe-area-inset-bottom))}
html.m-portrait .modalbox .top{flex-direction:row;align-items:center}
html.m-portrait .diagram{flex-direction:column;padding:10px}html.m-portrait .diagram .arrow{transform:rotate(90deg)}html.m-portrait .node{width:100%;text-align:center}
html.m-portrait .toast{left:16px;right:16px;bottom:calc(84px + env(safe-area-inset-bottom));max-width:none;text-align:center}
html.m-portrait .toast:not(.show){transform:translateY(18px) scale(.96)}

/* ===== Colour vision (Settings). Swaps the colours that carry meaning; ✓/✗ symbols are always shown too. ===== */
/* Red-green (protan/deutan): blue means right/success, orange means wrong/error. */
html[data-cvd="redgreen"]{--green:#1f6fd1;--red:#d55e00}
html.dark[data-cvd="redgreen"]{--green:#6aa8f0;--red:#ff9a4d}
html.hc[data-cvd="redgreen"]{--green:#0b4fa8;--red:#b34700}html.hc.dark[data-cvd="redgreen"]{--green:#7fb8ff;--red:#ffa04d}
html[data-cvd="redgreen"]:not(.dark):not(.hc) :is(.status.ok,.badge.good,.quiz-opt.right){background:#e6f0fb;color:#14508f}
html[data-cvd="redgreen"]:not(.dark):not(.hc) :is(.status.live,.quiz-opt.wrong){background:#fdeee3;color:#8f3f00}
html[data-cvd="redgreen"]:not(.dark):not(.hc) .badge.warn{background:#f1e8fb;color:#5b2a91}
html.dark[data-cvd="redgreen"]:not(.hc) :is(.status.ok,.badge.good,.quiz-opt.right){background:#13294a;color:#9cc6f7}
html.dark[data-cvd="redgreen"]:not(.hc) :is(.status.live,.quiz-opt.wrong){background:#3a2210;color:#ffc08a}
html.dark[data-cvd="redgreen"]:not(.hc) .badge.warn{background:#2c1f42;color:#d5b8ff}
/* Blue-yellow (tritan): red and green are still clear, so keep them; warnings avoid yellow/orange. */
html[data-cvd="blueyellow"]{--green:#0b7a4b;--red:#c62828}
html[data-cvd="blueyellow"]:not(.dark):not(.hc) .badge.warn{background:#fde7f1;color:#9b1650}
html.dark[data-cvd="blueyellow"]:not(.hc) .badge.warn{background:#3d1528;color:#ffb3d1}
/* Little or no colour: dark/light plus solid (right) vs dashed (wrong) outlines. */
html[data-cvd="mono"]{--green:var(--ink);--red:var(--ink)}
html[data-cvd="mono"] :is(.status.ok,.status.live,.badge.good,.badge.warn,.quiz-opt.right,.quiz-opt.wrong){background:var(--surface);color:var(--ink)}
html[data-cvd="mono"] :is(.status.ok,.quiz-opt.right,.badge.good){border:3px solid var(--ink)}
html[data-cvd="mono"] :is(.status.live,.quiz-opt.wrong,.badge.warn){border:3px dashed var(--ink)}
html[data-cvd="mono"] .quiz-opt.right{font-weight:800}
/* Colour vision choices and test */
.cvd-choices{display:grid;grid-template-columns:repeat(2,1fr);gap:8px;margin:12px 0}html.m-portrait .cvd-choices{grid-template-columns:1fr}
.cvd-choice{display:flex;flex-direction:column;align-items:flex-start;gap:6px;text-align:left;padding:12px;border:2px solid var(--line);border-radius:14px;background:var(--surface);color:var(--ink)}
.cvd-choice>span:last-child{font-size:13px;line-height:1.4;color:var(--muted)}
.cvd-choice[aria-checked="true"]{border-color:var(--brand);background:var(--soft);box-shadow:0 0 0 1px var(--brand)}
.cvd-choice:focus,html.hc .cvd-choice:focus{outline:none}.cvd-choice:focus-visible{outline:3px dashed var(--focus);outline-offset:3px}
.cvd-swatch{display:flex;gap:4px}.cvd-swatch i{display:inline-flex;align-items:center;justify-content:center;width:28px;height:22px;border-radius:6px;color:#fff;font-style:normal;font-size:12px;font-weight:700}
.cv-plate{display:block;width:min(300px,78vw);height:auto;margin:12px auto;border-radius:50%}
.cv-digits{display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin:12px 0}
/* Theme choice: System / Light / Dark */
.theme-choices{display:inline-flex;flex:0 0 auto;gap:4px;padding:4px;border:1px solid var(--line);border-radius:12px;background:var(--surface2)}
.theme-choice{border:0;background:none;color:var(--ink);padding:8px 12px;border-radius:9px;font-weight:700;white-space:nowrap}
.theme-choice[aria-checked="true"]{background:var(--brand);color:#fff}html.hc .theme-choice[aria-checked="true"]{color:var(--hc-on-brand)}
.theme-choice:focus,html.hc .theme-choice:focus{outline:none}.theme-choice:focus-visible{outline:3px dashed var(--focus);outline-offset:2px}
html.m-portrait .setting:has(.theme-choices){flex-wrap:wrap}html.m-portrait .theme-choices{width:100%}html.m-portrait .theme-choice{flex:1}

/* ===== Settings: its own screen. The app menu is hidden; categories run down the left. ===== */
html.in-settings .side,html.in-settings .mbar{display:none}
html.in-settings main{max-width:1200px}
.settings-page.active{display:grid;grid-template-columns:250px minmax(0,1fr);gap:24px;align-items:start}
.set-nav{position:sticky;top:20px}
.set-back{padding-left:6px;margin-bottom:12px;color:var(--brand);font-weight:700}
.set-title{margin:0 0 14px 6px}
.set-cats{display:flex;flex-direction:column;gap:2px}
.set-cats [role=tab]{display:flex;align-items:center;gap:10px;width:100%;text-align:left;padding:10px 12px;border:0;border-radius:11px;background:none;color:var(--ink);font-weight:700}
.set-cats [role=tab]:hover{background:var(--surface2)}
.set-cats [role=tab][aria-selected="true"]{background:var(--soft);color:var(--brand);box-shadow:inset 3px 0 0 var(--brand)}
.set-cats [role=tab]:focus{outline:none}.set-cats [role=tab]:focus-visible{outline:3px dashed var(--focus);outline-offset:2px}
html.hc .set-cats [role=tab][aria-selected="true"]{background:var(--brand);color:var(--hc-on-brand);box-shadow:none}
.set-ic{width:1.6em;text-align:center}
.set-note{margin:14px 0 0 12px}
.set-panel{display:none}.set-panel.active{display:block;animation:riseIn .25s cubic-bezier(.2,.7,.3,1) both}
.set-panel h2{font-size:24px;margin-bottom:6px}
.set-sub{font-size:13px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);margin:26px 0 4px;padding-top:18px;border-top:1px solid var(--line)}
.set-panel h2+.set-sub{border-top:0;padding-top:0;margin-top:14px}
.range-field input{display:block;width:100%;margin-top:6px}
/* Category descriptions, arrows and the "All settings" button only appear on phones (below). */
.set-desc,.set-chev,.set-up{display:none}
.set-lbl{min-width:0}
/* Narrow computer windows: back button and title on top, categories as a scrollable row of chips. */
@media(max-width:900px){
 html:not(.is-mobile) .settings-page.active{grid-template-columns:1fr;gap:12px}
 html:not(.is-mobile) .set-nav{position:sticky;top:0;z-index:20;background:var(--bg);padding:10px 0 8px;margin-top:-10px}
 html:not(.is-mobile) .set-title{margin:0 0 10px 6px;font-size:24px}
 html:not(.is-mobile) .set-cats{flex-direction:row;overflow-x:auto;gap:6px;padding-bottom:4px;scrollbar-width:none}html:not(.is-mobile) .set-cats::-webkit-scrollbar{display:none}
 html:not(.is-mobile) .set-cats [role=tab]{width:auto;flex:0 0 auto;white-space:nowrap;padding:8px 12px;border:1px solid var(--line);background:var(--surface)}
 html:not(.is-mobile) .set-cats [role=tab][aria-selected="true"]{box-shadow:none;border-color:var(--brand)}
 html:not(.is-mobile) .set-note{display:none}

 /* Phones and tablets: like a phone's own Settings app. First a full-screen list of categories; tapping one
    opens it full-screen, with "← All settings" at the top to go back. */
 html.is-mobile .settings-page.active{display:block}
 html.is-mobile.set-detail .set-nav,html.is-mobile:not(.set-detail) .set-main{display:none}
 html.is-mobile .set-title{font-size:28px;margin:4px 0 14px 4px}
 html.is-mobile .set-cats{gap:0;background:var(--surface);border:1px solid var(--line);border-radius:18px;overflow:hidden}
 html.is-mobile .set-cats [role=tab]{gap:12px;min-height:64px;padding:12px 14px;border-radius:0;border-bottom:1px solid var(--line);box-shadow:none;background:none;color:var(--ink)}
 html.is-mobile .set-cats [role=tab]:last-child{border-bottom:0}
 html.is-mobile .set-cats [role=tab][aria-selected="true"]{background:none;color:var(--ink)}
 html.is-mobile .set-cats [role=tab]:active{background:var(--surface2)}
 html.is-mobile .set-ic{font-size:22px;width:1.5em;flex:0 0 auto}
 html.is-mobile .set-lbl{flex:1;display:flex;flex-direction:column;gap:2px;line-height:1.3}
 html.is-mobile .set-desc{display:block;font-size:13px;font-weight:400;color:var(--muted)}
 html.is-mobile .set-chev{display:block;font-size:24px;line-height:1;color:var(--muted)}
 html.is-mobile .set-note{margin:12px 0 0 6px}
 html.is-mobile .set-up{display:inline-flex;position:sticky;top:0;z-index:20;margin:-4px 0 10px -6px;padding:10px 8px;background:var(--bg);border:0;color:var(--brand);font-weight:700}
 html.is-mobile .set-panel{border-radius:18px;padding:18px 16px}
 html.is-mobile .set-panel h2{font-size:26px}
 html.is-mobile .set-panel .setting{gap:14px}
 html.is-mobile .set-panel .controls .btn{flex:1 1 auto}
 html.is-mobile.hc .set-cats [role=tab]{border-bottom:2px solid var(--line)}
}
html.m-portrait.in-settings main{padding-bottom:calc(24px + env(safe-area-inset-bottom))}

/* ===== AI model picker: dropdown with a search box ===== */
.mpick{position:relative;margin-top:6px;font-weight:400}
.mpick-btn{display:flex;width:100%;justify-content:space-between;align-items:center;gap:10px;padding:12px;border-radius:12px;text-align:left;background:var(--surface2)}
.mpick-btn span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.mpick-pop{position:absolute;left:0;right:0;top:calc(100% + 6px);z-index:40;background:var(--surface);border:1px solid var(--line);border-radius:14px;box-shadow:0 14px 34px #17212b29;padding:8px}
.mpick-pop input[type=search]{display:block;width:100%;margin:0 0 6px;border:1px solid var(--line);border-radius:10px;padding:10px 12px;background:var(--surface2);color:var(--ink)}
#modelOptions{max-height:280px;overflow-y:auto;overscroll-behavior:contain}
.mopt{display:flex;align-items:center;gap:8px;padding:9px 10px;border-radius:10px;cursor:pointer;line-height:1.3}.mopt>span:first-child{flex:1;min-width:0;overflow-wrap:anywhere}
.mopt:hover,.mopt.active{background:var(--soft)}.mopt[aria-selected="true"]{font-weight:700}
.mopt-rec{background:var(--soft);color:var(--brand);margin:0}html.dark .mopt-rec{color:#c9c7ff}
#modelSource{padding:6px 4px 2px}
html.dark .mpick-pop{box-shadow:0 14px 34px #0000008a}
html.hc .mpick-pop,html.hc .mpick-pop input[type=search]{border:2px solid var(--line)}html.hc .mopt.active{outline:2px solid var(--line)}
html.m-portrait .mpick-pop input[type=search]{font-size:max(16px,1em)}
.switch:disabled{opacity:.45;cursor:not-allowed}

/* ===== In-app camera (Import → Take photos) ===== */
.cam{position:relative;background:#000;border-radius:14px;overflow:hidden;aspect-ratio:3/4;max-height:58vh;margin:0 auto}
.cam video{display:block;width:100%;height:100%;object-fit:contain}.cam video.mirror{transform:scaleX(-1)}
.cam-flash{position:absolute;inset:0;background:#fff;opacity:0;pointer-events:none}.cam-flash.go{animation:camFlash .35s ease-out}
@keyframes camFlash{from{opacity:.85}to{opacity:0}}html.reduce-motion .cam-flash.go{animation:none}
.cam-controls{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:10px;margin-top:10px}.cam-controls .btn{justify-self:end}
.cam-shutter{width:68px;height:68px;border-radius:50%;background:#fff;border:5px solid var(--brand);box-shadow:0 0 0 3px var(--surface),0 0 0 5px var(--line);padding:0}
.cam-shutter:active{transform:scale(.92)}.cam-shutter:disabled{opacity:.4}
.linkbtn{background:none;border:0;padding:4px;color:var(--brand);text-decoration:underline;font-weight:700}
