:root {
  /* Terminal surface — matches the Ghostty "Mathias" dark background. */
  --terminal-bg: #101010;
  --terminal-fg: #ededed;
  --terminal-cursor: #b62eb2;
  --terminal-selection: #005be7;

  /* Ghostty window padding (window-padding-x/y). */
  --pad-x: 14px;
  --pad-y: 5px;

  /* Chrome surfaces (tab strip + status line) sit a step above the terminal. */
  --chrome: #171717;
  --chrome-hover: #1f1f1f;

  /* Geist gray ramp (dark), used for text hierarchy and hairlines. */
  --fg: #ededed;
  --fg-secondary: #a1a1a1;
  --fg-muted: #7d7d7d;
  --fg-faint: #565656;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --fill: rgba(255, 255, 255, 0.06);
  --fill-hover: rgba(255, 255, 255, 0.1);

  /* Accents. */
  --accent: #b62eb2;
  --green: #4be15d;
  --amber: #ffae00;
  --red: #ff6166;
  --focus: #006bff;

  /* Geist radii + motion. */
  --r-sm: 6px;
  --r-tab: 8px;
  --ease: cubic-bezier(0.175, 0.885, 0.32, 1.1);
  --dur: 150ms;

  --font-mono: "GeistMono NF", "Geist Mono", ui-monospace, SFMono-Regular,
    Menlo, monospace;
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--terminal-bg);
  color: var(--terminal-fg);
  font-family: var(--font-mono);
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
}

.ghostty {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--terminal-bg);
}

/* ── Tab strip (macOS Ghostty titlebar tabs) ─────────────────────────────── */
.ghostty-tabs {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 38px;
  padding: 6px 8px 0;
  background: var(--chrome);
  user-select: none;
}

.ghostty-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 128px;
  max-width: 240px;
  height: 30px;
  padding: 0 6px 0 11px;
  border-radius: var(--r-tab) var(--r-tab) 0 0;
  background: transparent;
  color: var(--fg-muted);
  cursor: default;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.ghostty-tab:hover {
  background: var(--chrome-hover);
  color: var(--fg-secondary);
}

/* Active tab reads as a cutout into the terminal below it. */
.ghostty-tab--active {
  background: var(--terminal-bg);
  color: var(--fg);
}

.ghostty-tab__path {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghostty-tab__close {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity var(--dur) var(--ease),
    background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.ghostty-tab:hover .ghostty-tab__close,
.ghostty-tab--active .ghostty-tab__close {
  opacity: 1;
}

.ghostty-tab__close:hover {
  background: var(--fill-hover);
  color: var(--fg);
}

.ghostty-tab__add {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 1px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.ghostty-tab__add:hover {
  background: var(--chrome-hover);
  color: var(--fg);
}

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--terminal-bg), 0 0 0 4px var(--focus);
}

/* ── Terminal + preview split ────────────────────────────────────────────── */
.ghostty-screen {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  padding: var(--pad-y) var(--pad-x);
  background: var(--terminal-bg);
  --preview-width: 0px;
}

#terminal {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
}

/* One pane per shell tab; only the active one is shown. */
.term-pane {
  position: absolute;
  inset: 0;
}

.term-pane[hidden] {
  display: none;
}

#terminal .xterm {
  height: 100%;
  padding: 0;
}

#terminal .xterm-screen {
  padding-top: 0;
}

/* xterm's viewport is a hair taller than the rendered rows (fit() rounds the
   row count down); match its background to the terminal so the remainder
   blends in instead of showing as a black bar. */
#terminal .xterm-viewport {
  background-color: var(--terminal-bg) !important;
  overflow-y: auto;
}

/* Thin, overlay-style scrollbar so it never shifts terminal content. */
#terminal .xterm-viewport::-webkit-scrollbar {
  width: 9px;
}
#terminal .xterm-viewport::-webkit-scrollbar-track {
  background: transparent;
}
#terminal .xterm-viewport::-webkit-scrollbar-thumb {
  background: var(--fill);
  border: 2px solid var(--terminal-bg);
  border-radius: var(--r-sm);
}
#terminal .xterm-viewport:hover::-webkit-scrollbar-thumb {
  background: var(--fill-hover);
}

/* Draggable divider — only interactive while a preview is open. */
.preview__resizer {
  flex: 0 0 auto;
  width: 0;
  cursor: col-resize;
  background: var(--border);
  opacity: 0;
  transition:
    width 0.3s var(--ease),
    opacity var(--dur) var(--ease),
    background var(--dur) var(--ease);
}

