/* ═══════════════════════════════════════════════════════════════
   sambai apps — shared shell
   Design tokens mirror the directory: dark, Inter + Space Grotesk,
   14px radii, gradient accents. Each app sets --acc on <html>
   to tint its own accent.
   ═══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;
  --bg: #08080d;
  --bg-2: #0b0b13;
  --panel: rgba(255, 255, 255, 0.028);
  --panel-hover: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f2f2f7;
  --muted: rgba(233, 233, 245, 0.56);
  --faint: rgba(233, 233, 245, 0.34);
  --nav-bg: rgba(8, 8, 13, 0.75);
  --footer-bg: rgba(8, 8, 13, 0.6);
  --grid-line: rgba(255, 255, 255, 0.03);
  --grad-ink: #0b0b13;
  --wave-rest: rgba(255, 255, 255, 0.14);
  --a1: #7c5cff;
  --a2: #22d3ee;
  --green: #34d399;
  --amber: #f5b04c;
  --pink: #ff5c8a;
  --radius: 14px;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-display: "Space Grotesk", var(--font-ui);
  --acc: linear-gradient(135deg, var(--a1), var(--a2));
  --acc-1: var(--a1);
  --acc-2: var(--a2);
}

/* light theme — same palette family as the directory page */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7fb;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-hover: #fbfbff;
  --border: rgba(15, 15, 32, 0.1);
  --border-strong: rgba(15, 15, 32, 0.2);
  --text: #191924;
  --muted: rgba(28, 28, 44, 0.62);
  --faint: rgba(28, 28, 44, 0.42);
  --nav-bg: rgba(255, 255, 255, 0.75);
  --footer-bg: rgba(255, 255, 255, 0.6);
  --grid-line: rgba(15, 15, 40, 0.05);
  --grad-ink: #ffffff;
  --wave-rest: rgba(15, 15, 40, 0.12);
  --green: #0d9668;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.25s ease, color 0.25s ease;
}

/* faint engineering grid, same as the directory */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 90% 50% at 50% -5%, #000 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 90% 50% at 50% -5%, #000 20%, transparent 70%);
  z-index: 0;
}

main { position: relative; z-index: 1; width: 100%; }

::selection { background: rgba(124, 92, 255, 0.4); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--acc-2); outline-offset: 2px; border-radius: 4px; }

/* ── header ─────────────────────────────────────────────── */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
}

.top-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--acc);
  color: var(--grad-ink);
  font-size: 15px;
}

.logo em { font-style: normal; color: var(--muted); }

.app-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
}

.top-spacer { flex: 1; }

/* status pill */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 5px 11px;
  border-radius: 99px;
  white-space: nowrap;
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.2s ease;
}

.pill[data-state="ready"] .dot { background: var(--green); box-shadow: 0 0 8px rgba(52, 211, 153, 0.6); }
.pill[data-state="busy"] .dot { background: var(--amber); animation: pulse 1.1s ease infinite; }
.pill[data-state="error"] .dot { background: var(--pink); }

@keyframes pulse {
  50% { opacity: 0.35; }
}

/* ── hero ────────────────────────────────────────────────── */

.hero { max-width: 980px; margin: 0 auto; padding: 54px 22px 30px; }

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.hero h1 .grad {
  background: var(--acc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  margin-top: 12px;
  max-width: 62ch;
  color: var(--muted);
  font-size: 0.98rem;
}

/* ── workspace card ─────────────────────────────────────── */

.workspace {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 22px 70px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

/* ── buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.925rem;
  padding: 11px 20px;
  border: 1px solid transparent;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.btn.primary {
  background: var(--acc);
  color: var(--grad-ink);
}
.btn.primary:hover { transform: translateY(-1px); filter: brightness(1.08); }

.btn.ghost {
  background: var(--panel);
  border-color: var(--border-strong);
}
.btn.ghost:hover { background: var(--panel-hover); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ── progress + notes ────────────────────────────────────── */

.track {
  height: 4px;
  border-radius: 99px;
  background: var(--panel);
  border: 1px solid var(--border);
  overflow: hidden;
}

.track span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--acc);
  border-radius: 99px;
  transition: width 0.15s ease;
}

.note {
  font-size: 0.82rem;
  color: var(--faint);
  min-height: 1.2em;
}

.note.error { color: var(--pink); }

/* ── footer ──────────────────────────────────────────────── */

.foot {
  position: relative;
  z-index: 1;
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--footer-bg);
}

.foot-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--faint);
}

.foot a { color: var(--muted); border-bottom: 1px solid transparent; }
.foot a:hover { border-bottom-color: var(--muted); }

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--green);
  font-weight: 600;
}

/* theme toggle — same control as the directory nav */
.theme-toggle {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); }

/* show the icon for the theme you'd switch TO */
:root[data-theme="light"] .theme-toggle .ico-moon { display: block; }
:root[data-theme="light"] .theme-toggle .ico-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-sun { display: block; }

/* Freeze CSS animations while WebGPU generation runs — a compositor
   animation can deadlock WebGPU inference (seen with LFM3 on Chrome). */
html[data-llm-busy] *, html[data-llm-busy] *::before, html[data-llm-busy] *::after {
  animation-play-state: paused !important;
  transition: none !important;
}

@media (max-width: 640px) {
  .top-inner { padding: 12px 16px; }
  .hero { padding: 38px 16px 22px; }
  .workspace { padding: 0 16px 54px; }
  .app-title { display: none; }
}
