:root {
  --bg: #1c1a27;
  --surface: #282538;
  --surface-2: #332f47;
  --line: #3d3854;
  --ink: #f3f1f8;
  --muted: #a9a4bf;
  --accent: #ea4b71;
  --accent-ink: #ff7a98;
  --user: #c7335a;
  --high: #6fdc9f;
  --med: #f2c46d;
  --low: #ff7a98;
  --radius: 14px;
  --font-display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent-ink); text-underline-offset: 3px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -48px; background: var(--accent); color: #1c1a27; padding: 8px 12px; border-radius: 8px; z-index: 10; font-weight: 600; }
.skip:focus { top: 12px; }

/* ------------------------------------------------------------------ header */
.site-head {
  max-width: 1280px; margin: 0 auto; padding: 20px 24px 12px;
  display: flex; gap: 20px 32px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); display: grid; place-items: center; border: 1px solid var(--line); flex: none; }
.brand h1 { font: 700 22px/1.1 var(--font-display); margin: 0; letter-spacing: -0.01em; }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.honesty {
  margin: 0; max-width: 620px; display: flex; gap: 10px; align-items: flex-start;
  font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  padding: 10px 14px; border-radius: 12px;
}
.honesty a { white-space: nowrap; font-weight: 500; }
.honesty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--high); margin-top: 6px; flex: none; box-shadow: 0 0 0 3px rgba(111, 220, 159, .18); }

/* ------------------------------------------------------------------ layout */
.layout {
  max-width: 1280px; margin: 0 auto; padding: 8px 24px 28px;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start;
}

