:root {
  --bg: #000000;
  --fg: #cccccc;
  --bright: #ffffff;
  --dim: #777777;
  --accent: #33ff33;
  --red: #ff5555;
  --blue: #58a6ff;
  --border: #1f1f1f;
  --edge: #2a2a2a;
  --panel: #0a0a0a;
  --input: #000000;
  --code: #141414;
  --thumb: #3a3a3a;
  --veil: rgba(0, 0, 0, 0.85);
  --on-accent: #000000;
  --cell: 1.3;
}

[data-theme="light"] {
  --bg: #f6f6f6;
  --fg: #303030;
  --bright: #101010;
  --dim: #6f6f6f;
  --accent: #000000;
  --red: #cc241d;
  --blue: #1260b0;
  --border: #dcdcdc;
  --edge: #c9c9c9;
  --panel: #ffffff;
  --input: #ffffff;
  --code: #ececec;
  --thumb: #bfbfbf;
  --veil: rgba(0, 0, 0, 0.4);
  --on-accent: #ffffff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

html,
body {
  height: 100%;
}

@supports (height: 100dvh) {
  body {
    height: 100dvh;
  }
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, Menlo, "DejaVu Sans Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: var(--cell);
  font-weight: 400;
  letter-spacing: 0;
  font-variant-ligatures: none;
  font-feature-settings: "calt" 0, "liga" 0, "clig" 0;
  text-rendering: optimizeSpeed;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

/* title bar */
#titlebar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.t-name {
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
}

.t-name:hover {
  color: var(--accent);
}

.t-left {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.t-ver {
  color: var(--dim);
}

.t-model {
  color: var(--dim);
  cursor: pointer;
}

.t-model:hover {
  color: var(--accent);
}

#app {
  position: relative;
  max-width: 960px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* thin terminal scrollbars */
.output,
.palette {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.output::-webkit-scrollbar,
.palette::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.output::-webkit-scrollbar-track,
.palette::-webkit-scrollbar-track {
  background: transparent;
}

.output::-webkit-scrollbar-thumb,
.palette::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 2px solid var(--bg);
  border-radius: 0;
}

.output::-webkit-scrollbar-thumb:hover,
.palette::-webkit-scrollbar-thumb:hover {
  background: var(--thumb);
}

/* command palette — like a shell completion list */
.palette {
  flex-shrink: 0;
  max-height: 45%;
  overflow-y: auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.palette.hidden {
  display: none;
}

#palette-list {
  padding: 4px 0;
}

.palette-item {
  display: flex;
  padding: 0 12px;
  cursor: pointer;
  user-select: none;
}

.palette-item .k {
  min-width: 12ch;
  flex-shrink: 0;
  color: var(--accent);
}

.palette-item .d {
  color: var(--dim);
}

.palette-item.selected {
  background: var(--accent);
}

.palette-item.selected .k,
.palette-item.selected .d {
  color: var(--on-accent);
}

/* terminal screen */
.term {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  cursor: text;
}

.banner {
  flex-shrink: 0;
  padding: 12px 16px 0;
}

.output {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  overscroll-behavior: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.output::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.term-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.term-line.user,
.term-line.ai {
  margin-top: 0.5em;
}

.ai {
  color: var(--fg);
  white-space: normal;
}

.ai p {
  margin: 0;
}

.ai p + p {
  margin-top: 1em;
}

.ai strong {
  color: var(--bright);
  font-weight: 700;
}

.ai em {
  color: var(--bright);
}

.ai del {
  color: var(--dim);
}

.ai ul,
.ai ol {
  margin: 0.75em 0;
  padding-left: 1.6em;
}

.ai li {
  margin: 0;
}

.ai hr {
  border: none;
  border-top: 1px solid var(--dim);
  margin: 1em 0;
}

.ai blockquote {
  margin: 0.75em 0;
  color: var(--dim);
}

.ai blockquote::before {
  content: "> ";
}

.ai code {
  background: var(--code);
  padding: 0 3px;
  color: var(--accent);
}

.ai a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai h1,
.ai h2,
.ai h3,
.ai h4,
.ai h5,
.ai h6 {
  color: var(--bright);
  font-size: inherit;
  font-weight: 700;
  margin: 1em 0 0.25em;
}

.user {
  color: var(--bright);
}

.cmd {
  color: var(--dim);
}

.hlp {
  display: flex;
}

.hlp-c {
  min-width: 14ch;
  flex-shrink: 0;
  color: var(--accent);
}

.hlp-d {
  color: var(--fg);
}

.err {
  color: var(--red);
}

.prompt {
  color: var(--accent);
  font-weight: 700;
  margin-right: 8px;
  user-select: none;
}

.blk {
  display: inline-block;
  width: 0.55em;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.spin {
  display: inline-block;
  width: 1ch;
  color: var(--accent);
}

@keyframes blink {
  50% { opacity: 0; }
}

/* turn-1 action buttons */
.actrow {
  flex-shrink: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.actrow.hidden {
  display: none;
}

.act {
  flex: 1;
  text-align: center;
  background: transparent;
  border: 1px solid var(--edge);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  padding: 6px 0;
  cursor: pointer;
  border-radius: 0;
}

.act:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.act.special {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.act.special:hover:not(:disabled) {
  color: var(--on-accent);
}

.act:disabled {
  opacity: 0.4;
  cursor: default;
}

/* input line */
.line {
  display: flex;
  align-items: center;
  padding: 20px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.line .prompt {
  flex-shrink: 0;
}

#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--bright);
  font: inherit;
  caret-color: var(--accent);
  caret-shape: block;
  min-width: 0;
}

#input:disabled {
  color: var(--dim);
  caret-color: transparent;
}

/* config overlay — a tty-style dialog */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--veil);
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: 480px;
  max-width: 92vw;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--edge);
  padding: 20px 22px;
}

.panel h1 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}

.panel .sep {
  border: none;
  border-top: 1px solid var(--edge);
  margin: 18px 0 14px;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  color: var(--dim);
  font-size: 12px;
  margin-bottom: 5px;
  user-select: none;
}

.field input {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  padding: 6px 9px;
  outline: none;
  border-radius: 0;
}

.field input:focus {
  border-color: var(--accent);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch {
  position: relative;
  width: 64px;
  height: 30px;
  background: var(--input);
  border: 1px solid var(--edge);
  cursor: pointer;
  padding: 0;
  border-radius: 0;
  flex-shrink: 0;
}

.switch:hover {
  border-color: var(--accent);
}

.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: var(--fg);
  transition: left 0.15s ease;
}

.switch[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
}

.switch[aria-checked="true"] .knob {
  left: 37px;
  background: var(--on-accent);
}

.state {
  color: var(--dim);
  font-size: 12px;
  text-transform: uppercase;
  user-select: none;
}

.note {
  color: var(--dim);
  font-size: 12px;
  margin-top: 14px;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  padding: 5px 14px;
  cursor: pointer;
  border-radius: 0;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

button.primary:hover {
  color: var(--on-accent);
}

/* ---- responsive ---- */

@media (max-width: 640px) {
  body {
    font-size: 13px;
  }

  .lbl {
    display: none;
  }

  .banner {
    padding: 10px 12px 0;
  }

  .output {
    padding: 10px 12px;
  }

  .line {
    padding: 14px 12px;
  }

  .actrow {
    gap: 6px;
    padding: 6px 12px;
  }

  .act {
    font-size: 12px;
    padding: 5px 0;
  }

  #titlebar {
    padding: 4px 10px;
  }

  .palette-item {
    padding: 0 10px;
  }
}

@media (max-width: 420px) {
  body {
    font-size: 12.5px;
  }

  .banner {
    padding: 8px 10px 0;
  }

  .output {
    padding: 8px 10px;
  }

  .line {
    padding: 12px 10px;
  }

  .actrow {
    gap: 5px;
    padding: 5px 10px;
  }

  .panel {
    padding: 14px 16px;
  }
}

@media (max-height: 500px) {
  #titlebar {
    padding: 2px 10px;
  }

  .banner {
    padding-top: 6px;
  }

  .output {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .line {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .actrow {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .act {
    padding-top: 3px;
    padding-bottom: 3px;
  }
}
