:root {
  --bg: #070a12;
  --panel: rgba(18, 23, 38, 0.78);
  --panel-solid: #121726;
  --panel-2: #1a2034;
  --line: rgba(140, 160, 220, 0.16);
  --line-strong: rgba(140, 160, 220, 0.32);
  --text: #e8ecf8;
  --muted: #8f99b5;
  --accent: #7cf0ff;
  --accent-2: #8b7bff;
  --good: #5ee3a1;
  --warn: #ffc857;
  --bad: #ff6b81;
  --radius: 18px;
  --gap: 14px;
  --font: 'Inter', system-ui, sans-serif;
  --display: 'Space Grotesk', 'Inter', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --soft-1: rgba(255, 255, 255, .03);
  --soft-2: rgba(255, 255, 255, .045);
  --soft-3: rgba(255, 255, 255, .07);
  --field: rgba(0, 0, 0, .28);
  --term-bg: #05070d;
  --accent-soft: rgba(124, 240, 255, .08);
  --accent-ring: rgba(124, 240, 255, .16);
  --on-accent: #061018;
  --primary-bg: linear-gradient(135deg, var(--accent), var(--accent-2));
  --icon-bg: linear-gradient(135deg, rgba(124, 240, 255, .18), rgba(139, 123, 255, .18));
  --welcome-bg: radial-gradient(60% 60% at 50% 40%, rgba(20, 28, 52, .96), rgba(7, 10, 18, .98));
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .45);
  --shadow-hover: 0 14px 40px rgba(0, 0, 0, .4), inset 0 0 0 1px rgba(124, 240, 255, .1);
  --spot: rgba(124, 240, 255, .10);
  --blur: 16px;
  --title-font: var(--display);
  --title-transform: none;
  --title-spacing: .01em;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font);
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.aurora {
  position: fixed; inset: -20%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40% 35% at 20% 20%, rgba(124, 240, 255, .10), transparent 70%),
    radial-gradient(35% 40% at 85% 30%, rgba(139, 123, 255, .12), transparent 70%),
    radial-gradient(45% 40% at 50% 100%, rgba(94, 227, 161, .06), transparent 70%);
  animation: drift 30s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(3%, -2%, 0) rotate(3deg); } }