/* -------------------------------------------------------------------- chat */
.chat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden;
  height: calc(100vh - 128px); height: calc(100dvh - 128px); min-height: 560px;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #2d2a40, var(--surface));
}
.chat-head h2 { font: 600 16px/1.2 var(--font-display); margin: 0; }
.chat-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.chat-tools { display: flex; gap: 12px; align-items: center; }
.memory { display: inline-flex; align-items: center; gap: 8px; font: 500 12px/1 var(--font-mono); color: var(--muted); }
.memory-bar { width: 64px; height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.memory-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.ghost-btn {
  font: 500 13px/1 var(--font-body); color: var(--ink); background: transparent; border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 999px; cursor: pointer; min-height: 36px;
}
.ghost-btn:hover { border-color: var(--accent-ink); }

.log { flex: 1; overflow-y: auto; padding: 20px 18px 8px; display: flex; flex-direction: column; gap: 14px; scroll-padding-top: 12px; }
.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.bubble { border-radius: var(--radius); padding: 11px 14px; max-width: min(640px, 88%); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.bot.card .bubble { max-width: min(760px, 100%); width: 100%; padding: 16px 18px; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 8px; padding-left: 20px; }
.bubble li { margin: 4px 0; }
.bubble li::marker { color: var(--accent-ink); }
.who { font: 500 11.5px/1 var(--font-mono); color: var(--muted); margin: 0 4px 6px; letter-spacing: .02em; }
.assume { color: var(--muted); font-size: 13.5px; }

/* typing */
.typing .bubble { display: inline-flex; gap: 5px; padding: 14px 16px; width: auto; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* analysis card */
.meta { font: 12px/1.5 var(--font-mono); color: var(--muted); margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.meta b { color: var(--ink); font-weight: 500; }
.note { font-size: 13.5px; color: var(--muted); margin: 0 0 10px; }
.callout { border: 1px solid var(--line); border-left: 3px solid var(--accent); background: rgba(234, 75, 113, .07); border-radius: 10px; padding: 12px 14px; margin: 0 0 14px; }
.callout h3 { margin: 0 0 6px; font: 600 14px/1.3 var(--font-display); color: var(--accent-ink); text-transform: none; }
.callout .moves { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.move { font: 12px/1 var(--font-mono); background: var(--bg); border-radius: 999px; padding: 6px 9px; color: var(--ink); }
.move .up { color: var(--high); } .move .down { color: var(--low); }
.sec { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.sec:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.sec h3 { font: 600 15px/1.3 var(--font-display); margin: 0 0 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sec h3 .n { font: 500 11px/1 var(--font-mono); color: var(--accent-ink); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.sec.focus { background: rgba(234, 75, 113, .06); border-radius: 10px; padding: 12px; }

.verdict { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pill { font: 700 14px/1 var(--font-display); letter-spacing: .02em; padding: 8px 14px; border-radius: 999px; border: 1.5px solid currentColor; }
.pill.High { color: var(--high); background: rgba(111, 220, 159, .1); }
.pill.Medium { color: var(--med); background: rgba(242, 196, 109, .1); }
.pill.Low { color: var(--low); background: rgba(255, 122, 152, .1); }
.composite { font: 500 13px/1 var(--font-mono); color: var(--muted); }
.cap { font-size: 13px; color: var(--muted); margin: -2px 0 10px; }

.dims { display: grid; gap: 6px; }
.dim { background: var(--bg); border-radius: 10px; }
.dim summary {
  list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto auto 16px; gap: 10px; align-items: center;
  padding: 9px 12px; border-radius: 10px; font-size: 13.5px; min-height: 40px;
}
.dim summary::-webkit-details-marker { display: none; }
.dim summary:hover { background: #221f30; }
.dim .lbl { overflow: hidden; text-overflow: ellipsis; }
.bar { display: flex; gap: 3px; }
.bar span { width: 14px; height: 8px; border-radius: 2px; background: var(--surface-2); position: relative; overflow: hidden; }
.bar span.full { background: var(--accent); }
.bar span.half { background: linear-gradient(90deg, var(--accent) 50%, var(--surface-2) 50%); }
.score { font: 500 12.5px/1 var(--font-mono); min-width: 32px; text-align: right; }
.chev { width: 16px; height: 16px; color: var(--muted); transition: transform .2s ease; }
.dim[open] .chev { transform: rotate(90deg); }
.why { padding: 2px 12px 10px 12px; font-size: 13px; color: var(--muted); }
.why-h { font: 500 11px/1 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0 6px; }
.why ul { list-style: none; padding: 0; margin: 0; }
.why li { display: grid; grid-template-columns: 44px 1fr; gap: 6px; margin: 4px 0; }
.why .d { font: 500 12px/1.55 var(--font-mono); color: var(--muted); }
.why .d.pos { color: var(--high); } .why .d.neg { color: var(--low); }

details.rest { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details.rest > summary { cursor: pointer; font: 500 13px/1.4 var(--font-body); color: var(--accent-ink); padding: 6px 0; min-height: 32px; }
details.rest[open] > summary { margin-bottom: 8px; }

.closing { margin-top: 12px; color: var(--muted); font-size: 13.5px; }

/* ---------------------------------------------------------------- composer */
.composer { border-top: 1px solid var(--line); padding: 10px 14px 12px; background: var(--surface); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: thin; }
.chips:empty { display: none; }
.chip {
  flex: none; max-width: 340px; text-align: left; font: 500 13px/1.35 var(--font-body); color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; cursor: pointer; min-height: 40px;
}
.chip:hover { border-color: var(--accent-ink); }
.chip.idea { white-space: normal; width: 260px; }
.chip.idea b { display: block; font: 600 11px/1 var(--font-mono); color: var(--accent-ink); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 5px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
textarea {
  flex: 1; height: 46px; min-width: 0; resize: none; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font: 15px/1.45 var(--font-body); max-height: 160px; min-height: 46px;
}
textarea::placeholder { color: var(--muted); opacity: 1; }
textarea:focus { outline: none; border-color: var(--accent-ink); box-shadow: 0 0 0 3px rgba(234, 75, 113, .25); }
.send { flex: none; width: 46px; height: 46px; border-radius: 12px; border: 0; background: var(--accent); color: #1c1a27; display: grid; place-items: center; cursor: pointer; }
.send:hover { background: var(--accent-ink); }
.send:disabled { opacity: .5; cursor: not-allowed; }
.hint { margin: 6px 2px 0; font: 11.5px/1.3 var(--font-mono); color: var(--muted); }

/* ------------------------------------------------------------------ aside */
.about { display: grid; gap: 14px; }
.orig { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.orig img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
.orig figcaption { font: 12px/1.3 var(--font-mono); color: var(--muted); padding: 10px 12px; }
.about-title { font: 600 15px/1.2 var(--font-display); margin: 4px 0 0; }
.map { margin: 0; display: grid; gap: 8px; }
.map div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.map dt { font: 500 12px/1.3 var(--font-mono); color: var(--accent-ink); }
.map dd { margin: 4px 0 0; font-size: 13.5px; color: var(--ink); }
.how { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; font-size: 13.5px; }
.how summary { cursor: pointer; padding: 8px 0; font-weight: 500; }
.how p { color: var(--muted); margin: 0 0 10px; }

/* -------------------------------------------------------------- responsive */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .about { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
  .about-title { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .site-head { padding: 14px 16px 10px; gap: 12px; }
  .brand h1 { font-size: 20px; }
  .honesty { font-size: 12.5px; padding: 9px 12px; }
  .honesty a { white-space: normal; }
  .layout { padding: 4px 16px 24px; gap: 18px; }
  .chat { height: calc(100vh - 196px); height: calc(100dvh - 196px); min-height: 500px; border-radius: 16px; }
  .chat-head { padding: 12px 14px; }
  .chat-sub { display: none; }
  .memory-bar { width: 40px; }
  .log { padding: 16px 12px 8px; }
  .bubble { max-width: 92%; }
  .msg.bot.card .bubble { padding: 14px 13px; }
  .dim summary { grid-template-columns: minmax(0, 1fr) auto 16px; gap: 8px; padding: 9px 10px; }
  .dim summary .bar { display: none; }
  .composer { padding: 8px 10px 10px; }
  .chip.idea { width: 230px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; transition: none !important; scroll-behavior: auto !important; }
  .typing i { opacity: .7; }
}
