:root {
  --bg: #000000;
  --text: #e2e8e4;
  --muted: #6c7870;
  --border: #444444;
  --green: #4af626;
  --yellow: #f5b041;
  --red: #e74c3c;
  --blue: #5dade2;
  --purple: #d787ff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: fixed; /* Prevents iOS rubber-band scrolling behind keyboard */
  background: var(--bg);
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  line-height: 1.45;
}

.terminal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--bg);
}

/* Rounded TUI Box with embedded top border titles */
.tui-box {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.box-title-row {
  position: absolute;
  top: -0.7em;
  left: 0.75rem;
  right: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  font-size: 12px;
  line-height: 1.2;
}

.box-title,
.box-title-right {
  background: var(--bg);
  padding: 0 0.45rem;
  color: var(--muted);
  white-space: nowrap;
}

.title-brand {
  color: var(--green);
  font-weight: 700;
}

.box-title-right.scrolled {
  color: var(--yellow);
}

.box-title.target-secret {
  color: var(--purple);
}

/* 1. Status Box */
.status-box {
  flex-shrink: 0;
  padding: 0.65rem 0.9rem 0.55rem;
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.25rem;
  font-size: 13px;
  color: var(--muted);
}

.status-bar strong {
  color: var(--text);
  font-weight: 700;
}

.status-connected { color: var(--green); }
.status-disconnected { color: var(--red); }
.key-set { color: var(--green) !important; }
.key-unset { color: var(--yellow) !important; }
.wipe-warn { color: var(--yellow) !important; }
.wipe-urgent { color: var(--red) !important; }
.target-active { color: var(--purple) !important; }

/* 2. Chat Box */
.chat-box {
  flex: 1;
  min-height: 0; /* Allows flex child to scroll properly */
  display: flex;
  flex-direction: column;
  padding: 0.65rem 0.25rem 0.45rem;
}

.output {
  flex: 1;
  overflow-y: auto;
  padding: 0.2rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.line {
  white-space: pre-wrap;
  word-break: break-word;
}

.line.system { color: var(--muted); }
.line.warn { color: var(--yellow); }
.line.error { color: var(--red); }
.line.locked { color: var(--muted); font-style: italic; }
.line.pubkey { color: var(--blue); }
.line.secret { color: var(--purple); }

.timestamp {
  color: var(--muted);
  margin-right: 0.5rem;
}

.handle {
  font-weight: 700;
  margin-right: 0.5rem;
}

.secret-tag {
  color: var(--purple);
  font-weight: 700;
  margin-right: 0.5rem;
}

/* 3. Input Box */
.input-box {
  flex-shrink: 0;
  padding: 0.6rem 0.9rem 0.55rem;
}

.input-bar {
  display: flex;
  align-items: center;
}

.prompt {
  color: var(--green);
  margin-right: 0.6rem;
  font-weight: 700;
  user-select: none;
}

#cmd-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font: inherit;
}

/* Prevent iOS Safari auto-zoom on touch devices */
@media (pointer: coarse) {
  #cmd-input {
    font-size: 16px;
  }
}