:root { --accent: #3b5bdb; --col: 760px; --bubble: #f0f0f3; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --accent: #7b93ff; --bubble: #232326; } }

html, body { height: 100%; }
body.chat-page { margin: 0; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; color: inherit; }
svg { display: block; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 56px; padding: 0 max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; flex: none; }
.mark svg { width: 20px; height: 20px; }
.mark path { stroke: #fff; stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand-text span { font-size: 12px; color: var(--ink-2); }
.top-actions { display: flex; align-items: center; gap: 4px; }
.ghost { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 980px; border: 0; background: transparent;
  color: var(--ink); font-size: 14px; cursor: pointer; text-decoration: none; }
.ghost:hover { background: var(--bg-alt); text-decoration: none; }
.ghost svg { width: 16px; height: 16px; }
.ghost path { stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; }
.ghost path.fill { fill: currentColor; stroke: none; }
.ghost.icon-only { width: 34px; padding: 0; justify-content: center; }

/* layout */
main { flex: 1; width: 100%; max-width: calc(var(--col) + 32px); margin: 0 auto; padding: 8px 16px 24px; box-sizing: border-box; }
.welcome { display: none; text-align: center; padding: 0 8px; }
.welcome h1 { font-size: clamp(30px, 5vw, 44px); font-weight: 600; letter-spacing: -0.035em; line-height: 1.08; margin: 0 0 12px; }
.welcome .lede { color: var(--ink-2); font-size: 17px; line-height: 1.45; max-width: 520px; margin: 0 auto; }

body.empty { justify-content: flex-start; }
body.empty main { flex: 0 0 auto; padding-top: max(10vh, 40px); }
body.empty .welcome { display: block; }
body.empty .dock { position: static; padding-top: 28px; }
body:not(.empty) .starters { display: none; }
body.empty .fine { margin-top: 28px; }

/* thread */
.thread { display: flex; flex-direction: column; gap: 28px; }
.msg { display: flex; gap: 14px; animation: rise 0.28s ease-out both; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--bubble); border-radius: 22px; padding: 10px 16px; max-width: 78%; font-size: 16px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot .avatar { flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; margin-top: 2px; }
.msg.bot .avatar svg { width: 18px; height: 18px; }
.msg.bot .avatar path { stroke: #fff; stroke-width: 3.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.msg.bot .body { flex: 1; min-width: 0; font-size: 16px; line-height: 1.6; }
.body > * { animation: rise 0.32s ease-out both; }
.body > *:nth-child(2) { animation-delay: 0.04s; } .body > *:nth-child(3) { animation-delay: 0.08s; } .body > *:nth-child(n+4) { animation-delay: 0.12s; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .msg, .body > * { animation: none; } }
.body p { margin: 0 0 12px; }
.body p:last-child { margin-bottom: 0; }
.body i { color: var(--ink-2); }
.muted { color: var(--ink-2); font-size: 14px; }
.body h4.sub { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 18px 0 8px; letter-spacing: 0.02em; text-transform: uppercase; }
.bullets { margin: 0 0 12px; padding-left: 20px; }
.bullets li { margin: 4px 0; }

/* thinking dots */
.dots { display: inline-flex; gap: 5px; padding: 10px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; } .dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); } 40% { opacity: 1; transform: none; } }

/* inline course link */
.lc { display: inline; border: 0; background: color-mix(in srgb, var(--accent) 11%, transparent); color: var(--accent); font: 600 0.88em var(--mono);
  letter-spacing: 0; padding: 1px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.lc:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* rows */
.rows { list-style: none; margin: 4px 0 12px; padding: 0; border-top: 1px solid var(--hair-soft); }
.rows li { border-bottom: 1px solid var(--hair-soft); }
.row-btn { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: baseline; padding: 10px 4px; border: 0; background: none;
  text-align: left; cursor: pointer; font-size: 15px; border-radius: 8px; }
.row-btn:hover { background: var(--bg-alt); }
.row-btn .code { font: 600 13px var(--mono); color: var(--accent); letter-spacing: 0; min-width: 84px; }
.row-btn .title { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.row-btn .cr { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }

/* course card */
.card { border: 1px solid var(--hair-soft); border-radius: var(--radius); padding: 18px 20px; margin: 0 0 12px; }
.card header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.code.big { font: 600 14px var(--mono); color: var(--accent); letter-spacing: 0; }
.pill { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--bg-alt); padding: 3px 10px; border-radius: 980px; white-space: nowrap; }
.card h3 { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; margin: 6px 0 10px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { font-size: 12px; color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); padding: 2px 9px; border-radius: 980px; }
.card .desc { color: var(--ink-2); font-size: 15px; line-height: 1.55; }
.card .desc:empty { display: none; }
.card dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 14px; margin: 12px 0; font-size: 14px; }
.card dt { color: var(--ink-3); }
.card dd { margin: 0; }
.ext { font-size: 14px; }
.ext::after { content: " ↗"; }

