:root {
  --bg: #07080c;
  --panel: rgba(14, 18, 27, 0.92);
  --panel-2: rgba(18, 23, 34, 0.98);
  --line: rgba(131, 108, 47, 0.38);
  --line-soft: rgba(131, 108, 47, 0.22);
  --gold: #f4c75c;
  --amber: #ffb347;
  --green: #67f0a2;
  --blue: #6aa9ff;
  --red: #ff7171;
  --text: #ede6d4;
  --muted: #8f8b7c;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.5);
  --radius: 16px;
  --font: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --topbar-offset: 68px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(255, 179, 71, 0.08), transparent 35%),
    radial-gradient(circle at bottom right, rgba(106, 169, 255, 0.08), transparent 32%),
    linear-gradient(180deg, #05060a 0%, #090b11 100%);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

#bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black 55%, transparent 100%);
  opacity: 0.5;
}

#topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  height: 68px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(8, 10, 16, 0.96), rgba(6, 8, 12, 0.72));
  backdrop-filter: blur(12px);
}
.topbar-left, .topbar-center, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-left { flex-direction: column; align-items: flex-start; gap: 2px; }
.brand { font-size: 20px; font-weight: 800; letter-spacing: 0.08em; color: var(--gold); }
.subtitle { font-size: 11px; color: var(--muted); }
.topbar-center { flex: 1; justify-content: center; flex-wrap: wrap; }
.topbar-right { color: var(--muted); font-size: 12px; }

