/* 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 {
  --bg: #1a1b26;
  --bg-surface: #24283b;
  --bg-highlight: #292e42;
  --border: #3b4261;
  --fg: #c0caf5;
  --fg-dim: #565f89;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --green: #9ece6a;
  --red: #f7768e;
  --orange: #ff9e64;
  --purple: #bb9af7;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 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;
  position: relative; /* anchor the copy-flash overlay */
  overflow: hidden;
  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;
}

/* Displaced overlay — sits over the frozen last frame; tap/keypress reclaims */
#displaced {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(26,27,38,0.72);   /* dims the frozen frame behind it */
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
#displaced[hidden] { display: none; }
.displaced-card {
  text-align: center; padding: 20px 28px; border-radius: 14px;
  background: var(--bg-surface); border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0,0,0,.45); max-width: min(90vw, 22rem);
}
.displaced-card p { font-family: 'JetBrains Mono', monospace; font-size: 1rem; color: var(--accent); margin-bottom: 8px; }
.displaced-card span { font-size: 0.8rem; color: var(--fg-dim); }

/* 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; }

  .header-btn { padding: 6px 12px; font-size: 0.8rem; }
}

/* (mobile soft-key bar is shown on touch devices — see body.is-touch #mobile-bar above) */

/* ── instance dropdown (multi-instance header selector) ── */
.title { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.prompt-glyph { color: #7aa2f7; font-weight: 600; }
.idot { font-size: 12px; line-height: 1; color: #565f89; transition: color .3s; }
#instance-select {
  background: #1f2335; color: #c0caf5; border: 1px solid #2a2e42;
  border-radius: 6px; padding: 4px 8px; font: inherit; font-size: 13px; cursor: pointer;
}
#instance-select:focus { outline: none; border-color: #7aa2f7; }
#instance-select option { background: #1f2335; color: #c0caf5; }

/* ── copy confirmation: a quick camera-like flash over the terminal ── */
#copy-flash {
  position: absolute; inset: 0; pointer-events: none; z-index: 50;
  background: #c0caf5; opacity: 0;
}
#copy-flash.flash { animation: copyflash 200ms ease-out; }
@keyframes copyflash { 0% { opacity: 0; } 30% { opacity: 0.22; } 100% { opacity: 0; } }
