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

:root {
  --ui-bg: #16171b;
  --ui-panel: #1c1e23;
  --ui-panel-2: #22252b;
  --ui-line: #2e323a;
  --ui-text: #e4e6eb;
  --ui-dim: #8b919d;
  --ui-accent: #7c9cff;
  --ui-good: #4ec98a;
  --ui-warn: #e6b84f;
  --ui-bad: #e06a6a;
  --radius: 8px;
  color-scheme: dark;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ui-bg);
  color: var(--ui-text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- top bar --------------------------------------------------------------- */

.topbar {
  flex: none;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-line);
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.brand .ghost { font-size: 16px; }
.brand .sep { color: var(--ui-dim); }
.theme-name { color: var(--ui-accent); font-variant-numeric: tabular-nums; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-line);
  color: var(--ui-dim);
}
.badge.good { color: var(--ui-good); border-color: color-mix(in srgb, var(--ui-good) 40%, transparent); }
.badge.ok   { color: var(--ui-warn); border-color: color-mix(in srgb, var(--ui-warn) 40%, transparent); }
.badge.bad  { color: var(--ui-bad);  border-color: color-mix(in srgb, var(--ui-bad) 40%, transparent); }

.btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: var(--ui-panel-2);
  color: var(--ui-text);
  cursor: pointer;
}
.btn:hover { background: #2b2f37; }
.btn.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #0d1020; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 9px; font-size: 11px; width: 100%; margin-top: 6px; }

/* --- layout ---------------------------------------------------------------- */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(420px, 1fr) 360px;
}

.panel { overflow-y: auto; background: var(--ui-panel); }
.panel.left { border-right: 1px solid var(--ui-line); }
.panel.right { border-left: 1px solid var(--ui-line); display: flex; flex-direction: column; }

/* --- controls -------------------------------------------------------------- */

.section { border-bottom: 1px solid var(--ui-line); }

.section-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  background: none;
  border: 0;
  color: var(--ui-text);
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
}
.section-header:hover { background: var(--ui-panel-2); }
.section-header .chev { color: var(--ui-dim); font-size: 10px; width: 10px; }

.section-body { padding: 2px 14px 14px; }
.section-body.collapsed { display: none; }

.hint { margin: 0 0 10px; color: var(--ui-dim); font-size: 11px; line-height: 1.4; }

.row { padding: 7px 0; border-top: 1px solid transparent; }
.row + .row { border-top-color: #24262c; }

.row-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}
.row-label .key {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--ui-dim);
}
.row.modified .key { color: var(--ui-accent); }
.row.modified .key::after { content: " •"; }

.reset {
  opacity: 0;
  background: none;
  border: 0;
  color: var(--ui-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
}
.row:hover .reset { opacity: 1; }
.reset:hover { color: var(--ui-text); }

.help { margin: 5px 0 0; font-size: 10.5px; line-height: 1.4; color: #6e7480; }

input[type="text"], input[type="search"], input[type="number"], select {
  font: inherit;
  font-size: 12px;
  width: 100%;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--ui-line);
  background: #15171b;
  color: var(--ui-text);
}
input:focus, select:focus { outline: 1px solid var(--ui-accent); outline-offset: -1px; }

/* theme picker */
.theme-picker { display: block; }
.theme-list {
  width: 100%;
  margin-top: 6px;
  padding: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
}
.theme-list option { padding: 3px 5px; border-radius: 4px; }

/* colors */
.color-input { display: flex; gap: 7px; align-items: center; }
.color-input .hex { font-family: ui-monospace, Menlo, monospace; text-transform: lowercase; }

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 30px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--ui-line);
  border-radius: 5px;
  background: none;
  cursor: pointer;
  flex: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 3px; }

