/* Aegis Web — styles. No inline styles anywhere (strict CSP). Tokens first, so theming is one place. */
:root {
  --scale: 1;
  --navy: #0f1624; --navy-2: #1a2642; --gold: #c8960c; --teal: #028090; --teal-dark: #016070;
  --bg: #f6f8fb; --surface: #ffffff; --surface-2: #eef2f7; --text: #0f1624; --muted: #4a5568; --line: #cfd8e3;
  --accent: #028090; --accent-text: #ffffff; --warn-bg: #fff6e0; --warn-line: #c8960c; --focus: #c8960c;
  --tutor-bg: #ffffff; --student-bg: #028090; --student-text: #ffffff; --danger: #a32d2d;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b111d; --surface: #131c30; --surface-2: #1a2642; --text: #eef2f7; --muted: #b4c0d0; --line: #2a3a5c;
    --accent: #2fb5c6; --accent-text: #06202a; --warn-bg: #2a2410; --focus: #e8b020;
    --tutor-bg: #131c30; --student-bg: #1f8b99; --student-text: #ffffff;
  }
}
:root[data-contrast="1"] {
  --bg: #000; --surface: #000; --surface-2: #111; --text: #fff; --muted: #fff; --line: #fff; --accent: #ffe14d; --accent-text: #000;
  --tutor-bg: #000; --student-bg: #ffe14d; --student-text: #000; --warn-bg: #000; --warn-line: #ffe14d; --focus: #ffe14d;
}
:root[data-comfort="1"] body { letter-spacing: .02em; word-spacing: .1em; line-height: 1.75; }

