/* Mobile-first, PWA standalone, iPhone notch aware */

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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --accent: #e94560;
  --accent-dim: #b03248;
  --text-primary: #eaeaea;
  --text-muted: #8892a4;
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --border: #2a3a5c;
  --record-active: #e94560;
  --record-idle: #4caf50;

  /* iPhone notch / home indicator safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ---- Status bar ---- */
#status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
  flex-shrink: 0;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
}

.status-dot::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.connected {
  border-color: var(--success);
  color: var(--success);
}
.status-dot.connected::before { background: var(--success); }

.status-dot.disconnected {
  border-color: var(--error);
  color: var(--error);
}
.status-dot.disconnected::before { background: var(--error); }

.status-dot.connecting {
  border-color: var(--warning);
  color: var(--warning);
}
.status-dot.connecting::before {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--warning);
  font-weight: 500;
}

/* ---- Record section ---- */
#record-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.record-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 3px solid var(--record-idle);
  background: transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  outline: none;
}

.record-btn .btn-icon {
  font-size: 28px;
  line-height: 1;
}

.record-btn .btn-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}

.record-btn:active,
.record-btn.recording {
  border-color: var(--record-active);
  background: rgba(233, 69, 96, 0.12);
  transform: scale(0.95);
}

.record-btn.recording .btn-icon::after {
  content: "";
}

.record-status {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

.partial-text {
  font-size: 14px;
  color: var(--text-primary);
  opacity: 0.7;
  min-height: 20px;
  max-height: 60px;
  overflow-y: auto;
  width: 100%;
  text-align: center;
  font-style: italic;
  padding: 0 8px;
}

/* ---- Transcript section ---- */
#transcript-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  min-height: 80px;
  max-height: 180px;
}

.transcript-area {
  flex: 1;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.transcript-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.action-btn {
  flex: 1 1 auto;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.action-btn.primary {
  background: var(--accent);
  color: #fff;
}
.action-btn.primary:active { opacity: 0.75; }

.action-btn.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.action-btn.secondary:active { opacity: 0.65; }

/* ---- Terminal section ---- */
#terminal-section {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #000;
}

#terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: var(--bg-secondary);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { opacity: 0.6; }

#terminal {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

/* ---- Terminal controls: virtual keys + quick launchers ---- */
#terminal-controls {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 6px 6px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.vkey-row, .launch-row {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.vkey-row::-webkit-scrollbar,
.launch-row::-webkit-scrollbar { display: none; }

.vkey {
  flex: 0 0 auto;
  min-width: 38px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.vkey:active {
  background: var(--accent-dim);
  border-color: var(--accent);
  transform: scale(0.95);
}
.vkey-enter {
  background: var(--accent);
  border-color: var(--accent);
  min-width: 48px;
}

.launch-btn {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.launch-btn:active {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* xterm overrides */
.xterm-viewport::-webkit-scrollbar { width: 4px; }
.xterm-viewport::-webkit-scrollbar-track { background: #111; }
.xterm-viewport::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---- Utility ---- */
.hidden { display: none !important; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---- Error / notification toast ---- */
#toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  max-width: 90vw;
  text-align: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
#toast.show { opacity: 1; }
#toast.error { border-color: var(--error); color: var(--error); }
#toast.success { border-color: var(--success); color: var(--success); }

/* Landscape: give more room to terminal */
@media (orientation: landscape) {
  #record-section { padding: 8px 16px 6px; gap: 6px; }
  .record-btn { width: 70px; height: 70px; }
  .record-btn .btn-icon { font-size: 22px; }
  #transcript-section { max-height: 110px; min-height: 60px; }
}