.palette-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.swatch-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.swatch-cell input[type="color"] { width: 100%; height: 22px; }
.swatch-cell span { font-size: 9px; color: #5f6572; font-family: ui-monospace, monospace; }

/* toggle */
.toggle { display: inline-flex; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track {
  width: 34px; height: 20px;
  border-radius: 999px;
  background: #33373f;
  position: relative;
  transition: background 0.15s;
}
.toggle .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #b7bcc6;
  transition: transform 0.15s, background 0.15s;
}
.toggle input:checked + .track { background: var(--ui-accent); }
.toggle input:checked + .track::after { transform: translateX(14px); background: #0d1020; }

/* range */
.range-input { display: flex; align-items: center; gap: 9px; }
.range-input input[type="range"] { flex: 1; accent-color: var(--ui-accent); min-width: 0; }
.range-input .num { width: 68px; flex: none; font-variant-numeric: tabular-nums; }

/* --- preview stage --------------------------------------------------------- */

.preview {
  min-width: 0;
  display: flex;
  padding: 22px;
  overflow: auto;
}

#stage {
  flex: 1;
  min-width: 0;
  border-radius: 12px;
  padding: 34px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* Wallpapers exist purely so opacity and blur have something to act on. */
#stage[data-wallpaper="1"] {
  background:
    radial-gradient(circle at 22% 28%, #ff8a4c 0%, transparent 42%),
    radial-gradient(circle at 78% 18%, #7b5cff 0%, transparent 46%),
    radial-gradient(circle at 60% 85%, #21c8a8 0%, transparent 48%),
    linear-gradient(140deg, #2b1a4d, #101126 60%, #05060f);
}
#stage[data-wallpaper="2"] {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.045) 0 2px, transparent 2px 16px),
    linear-gradient(160deg, #f5f0e6, #d9cfc0 55%, #b9ac99);
}
#stage[data-wallpaper="3"] { background: #000; }
#stage[data-wallpaper="4"] {
  background:
    radial-gradient(circle at 50% 120%, #1b3a5c 0%, transparent 60%),
    repeating-linear-gradient(90deg, #0d1117 0 38px, #11161f 38px 76px);
}

.win {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  isolation: isolate;
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
}

/* The tinted, optionally-blurred background plate. Text sits above it and
   stays fully opaque, which is exactly how Ghostty behaves. */
.win::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--bg-a);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.win.shadow { box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 3px 10px rgba(0,0,0,0.4); }
.win.thicken .grid { -webkit-text-stroke: 0.32px currentColor; }
.win.p3 .grid { filter: saturate(1.18); }
.win[data-titlebar="hidden"] { border-radius: 10px; }

#bg-image {
  position: absolute;
  inset: 0;
  z-index: -1;
  display: none;
  pointer-events: none;
}

/* --- titlebar -------------------------------------------------------------- */

.titlebar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: 38px;
  position: relative;
  user-select: none;
}
.titlebar.style-hidden { display: none; }
.titlebar.style-native { background: rgba(48,50,56,0.96); border-bottom: 1px solid rgba(0,0,0,0.35); }
.win[data-chrome="light"] .titlebar.style-native { background: rgba(232,232,235,0.96); color: #1a1a1a; }
.titlebar.style-transparent { background: transparent; }
.titlebar.style-tabs { background: rgba(0,0,0,0.22); height: 40px; padding: 0 10px; }
.win[data-chrome="light"] .titlebar.style-tabs { background: rgba(255,255,255,0.22); }
.win[data-chrome="ghostty"] .titlebar { background: rgba(0,0,0,0.28); }

.traffic { display: flex; gap: 8px; flex: none; }
.traffic .l { width: 12px; height: 12px; border-radius: 50%; display: block; }
.traffic .close { background: #ff5f57; }
.traffic .min { background: #febc2e; }
.traffic .zoom { background: #28c840; }

.title {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: color-mix(in srgb, var(--fg) 78%, transparent);
  pointer-events: none;
}
.title .proxy { font-size: 11px; }

.tabs { display: flex; gap: 5px; align-items: center; flex: 1; min-width: 0; padding-left: 6px; }
.tab {
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 11.5px;
  font-family: -apple-system, system-ui, sans-serif;
  color: color-mix(in srgb, var(--fg) 55%, transparent);
  background: rgba(255,255,255,0.05);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.tab.active { background: color-mix(in srgb, var(--bg) 82%, #fff 10%); color: var(--fg); }
.tab.new { flex: none; padding: 5px 10px; background: none; }

/* --- terminal body --------------------------------------------------------- */

.term-body { flex: 1; min-height: 0; display: flex; }

.pane { flex: 1; min-width: 0; position: relative; overflow: hidden; display: flex; }
.pane-surface { flex: 1; min-width: 0; position: relative; overflow: hidden; }

/* Unfocused splits get a translucent wash of the fill color over them. */
.pane:not(.focused) .pane-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--unfocused-fill);
  opacity: var(--unfocused-opacity);
  pointer-events: none;
}

.split-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.divider { background: var(--divider); flex: none; }
.divider.v { width: 1px; }
.divider.h { height: 1px; }

.grid {
  height: 100%;
  overflow: hidden;
  color: var(--fg);
  white-space: pre;
  font-variant-ligatures: contextual;
}
.grid.balanced { display: flex; flex-direction: column; justify-content: flex-start; }
.grid.padding-extend { position: relative; }

.line { min-height: 1em; }

.pal-strip { display: inline-flex; }
.pal-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2ch;
  font-size: 0.85em;
}

/* --- cursor ---------------------------------------------------------------- */

.cursor {
  --cursor-thickness: 2px;
  display: inline-block;
  position: relative;
  width: 1ch;
  vertical-align: baseline;
}
.cursor-block { color: transparent; background: var(--cursor-color); }
.cursor-block_hollow { box-shadow: inset 0 0 0 1px var(--cursor-color); color: transparent; }
.cursor-bar { width: 0; }
.cursor-bar::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--cursor-thickness);
  background: var(--cursor-color);
}
.cursor-underline::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: var(--cursor-thickness);
  background: var(--cursor-color);
}
.cursor.blink { animation: blink 1.2s steps(1, end) infinite; }
@keyframes blink { 0%, 49% { opacity: inherit; } 50%, 100% { opacity: 0; } }

/* --- config output --------------------------------------------------------- */

.out-header {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ui-line);
}
.out-header h2 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ui-dim);
}
.path {
  margin: 3px 0 0;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  color: #5f6572;
  overflow-wrap: anywhere;
  /* Two lines maximum; the full path is in the tooltip. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.config-out {
  flex: 1;
  margin: 0;
  padding: 14px;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: #cdd3de;
  white-space: pre;
  tab-size: 2;
}

.footnote {
  flex: none;
  margin: 0;
  overflow-wrap: anywhere;
  padding: 10px 14px;
  border-top: 1px solid var(--ui-line);
  font-size: 10.5px;
  line-height: 1.5;
  color: #6e7480;
}
.footnote code { font-size: 10px; color: #8b919d; overflow-wrap: anywhere; }
kbd {
  display: inline-block;
  padding: 1px 4px;
  border: 1px solid var(--ui-line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--ui-panel-2);
  font-family: inherit;
  font-size: 9.5px;
  color: var(--ui-text);
}

@media (max-width: 1280px) {
  .layout { grid-template-columns: 290px minmax(360px, 1fr) 310px; }
}