*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(100% * var(--scale)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
h1 { font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
p { margin: 0 0 .8rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--navy); color: #fff; padding: .6rem 1rem; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }

/* header */
.top { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; padding: .6rem 1rem; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand-name { display: block; font-weight: 700; font-size: 1.1rem; line-height: 1; }
.brand-sub { display: block; font-size: .72rem; color: var(--gold); letter-spacing: .08em; text-transform: uppercase; }
.pills { display: flex; gap: .4rem; flex-wrap: wrap; margin-left: .5rem; }
.pill { font-size: .75rem; padding: .2rem .6rem; border-radius: 999px; border: 1px solid #ffffff55; color: #fff; }
.top-actions { margin-left: auto; display: flex; gap: .4rem; }
.top .btn.ghost { color: #fff; border-color: #ffffff66; }

/* layout */
main { max-width: 920px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.screen > h1:focus { outline: none; }
.lead { color: var(--muted); font-size: 1.05rem; max-width: 60ch; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 1rem 0; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .8rem; }
.row.between { justify-content: space-between; align-items: flex-end; }
.row.end { justify-content: flex-end; }
.hint { color: var(--muted); font-size: .9rem; margin: .6rem 0 0; }

/* buttons: all targets at least 44px */
.btn {
  appearance: none; min-height: 44px; min-width: 44px; padding: .55rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text); border: 2px solid var(--line); border-radius: 12px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.field { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; font-size: .95rem; }
input[type="text"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 2px solid var(--line); border-radius: 10px; padding: .55rem .7rem; min-height: 44px;
}
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--accent); }
.switch { display: flex; align-items: center; gap: .5rem; min-height: 44px; font-weight: 500; }
.switch input { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); }

/* setup */
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.checks li { display: flex; gap: .6rem; align-items: baseline; }
.badge { flex: none; font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.badge.ok { background: #d9f2e1; color: #14532d; border-color: #86c79d; }
.badge.no { background: #ffe1e1; color: #7f1d1d; border-color: #e3a1a1; }
:root[data-contrast="1"] .badge { color: #fff; background: #000; }
.choices { display: grid; gap: .6rem; }
.choice { display: flex; gap: .8rem; align-items: flex-start; border: 2px solid var(--line); border-radius: 12px; padding: .8rem; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.choice input { margin-top: .3rem; width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }
.choice-body { display: grid; gap: .15rem; }
.choice-body span { color: var(--muted); font-size: .92rem; }
.rec { font-style: normal; font-size: .78rem; font-weight: 700; color: var(--accent); }
.progress progress { width: 100%; height: 1rem; accent-color: var(--accent); }
#load-text { font-size: .9rem; color: var(--muted); }

/* topics */
.topics { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.topic { display: flex; gap: .8rem; align-items: center; width: 100%; text-align: left; min-height: 72px; padding: .8rem 1rem; }
.topic .sym { flex: none; width: 2.6rem; height: 2.6rem; display: grid; place-items: center; border-radius: 10px; background: var(--navy); color: var(--gold); font-weight: 700; font-size: .95rem; }
.topic .t { font-weight: 700; }
.topic .n { display: block; font-weight: 400; font-size: .82rem; color: var(--muted); }

/* tutor */
.tutor-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.tutor-head h1 { margin: 0; flex: 1; font-size: 1.25rem; }
.hints { display: flex; gap: .3rem; }
.hints span { width: .9rem; height: .9rem; border-radius: 50%; border: 2px solid var(--gold); }
.hints span.on { background: var(--gold); }
.log { list-style: none; margin: 1rem 0 .5rem; padding: 0; display: flex; flex-direction: column; gap: .7rem; min-height: 40vh; max-height: 56vh; overflow-y: auto; scroll-behavior: smooth; }
.bubble { max-width: 88%; padding: .7rem .95rem; border-radius: 16px; border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.tutor { align-self: flex-start; background: var(--tutor-bg); border-bottom-left-radius: 4px; }
.bubble.student { align-self: flex-end; background: var(--student-bg); color: var(--student-text); border-color: transparent; border-bottom-right-radius: 4px; }
.bubble.safeguard { background: var(--warn-bg); border: 2px solid var(--warn-line); }
.bubble .tools { display: flex; gap: .4rem; margin-top: .4rem; }
.bubble .mini { min-height: 36px; padding: .2rem .7rem; font-size: .85rem; }
.bubble.streaming::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.helplines { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .5rem; }
.helplines li { display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 12px; padding: .5rem .7rem; background: var(--surface); color: var(--text); }
.helplines .hl-name { font-weight: 700; display: block; }
.helplines .hl-detail { font-size: .85rem; color: var(--muted); }
.helplines .hl-links { display: flex; gap: .4rem; }
.helplines a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.status { min-height: 1.6rem; color: var(--muted); font-size: .92rem; margin: 0 0 .4rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: center; margin-bottom: .6rem; }
.composer { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: end; position: sticky; bottom: 0; background: var(--bg); padding: .5rem 0 calc(.5rem + env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 9rem; }
.mic { display: inline-flex; align-items: center; gap: .5rem; }
.mic-dot { width: .8rem; height: .8rem; border-radius: 50%; background: var(--danger); }
.mic[aria-pressed="true"] { border-color: var(--danger); background: var(--surface-2); }
.mic[aria-pressed="true"] .mic-dot { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.5); opacity: .55; } }

/* dialogs */
dialog { border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(620px, 94vw); width: 100%; padding: 0; }
dialog::backdrop { background: #000a; }
.dlg { padding: 1.1rem 1.2rem; display: grid; gap: .9rem; max-height: 86dvh; overflow: auto; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem .9rem; display: grid; gap: .6rem; margin: 0; }
legend { font-weight: 700; padding: 0 .4rem; }

.toast { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--navy); color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 50; max-width: 90vw; }

@media (max-width: 560px) {
  .composer { grid-template-columns: 1fr 1fr; }
  .composer textarea { grid-column: 1 / -1; }
  .bubble { max-width: 96%; }
  .top-actions { width: 100%; margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
  .bubble.streaming::after { content: "…"; }
}

/* ───────── Project Aegis (cloud version) additions ───────── */
input[type="password"], input[type="text"], textarea { font: inherit; }
input[type="password"] { width: 100%; min-height: 44px; padding: .5rem .7rem; border: 2px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
.banner { margin: 0; padding: .6rem 1rem; background: var(--warn-bg); border-bottom: 2px solid var(--warn-line); font-weight: 600; }
.error { color: var(--danger); font-weight: 600; margin: .6rem 0 0; }
:root[data-contrast="1"] .error { color: #ff9b9b; }
.pill.bad { border-color: #ffb4b4; color: #ffd0d0; }
.profiles { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.profiles:empty { display: none; }
.nav-row { margin: .4rem 0 .8rem; }
.plain { margin: .3rem 0 0; padding-left: 1.2rem; }
.plain li { margin: .3rem 0; }
.dlg h3 { margin: .4rem 0 0; font-size: 1rem; }
.assess-list { grid-template-columns: 1fr; }
.assess-item { display: flex; gap: .8rem; justify-content: space-between; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.assess-item .row { margin: 0; }
.assess-body .t { display: block; font-weight: 700; margin-bottom: .3rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { font-size: .8rem; padding: .15rem .6rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); }
.chip.mastered { border-color: #1f8a4c; } .chip.developing { border-color: var(--gold); } .chip.beginning { border-color: var(--danger); }
progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.qcard { display: grid; gap: .6rem; }
.qlabel { margin: 0; font-weight: 700; color: var(--muted); font-size: .9rem; }
.qprompt { margin: 0; font-size: 1.2rem; line-height: 1.45; }
#q-input { width: 100%; padding: .6rem .8rem; border: 2px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); resize: vertical; }
.result .big { font-size: 2rem; font-weight: 800; margin: 0; }
.result .tier { display: inline-block; font-weight: 700; padding: .2rem .8rem; border-radius: 999px; border: 2px solid var(--line); margin: .3rem 0 .6rem; }
.result .tier.mastered { border-color: #1f8a4c; } .result .tier.developing { border-color: var(--gold); } .result .tier.beginning { border-color: var(--danger); }
.result .growth { font-weight: 600; }
.qres { list-style: none; padding: 0; }
.qres li { padding: .3rem 0; border-bottom: 1px solid var(--line); }
.tablewrap { overflow-x: auto; }
.progress-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.progress-table th, .progress-table td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
.progress-table td.up { color: #1f8a4c; font-weight: 700; } .progress-table td.down { color: var(--danger); font-weight: 700; }
@media (max-width: 520px) { .assess-item { flex-direction: column; align-items: stretch; } }

main .pill { color: var(--text); border-color: var(--line); background: var(--surface-2); }
:root { --ok: #146c3a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ok: #5fd39a; --danger: #ff9b9b; } }
.progress-table td.up { color: var(--ok); }

#model-progress { margin: .6rem 0 0; }

/* Learning workspace */
:root:not([data-contrast="1"]) {
  --radius: 20px;
  --navy: #142b38;
  --gold: #f4cf83;
}
@media (prefers-color-scheme: light) {
  :root:not([data-contrast="1"]) { color-scheme: light; }
}
:root[data-theme="light"] { color-scheme: light; }
:root:not([data-contrast="1"]) {
  --bg: #f6f7f4; --surface: #ffffff; --surface-2: #e6f2ef;
  --text: #16303a; --muted: #425861; --line: #becfd0;
  --accent: #00665e; --accent-text: #fff; --focus: #007469;
  --tutor-bg: #ffffff; --student-bg: #00665e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-contrast="1"]) {
    --bg: #101d27; --surface: #172b36; --surface-2: #233f49;
    --text: #edf7f5; --muted: #c0d4d9; --line: #4a6871;
    --accent: #8be2d1; --accent-text: #103831; --focus: #ffd084;
    --tutor-bg: #172b36; --student-bg: #14645f;
  }
}

.top {
  padding: .65rem max(1rem, calc((100% - 1080px) / 2));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.brand img { width: 2.35rem; height: 2.35rem; padding: .2rem; background: var(--navy); border-radius: 10px; }
.brand-sub { color: var(--muted); }
.top .pill, .top .btn.ghost { color: var(--text); border-color: var(--line); }
.top .pill { background: var(--surface-2); }
.top .pill.bad { color: var(--danger); border-color: currentColor; }
.top .btn.ghost:hover { background: var(--surface-2); }

main { max-width: 1112px; padding-top: clamp(1.2rem, 3vw, 2.65rem); }
.screen > h1 { font-size: clamp(1.9rem, 5vw, 3.1rem); letter-spacing: -.055em; }
.card { padding: clamp(1rem, 3vw, 1.8rem); }
.btn { border-radius: 11px; }
.btn.primary:hover:not(:disabled) { filter: brightness(.9); }

.setup-intro {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(1.25rem, 5vw, 4rem);
  padding: clamp(1.2rem, 4.5vw, 3.3rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}
.welcome-copy h1 { font-size: clamp(2.25rem, 5.2vw, 4.15rem); letter-spacing: -.06em; line-height: 1.04; }
.welcome-copy h1 em { color: var(--accent); font: italic 1em Georgia, serif; }
.welcome-copy .lead { color: var(--muted); max-width: 35ch; margin: .9rem 0 0; }
.practice-preview {
  padding: clamp(1rem, 3vw, 1.6rem);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.practice-label { color: var(--muted); font-size: .8rem; font-weight: 700; margin: 0 0 .5rem; }
.practice-problem { font-size: clamp(1.07rem, 2vw, 1.35rem); font-weight: 750; margin: 0 0 .85rem; }
.practice-hint { color: var(--text); background: var(--surface-2); border-inline-start: 3px solid var(--accent); border-radius: 0 8px 8px 0; margin: 0; padding: .7rem .85rem; font-size: .9rem; }

.model-panel { background: transparent; border: 0; border-radius: 0; margin: 0; padding: clamp(1.35rem, 3vw, 2.4rem) 0 0; }
.model-panel h2 { font-size: clamp(1.3rem, 3vw, 1.85rem); letter-spacing: -.03em; margin-bottom: .3rem; }
#model-reason { color: var(--muted); margin-bottom: .5rem; }
.model-panel .model-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 225px), 1fr)); gap: .8rem; }
.model-option {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .3rem;
  min-width: 0;
  min-height: 100px;
  height: 100%;
  padding: .8rem 2rem .8rem 1rem;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 15px;
  overflow-wrap: anywhere;
}
.model-option::after { content: ""; position: absolute; right: 1rem; top: calc(50% - .25rem); width: .5rem; height: .5rem; border-top: 2px solid var(--accent); border-right: 2px solid var(--accent); transform: rotate(45deg); }
.model-option.recommended { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.model-option.recommended .option-detail, .model-option.recommended::after { color: inherit; border-color: currentColor; }
.model-option.recommended:hover:not(:disabled) { filter: brightness(.92); color: var(--accent-text); background: var(--accent); }
.model-option:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-2); }
.option-name { font-weight: 750; }
.option-detail { color: var(--muted); font-size: .86rem; font-weight: 500; }
.model-panel #model-status:empty { display: none; }
.model-panel > .hint:last-child { margin-top: .5rem; }

#form-profile { max-width: 680px; }
#form-profile .field + .field { margin-top: .9rem; }
#form-profile .switch { align-items: start; margin-top: 1rem; }
#form-profile .switch input { flex: none; margin-top: .15rem; }
.topics:not(.assess-list) { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.topic { min-height: 90px; border-width: 1px; border-radius: 16px; }
.topic .sym { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.tutor-head { padding: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.tutor-head h1 { min-width: 0; overflow-wrap: anywhere; }
.log { padding: .65rem .25rem .65rem 0; }
.bubble { padding: .9rem 1.05rem; }
.composer { grid-template-columns: minmax(0, 1fr) auto auto; border-top: 1px solid var(--line); padding-top: .75rem; }

@media (max-width: 650px) {
  .setup-intro { grid-template-columns: minmax(0, 1fr); }
  .model-option { min-height: 68px; }
}
@media (max-width: 560px) {
  .top { gap: .5rem; }
  .top-actions { flex-wrap: wrap; }
  .top-actions .btn { padding-inline: .7rem; }
  .composer { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Learner dashboard */
.learning-header {
  padding: clamp(1.2rem, 4vw, 2.1rem);
  margin-bottom: clamp(1.15rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.learning-header h1 { font-size: clamp(1.8rem, 4.5vw, 3.1rem); letter-spacing: -.05em; }
.learning-header .lead { margin-bottom: 0; }
.learning-layout { display: grid; grid-template-columns: minmax(0, 190px) minmax(0, 1fr); gap: clamp(1rem, 3vw, 2rem); align-items: start; }
.learner-nav {
  display: grid;
  gap: .28rem;
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.learner-nav .btn { text-align: left; border-color: transparent; }
.learner-nav .btn:hover { background: var(--surface-2); border-color: var(--line); }
.learner-nav #btn-switch { color: var(--muted); }
.learning-content { min-width: 0; }
.learning-content > h2 { font-size: 1.4rem; letter-spacing: -.025em; }
#topics { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); margin-top: .7rem; }
#topics .topic {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  gap: .65rem;
  padding: .95rem;
}
#topics .topic .sym { width: auto; min-width: 2.6rem; padding-inline: .5rem; }
.topic-body { display: grid; width: 100%; align-self: end; gap: .35rem; }
.topic-progress {
  appearance: none;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  height: .3rem;
  margin-top: .3rem;
  background: var(--surface-2);
}
.topic-progress::-webkit-progress-bar { background: var(--surface-2); }
.topic-progress::-webkit-progress-value { background: var(--accent); }
.topic-progress::-moz-progress-bar { background: var(--accent); }
.learning-content .ask { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .8rem; }
.learning-content .ask p { margin: 0; color: var(--muted); }
@media (max-width: 680px) {
  .learning-layout { grid-template-columns: minmax(0, 1fr); }
  .learner-nav { display: flex; flex-wrap: wrap; }
  .learner-nav .btn { flex: 1 1 auto; text-align: center; }
}