.pill, .chip, .ghost-btn, .primary-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 11px;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pill { color: var(--gold); }
.pill.good { color: var(--green); }
.pill.warn { color: var(--amber); }
.ghost-btn, .primary-btn { cursor: pointer; }
.ghost-btn:hover, .chip:hover, .primary-btn:hover { transform: translateY(-1px); border-color: rgba(244, 199, 92, 0.9); background: rgba(244, 199, 92, 0.08); }
.ghost-btn.active { border-color: rgba(103, 240, 162, 0.6); color: #67fb7f; background: rgba(103, 240, 162, 0.08); }

/* Toast notifications */
#toast-container { position: fixed; top: calc(var(--topbar-offset, 68px) + 8px); right: 12px; z-index: 1000; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { pointer-events: auto; padding: 8px 14px; border-radius: 6px; font-size: 12px; font-family: 'JetBrains Mono', monospace; color: #ede6d4; background: rgba(14, 18, 27, 0.95); border: 1px solid rgba(244, 199, 92, 0.3); backdrop-filter: blur(8px); animation: toast-in 0.2s ease-out; max-width: 320px; }
.toast.success { border-color: rgba(103, 240, 162, 0.5); color: #67fb7f; }
.toast.error { border-color: rgba(255, 80, 80, 0.5); color: #ff7171; }
.toast.info { border-color: rgba(154, 215, 255, 0.5); color: #9ad7ff; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
.toast.fade-out { animation: toast-out 0.3s ease-in forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

#shell { display: grid; grid-template-columns: 300px 1fr; height: calc(100dvh - var(--topbar-offset)); min-height: 0; }
#sidebar { border-right: 1px solid var(--line-soft); background: linear-gradient(180deg, rgba(9, 12, 18, 0.95), rgba(5, 7, 11, 0.92)); padding: 14px 12px; overflow: auto; }
.side-section { padding: 12px; margin-bottom: 12px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: rgba(255,255,255,0.02); }
.side-section:last-child { margin-bottom: 0; }
.side-title { color: var(--gold); text-transform: uppercase; letter-spacing: 0.14em; font-size: 11px; margin-bottom: 10px; }
.sidebar-agent-section { display: flex; flex-direction: column; align-items: center; }
.sidebar-agent-stage { position: relative; width: 108px; height: 108px; display: flex; align-items: center; justify-content: center; }
.sidebar-agent-sprite { border-radius: 4px; image-rendering: pixelated; }
.sidebar-info { font-size: 11px; line-height: 1.5; color: #9ca3af; max-height: 300px; overflow-y: auto; overflow-x: hidden; word-break: break-word; }
.sidebar-info h1, .sidebar-info h2, .sidebar-info h3 { color: #ede6d4; font-size: 12px; margin: 8px 0 4px; }
.sidebar-info pre { background: rgba(0,0,0,0.3); padding: 6px 8px; border-radius: 4px; overflow-x: auto; font-size: 10px; margin: 4px 0; }
.sidebar-info code { font-family: 'JetBrains Mono', monospace; }

/* Logs panel */
.logs-body { display: flex; flex-direction: column; height: 100%; padding: 0 !important; }
.logs-toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line-soft); flex-shrink: 0; }
.logs-tabs { display: flex; gap: 4px; }
.logs-tabs .log-tab { font-size: 10px; padding: 3px 8px; min-height: auto; }
.logs-tabs .log-tab.active { border-color: rgba(103, 240, 162, 0.6); color: #67fb7f; background: rgba(103, 240, 162, 0.08); }
.log-level-select { background: #0e121b; color: #ede6d4; border: 1px solid rgba(244, 199, 92, 0.3); border-radius: 4px; padding: 2px 6px; font-size: 10px; font-family: 'JetBrains Mono', monospace; margin-left: auto; }
.logs-output { flex: 1; overflow-y: auto; padding: 6px 10px; font-size: 11px; font-family: 'JetBrains Mono', monospace; line-height: 1.6; color: #9ca3af; }
.logs-output .log-line { white-space: pre-wrap; word-break: break-all; }
.logs-output .log-line .log-time { color: #6b7280; }
.logs-output .log-line .log-level-INFO { color: #9ad7ff; }
.logs-output .log-line .log-level-WARNING { color: #f4c75c; }
.logs-output .log-line .log-level-ERROR { color: #ff7171; }
.logs-output .log-line .log-level-DEBUG { color: #6b7280; }
.sidebar-agent-shadow { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 80px; height: 12px; background: radial-gradient(ellipse, rgba(0,0,0,0.5) 0%, transparent 70%); }
.sidebar-agent-info { text-align: center; width: 100%; margin-top: 6px; }
.sidebar-agent-state { font-size: 13px; font-weight: 600; color: var(--gold); text-transform: capitalize; }
.sidebar-agent-details { font-size: 10px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-agent-status { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; margin-bottom: 2px; }
.sidebar-agent-status.live { color: #67fb7f; }
.sidebar-agent-status.locked { color: #f4c75c; }
.sidebar-agent-model { font-size: 10px; color: #9ad7ff; margin-bottom: 2px; }
.sidebar-agent-controls { display: flex; gap: 6px; margin-top: 8px; padding: 0 2px; width: 100%; }
.sidebar-agent-controls .ghost-btn { flex: 1; font-size: 10px; padding: 4px 0; }
.sessions-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.sessions-list .list-item { padding: 5px 6px; font-size: 11px; }
.list { display: grid; gap: 8px; }
.list-item { display: flex; align-items: flex-start; gap: 8px; color: var(--text); font-size: 12px; padding: 7px 8px; border-radius: 10px; background: rgba(255,255,255,0.02); border: 1px solid transparent; }
.list-item:hover { border-color: rgba(244, 199, 92, 0.25); }
.bullet { width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; background: var(--green); box-shadow: 0 0 14px rgba(103, 240, 162, 0.6); flex: 0 0 auto; }
.item-text { line-height: 1.35; word-break: break-word; }
.item-text .meta { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { cursor: pointer; }

/* Agent List */
.agent-list { display: flex; flex-direction: column; gap: 6px; }
.agent-empty { color: var(--muted); font-size: 11px; padding: 4px 0; }
.agent-item { padding: 8px 10px; border-radius: 8px; background: rgba(255,255,255,0.02); border: 1px solid transparent; cursor: default; transition: border-color 0.15s; }
.agent-item:hover { border-color: rgba(244, 199, 92, 0.2); }
.agent-item.active-profile { background: rgba(103, 240, 162, 0.04); border-color: rgba(103, 240, 162, 0.15); }
.agent-row { display: flex; align-items: center; gap: 8px; }
.agent-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.agent-dot.running { background: var(--green); box-shadow: 0 0 8px rgba(103, 240, 162, 0.5); }
.agent-dot.stopped { background: var(--muted); opacity: 0.5; }
.agent-name { font-size: 12px; font-weight: 500; color: var(--text); }
.agent-badge { font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; padding: 1px 6px; border-radius: 4px; background: rgba(103, 240, 162, 0.12); color: var(--green); font-weight: 600; }
.agent-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; padding-left: 15px; }
.agent-actions { display: flex; gap: 4px; }
.agent-model { font-size: 10px; color: var(--muted); max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gw-toggle { font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 3px; border: 1px solid rgba(255,255,255,0.1); cursor: pointer; background: rgba(255,255,255,0.04); color: var(--muted); transition: all 0.15s; }
.gw-toggle:hover { border-color: rgba(255,255,255,0.2); background: rgba(255,255,255,0.08); }
.gw-toggle.running { color: var(--green); background: rgba(103, 240, 162, 0.08); border-color: rgba(103, 240, 162, 0.2); }
.gw-toggle.running:hover { background: rgba(103, 240, 162, 0.15); }
.gw-toggle.activate { color: var(--gold); background: rgba(244, 199, 92, 0.08); border-color: rgba(244, 199, 92, 0.2); }
.gw-toggle.activate:hover { background: rgba(244, 199, 92, 0.15); }

.footer-note { color: var(--muted); font-size: 11px; line-height: 1.6; }
.small-meta { color: var(--muted); font-size: 11px; line-height: 1.7; }

#main { min-width: 0; overflow: hidden; }
#workspace { position: relative; width: 100%; height: 100%; min-height: 0; padding: 12px; overflow: auto; }
.panel { position: absolute; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, var(--panel), var(--panel-2)); box-shadow: var(--shadow); min-width: 260px; min-height: 190px; }
.panel::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(135deg, rgba(244, 199, 92, 0.08), transparent 20%, transparent 80%, rgba(103, 240, 162, 0.04)); opacity: 0.65; }
.panel-head { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); color: var(--gold); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; cursor: grab; user-select: none; }
.panel-head:active { cursor: grabbing; }
.panel-head-right { display: flex; align-items: center; gap: 7px; color: var(--muted); letter-spacing: 0.06em; }
.mini-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.mini-dot.green { background: var(--green); box-shadow: 0 0 12px rgba(103, 240, 162, 0.65); }
.mini-dot.amber { background: var(--amber); box-shadow: 0 0 12px rgba(255, 179, 71, 0.6); }
.mini-dot.gold { background: var(--gold); box-shadow: 0 0 12px rgba(244, 199, 92, 0.6); }
.mini-label { font-size: 10px; }
.panel-body { position: relative; z-index: 1; padding: 12px; overflow: auto; min-height: 0; flex: 1; }
.resize-handle { position: absolute; width: 16px; height: 16px; right: 4px; bottom: 4px; cursor: nwse-resize; z-index: 3; background: linear-gradient(135deg, transparent 50%, rgba(244, 199, 92, 0.7) 50%); border-radius: 3px; display: none; }
.layout-edit-mode .resize-handle { display: block; }
.layout-edit-mode .panel-head { cursor: move; }
.layout-edit-mode .panel { outline: 1px dashed rgba(244, 199, 92, 0.35); outline-offset: 0; }

.terminal-panel { min-height: 360px; }
.terminal-body { display: flex; flex-direction: column; height: 100%; }
.terminal-output {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(0,0,0,0.32);
}
.terminal-output .xterm {
  padding: 10px 12px;
  height: 100%;
}
.terminal-output .xterm-viewport { overflow-y: auto !important; -webkit-overflow-scrolling: touch; }
.terminal-output .xterm-screen { height: 100%; }
.terminal-line { white-space: pre-wrap; color: var(--text); font-size: 12px; line-height: 1.6; }
.terminal-line.system { color: var(--gold); }
.terminal-line.dim { color: var(--muted); }
.terminal-line.green { color: var(--green); }
.terminal-line.blue { color: var(--blue); }
.terminal-line.red { color: var(--red); }
.panel-action {
  padding: 5px 8px;
  font-size: 9px;
  letter-spacing: 0.08em;
}
body.terminal-fullscreen {
  overflow: hidden;
}
body.terminal-fullscreen #topbar {
  display: none;
}
body.terminal-fullscreen #shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
}
body.terminal-fullscreen #sidebar {
  display: none;
}
body.terminal-fullscreen #main {
  grid-column: 1 / -1;
  overflow: hidden;
}
body.terminal-fullscreen #workspace {
  padding: 0;
  overflow: hidden;
}
body.terminal-fullscreen #workspace > .panel:not(.terminal-panel) {
  display: none !important;
}
body.terminal-fullscreen .terminal-panel {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  min-height: 0 !important;
  z-index: 50;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}
body.terminal-fullscreen .terminal-panel .panel-head {
  cursor: default;
}
body.terminal-fullscreen .terminal-body {
  height: 100%;
}
body.terminal-fullscreen .terminal-output {
  flex: 1;
  min-height: 0;
  max-height: none;
  min-height: 0;
  height: 100%;
}
body.terminal-fullscreen .resize-handle { display: none; }

body.explorer-fullscreen {
  overflow: hidden;
}
body.explorer-fullscreen #topbar {
  display: none;
}
body.explorer-fullscreen #shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
}
body.explorer-fullscreen #sidebar {
  display: none;
}
body.explorer-fullscreen #main {
  grid-column: 1 / -1;
  overflow: hidden;
}
body.explorer-fullscreen #workspace {
  padding: 0;
  overflow: hidden;
}
body.explorer-fullscreen #workspace > .panel:not(.explorer-panel) {
  display: none !important;
}
body.explorer-fullscreen .explorer-panel {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  min-height: 0 !important;
  z-index: 50;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}
body.explorer-fullscreen .explorer-panel .panel-head {
  cursor: default;
}
body.explorer-fullscreen .explorer-panel .panel-body {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
body.explorer-fullscreen .explorer-body {
  height: 100%;
  grid-template-columns: 1fr 1.3fr;
  grid-template-rows: 1fr;
}
body.explorer-fullscreen .explorer-roots {
  max-height: none;
  overflow-y: auto;
}
body.explorer-fullscreen .editor-shell {
  min-height: 0;
  height: 100%;
}
body.explorer-fullscreen .file-editor {
  height: 100%;
  min-height: 0;
}
body.explorer-fullscreen .tree {
  max-height: none;
  overflow-y: auto;
}
body.explorer-fullscreen .resize-handle { display: none; }

.explorer-panel { min-height: 360px; }
.explorer-panel .panel-body { overflow: hidden; }
.explorer-body { display: grid; grid-template-columns: 1.05fr 1.25fr; gap: 12px; min-height: 0; height: 100%; overflow: hidden; }
.explorer-roots, .editor-shell { min-height: 0; }
.explorer-roots { display: grid; gap: 10px; overflow-y: auto; overflow-x: hidden; padding-right: 4px; max-height: none; }
.explorer-roots::-webkit-scrollbar { width: 8px; }
.explorer-roots::-webkit-scrollbar-thumb { background: rgba(244, 199, 92, 0.35); border-radius: 999px; }
.editor-shell { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.file-editor { height: 100%; min-height: 0; }
.root-block { border: 1px solid var(--line-soft); border-radius: 14px; background: rgba(0,0,0,0.22); overflow: hidden; }
.root-head { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; border: 0; padding: 10px 12px; color: var(--gold); background: rgba(255,255,255,0.02); font: inherit; text-align: left; }
.root-head:hover { background: rgba(244, 199, 92, 0.08); }
.root-state { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.root-block.collapsed .tree { display: none; }
.tree { display: grid; gap: 4px; padding: 8px; overflow-y: auto; max-height: 260px; }
.tree-group { display: grid; gap: 4px; }
.tree-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 11px;
  color: var(--text);
  width: 100%;
  text-align: left;
  font-family: inherit;
  background: transparent;
}
.tree-row:hover { border-color: rgba(244, 199, 92, 0.25); background: rgba(255,255,255,0.03); }
.tree-row.dir { color: var(--amber); }
.tree-row.file { color: var(--text); }
.tree-chevron { color: var(--muted); font-size: 10px; width: 12px; }
.tree-row.active { border-color: rgba(103,240,162,0.5); background: rgba(103,240,162,0.08); }
.tree-children { margin-left: 14px; padding-left: 10px; border-left: 1px dashed rgba(131, 108, 47, 0.22); display: grid; gap: 4px; }
.tree-children.collapsed { display: none; }

.editor-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  min-height: 0;
}
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 14px; background: rgba(0,0,0,0.22); }
.editor-path { color: var(--gold); font-size: 11px; }
.editor-meta { margin-top: 3px; color: var(--muted); font-size: 10px; }
.editor-actions { display: flex; gap: 8px; }
.file-editor {
  width: 100%;
  min-height: 0;
  resize: none;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line-soft);
  background: rgba(0,0,0,0.28);
  color: var(--text);
  outline: none;
  font-family: inherit;
  font-size: 11px;
  line-height: 1.7;
}
.file-editor:focus { border-color: rgba(244, 199, 92, 0.85); box-shadow: 0 0 0 3px rgba(244, 199, 92, 0.08); }
.file-editor[disabled] { opacity: 0.55; cursor: not-allowed; }

.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat-card { padding: 12px; border-radius: 14px; background: rgba(255,255,255,0.03); border: 1px solid var(--line-soft); }
.stat-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; }
.stat-value { margin-top: 8px; color: var(--text); font-size: 18px; font-weight: 700; }
.stat-note { margin-top: 6px; color: var(--muted); font-size: 11px; }
.progress { height: 10px; border-radius: 999px; background: rgba(255,255,255,0.07); overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--green)); }
.full-span { grid-column: 1 / -1; }
.metric-list, .process-list, .job-list { display: grid; gap: 8px; }
.metric-row, .process-row, .job-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,0.03); border: 1px solid var(--line-soft); font-size: 12px; }
.metric-row .left, .process-row .left, .job-row .left { display: flex; flex-direction: column; gap: 2px; }
.metric-row .title, .process-row .title, .job-row .title { color: var(--text); }
.metric-row .sub, .process-row .sub, .job-row .sub { color: var(--muted); font-size: 10px; }
.metric-row .value, .process-row .value, .job-row .value { color: var(--gold); font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; border: 1px solid var(--line); }
.badge.green { color: var(--green); }
.badge.amber { color: var(--amber); }
.badge.red { color: var(--red); }