/* plan */
.plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 14px 0; }
.sem { background: var(--bg-alt); border-radius: var(--radius); padding: 14px 14px 8px; min-width: 0; }
.sem h4 { display: flex; justify-content: space-between; margin: 0 4px 8px; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.sem h4 span { color: var(--ink-3); font-weight: 500; font-size: 13px; }
.sem ul { list-style: none; margin: 0; padding: 0; }
.sem li { border-top: 1px solid var(--hair-soft); }
.sem .row-btn { grid-template-columns: 76px 1fr auto; gap: 10px; padding: 8px 4px; font-size: 14px; }
.sem .row-btn .code { min-width: 0; font-size: 12px; }
.sem .row-btn .title { white-space: normal; line-height: 1.35; }
.sem li.ph { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 8px 4px; font-size: 14px; color: var(--ink-2); font-style: italic; }
.sem li.ph .cr { color: var(--ink-3); font-style: normal; font-size: 13px; }

.referee { border-radius: 14px; padding: 12px 16px; margin: 0 0 14px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.referee b { font-weight: 600; }
.referee span { color: var(--ink-2); }
.referee.ok { background: color-mix(in srgb, var(--good) 10%, transparent); }
.referee.ok b { color: var(--good); }
.referee.bad { background: color-mix(in srgb, var(--bad) 9%, transparent); }
.referee.bad b { color: var(--bad); }
.referee ul { flex-basis: 100%; margin: 6px 0 0; padding-left: 18px; font: 12.5px/1.6 var(--mono); letter-spacing: 0; }

.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 12px; }
.chain .arrow { color: var(--ink-3); }
.chips { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li.choice { flex-basis: 100%; }
.chips .or { color: var(--ink-3); font-size: 13px; margin: 0 2px; }

blockquote { margin: 0 0 6px; padding: 2px 0 2px 16px; border-left: 3px solid var(--accent); color: var(--ink); }
.source { font-size: 13px; color: var(--ink-3); }
details { margin: 0 0 10px; border-top: 1px solid var(--hair-soft); padding-top: 8px; }
details summary { cursor: pointer; font-size: 14px; color: var(--ink-2); list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "›"; display: inline-block; width: 14px; transition: transform 0.15s; }
details[open] summary::before { transform: rotate(90deg); }
details p { font-size: 14px; color: var(--ink-2); margin: 8px 0 4px; }

/* follow-up chips */
.follow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.follow button { border: 1px solid var(--hair); background: var(--bg); border-radius: 980px; padding: 7px 14px; font-size: 14px; cursor: pointer; text-align: left;
  line-height: 1.3; }
.follow button:hover { border-color: var(--ink-3); background: var(--bg-alt); }

/* dock + composer */
.dock { position: sticky; bottom: 0; z-index: 4; width: 100%; max-width: calc(var(--col) + 32px); margin: 0 auto; box-sizing: border-box;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--hair); border-radius: 26px; padding: 8px 8px 8px 18px; background: var(--bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(0, 0, 0, 0.06); transition: border-color 0.15s; }
.composer:focus-within { border-color: var(--ink-3); }
#input { flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--ink); font: 16px/1.5 var(--font); padding: 7px 0; max-height: 200px; }
#input::placeholder { color: var(--ink-3); }
.send { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--ink); cursor: pointer; display: grid; place-items: center; transition: opacity 0.15s; }
.send svg { width: 18px; height: 18px; }
.send path { stroke: var(--bg); stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.send:disabled { opacity: 0.25; cursor: default; }
.fine { text-align: center; font-size: 12px; color: var(--ink-3); margin: 10px 0 0; line-height: 1.4; }

.context { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 4px 8px; }
.context b { color: var(--ink); font-weight: 600; }
.context button { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }

.starters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.starters button { text-align: left; border: 1px solid var(--hair-soft); background: var(--bg); border-radius: 16px; padding: 14px 16px; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.starters button:hover { background: var(--bg-alt); border-color: var(--hair); }
.starters b { display: block; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 3px; }
.starters span { display: block; font-size: 14px; color: var(--ink-2); line-height: 1.4; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .composer { box-shadow: none; background: var(--bg-alt); border-color: var(--hair); }
  :root:not([data-theme="light"]) .follow button, :root:not([data-theme="light"]) .starters button { background: transparent; }
}

@media (max-width: 640px) {
  .brand-text span { display: none; }
  .ghost span { display: none; }
  #new-chat { width: 34px; padding: 0; justify-content: center; }
  .starters { grid-template-columns: 1fr; }
  .starters button:nth-child(n+4) { display: none; }
  body.empty main { padding-top: 5vh; }
  .msg { gap: 10px; }
  .msg.bot .avatar { display: none; }
  .msg.user .bubble { max-width: 88%; }
  .card dl { grid-template-columns: 1fr; gap: 2px; }
  .card dd { margin-bottom: 8px; }
  .row-btn { grid-template-columns: 76px 1fr auto; gap: 10px; }
  .row-btn .code { min-width: 0; }
  .sem .row-btn .title { white-space: normal; }
}