.ghostty-screen.is-open .preview__resizer {
  width: 5px;
  margin: 0 5px;
  opacity: 1;
  border-radius: var(--r-sm);
}

.preview__resizer:hover,
.ghostty-screen.is-dragging .preview__resizer {
  background: var(--accent);
}

.preview {
  flex: 0 0 auto;
  width: var(--preview-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: #0b0b0b;
  opacity: 0;
  transform: translateX(10px);
  transition:
    width 0.3s var(--ease),
    opacity 0.26s var(--ease),
    transform 0.3s var(--ease);
}

.ghostty-screen.is-open .preview {
  opacity: 1;
  transform: none;
}

.ghostty-screen.is-dragging .preview,
.ghostty-screen.is-dragging .preview__resizer {
  transition: none;
}

.preview__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 8px;
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
}

.preview__badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: var(--r-full, 999px);
  background: var(--fill);
  color: var(--fg-secondary);
  font-size: 11.5px;
  line-height: 1;
}

.preview__url {
  flex: 1 1 auto;
  min-width: 0;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--terminal-bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color var(--dur) var(--ease);
}

.preview__url:focus {
  border-color: var(--border-strong);
}

.preview__url::placeholder {
  color: var(--fg-faint);
}

.preview__btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.preview__btn:hover {
  background: var(--fill-hover);
  color: var(--fg);
}

.preview__btn svg {
  width: 15px;
  height: 15px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.preview__body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #fff;
}

.preview__frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Custom "waiting for port" state, shown instead of the proxy's 502 page. */
.preview__wait {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--terminal-bg);
}

.preview__wait[hidden] {
  display: none;
}

.preview__wait-card {
  max-width: 320px;
  text-align: center;
}

.preview__wait-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-bottom: 16px;
  border-radius: 50%;
  background: var(--amber);
  animation: pulse 1.1s var(--ease) infinite;
}

.preview__wait-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.28px;
  color: var(--fg);
}

.preview__wait-body {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-muted);
}

.preview__wait-body code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--fill);
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
}

.preview__wait-btn {
  margin-top: 16px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--fg-secondary);
  font-size: 13px;
  cursor: pointer;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.preview__wait-btn:hover {
  background: var(--fill-hover);
  color: var(--fg);
  border-color: var(--border-strong);
}

/* ── Status line ─────────────────────────────────────────────────────────── */
.statusline {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 30px;
  padding: 0 var(--pad-x);
  background: var(--chrome);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  line-height: 1;
  color: var(--fg-muted);
  user-select: none;
  white-space: nowrap;
}

.statusline__conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  color: var(--fg-secondary);
}

.statusline__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-faint);
  box-shadow: 0 0 0 0 transparent;
}

.statusline__conn[data-state="connected"] .statusline__dot {
  background: var(--green);
  box-shadow: 0 0 6px 0 rgba(75, 225, 93, 0.6);
}
.statusline__conn[data-state="connecting"] .statusline__dot {
  background: var(--amber);
  animation: pulse 1.1s var(--ease) infinite;
}
.statusline__conn[data-state="disconnected"] .statusline__dot,
.statusline__conn[data-state="stopped"] .statusline__dot {
  background: var(--red);
}

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

.statusline__div {
  width: 1px;
  height: 14px;
  background: var(--border);
  flex-shrink: 0;
}

.statusline__label {
  flex-shrink: 0;
  color: var(--fg-muted);
}

.statusline__chips {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.statusline__muted {
  color: var(--fg-faint);
}

.statusline__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 8px;
  border-radius: var(--r-full, 999px);
  border: 1px solid var(--border);
  background: var(--fill);
  color: var(--fg-secondary);
  text-decoration: none;
  transition:
    background var(--dur) var(--ease),
    color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}

.statusline__chip:hover {
  background: var(--fill-hover);
  color: var(--fg);
  border-color: var(--border-strong);
}

/* On: the port whose preview is currently open. */
.statusline__chip.is-active {
  background: rgba(182, 46, 178, 0.16);
  border-color: var(--accent);
  color: var(--fg);
}

.statusline__chip-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--fg-faint);
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.statusline__chip.is-active .statusline__chip-dot {
  background: var(--accent);
  box-shadow: 0 0 6px 0 rgba(182, 46, 178, 0.7);
}

.statusline__hint {
  margin-left: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg-faint);
}

.statusline__hint code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--fill);
  color: var(--fg-secondary);
  font-family: inherit;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