.agent-body { display: grid; gap: 14px; justify-items: center; }
.avatar-stage { position: relative; width: 210px; height: 236px; display: grid; place-items: center; }
.avatar-shadow { position: absolute; bottom: 14px; width: 130px; height: 22px; border-radius: 50%; background: radial-gradient(circle, rgba(0,0,0,0.45), transparent 75%); filter: blur(3px); transform: scale(1.05); animation: shadowPulse 2.4s ease-in-out infinite; }
.sprite {
  width: min(100%, 220px);
  min-height: 208px;
  display: grid;
  place-items: center;
  padding: 12px 14px;
  border-radius: 22px;
  background: radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.05), transparent 54%), rgba(0,0,0,0.28);
  border: 1px solid var(--line-soft);
  box-shadow: inset 0 0 34px rgba(255, 179, 71, 0.06), 0 0 30px rgba(244, 199, 92, 0.08);
  animation: bob 2.6s ease-in-out infinite;
  overflow: hidden;
}
.sprite .avatar-canvas {
  display: block;
  width: min(100%, 220px);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 16px;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
}
.sprite .ascii-david {
  display: none;
}
.agent-meta { text-align: center; }
.agent-name { color: var(--gold); font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; }
.agent-details { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.6; }

.markdown-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--muted); font-size: 11px; }
.markdown-view { padding: 14px; border-radius: 14px; min-height: 250px; background: rgba(0,0,0,0.28); border: 1px solid var(--line-soft); white-space: normal; overflow: auto; }
.markdown-view h1, .markdown-view h2, .markdown-view h3 { margin: 0 0 8px; color: var(--gold); }
.markdown-view p { margin: 0 0 10px; color: var(--text); font-size: 12px; line-height: 1.7; }
.markdown-view ul { margin: 0 0 10px 18px; padding: 0; color: var(--text); font-size: 12px; line-height: 1.7; }
.markdown-view li { margin-bottom: 6px; }
.markdown-view code { color: #9ff2b9; background: rgba(255,255,255,0.04); border: 1px solid var(--line-soft); border-radius: 6px; padding: 2px 5px; }
.markdown-view pre { margin: 0 0 12px; padding: 10px 12px; overflow: auto; border-radius: 12px; background: rgba(0,0,0,0.3); border: 1px solid var(--line-soft); color: var(--text); font-size: 11px; line-height: 1.7; }
.markdown-view blockquote { margin: 0 0 12px; padding: 6px 10px; border-left: 3px solid var(--amber); color: var(--muted); background: rgba(255, 179, 71, 0.04); }

.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(3, 4, 7, 0.78); backdrop-filter: blur(10px); }
.overlay.hidden { display: none; }
.login-card { width: min(420px, calc(100vw - 36px)); padding: 24px; border-radius: 20px; background: linear-gradient(180deg, rgba(18, 23, 34, 0.98), rgba(10, 12, 18, 0.98)); border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-title { color: var(--gold); font-size: 20px; font-weight: 800; letter-spacing: 0.06em; }
.login-sub { margin-top: 6px; color: var(--muted); font-size: 12px; }
.login-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 18px; }
#password-input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,0.28); color: var(--text); outline: none; font-family: inherit; }
.login-error { min-height: 18px; margin-top: 10px; color: var(--red); font-size: 12px; }
.locked #shell { filter: blur(4px); pointer-events: none; user-select: none; }

