/* 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: "…"; }
}
