:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #17191f;
  --muted: #6f7480;
  --line: #dfe2e8;
  --line-strong: #c9cdd6;
  --brand: #df1f32;
  --brand-strong: #bd1425;
  --brand-soft: #fff0f2;
  --success: #16784c;
  --success-soft: #eaf7f0;
  --orange: #9a6513;
  --orange-soft: #fff7df;
  --red: #b81f31;
  --red-soft: #fff0f2;
  --gold: #f0bd3c;
  --tech: #1677a6;
  --tech-soft: #eaf6fb;
  --shadow: 0 12px 34px rgba(24, 29, 39, .07);
  --study-progress: 0%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242b;
  --ink: #f5f6f8;
  --muted: #a4a9b3;
  --line: #30353e;
  --line-strong: #414853;
  --brand: #ff4558;
  --brand-strong: #ef3147;
  --brand-soft: #3a1e25;
  --success: #65d39b;
  --success-soft: #19362a;
  --orange: #f1bd66;
  --orange-soft: #372d1b;
  --red: #ff7180;
  --red-soft: #3b2026;
  --gold: #f3c653;
  --tech: #65c8ef;
  --tech-soft: #17313d;
  --shadow: 0 16px 44px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--bg); letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, label[for] { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
svg, .lucide-icon { width: 18px; height: 18px; }
.lucide-icon { display: inline-block; flex: none; background: currentColor; -webkit-mask: var(--icon-mask) center / contain no-repeat; mask: var(--icon-mask) center / contain no-repeat; }
h1 { margin: 0; font-size: 25px; line-height: 1.18; }
h2 { margin: 0; font-size: 18px; line-height: 1.28; }
h3 { margin: 0; font-size: 15px; line-height: 1.4; }
p { line-height: 1.62; }

.topbar {
  position: sticky; z-index: 30; top: 0; height: calc(62px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 18px 0; display: flex; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, var(--surface) 90%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(18px) saturate(140%);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 36px; height: 36px; border-radius: 8px; box-shadow: 0 6px 18px rgba(223, 31, 50, .18); }
.brand div { display: grid; }
.brand strong { font-size: 17px; }
.brand span { margin-top: 1px; color: var(--muted); font-size: 11px; }
.icon-button { width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: 8px; color: var(--ink); background: transparent; cursor: pointer; }
.icon-button:hover { border-color: var(--line); background: var(--surface-2); }
.icon-button:active { transform: scale(.96); }
.icon-button.danger { color: var(--red); }
.icon-button.small { position: absolute; right: 8px; top: 8px; width: 34px; height: 34px; color: #fff; background: rgba(12, 14, 18, .7); }

main { width: min(980px, 100%); margin: 0 auto; padding: 24px 18px calc(94px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; animation: appear .2s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.status-dot, .count { flex: none; padding: 5px 9px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }
.status-dot.ready { color: var(--success); background: var(--success-soft); border-color: transparent; }

.composer, .settings-form, .inline-form, .doubt-composer { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.composer > label, .settings-form > label:not(.toggle-row) { display: grid; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 750; }
textarea, .settings-form input, .inline-form input, .filters input, .standalone input, select, .study-settings input {
  width: 100%; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; outline: none;
}
textarea { min-height: 240px; padding: 13px; resize: vertical; field-sizing: content; font-size: 16px; line-height: 1.65; }
textarea:focus, input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; }
.image-pickers { display: flex; gap: 8px; }
.primary-button, .secondary-button { min-height: 44px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid transparent; border-radius: 7px; font-weight: 750; cursor: pointer; }
.primary-button { color: #fff; background: var(--brand); box-shadow: 0 7px 18px rgba(223, 31, 50, .18); }
.primary-button:hover { background: var(--brand-strong); }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .5; cursor: wait; }
.secondary-button { color: var(--brand); background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 15%, transparent); }
.secondary-button.danger { color: var(--red); background: var(--red-soft); }
.primary-button.full { width: 100%; }
.file-button { font-size: 13px; }
.file-button svg, .primary-button svg, .secondary-button svg, .file-button .lucide-icon, .primary-button .lucide-icon, .secondary-button .lucide-icon { width: 16px; height: 16px; }

.image-strip { position: relative; margin: 12px 0; padding: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.image-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.image-item { position: relative; margin: 0; aspect-ratio: 1; overflow: hidden; background: var(--line); border-radius: 7px; }
.image-item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.image-item figcaption { position: absolute; left: 5px; top: 5px; padding: 2px 5px; color: #fff; background: rgba(8, 10, 14, .7); border-radius: 4px; font-size: 10px; }
.image-item div { position: absolute; left: 4px; right: 4px; bottom: 4px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.image-item button { height: 28px; padding: 0; color: #fff; background: rgba(8, 10, 14, .72); border: 0; border-radius: 4px; font-size: 20px; }

.notice, .security-note { margin-top: 16px; padding: 14px 15px; background: var(--orange-soft); border-left: 3px solid var(--gold); border-radius: 0 7px 7px 0; }
.notice strong, .security-note strong { font-size: 14px; }
.notice p, .security-note p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.loading { min-height: 190px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.loading span { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.loading p { font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

.study-progress { position: relative; min-height: 136px; margin: -4px 0 16px; padding: 15px 16px 10px; overflow: hidden; color: #fff; background: #20242b; border: 1px solid #303640; border-radius: 8px; box-shadow: var(--shadow); }
.study-progress::after { content: ""; position: absolute; top: 15px; right: 16px; width: 7px; height: 7px; background: var(--gold); border-radius: 2px; transform: rotate(12deg); }
.study-progress-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.study-progress-head > div:first-child { display: grid; gap: 2px; }
.study-progress-head span { font-size: 11px; opacity: .72; }
.study-progress-head strong { font-size: 17px; }
.study-progress-head strong b { font-size: 22px; }
.study-mini { display: flex; gap: 12px; padding: 6px 20px 0 0; }
.study-mini b { color: #ffd568; }
.study-track { position: relative; height: 74px; margin-top: 3px; border-bottom: 4px solid #f3f5f8; }
.study-fill { position: absolute; left: 0; bottom: -4px; width: var(--study-progress); height: 4px; background: var(--brand); transition: width .4s ease; }
.study-mascot { --study-position: 0%; position: absolute; z-index: 2; left: clamp(0px, calc(var(--study-position) - 34px), calc(100% - 70px)); bottom: 0; width: 70px; height: 72px; transition: left .45s ease; }
.study-mascot img { width: 100%; height: 100%; object-fit: contain; }
.study-mascot .person-prop { width: 22px; height: 22px; right: 0; top: 36%; }
.start-flag, .finish-flag { position: absolute; bottom: 8px; color: #dfe3e9; font-size: 10px; opacity: .72; }
.start-flag { left: 0; } .finish-flag { right: 0; }

.result-header { margin-top: 18px; padding: 16px; color: #fff; background: #20242b; border-left: 4px solid var(--brand); border-radius: 8px; box-shadow: var(--shadow); }
.answer-overview { margin-top: 18px; padding: 15px 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: 8px; box-shadow: var(--shadow); }
.answer-overview h2 { margin-bottom: 9px; color: var(--brand); font-size: 13px; }
.answer-overview .answer-row { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); line-height: 1.5; }
.answer-overview small { color: var(--muted); }
.manual-knowledge-button { width: max-content; min-height: 34px; }
.manual-knowledge-picker fieldset, .selection-panel fieldset { display: grid; gap: 8px; margin: 0 0 10px; padding: 10px 0; border: 0; }
.manual-knowledge-picker legend, .selection-panel legend { margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 750; }
.manual-knowledge-picker label, .selection-panel label { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.manual-knowledge-picker input, .selection-panel input { flex: none; margin-top: 3px; }
.selection-panel { margin-top: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.selection-panel label span { flex: none; color: var(--brand); font-weight: 800; }
.result-header.review { border-left-color: var(--gold); }
.result-header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.result-header p { margin: 6px 0 0; color: #c9ced7; font-size: 13px; }
.confidence { flex: none; color: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 20px; font-weight: 800; }
.result-mode-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 2px; padding: 8px 0; color: var(--muted); font-size: 12px; }
.result-section { padding: 19px 2px; border-bottom: 1px solid var(--line); }
details.result-section > summary { list-style: none; cursor: pointer; }
details.result-section > summary::-webkit-details-marker { display: none; }
details.result-section > summary svg, details.result-section > summary .lucide-icon { margin-left: auto; color: var(--muted); transition: transform .18s ease; }
details.result-section[open] > summary svg, details.result-section[open] > summary .lucide-icon { transform: rotate(180deg); }
.sub-question { margin-top: 18px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 26px rgba(26, 31, 41, .05); }
.sub-question > header { display: flex; align-items: baseline; gap: 10px; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.sub-question > header span { flex: none; color: var(--brand); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 800; }
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; overflow: hidden; background: var(--line); border: 1px solid var(--line); border-radius: 7px; }
.quick-grid p { margin: 0; padding: 12px; background: var(--surface); }
.material-brief, .question-focus { display: grid; }
.material-brief p, .question-focus p { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line); line-height: 1.55; }
.material-brief p:last-child, .question-focus p:last-child { border-bottom: 0; }
.material-brief strong, .question-focus strong { color: var(--brand); }
.result-section-title { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.result-section-title span { width: 26px; height: 26px; display: grid; place-items: center; color: var(--brand); background: var(--brand-soft); border-radius: 5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 800; }
.formula { padding: 13px; overflow-x: auto; color: var(--tech); background: var(--tech-soft); border-left: 3px solid var(--tech); border-radius: 0 6px 6px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.55; }
.steps { margin: 0; padding-left: 22px; }
.steps li { padding: 4px 0 9px; line-height: 1.55; }
.tip { margin-top: 9px; padding: 12px 14px; color: var(--orange); background: var(--orange-soft); border-radius: 7px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 5px 9px; color: var(--brand); background: var(--brand-soft); border-radius: 999px; font-size: 12px; }
.source-list, .doubt-list { margin: 0; padding-left: 20px; }
.risk-list { margin: 0; padding: 0; display: grid; gap: 8px; list-style: none; }
.risk-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 10px; padding: 11px 12px; background: var(--brand-soft); border-left: 3px solid var(--brand); border-radius: 6px; }
.risk-list li p { margin: 3px 0 0; font-size: 13px; line-height: 1.45; }
.risk-list details { grid-column: 1 / -1; width: 100%; color: var(--brand); font-size: 12px; }
.risk-list details summary { width: max-content; cursor: pointer; }
.risk-list details p { width: 100%; max-width: none; margin-top: 8px; color: var(--muted); overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 12px; }
.source-list a, .message-sources a { color: var(--tech); word-break: break-all; }
.similar-grid { display: grid; gap: 10px; }
.similar-item, .list-item, .history-item { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.similar-item header, .list-item header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.similar-item p, .list-item p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.similar-item details { margin-top: 10px; }
.similar-item summary { color: var(--brand); font-size: 13px; font-weight: 750; cursor: pointer; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 0 4px; }
.result-actions button { flex: 1; }

.segmented-control { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.segmented-control button { min-height: 34px; padding: 0 12px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.segmented-control button.active { color: var(--ink); background: var(--surface); box-shadow: 0 2px 8px rgba(20, 24, 32, .08); }
.page-segments { margin-bottom: 16px; }
.filters { display: grid; grid-template-columns: minmax(0, 1fr) 128px; gap: 9px; margin-bottom: 14px; }
.search-field { position: relative; }
.search-field > svg, .search-field > .lucide-icon { position: absolute; z-index: 1; left: 11px; top: 12px; width: 16px; height: 16px; color: var(--muted); }
.search-field > span { position: absolute; left: 11px; top: 10px; color: var(--muted); }
.filters input, .standalone input { height: 42px; padding: 0 10px 0 34px; }
select { height: 42px; padding: 0 10px; }
.list { display: grid; gap: 10px; }
.list-empty { padding: 50px 20px; color: var(--muted); text-align: center; }
.list-item .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.list-item .row, .row { display: flex; gap: 8px; margin-top: 12px; }
.list-item .row button { min-height: 38px; }
.mistake-item > details { margin-top: 11px; }
.mistake-item > details > summary { color: var(--brand); font-size: 13px; font-weight: 750; cursor: pointer; }
.mistake-preview p { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; }
.mistake-preview strong { color: var(--brand); }
.mistake-images { display: grid; gap: 8px; margin-top: 10px; }
.mistake-images img { width: 100%; max-height: 420px; object-fit: contain; background: var(--surface-2); border-radius: 6px; }
.knowledge-item > details { margin-top: 11px; }
.knowledge-item > details > summary { color: var(--brand); font-size: 13px; font-weight: 750; cursor: pointer; }
.knowledge-sources { display: grid; gap: 12px; margin-top: 10px; }
.knowledge-sources section { padding-top: 10px; border-top: 1px solid var(--line); }
.knowledge-sources time { color: var(--muted); font-size: 11px; }
.knowledge-sources .source-question { max-height: 150px; overflow: auto; color: var(--ink); white-space: pre-wrap; }
.knowledge-editor form { display: grid; gap: 10px; margin-top: 12px; }
.knowledge-editor label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 750; }
.knowledge-editor input, .knowledge-editor textarea { width: 100%; }
.history-item { display: grid; gap: 10px; }
.history-open { width: 100%; padding: 0; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 12px; color: inherit; background: transparent; border: 0; text-align: left; cursor: pointer; }
.history-thumb { width: 56px; height: 56px; display: grid; place-items: center; overflow: hidden; color: var(--brand); background: var(--brand-soft); border-radius: 7px; }
.history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-copy { min-width: 0; display: grid; gap: 4px; }
.history-copy > span { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.history-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-copy small { flex: none; color: var(--muted); }
.history-copy b { color: var(--brand); font-size: 13px; }
.history-copy em { color: var(--muted); font-size: 11px; font-style: normal; }
.history-actions { align-items: center; margin-top: 0; }
.history-actions .secondary-button { margin-right: auto; min-height: 38px; }
.history-actions .icon-button { width: 36px; height: 36px; }

.module-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 32px 0 14px; padding-top: 24px; border-top: 1px solid var(--line); }
.module-heading.compact { margin: 20px 0 14px; padding-top: 18px; }
.standalone { display: block; margin-bottom: 12px; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.inline-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 750; }
.inline-form label:nth-of-type(3), .inline-form .row { grid-column: 1 / -1; }
.inline-form input { height: 42px; padding: 0 10px; font-weight: 400; }
.inline-form textarea { min-height: 76px; }
.inline-form .row, .resolution-actions { display: flex; gap: 10px; }
.doubt-filters { grid-template-columns: 1fr auto; }
.chat-heading { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.chat-heading p { margin: 3px 0 0; overflow: hidden; color: var(--muted); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.messages { max-height: min(54vh, 560px); padding: 16px 0; display: grid; gap: 12px; overflow-y: auto; }
.message { max-width: 92%; padding: 12px 14px; border-radius: 8px; }
.message > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 750; }
.message p { margin: 0; white-space: pre-wrap; }
.message.user { justify-self: end; color: #fff; background: var(--brand); }
.message.user > span { color: rgba(255, 255, 255, .72); }
.message.assistant { justify-self: start; background: var(--surface); border: 1px solid var(--line); }
.message.assistant h3 { margin-bottom: 8px; line-height: 1.55; }
.message-sources { padding-top: 9px; border-top: 1px solid var(--line); }
.doubt-composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.doubt-composer label { grid-column: 1 / -1; color: var(--muted); font-size: 12px; font-weight: 750; }
.doubt-composer textarea { min-height: 86px; }
.doubt-image-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.doubt-image-tools > span { color: var(--muted); font-size: 11px; }
.resolution-actions { justify-content: flex-end; margin-top: 10px; }

.section-note { margin: -7px 0 16px; color: var(--muted); font-size: 13px; }
.knowledge-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; margin-bottom: 18px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.knowledge-tabs button { height: 38px; color: var(--muted); background: transparent; border: 0; border-radius: 6px; font-weight: 750; }
.knowledge-tabs button.active { color: var(--ink); background: var(--surface); box-shadow: 0 2px 8px rgba(20, 24, 32, .08); }
.single-filter { grid-template-columns: 160px; justify-content: end; }
.syllabus-item { padding: 16px 2px; border-bottom: 1px solid var(--line); }
.syllabus-item header { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.syllabus-item header > div { display: flex; align-items: center; gap: 8px; }
.syllabus-item small { color: var(--muted); }
.frequency { min-height: 24px; padding: 3px 7px; display: inline-flex; align-items: center; color: #73510e; background: #fff0bd; border-radius: 4px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.frequency.hot { color: #fff; background: var(--brand); }
.practice-tools { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto; gap: 8px; margin-bottom: 14px; }
.practice-tools .search-field input { height: 44px; padding: 0 10px 0 34px; }
.practice-tools select { height: 44px; }

.study-settings, .preference-settings { margin-bottom: 16px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.study-settings { border-top: 3px solid var(--brand); }
.settings-stats { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.settings-stats div { display: grid; justify-items: center; gap: 3px; padding: 7px 4px 13px; border-right: 1px solid var(--line); }
.settings-stats div:last-child { border-right: 0; }
.settings-stats b { color: var(--brand); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 22px; }
.settings-stats span { color: var(--muted); font-size: 10px; }
.study-settings > label { display: grid; grid-template-columns: 1fr 90px; align-items: center; gap: 12px; font-size: 13px; font-weight: 800; }
.study-settings input { width: 90px; height: 42px; padding: 0 10px; }
.study-settings p { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.preference-settings { display: grid; gap: 0; }
.person-settings { min-height: 208px; margin-bottom: 16px; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr) 184px; align-items: center; gap: 14px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: 8px; }
.person-settings p:not(.eyebrow) { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
#settings-person { width: 184px; height: 184px; justify-self: end; }

.interactive-person { --person-look-x: 0px; --person-look-y: 0px; position: fixed; z-index: 45; width: clamp(88px, 24vw, 120px); height: 146px; touch-action: none; user-select: none; pointer-events: none; }
.person-stage { --person-tilt: 0deg; position: relative; width: 100%; height: 100%; display: grid; place-items: center; transform: rotate(var(--person-tilt)); transform-origin: 50% 88%; }
.person-stage-interactive { pointer-events: none; }
.person-hit-target { position: absolute; z-index: 6; left: 30%; top: 17%; width: 42%; aspect-ratio: 1; padding: 0; cursor: grab; pointer-events: auto; touch-action: none; background: transparent; border: 0; border-radius: 50%; }
.person-hit-target:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.dragging .person-hit-target { cursor: grabbing; }
.person-character { position: relative; width: 100%; height: 100%; animation: person-breathe 3.2s ease-in-out infinite; }
.person-character img { width: 100%; height: 100%; display: block; object-fit: contain; transform: translate(var(--person-look-x), var(--person-look-y)); filter: drop-shadow(0 8px 12px rgba(20, 24, 32, .18)); transition: transform .2s ease, filter .2s ease; }
.person-character img.person-static-hidden { opacity: 0; }
.person-render-layer { position: absolute; inset: 0; display: block; pointer-events: none; filter: drop-shadow(0 8px 12px rgba(20, 24, 32, .18)); }
.person-pixi-canvas { width: 100%; height: 100%; display: block; }
.person-auto-speak { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
.person-auto-speak span { display: grid; gap: 2px; }
.person-auto-speak small { color: var(--muted); font-size: 10px; font-weight: 400; }
.person-auto-speak input { width: 22px; height: 22px; accent-color: var(--brand); }
.person-prop { --person-prop: none; position: absolute; z-index: 3; right: -2%; top: 42%; width: 30%; aspect-ratio: 1; display: grid; place-items: center; color: #fff; background: var(--brand); border: 2px solid rgba(255, 255, 255, .9); border-radius: 7px; box-shadow: 0 5px 12px rgba(20, 24, 32, .2); transform: rotate(7deg); }
.person-prop::after { content: ""; width: 62%; height: 62%; background: currentColor; -webkit-mask: var(--person-prop) center / contain no-repeat; mask: var(--person-prop) center / contain no-repeat; }
.person-bubble { position: absolute; z-index: 5; right: 2px; bottom: calc(100% - 8px); width: max-content; max-width: min(210px, calc(100vw - 28px)); padding: 9px 11px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px 8px 2px 8px; box-shadow: var(--shadow); font-size: 12px; line-height: 1.45; pointer-events: none; }
.person-left .person-bubble { right: auto; left: 2px; border-radius: 8px 8px 8px 2px; }
body[data-active-view="settings"] .interactive-person { display: none; }
.person-pop .person-character { animation: person-pop .4s ease; }
[data-person-state="upload"] .person-character { animation: person-peek 1.2s ease-in-out infinite alternate; }
[data-person-state="analyzing"] .person-character { animation: person-read 1.4s ease-in-out infinite; }
[data-person-state="walking"] .person-character { animation: person-walk .7s ease-in-out infinite; }
[data-person-state="success"] .person-character { animation: person-success .8s ease-in-out infinite alternate; }
[data-person-state="review"] .person-character { animation: person-review 1.8s ease-in-out infinite; }
[data-person-state="mistake"] .person-character { animation: person-note 1s ease-in-out infinite alternate; }
@keyframes person-breathe { 50% { transform: translateY(-2px) scale(1.01); } }
@keyframes person-pop { 45% { transform: translateY(-10px) scale(1.05); } }
@keyframes person-peek { to { transform: translateX(-3px) rotate(-1deg); } }
@keyframes person-read { 50% { transform: translateY(2px) rotate(.8deg); } }
@keyframes person-walk { 50% { transform: translateY(-5px) rotate(1.5deg); } }
@keyframes person-success { to { transform: translateY(-7px) rotate(2deg); } }
@keyframes person-review { 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
@keyframes person-note { to { transform: translateY(2px) rotate(-1deg); } }
.preference-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.preference-row:first-child { padding-top: 0; }
.preference-row:last-child { padding-bottom: 0; border-bottom: 0; }
.preference-row > div:first-child { display: grid; gap: 3px; }
.preference-row strong { font-size: 13px; }
.preference-row span { color: var(--muted); font-size: 11px; }
.settings-form { display: grid; gap: 16px; }
.settings-form input { height: 46px; padding: 0 12px; font-weight: 400; }
.model-input { display: flex; gap: 8px; }
.model-input input { min-width: 0; flex: 1; }
.model-input button { flex: none; min-height: 46px; padding: 0 11px; font-size: 12px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.toggle-row span { display: grid; gap: 3px; }
.toggle-row small { color: var(--muted); font-weight: 400; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--brand); }
.security-note { margin: 0; }

.bottom-nav { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; height: calc(68px + env(safe-area-inset-bottom)); padding: 5px max(10px, env(safe-area-inset-left)) env(safe-area-inset-bottom) max(10px, env(safe-area-inset-right)); display: grid; grid-template-columns: repeat(5, 1fr); background: color-mix(in srgb, var(--surface) 92%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(20px) saturate(150%); }
.bottom-nav button { position: relative; padding: 4px 0 2px; display: grid; place-items: center; align-content: center; gap: 3px; color: var(--muted); background: transparent; border: 0; font-size: 10px; cursor: pointer; }
.bottom-nav button svg, .bottom-nav button .lucide-icon { width: 21px; height: 21px; }
.bottom-nav button span { height: auto; font-size: 10px; }
.bottom-nav button::before { content: ""; position: absolute; top: 0; width: 18px; height: 2px; background: transparent; border-radius: 2px; }
.bottom-nav button.active { color: var(--brand); font-weight: 800; }
.bottom-nav button.active::before { background: var(--brand); }
.bottom-nav button.active svg, .bottom-nav button.active .lucide-icon { transform: translateY(-1px); }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 36px); padding: 11px 14px; color: #fff; background: #22262d; border-radius: 7px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: .2s; font-size: 13px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .topbar { padding-left: max(24px, calc((100% - 900px) / 2)); padding-right: max(24px, calc((100% - 900px) / 2)); }
  main { padding-top: 34px; }
  .bottom-nav { left: 50%; right: auto; width: 470px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; }
  .similar-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .quick-grid, .inline-form { grid-template-columns: 1fr; }
  .material-brief p, .question-focus p { grid-template-columns: 1fr; gap: 3px; }
  .inline-form label, .inline-form label:nth-of-type(3), .inline-form .row { grid-column: 1; }
  .sub-question { padding: 14px; }
  .composer-actions { align-items: flex-end; }
  .file-button { padding: 0 11px; }
  .preference-row { align-items: stretch; flex-direction: column; gap: 9px; }
  .preference-row .segmented-control { width: 100%; }
  .result-mode-switch { align-items: stretch; flex-direction: column; gap: 6px; }
  .result-mode-switch .segmented-control { width: 100%; }
  .person-settings { grid-template-columns: minmax(0, 1fr) 138px; min-height: 170px; }
  #settings-person { width: 138px; height: 156px; }
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #0f1115; --surface: #181b21; --surface-2: #20242b; --ink: #f5f6f8; --muted: #a4a9b3;
    --line: #30353e; --line-strong: #414853; --brand: #ff4558; --brand-strong: #ef3147; --brand-soft: #3a1e25;
    --success: #65d39b; --success-soft: #19362a; --orange: #f1bd66; --orange-soft: #372d1b; --red: #ff7180;
    --red-soft: #3b2026; --gold: #f3c653; --tech: #65c8ef; --tech-soft: #17313d; --shadow: 0 16px 44px rgba(0, 0, 0, .24);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .person-stage, .person-character, .person-character img { transform: none !important; }
  .person-render-layer { display: none; }
}