@keyframes bob {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-5px); }
}
@keyframes shadowPulse {
  0%, 100% { transform: scale(1); opacity: 0.48; }
  50% { transform: scale(0.92); opacity: 0.35; }
}

@media (max-width: 1200px) {
  body { overflow: auto; }
  #shell { grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - 68px); }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  #main, #workspace { height: auto; overflow: visible; }
  #workspace { display: grid; gap: 12px; }
  .panel { position: relative !important; inset: auto !important; width: 100% !important; height: auto !important; min-height: 320px; }
  .resize-handle { display: none !important; }
  .explorer-body { grid-template-columns: 1fr; }

  /* Fullscreen overrides for small screens */
  body.terminal-fullscreen .terminal-panel,
  body.explorer-fullscreen .explorer-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 0 !important;
  }
}

@media (max-width: 820px) {
  :root { --radius: 16px; }
  html, body { height: 100%; }
  body {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #topbar {
    height: auto;
    min-height: 0;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: stretch;
  }
  .brand { font-size: 16px; letter-spacing: 0.05em; }
  .subtitle { display: none; }
  .topbar-left,
  .topbar-center,
  .topbar-right {
    width: 100%;
    flex: none;
  }
  .topbar-left { align-items: flex-start; }
  .topbar-center {
    justify-content: flex-start;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .topbar-right {
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .ghost-btn, .primary-btn, .pill, .chip { min-height: 36px; }
  #shell { grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - var(--topbar-offset)); }
  #sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    padding: 10px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    overflow-x: hidden;
    max-width: 100vw;
  }
  .side-section { margin-bottom: 0; padding: 10px; overflow-x: hidden; }
  #main, #workspace { height: auto; overflow: visible; }
  #workspace { display: grid; gap: 10px; padding: 10px; }
  .panel {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: 300px;
  }
  .panel-head { padding: 10px 10px 9px; cursor: default; }
  .panel-body { padding: 10px; }
  .terminal-panel, .explorer-panel { min-height: 0; }
  .terminal-output { flex: 1; min-height: 0; }
  .explorer-body { grid-template-columns: 1fr; gap: 10px; }
  .explorer-roots { max-height: 44vh; }
  .editor-shell { min-height: 0; }
  .editor-toolbar { gap: 8px; }
  .editor-actions { width: 100%; justify-content: stretch; }
  .editor-actions .ghost-btn { width: 100%; }
  .tree-row { padding: 8px 10px; font-size: 12px; }
  .tree-children { margin-left: 10px; padding-left: 8px; }
  .quick-actions { grid-template-columns: 1fr 1fr; }
  .quick-actions .ghost-btn { width: 100%; }
  .list, .small-meta, .editor-meta, .editor-path, .terminal-hint { font-size: 11px; }

  /* Fullscreen overrides for mobile */
  body.terminal-fullscreen .terminal-panel,
  body.explorer-fullscreen .explorer-panel {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 0 !important;
  }
  body.terminal-fullscreen #sidebar,
  body.explorer-fullscreen #sidebar { display: none !important; }
  body.terminal-fullscreen #topbar,
  body.explorer-fullscreen #topbar { display: none !important; }
}

@media (max-width: 480px) {
  #topbar { padding-inline: 10px; }
  .pill { padding: 6px 8px; font-size: 10px; }
  .side-section { padding: 9px; }
  .quick-actions { grid-template-columns: 1fr; }
  .terminal-output { flex: 1; min-height: 0; }
  .explorer-roots { max-height: 38vh; }
}
