:root {
  --bg: #0d0d12;
  --panel: #14141b;
  --fg: #e6e6ea;
  --dim: #808088;
  --cyan: #38c6dc;
  --magenta: #c98bff;
  --magenta-border: #7d4fa8;
  --red: #ff6b6b;
  --mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", Menlo, Consolas,
    monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;               /* only the message log scrolls */
  overscroll-behavior: none;
}

.terminal {
  display: flex;
  flex-direction: column;
  height: 100vh;                  /* fallback */
  height: var(--app-height, 100dvh); /* tracks the visible viewport (keyboard-aware) */
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- app bar (console prompt line) ---- */
.appbar {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 4px 10px;
  border-bottom: 1px solid #22222c;
  white-space: nowrap;
  overflow: hidden;
}
.avatar {
  flex: none;
  color: var(--magenta);
  font-size: 15px;
}
.appbar-title {
  color: var(--cyan);
  font-weight: 700;
}
.appbar-title::after {
  content: ":";
  color: var(--dim);
}
.appbar-sub {
  color: var(--dim);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cursor {
  color: var(--magenta);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.appbar-status {
  flex: none;
  margin-left: auto;
  align-self: center;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.3s;
}
.appbar-status.online {
  background: #3ddc84;
  box-shadow: 0 0 8px rgba(61, 220, 132, 0.55);
}
.appbar-status.offline {
  background: var(--red);
}
.appbar-status.connecting {
  background: #d0a24a;
}

/* jump-to-latest pill (shown when scrolled up during new messages) */
.jump {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 14px);
  transform: translateX(-50%);
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--magenta-border);
  border-radius: 2px;
  padding: 6px 14px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  z-index: 6;
}
.jump[hidden] {
  display: none;
}
.jump:hover {
  border-color: var(--magenta);
}

/* ---- log ---- */
.log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;   /* no page-level bounce on mobile */
  -webkit-overflow-scrolling: touch;
  padding: 8px 2px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.turn-user {
  color: var(--cyan);
  white-space: pre-wrap;
  word-break: break-word;
}
.turn-user .caret {
  font-weight: 700;
}

/* assistant panel — mirrors the rich "Evtim" bordered panel */
.panel {
  border: 1px solid var(--magenta-border);
  border-radius: 2px;
  position: relative;
  padding: 16px 20px;
}
.panel-title {
  position: absolute;
  top: -0.72em;
  left: 14px;
  background: var(--bg);
  padding: 0 6px;
  color: var(--magenta);
  font-weight: 700;
}
.panel-stats {
  position: absolute;
  bottom: -0.72em;
  right: 14px;
  background: var(--bg);
  padding: 0 6px;
  color: var(--dim);
  font-size: 12px;
}
.panel.error {
  border-color: var(--red);
}
.panel.error .panel-title {
  color: var(--red);
}

/* thinking spinner */
.thinking {
  color: var(--dim);
}
.dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0% {
    content: "";
  }
  25% {
    content: "·";
  }
  50% {
    content: "··";
  }
  75% {
    content: "···";
  }
}

/* system / rule lines */
.rule {
  color: var(--dim);
  text-align: center;
  border-top: 1px dashed #333;
  line-height: 0.1em;
  margin: 6px 0;
}
.rule span {
  background: var(--bg);
  padding: 0 10px;
}
.system {
  color: var(--dim);
}

/* markdown inside panels */
.md > *:first-child {
  margin-top: 0;
}
.md > *:last-child {
  margin-bottom: 0;
}
.md h1,
.md h2,
.md h3 {
  color: var(--magenta);
  margin: 0.6em 0 0.3em;
}
.md code {
  background: #000;
  border-radius: 2px;
  padding: 1px 5px;
  color: #9cdcfe;
}
.md pre {
  background: #000;
  border-radius: 2px;
  padding: 12px;
  overflow-x: auto;
}
.md pre code {
  padding: 0;
}
.md a {
  color: var(--cyan);
}
.md ul,
.md ol {
  padding-left: 22px;
  margin: 0.4em 0;
}

/* ---- composer ---- */
.composer {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid #22222c;
}
.prompt-caret {
  color: var(--cyan);
  font-weight: 700;
  white-space: nowrap;
  padding-top: 4px;
}
.input-wrap {
  position: relative;
  flex: 1;
}
.input {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  padding: 4px 0;
  margin: 0;
  resize: none;
  overflow-y: auto;
  max-height: 40vh;
  white-space: pre-wrap;
  word-break: break-word;
}
.input::placeholder {
  color: #55555e;
  font-style: italic;
}

/* autocomplete */
.complete {
  position: absolute;
  bottom: 130%;
  left: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--magenta-border);
  border-radius: 2px;
  min-width: 320px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.complete li {
  padding: 5px 8px;
  border-radius: 2px;
  display: flex;
  gap: 12px;
  cursor: pointer;
}
.complete li .cmd {
  color: var(--cyan);
  font-weight: 600;
  min-width: 72px;
}
.complete li .desc {
  color: var(--dim);
}
.complete li.active,
.complete li:hover {
  background: #24243040;
}
.complete li.active {
  background: #2a2a38;
}

/* ---- mobile: native chat-app behaviour ---- */
@media (max-width: 640px) {
  .terminal {
    max-width: none;
    padding: 0 10px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Compact header to maximise conversation space. */
  .appbar {
    gap: 7px;
    padding: 9px 2px;
  }

  /* 16px prevents iOS Safari from auto-zooming when the field is focused. */
  .input {
    font-size: 16px;
  }

  /* Roomier tap targets / readable panels on small screens. */
  .panel {
    padding: 14px 16px;
  }
  .complete {
    min-width: 0;
    width: 100%;
  }
}
