@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* Self-hosted FULL JetBrains Mono (Google Fonts' subset omits the box-drawing
   block U+2500–257F, which made tmux/Claude borders garble on some devices,
   e.g. Oppo/ColorOS). The full font covers box-drawing, so every device renders
   the same glyphs. */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/JetBrainsMono-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/JetBrainsMono-Bold.woff2') format('woff2');
}

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Light theme — white background, near-black text (matches the xterm theme
     in terminal.js). Drives the whole UI chrome: page, header, mobile bar. */
  --bg: #ffffff;
  --bg-surface: #f3f4f6;
  --bg-highlight: #e7eaee;
  --border: #d0d7de;
  --fg: #1a1a1a;
  --fg-dim: #6e7781;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --green: #1a7f37;
  --red: #cf222e;
  --orange: #9a6700;
  --purple: #8250df;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #1a1b26 0%, #16161e 50%, #1a1b26 100%);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.login-card h1 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.login-card p {
  color: var(--fg-dim);
  font-size: 0.85rem;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--fg-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
}

.login-btn:hover { background: var(--accent-hover); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
  color: var(--red);
  font-size: 0.8rem;
  margin-top: 12px;
  text-align: center;
  min-height: 20px;
}

/* Terminal */
#terminal-screen {
  display: none;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* On touch devices, JS overrides height/top via visualViewport to handle
     the soft keyboard shrinking the visible area */
}

#terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#terminal-header .title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

#terminal-header .status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--fg-dim);
}

#terminal-header .status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

#terminal-header .status .dot.disconnected {
  background: var(--red);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-btn {
  background: var(--bg-highlight);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.header-btn:hover {
  color: var(--fg);
  border-color: var(--accent);
}

#terminal-container {
  flex: 1;
  overflow: hidden;
  /* We hand-roll touch scrolling (term.scrollLines) because native touch scroll
     doesn't reliably reach xterm's split viewport/screen DOM on mobile. Block the
     browser's own touch handling so the two don't fight. */
  touch-action: none;
  overscroll-behavior: none;
  /* Prevent text from bleeding to screen edges + clear the notch in landscape */
  padding-left: max(4px, env(safe-area-inset-left));
  padding-right: max(4px, env(safe-area-inset-right));
}

/* Mobile control bar — only on touch devices */
#mobile-bar { display: none; }
body.is-touch #mobile-bar {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
body.is-touch #mobile-bar::-webkit-scrollbar { display: none; }
#mobile-bar button {
  flex: 0 0 auto;
  min-width: 42px;
  height: 38px;
  padding: 0 12px;
  background: var(--bg-highlight);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
#mobile-bar button:active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
#mobile-bar button.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* xterm creates canvas/viewport elements — give them touch-action:none too
   so the browser doesn't intercept swipe gestures before our handlers run */
#terminal-container .xterm,
#terminal-container .xterm-viewport,
#terminal-container .xterm-screen,
#terminal-container canvas {
  touch-action: none !important;
}

/* Voice toolbar */
#voice-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.voice-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-highlight);
  color: var(--fg-dim);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.voice-btn:hover {
  border-color: var(--accent);
  color: var(--fg);
}

.voice-btn.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.voice-btn.listening {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122, 162, 247, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(122, 162, 247, 0); }
}

.voice-btn svg {
  width: 18px;
  height: 18px;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--fg-dim);
}

.toggle {
  width: 34px;
  height: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--fg);
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle.on::after {
  transform: translateX(16px);
}

.voice-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-dim);
  font-size: 0.7rem;
  padding: 3px 6px;
  outline: none;
  max-width: 140px;
}

#voice-status {
  font-size: 0.7rem;
  color: var(--fg-dim);
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
}

/* Responsive */
@media (max-width: 600px) {
  .login-card { width: 92%; padding: 24px 20px; }

  #terminal-header {
    padding: 6px 10px;
  }

  #terminal-header .title span { font-size: 0.75rem; }

  #voice-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 10px;
  }

  /* Hide text labels on toggles to save space */
  .toggle-group span { display: none; }

  /* Compact voice select */
  .voice-select { max-width: 110px; font-size: 0.7rem; }

  /* Hide verbose status text */
  #voice-status { display: none; }

  /* Larger tap targets */
  .voice-btn { width: 42px; height: 42px; }

  .header-btn { padding: 6px 12px; font-size: 0.8rem; }
}

/* HIDE-MOBILE-BAR-20260602 (user: toolbar not needed for now; remove this block to restore) */
body.is-touch #mobile-bar{display:none!important;}
