:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #eef1f7;
  --ink: #131722;
  --ink-soft: #5b6478;
  --line: #e2e6ef;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --bubble-user: #1d4ed8;
  --bubble-user-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #131b2c;
    --panel-2: #1b2540;
    --ink: #e8ecf6;
    --ink-soft: #94a1bd;
    --line: #24304b;
    --accent: #5b8cff;
    --accent-ink: #08101f;
    --bubble-user: #2a56d6;
    --bubble-user-ink: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- gate --- */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, var(--panel-2), var(--bg));
}
.gate-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
}
.gate-emoji { font-size: 40px; }
.gate-card h1 { margin: 10px 0 6px; font-size: 22px; }
.gate-card p { margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; }
.gate-card input {
  width: 100%; padding: 14px 16px; font-size: 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); outline: none;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-card button {
  width: 100%; margin-top: 12px; padding: 14px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.gate-err { margin-top: 12px; color: #e5484d; font-size: 14px; }

/* ----------------------------------------------------------------- app --- */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh; max-width: 820px; margin: 0 auto;
}
.top {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.brand p {
  margin: 0; font-size: 12px; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent);
}
.ghost {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 11px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.ghost:active { transform: scale(.94); }

/* -------------------------------------------------------------- thread --- */
.thread {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 14px;
}
.welcome { text-align: center; padding: 28px 6px 6px; }
.welcome-emoji { font-size: 44px; }
.welcome h2 { margin: 10px 0 6px; font-size: 20px; }
.welcome p { margin: 0 auto 18px; color: var(--ink-soft); font-size: 14px; max-width: 44ch; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 9px 13px; border-radius: 999px; font-size: 13.5px; line-height: 1.2;
}
.chip:active { background: var(--panel-2); }

.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.bubble {
  padding: 11px 14px; border-radius: var(--radius); max-width: 88%;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--bubble-user); color: var(--bubble-user-ink);
  border-bottom-right-radius: 6px;
}
.msg.ai .bubble {
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-bottom-left-radius: 6px; max-width: 100%; width: 100%;
}
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: .5em 0; }
.bubble ul, .bubble ol { margin: .5em 0; padding-left: 1.25em; }
.bubble li { margin: .25em 0; }
.bubble h3 { font-size: 15px; margin: .9em 0 .35em; }
.bubble h4 { font-size: 14px; margin: .8em 0 .3em; color: var(--ink-soft); }
.bubble code {
  background: var(--panel-2); padding: 1px 5px; border-radius: 5px;
  font-size: .88em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble pre {
  background: var(--panel-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto;
}
.bubble pre code { background: none; padding: 0; }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: .9em 0; }
.tbl-wrap { overflow-x: auto; margin: .6em 0; -webkit-overflow-scrolling: touch; }
.bubble table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.bubble table { width: 100%; }
.bubble th, .bubble td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: left;
  vertical-align: top; white-space: normal;
}
.bubble th, .bubble td:first-child { white-space: nowrap; }
.bubble td { min-width: 12ch; }
.bubble blockquote {
  margin: .6em 0; padding: 8px 12px; border-left: 3px solid var(--accent);
  background: var(--panel-2); border-radius: 0 10px 10px 0; color: var(--ink-soft);
  font-size: 14px;
}
.bubble blockquote p { margin: .25em 0; }
.bubble th { background: var(--panel-2); font-weight: 600; }

.steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.step {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--panel-2); color: var(--ink-soft); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px;
}
.step.run::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s infinite;
}
.step.ok::before { content: "✓"; color: var(--accent); font-size: 11px; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.nalar { margin-bottom: 8px; }
.nalar summary {
  list-style: none; cursor: pointer; font-size: 12px; color: var(--ink-soft);
  display: inline-flex; align-items: center; gap: 6px;
}
.nalar summary::-webkit-details-marker { display: none; }
.nalar summary::before { content: "🧠"; }
.nalar .isi {
  margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); white-space: pre-wrap;
  border-left: 2px solid var(--line); padding-left: 10px; max-height: 240px; overflow-y: auto;
}
.err {
  font-size: 13px; color: #e5484d; background: color-mix(in srgb, #e5484d 12%, transparent);
  border: 1px solid color-mix(in srgb, #e5484d 30%, transparent);
  padding: 8px 12px; border-radius: 10px;
}
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-soft);
  animation: bounce 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ------------------------------------------------------------ composer --- */
.composer {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
}
.composer-inner {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow);
}
.composer-inner:focus-within { border-color: var(--accent); }
#input {
  flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.45; max-height: 140px; padding: 7px 0;
}
#kirim {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  transition: transform .12s, opacity .12s;
}
#kirim:disabled { opacity: .4; }
#kirim:active:not(:disabled) { transform: scale(.92); }
.hint { text-align: center; font-size: 11px; color: var(--ink-soft); padding: 6px 0 0; }

@media (min-width: 700px) {
  .thread { padding: 22px 20px 10px; }
  .composer { padding: 10px 20px 16px; }
}
