:root {
  color-scheme: light dark;
  --bg: #fff;
  --fg: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2b6cb0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #e8eaed;
    --muted: #9aa1ac;
    --line: #2a2e35;
    --accent: #7aa7d9;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem clamp(1rem, 5vw, 3rem);
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.5rem;
}

h1 { font-size: 1.15rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.muted { color: var(--muted); }

pre {
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 13px;
}

button {
  font: inherit;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover { opacity: 0.9; }

/* ---- chat layout ---- */
body { padding: 0; height: 100dvh; display: flex; flex-direction: column; }
header { padding: 0.75rem 1rem; margin: 0; }
header .who { display: flex; align-items: center; gap: 0.75rem; font-size: 13px; }
#gate { padding: 2rem 1rem; }
#app { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
#app[hidden] { display: none; }
aside { border-right: 1px solid var(--line); overflow-y: auto; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
aside .tabs { display: flex; gap: 0.25rem; }
aside .tabs button { flex: 1; padding: 0.3rem; font-size: 13px; background: transparent; color: var(--fg); border-color: var(--line); }
aside .tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.conv { text-align: left; background: transparent; color: var(--fg); border: 1px solid transparent; padding: 0.5rem; border-radius: 6px; width: 100%; }
.conv:hover { border-color: var(--line); opacity: 1; }
.conv.on { border-color: var(--accent); }
.conv .t { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .m { display: block; font-size: 12px; color: var(--muted); }
main { display: flex; flex-direction: column; min-height: 0; }
#log { flex: 1; overflow-y: auto; padding: 1rem clamp(1rem, 4vw, 3rem); }
.msg { max-width: 46rem; margin: 0 auto 1.25rem; }
.msg .role { font-size: 12px; color: var(--muted); margin-bottom: 0.25rem; }
.msg.user .body { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 8px; padding: 0.6rem 0.8rem; white-space: pre-wrap; }
.msg.assistant .body p { margin: 0 0 0.7rem; }
.msg.assistant .body code { font-size: 13px; background: color-mix(in srgb, var(--fg) 6%, transparent); padding: 0 0.25rem; border-radius: 4px; }
.msg.assistant .body pre code { background: none; padding: 0; }
.msg.assistant .body table { border-collapse: collapse; margin: 0.5rem 0 0.8rem; font-size: 14px; }
.msg.assistant .body th, .msg.assistant .body td { border: 1px solid var(--line); padding: 0.25rem 0.5rem; text-align: left; }
.msg .err { color: #c53030; font-size: 13px; }
.thinking { color: var(--muted); font-style: italic; }
.intro { max-width: 46rem; margin: 2rem auto; color: var(--muted); }
.intro li { margin: 0.25rem 0; cursor: pointer; color: var(--accent); }
form { display: flex; gap: 0.5rem; padding: 0.75rem clamp(1rem, 4vw, 3rem); border-top: 1px solid var(--line); }
form textarea { flex: 1; font: inherit; resize: none; padding: 0.6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); min-height: 3rem; max-height: 12rem; }
form[hidden] { display: none; }
.readonly { text-align: center; font-size: 13px; color: var(--muted); padding: 0.75rem; border-top: 1px solid var(--line); }
button:disabled { opacity: 0.5; cursor: default; }
#menu { display: none; }
h1 .short { display: none; }
h1 { white-space: nowrap; }
@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  aside { display: none; border-right: 0; border-bottom: 1px solid var(--line); max-height: 45dvh; }
  aside.open { display: flex; }
  #menu { display: inline-block; padding: 0.3rem 0.6rem; }
  h1 .long, #email { display: none; }
  h1 .short { display: inline; }
}
