:root {
  color-scheme: dark;
  --bg: #10141b;
  --rail: #0c1016;
  --surface: #171d27;
  --input: #111720;
  --line: #2a3443;
  --text: #edf2f8;
  --muted: #a2aec0;
  --blue: #8ab8ff;
  --action: #3477e6;
  font: 15px/1.55 "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--blue); text-underline-offset: 4px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.85rem, 4.5vw, 2.6rem); letter-spacing: -.05em; line-height: 1.15; font-weight: 750; }
h2 { font-size: 1rem; font-weight: 700; }
small { color: var(--muted); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.skip { position: fixed; top: 10px; left: 10px; transform: translateY(-150%); z-index: 5; background: var(--surface); padding: 8px 12px; }
.skip:focus { transform: none; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 225px; display: flex; flex-direction: column; background: var(--rail); border-right: 1px solid var(--line); padding: 23px 14px 17px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; color: var(--text); text-decoration: none; font-size: 1.3rem; line-height: 1.1; font-weight: 750; letter-spacing: -.04em; }
.brand small { display: block; font-size: .73rem; font-weight: 500; letter-spacing: .03em; margin-top: 5px; }
.mark { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #477dd0; border-radius: 9px; background: #1d4a8e; color: #fff; font-size: 1.12rem; }
.nav { display: grid; gap: 5px; margin-top: 41px; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 41px; padding: 7px 10px; border: 1px solid transparent; border-radius: 7px; text-decoration: none; white-space: nowrap; color: var(--muted); font-size: .91rem; font-weight: 600; }
.nav a:hover { background: #171e29; color: var(--text); }
.nav a[aria-current] { background: #17253a; border-color: #293e5e; color: #b9d5ff; }
.nav-icon { width: 17px; text-align: center; font: 18px/1 "Segoe UI Symbol", sans-serif; }
.sidebar footer { margin-top: auto; padding: 15px 8px 0; border-top: 1px solid var(--line); font-size: .74rem; }
.sidebar footer a { color: var(--muted); text-decoration: none; }
.sidebar footer a:hover { color: var(--blue); text-decoration: underline; }
.shell { margin-left: 225px; }
.top { min-height: 65px; display: flex; align-items: center; justify-content: flex-end; gap: 17px; padding: 9px clamp(17px, 4vw, 52px); border-bottom: 1px solid var(--line); }
.account-state { color: var(--muted); font-size: .84rem; }
main { width: min(1240px, 100%); margin: auto; padding: 0 clamp(17px, 4vw, 52px) 42px; }
.intro { padding: 39px 0 24px; }
.intro p { margin-top: 8px; color: var(--muted); }
.workspace { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: stretch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; min-width: 0; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 55px; padding: 9px 17px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 15px 17px 17px; }
.panel-actions { display: flex; justify-content: flex-end; padding: 13px 17px; border-top: 1px solid var(--line); }
.solver { display: flex; flex-direction: column; }
.solver .panel-body { flex: 1; }
label { display: block; font-size: .85rem; font-weight: 650; margin: 0 0 6px; }
label:not(:first-child) { margin-top: 15px; }
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=file]), select, textarea { width: 100%; display: block; border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; background: var(--input); }
textarea { resize: vertical; min-height: 92px; }
textarea::placeholder { color: #8f9db1; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 35px; padding: 6px 12px; border: 1px solid #39475a; border-radius: 7px; background: #202a38; color: var(--text); cursor: pointer; font-size: .86rem; font-weight: 650; text-decoration: none; }
button:hover, .button:hover { background: #2b384b; }
button:disabled { opacity: .58; cursor: default; }
.primary { background: var(--action); border-color: #5289e5; color: #fff; min-height: 39px; }
.primary:hover { background: #3e7dec; }
.upload { position: relative; display: flex; align-items: center; gap: 11px; margin: 14px 0 0; padding: 9px 10px; border: 1px dashed #40516a; border-radius: 7px; cursor: pointer; }
.upload:focus-within { outline: 2px solid var(--blue); outline-offset: 3px; }
.upload:hover, .upload.drag { border-color: var(--blue); background: #1b293d; }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon { display: grid; flex: none; place-items: center; width: 31px; height: 31px; border-radius: 6px; background: #23334a; color: var(--blue); font-size: 1.2rem; }
.upload small { display: block; font-size: .76rem; font-weight: 400; }
.attachments { list-style: none; padding: 0; display: grid; gap: 7px; margin: 10px 0 0; }
.attachment { display: flex; min-width: 0; align-items: center; gap: 8px; padding: 6px 8px; background: var(--input); border-radius: 6px; }
.attachment img { width: 40px; height: 34px; object-fit: cover; border-radius: 4px; }
.attachment span { min-width: 0; overflow-wrap: anywhere; flex: 1; font-size: .8rem; }
.attachment button { min-height: 28px; font-size: .74rem; padding: 3px 7px; }
.result { display: flex; flex-direction: column; }
.paper { display: grid; flex: 1; min-height: 300px; }
.empty { place-self: center; padding: 22px; text-align: center; color: var(--text); }
.empty small { display: block; margin-top: 4px; }
.sheet { margin: 0 auto 12px; width: 37px; height: 44px; border: 1px solid #4a6280; border-radius: 6px; display: grid; align-content: center; gap: 5px; padding: 8px; background: #1c2839; }
.sheet i { display: block; height: 1px; background: #8ab8ff; }
.sheet i:last-child { width: 65%; }
#answer { padding: 18px; white-space: pre-wrap; overflow-wrap: anywhere; font: .94rem/1.75 Consolas, "Courier New", monospace; }
.answer-final { color: #a9ccff; font-weight: 700; }
.status, .error, .notice { font-size: .84rem; overflow-wrap: anywhere; }
.status { color: var(--muted); padding: 10px 17px; border-top: 1px solid var(--line); }
.error { color: #ffb7b7; margin-top: 9px; }
.notice { color: #c4dcff; background: #18283e; border: 1px solid #2c4363; border-radius: 7px; padding: 9px 12px; margin-top: 18px; }
.plan-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 15px; }
.plan { display: flex; flex-direction: column; padding: 20px; }
.plan.featured { border-color: #4b7bc4; }
.price { margin-top: 8px; font-size: clamp(1.55rem, 3vw, 2.25rem); font-weight: 750; letter-spacing: -.04em; }
.price small { font-size: .82rem; font-weight: 500; letter-spacing: 0; }
.plan ul { list-style: none; margin: 12px 0 20px; padding: 12px 0 0; border-top: 1px solid var(--line); flex: 1; color: var(--muted); }
.plan li + li { margin-top: 7px; }
.plan li::before { content: '✓'; margin-right: 8px; color: var(--blue); }
#portal { margin-top: 16px; }
.locked { max-width: 530px; padding: 20px; }
.locked p { color: var(--muted); margin: 5px 0 14px; }
.chat { max-width: 830px; }
#chat-log { min-height: 180px; max-height: 52vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 17px; }
.bubble { max-width: min(92%,650px); padding: 11px 13px; border: 1px solid var(--line); background: var(--input); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble strong { display: block; font-size: .79rem; color: var(--blue); margin-bottom: 4px; }
.bubble.user { align-self: flex-end; background: #1c2d47; }
#chat-form { padding: 14px 17px; border-top: 1px solid var(--line); }
.chat-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 9px; }
.chat-actions p { margin: 0 auto 0 0; }
dialog { width: min(440px, calc(100% - 28px)); max-height: 90dvh; padding: 22px; border: 1px solid #42526a; border-radius: 13px; color: var(--text); background: var(--surface); }
dialog::backdrop { background: #060910bd; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 15px; }
.dialog-heading h2 { font-size: 1.26rem; }
#auth-close { min-width: 33px; font-size: 1.2rem; padding: 3px; }
.social { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.social a { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 6px; border: 1px solid #39475a; border-radius: 6px; text-decoration: none; color: var(--text); font-size: .8rem; font-weight: 650; }
.provider-icon { flex: none; width: 17px; height: 17px; }
.social a:hover { background: #212d3e; }
.social a[aria-disabled=true] { color: var(--muted); }
.divider { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .77rem; margin: 15px 0; }
.divider::before, .divider::after { content: ''; height: 1px; background: var(--line); flex: 1; }
#auth-form > div + div, #auth-form > input + div, #profile-fields + label { margin-top: 12px; }
#auth-form .primary { width: 100%; margin-top: 15px; }
#auth-switch, #logout { margin-top: 10px; }
@media (max-width: 870px) {
  .sidebar { width: 178px; }
  .shell { margin-left: 178px; }
  .workspace { grid-template-columns: 1fr; }
  .paper { min-height: 210px; }
  .plan-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  body { display: flex; flex-direction: column; min-height: 100dvh; }
  .sidebar { position: static; display: contents; }
  .brand { order: 0; padding: 13px 16px 8px; width: fit-content; }
  .nav { order: 1; display: flex; flex-wrap: wrap; margin: 0; padding: 5px 12px 9px; border-bottom: 1px solid var(--line); }
  .nav a { min-height: 35px; padding: 5px 8px; gap: 6px; }
  .sidebar footer { order: 3; padding: 13px 16px; }
  .shell { order: 2; margin-left: 0; flex: 1; }
  .top { min-height: 50px; justify-content: space-between; gap: 8px; }
  .top button { margin-left: auto; }
  .intro { padding-top: 24px; }
}
@media (max-width: 380px) {
  .social { grid-template-columns: 1fr; }
  .nav-icon { display: none; }
}


#notebook-settings { min-width: 0; margin: 14px 0 0; padding: 11px; border: 1px solid var(--line); border-radius: 7px; }
#notebook-settings legend { padding-inline: 5px; font-size: .85rem; font-weight: 650; color: var(--blue); }
.notebook-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.notebook-options label { min-width: 0; display: grid; gap: 5px; margin: 0; }
.notebook-options select { min-width: 0; }
#notebook-cost { display: block; margin-top: 10px; }
#notebook-preview { min-width: 0; padding: 14px; }
.notebook-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 13px; }
#notebook-summary { color: var(--muted); font-size: .84rem; }
#notebook-pages { display: grid; gap: 16px; }
#notebook-pages figure { margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--input); }
#notebook-pages img { display: block; width: 100%; aspect-ratio: 2/3; object-fit: contain; background: #edece7; }
#notebook-pages figcaption { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; font-size: .84rem; }
@media (max-width: 460px) { .notebook-options { grid-template-columns: 1fr; } }
