:root {
  color-scheme: dark;
  --bg: #0c0f0d;
  --panel: #111612;
  --panel-2: #171d18;
  --line: #2b352e;
  --text: #e8eee9;
  --muted: #8f9b91;
  --accent: #4fd48b;
  --accent-2: #75a7ff;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

button,
textarea {
  font: inherit;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover,
button:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  background: var(--bg);
}

.topbar,
.terminal-head,
.keybar,
.brand,
.top-actions,
.terminal-actions,
.key-group,
.prompt-actions,
.response-head {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  flex: 1;
  min-width: 0;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.brand-title {
  color: var(--text);
  font-weight: 700;
}

#status-label,
#run-state {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 14px var(--danger);
}

.dot.connected {
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

.dot.exited {
  background: #e6bc4d;
  box-shadow: 0 0 14px #e6bc4d;
}

.top-actions,
.terminal-actions,
.prompt-actions {
  gap: 8px;
}

.action-button,
.secondary-button,
.send-button {
  display: inline-grid;
  grid-auto-flow: column;
  place-items: center;
  gap: 7px;
  padding: 0 12px;
  font-size: 12px;
}

.send-button {
  background: #1b7f50;
  border-color: #2dbd72;
  color: #f4fff8;
  font-weight: 700;
}

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

.workspace {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  gap: 12px;
  padding: 12px;
}

.prompt-panel,
.response-panel,
.terminal-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.prompt-panel {
  display: grid;
  gap: 10px;
  padding: 10px;
}

#prompt-input {
  width: 100%;
  min-height: 122px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #070a08;
  color: var(--text);
  line-height: 1.5;
}

#prompt-input::placeholder {
  color: #78857b;
}

.prompt-actions {
  justify-content: flex-end;
}

.response-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
}

.response-head {
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.response-head span:first-child {
  color: var(--text);
  font-weight: 700;
}

#response-box {
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 14px;
  background: #050806;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  font-size: 14px;
}

.terminal-panel {
  overflow: hidden;
}

.terminal-panel[hidden] {
  display: none;
}

.terminal-head {
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.terminal-frame {
  height: min(52vh, 520px);
  min-height: 320px;
  padding: 10px;
  background: #080b09;
}

#terminal {
  width: 100%;
  height: 100%;
}

.xterm {
  height: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050806;
}

.xterm-viewport,
.xterm-screen {
  border-radius: 8px;
}

.keybar {
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.key-group {
  gap: 8px;
  min-width: 0;
}

.key-button {
  width: 48px;
  height: 38px;
  font-size: 13px;
}

.key-button.wide {
  width: 68px;
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-rows: 48px minmax(0, 1fr);
  }

  .topbar {
    gap: 8px;
    padding-inline: 10px;
  }

  .brand-title {
    display: none;
  }

  .button-label {
    display: none;
  }

  .action-button {
    min-width: 34px;
    padding: 0 8px;
  }

  .workspace {
    grid-template-rows: auto minmax(300px, 1fr) auto;
    gap: 8px;
    padding: 8px;
  }

  #prompt-input {
    min-height: 112px;
    font-size: 14px;
  }

  .prompt-actions {
    justify-content: stretch;
  }

  .send-button,
  .secondary-button {
    flex: 1;
  }

  .terminal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .terminal-actions {
    justify-content: space-between;
  }

  .terminal-frame {
    height: 48vh;
    min-height: 280px;
    padding: 6px;
  }

  .xterm {
    padding: 6px;
  }

  .keybar {
    align-content: center;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px 6px;
  }

  .key-group {
    gap: 6px;
    justify-content: center;
  }

  .key-button {
    width: 42px;
    height: 34px;
    font-size: 12px;
  }

  .key-button.wide {
    width: 60px;
  }
}