/* ---------- buttons & inputs ---------- */
button.primary, .login-card button, .welcome button {
  border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 600; color: var(--on-accent);
  background: var(--primary-bg);
}
button.ghost, .btn {
  border: 1px solid var(--line); background: var(--soft-1); border-radius: 10px; padding: 6px 12px;
}
button.ghost:hover, .btn:hover { border-color: var(--line-strong); background: var(--soft-3); }
button.danger { border: 1px solid rgba(255, 107, 129, .4); color: var(--bad); background: transparent; border-radius: 10px; padding: 6px 12px; }
input, select, textarea {
  background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
textarea { resize: vertical; min-height: 120px; font-family: var(--mono); font-size: 13px; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; grid-template-rows: 1fr; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 24px;
  padding: 28px; backdrop-filter: blur(18px); box-shadow: var(--shadow-lg);
}
.login-card form { display: grid; gap: 14px; margin-top: 22px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card .error { color: var(--bad); min-height: 1.5em; margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 20px var(--display); letter-spacing: .01em; }
.brand b { color: var(--accent); font-weight: 700; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 18px; position: relative; z-index: 5; }
.topbar .brand { background: none; border: 0; padding: 0; font-size: 18px; }
.search { max-width: 280px; }
.spacer { flex: 1; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.menu { position: relative; }
.menu-list {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; padding: 6px; z-index: 20;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.menu.open .menu-list { display: grid; gap: 2px; }
.menu-list button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; display: flex; gap: 8px; align-items: center; }
.menu-list button:hover { background: var(--soft-3); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.menu-list .x { margin-left: auto; color: var(--muted); }

/* ---------- stage & layouts ---------- */
.stage { padding: 4px 18px 12px; overflow: auto; display: grid; gap: var(--gap); align-content: start; min-height: 0; }
.stage.mode-home { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); grid-auto-rows: 170px; }
.stage.mode-focus { grid-template: "a" 1fr / 1fr; align-content: stretch; }
.stage.mode-split { grid-template: "a b" 1fr / 1fr 1fr; align-content: stretch; }
.stage.mode-trio  { grid-template: "a b" 1fr "a c" 1fr / 1.6fr 1fr; align-content: stretch; }
.stage:not(.mode-home) .block.off { display: none; }
.stage.mode-home .block.filtered { display: none; }

.block {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(var(--blur));
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; position: relative;
  transition: border-color .2s, box-shadow .2s;
}
.mode-home .block { cursor: pointer; }
.mode-home .block:hover { border-color: var(--line-strong); box-shadow: 0 10px 30px var(--field), inset 0 0 0 1px var(--accent-soft); }
.block.dragging { opacity: .4; }
.block.drop-target { border-color: var(--accent); }
.block-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.block-icon {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: var(--icon-bg); color: var(--accent);
}
.block-title { font: 600 15px var(--title-font); text-transform: var(--title-transform); letter-spacing: var(--title-spacing); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-group { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.block-actions { display: none; gap: 4px; }
.stage:not(.mode-home) .block-actions { display: flex; }
.stage:not(.mode-home) .block-group { display: none; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 8px; width: 28px; height: 28px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { border-color: var(--line); color: var(--text); }
.tile-body { padding: 0 14px 14px; flex: 1; min-height: 0; overflow: hidden; }
.full-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 16px 16px; display: none; }
.stage:not(.mode-home) .tile-body { display: none; }
.stage:not(.mode-home) .full-body { display: block; }

.tile-stat { font: 700 28px var(--display); line-height: 1.1; }
.tile-line { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; font-size: 13px; }
.tile-list li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--line); }
.pill.good { color: var(--good); border-color: rgba(94, 227, 161, .35); }
.pill.bad { color: var(--bad); border-color: rgba(255, 107, 129, .35); }
.pill.warn { color: var(--warn); border-color: rgba(255, 200, 87, .35); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.bar { height: 6px; background: var(--soft-3); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: inherit; }
.soon { display: grid; place-items: center; text-align: center; height: 100%; color: var(--muted); padding: 24px; gap: 6px; }
.soon b { color: var(--text); font-family: var(--display); font-size: 16px; }

/* ---------- block internals ---------- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.two-pane { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 14px; height: 100%; min-height: 0; }
.two-pane > * { min-height: 0; overflow: auto; }
.list { display: grid; gap: 4px; align-content: start; }
.list button { text-align: left; background: var(--soft-1); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.list button.active { border-color: var(--accent); background: var(--accent-soft); }
.list small { display: block; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
pre.box { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 12px/1.5 var(--mono); overflow: auto; white-space: pre-wrap; }
h3 { font: 600 14px var(--display); margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.md { line-height: 1.6; }
.md pre { background: var(--field); padding: 10px; border-radius: 8px; overflow: auto; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; }
.crumbs button { background: none; border: 0; color: var(--accent); padding: 2px 4px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.media-grid button { background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 0; overflow: hidden; text-align: left; }
.media-grid img, .media-grid .vid { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: grid; place-items: center; background: #000; color: var(--muted); }
.media-grid span { display: block; padding: 6px 8px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player video, .player img { width: 100%; max-height: 60vh; background: #000; border-radius: 12px; }

/* terminals */
.term-wrap { display: flex; flex-direction: column; height: 100%; gap: 8px; }
.term-tabs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.term-tabs .tab { border: 1px solid var(--line); background: var(--soft-1); border-radius: 9px; padding: 4px 10px; display: flex; gap: 8px; align-items: center; }
.term-tabs .tab.active { border-color: var(--accent); }
.term-tabs .tab .x { color: var(--muted); }
.term-host { flex: 1; min-height: 200px; background: var(--term-bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px; position: relative; }
.term-host > div { position: absolute; inset: 8px; }
.stage:not(.mode-home) .block[data-id="terminals"] .full-body { overflow: hidden; }

/* ---------- Jarvis ---------- */
.jarvis { padding: 0 18px 16px; position: relative; z-index: 6; }
.jarvis-log { display: grid; gap: 6px; justify-items: start; max-height: 30vh; overflow: auto; margin-bottom: 8px; }
.jarvis-log .msg { max-width: min(640px, 90%); padding: 8px 12px; border-radius: 14px; background: var(--panel-solid); border: 1px solid var(--line); animation: pop .25s var(--ease); }
.jarvis-log .msg.me { justify-self: end; background: var(--accent-soft); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.jarvis-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 99px;
  background: var(--panel); border: 1px solid var(--line-strong); backdrop-filter: blur(18px); box-shadow: var(--shadow-lg);
}
.jarvis-bar input { border: 0; background: none; box-shadow: none; padding: 8px 0; }
.jarvis-orb { width: 18px; height: 18px; border-radius: 50%; flex: none; background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent)); animation: spin 6s linear infinite; box-shadow: 0 0 16px rgba(124, 240, 255, .5); }
.jarvis.listening .jarvis-orb { animation-duration: .8s; box-shadow: 0 0 26px rgba(124, 240, 255, .9); }
@keyframes spin { to { transform: rotate(360deg); } }
.mic { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--soft-2); display: grid; place-items: center; flex: none; touch-action: none; }
.jarvis.listening .mic { background: var(--accent); color: var(--on-accent); }

/* ---------- welcome ---------- */
.welcome {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: var(--welcome-bg);
  transition: opacity .5s var(--ease), transform .5s var(--ease);
}
.welcome.leaving { opacity: 0; transform: scale(1.04); pointer-events: none; }
.welcome-inner { text-align: center; max-width: 520px; animation: pop .6s var(--ease); }
.welcome-logo { filter: drop-shadow(0 0 24px rgba(124, 240, 255, .45)); }
.welcome h1 { font: 700 clamp(28px, 6vw, 44px) var(--display); margin: 16px 0 4px; }
.welcome-facts { list-style: none; padding: 0; margin: 22px 0 26px; display: grid; gap: 8px; }
.welcome-facts li { background: var(--soft-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--panel-solid); border: 1px solid var(--line-strong); padding: 8px 16px; border-radius: 12px; transition: .25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; gap: 8px; flex-wrap: wrap; }
  .topbar .brand span, .clock { display: none; }
  .search { max-width: none; flex: 1; order: 10; min-width: 100%; }
  .stage { padding: 4px 16px 10px; }
  .stage.mode-home { grid-template-columns: 1fr 1fr; grid-auto-rows: 150px; }
  .stage.mode-split { grid-template: "a" 1fr "b" 1fr / 1fr; }
  .stage.mode-trio { grid-template: "a" 1.4fr "b" 1fr "c" 1fr / 1fr; }
  .two-pane { grid-template-columns: 1fr; }
  .jarvis { padding: 0 16px 12px; }
}
@media (max-width: 420px) { .stage.mode-home { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- assistant ---------- */
.chat { display: flex; flex-direction: column; height: 100%; gap: 10px; }
.stage:not(.mode-home) .block[data-id="assistant"] .full-body { overflow: hidden; }
.chat-log { flex: 1; min-height: 0; overflow: auto; display: grid; gap: 10px; align-content: start; padding-right: 4px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--soft-1); line-height: 1.6; overflow-wrap: anywhere; }
.bubble.user { justify-self: end; background: var(--accent-soft); white-space: pre-wrap; }
.bubble p:first-child { margin-top: 0; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--field); padding: 10px; border-radius: 8px; overflow: auto; }
.chat-form { align-items: stretch; flex-wrap: nowrap; }
.chat-form textarea { min-height: 52px; font-family: var(--font); font-size: 14px; }
.typing { color: var(--muted); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .4; } }
.err { color: var(--bad); }
.active-btn { border-color: var(--accent) !important; background: var(--accent-soft) !important; }
.editor { min-width: 0; }
.drop { margin-top: -4px; }
