:root {
  color-scheme: dark;
  --bg: #020403;
  --panel: #06100a;
  --panel-strong: #08170d;
  --grid: rgba(114, 255, 98, 0.08);
  --green: #7dff61;
  --green-dim: #4ebf43;
  --cyan: #4fe7ff;
  --amber: #ffd166;
  --red: #ff6b6b;
  --ink: #d7ffd2;
  --muted: #88a887;
  --border: #4cae43;
  --shadow: rgba(125, 255, 97, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0, rgba(255, 255, 255, 0.035) 1px, transparent 1px, transparent 4px),
    linear-gradient(135deg, #010201 0%, #071008 50%, #010302 100%);
  font-family: "Courier New", Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1440px, calc(100vw - 24px));
  min-height: calc(100vh - 24px);
  margin: 12px auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(0deg, var(--grid) 1px, transparent 1px),
    rgba(2, 8, 4, 0.94);
  background-size: 32px 32px;
  box-shadow: 0 0 28px var(--shadow), inset 0 0 64px rgba(0, 0, 0, 0.7);
}

.topbar {
  display: grid;
  gap: 12px;
}

.brand {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--green);
  text-shadow: 0 0 8px rgba(125, 255, 97, 0.5);
  white-space: pre;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.status-grid > div,
.panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(5, 16, 8, 0.9);
  box-shadow: inset 0 0 22px rgba(125, 255, 97, 0.08);
}

.status-grid > div {
  min-width: 0;
  padding: 10px 12px;
}

.label,
.status-grid strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.label {
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  color: var(--cyan);
  font-size: 14px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.panel {
  min-width: 0;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 16px;
}

h2 {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 14px;
  font-weight: 700;
}

.selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.model-button,
.small-button,
#sendButton {
  min-height: 38px;
  border: 1px solid var(--green-dim);
  border-radius: 6px;
  color: var(--green);
  background: #031006;
  text-align: center;
}

.model-button:hover,
.small-button:hover,
#sendButton:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.model-button.is-active,
#sendButton {
  color: #001f05;
  background: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 16px rgba(125, 255, 97, 0.35);
}

#sendButton:disabled {
  cursor: not-allowed;
  color: #244026;
  background: #6f8f6b;
  border-color: #6f8f6b;
  box-shadow: none;
}

.kv {
  display: grid;
  gap: 6px;
  margin: 0;
}

.kv div {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

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

.kv dd {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.log {
  display: grid;
  gap: 6px;
  min-height: 150px;
  max-height: 250px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  color: var(--muted);
  font-size: 13px;
}

.log li {
  overflow-wrap: anywhere;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  min-height: 690px;
  overflow: hidden;
}

.terminal-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--amber);
}

.small-button {
  min-width: 76px;
  min-height: 32px;
}

.conversation {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
  overflow: auto;
}

.message {
  width: min(860px, 100%);
  padding: 12px;
  border: 1px solid rgba(125, 255, 97, 0.34);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.26);
}

.message.user-message {
  justify-self: end;
  border-color: rgba(79, 231, 255, 0.52);
}

.message.assistant-message {
  justify-self: start;
}

.message.error-message {
  border-color: rgba(255, 107, 107, 0.72);
}

.message-head {
  margin-bottom: 8px;
  color: var(--cyan);
  font-size: 12px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(1, 5, 2, 0.72);
}

textarea {
  width: 100%;
  min-height: 118px;
  max-height: 280px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--green-dim);
  border-radius: 6px;
  color: var(--ink);
  background: #010602;
  outline: none;
}

textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(79, 231, 255, 0.18);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

#charCount {
  overflow-wrap: anywhere;
}

#sendButton {
  min-width: 110px;
}

.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;
}

@media (max-width: 900px) {
  .shell {
    width: calc(100vw - 12px);
    min-height: calc(100vh - 12px);
    margin: 6px auto;
    padding: 10px;
  }

  .brand {
    font-size: 12px;
  }

  .status-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    min-height: 620px;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .selector {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  #sendButton {
    width: 100%;
  }
}
