/* ==========================================================================
   CommonGrounds — the web app
   One stylesheet, no build step, served out of the binary.

   Design: deep ink ground, a single electric accent, generous type. Motion
   is short and honours prefers-reduced-motion. Nothing here needs a
   framework; the surface is small and the API is already the contract.
   ========================================================================== */

:root {
  --ink:      #0a0c10;
  --ink-2:    #0f1218;
  --surface:  #141821;
  --surface-2:#1a1f2a;
  --line:     rgba(255,255,255,.07);
  --line-2:   rgba(255,255,255,.12);
  --text:     #e9ebf1;
  --muted:    #8b92a5;
  --faint:    #5a6070;
  --accent:   #c9f24a;
  --accent-2: #a6d62b;
  --accent-ink: #101400;
  --sky:      #7dd3fc;
  --warn:     #fbbf24;
  --danger:   #fb7185;
  --radius:   14px;
  --radius-s: 9px;
  --shadow:   0 1px 0 rgba(255,255,255,.04) inset, 0 20px 60px -20px rgba(0,0,0,.7);
  --font:     "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:     "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease:     cubic-bezier(.2,.7,.2,1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
code, pre, .mono { font-family: var(--mono); font-size: .86em; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.02em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82em; }
.center { text-align: center; }
.fine { color: var(--faint); font-size: .82em; }

/* --- Ambient glow -------------------------------------------------------- */
.glow {
  position: fixed; inset: auto; pointer-events: none; z-index: 0;
  width: 60vmax; height: 60vmax; border-radius: 50%;
  filter: blur(90px); opacity: .28;
  animation: drift 24s var(--ease) infinite alternate;
}
.glow-a { top: -25vmax; left: -15vmax; background: radial-gradient(closest-side, var(--accent), transparent 70%); }
.glow-b { bottom: -30vmax; right: -20vmax; background: radial-gradient(closest-side, #3b82f6, transparent 70%); animation-delay: -12s; opacity: .16; }
@keyframes drift { from { transform: translate(0,0) scale(1); } to { transform: translate(6vmax, 4vmax) scale(1.12); } }

.view { position: relative; z-index: 1; }

/* --- Entrance ------------------------------------------------------------ */
.rise { animation: rise .7s var(--ease) both; animation-delay: var(--delay, 0s); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
  .glow { animation: none; }
  * { transition: none !important; }
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  padding: .55em 1.05em; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: .92em;
  transition: transform .18s var(--ease), background .18s, border-color .18s, box-shadow .18s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.2); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-accent {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 0 0 0 rgba(201,242,74,0);
}
.btn-accent:hover { background: #d6f95f; box-shadow: 0 8px 30px -8px rgba(201,242,74,.55); }
.btn-ghost { background: transparent; }
.btn-lg { padding: .8em 1.4em; font-size: 1em; }
.btn-block { width: 100%; }
.btn-danger { color: var(--danger); border-color: rgba(251,113,133,.35); }
.btn-danger:hover { background: rgba(251,113,133,.08); }
.btn-sm { padding: .3em .7em; font-size: .8em; }

/* --- Wordmark ------------------------------------------------------------ */
.wordmark { display: inline-flex; align-items: center; font-weight: 600; letter-spacing: -.01em; font-size: 1.05em; }
.wordmark b { font-weight: 800; }
.wordmark.small { font-size: .95em; }
/* The gap lives on the mark, not on the flex container: `common` and `<b>grounds</b>`
   are two flex items, and a container gap would split the word. */
.mark { width: 22px; height: 22px; border-radius: 6px; background: var(--ink-2); position: relative; border: 1px solid var(--line-2); margin-right: .55em; flex: none; }
.mark::before, .mark::after {
  content: ""; position: absolute; top: 50%; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); transform: translateY(-50%);
}
.mark::before { left: 4px; }
.mark::after { left: 9px; opacity: .55; }

/* ==========================================================================
   Landing
   ========================================================================== */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1120px; margin: 0 auto; padding: 22px 28px;
}
.nav-links { display: flex; align-items: center; gap: 22px; font-weight: 500; color: var(--muted); }
.nav-links a:hover { color: var(--text); }
.nav-links .btn { color: var(--accent-ink); }

.hero {
  max-width: 1120px; margin: 40px auto 0; padding: 0 28px;
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 48px; align-items: center;
  /* Capped: on a tall or portrait display 72vh alone opens a canyon
     between the nav and the headline. */
  min-height: min(72vh, 720px);
}
.eyebrow { color: var(--accent); font-weight: 600; letter-spacing: .12em; text-transform: uppercase; font-size: .72em; margin-bottom: 18px; }
.hero h1 { font-size: clamp(2.6rem, 6vw, 4.6rem); line-height: 1.02; letter-spacing: -.035em; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--accent), #d9ff7a 60%, var(--sky)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { margin-top: 22px; font-size: 1.15em; color: var(--muted); max-width: 46ch; }
.cta { display: flex; gap: 12px; margin-top: 30px; flex-wrap: wrap; }
.hero .fine { margin-top: 18px; }

.hero-card {
  background: linear-gradient(180deg, var(--surface), var(--ink-2));
  border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 18px 18px; position: relative;
  transform: rotate(-1deg);
  transition: transform .5s var(--ease);
}
.hero-card:hover { transform: rotate(0deg) translateY(-3px); }
.card-head { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.card-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); }
.card-head .dot:first-child { background: #fb7185; opacity: .7; }
.card-head .dot:nth-child(2) { background: #fbbf24; opacity: .7; }
.card-head .dot:nth-child(3) { background: #34d399; opacity: .7; }
.card-title { margin-left: auto; font-family: var(--mono); font-size: .78em; color: var(--faint); }
.card-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .86em; }
.card-foot em { color: var(--text); font-style: normal; font-weight: 600; }

.pillars {
  max-width: 1120px; margin: 90px auto 0; padding: 0 28px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px;
}
.pillar {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px 24px; transition: border-color .2s, transform .3s var(--ease);
}
.pillar:hover { border-color: var(--line-2); transform: translateY(-3px); }
.pillar-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--sky); margin-bottom: 18px; }
.pillar-icon.accent { color: var(--accent); }
.pillar-icon svg { width: 22px; height: 22px; }
.pillar h3 { font-size: 1.15em; margin-bottom: 8px; }
.pillar p { color: var(--muted); font-size: .95em; }

.how { max-width: 1120px; margin: 110px auto 0; padding: 0 28px; }
.how h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin-bottom: 30px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.step { position: relative; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.step .n { position: absolute; top: 18px; right: 20px; font-family: var(--mono); color: var(--faint); font-size: .8em; }
.step h4 { font-size: 1.02em; margin-bottom: 12px; }
.step pre { margin: 0 0 12px; padding: 12px 14px; background: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-s); overflow-x: auto; color: #d7dbe6; font-size: .8em; line-height: 1.5; }
.step p { color: var(--muted); font-size: .92em; }

/* --- Downloads ----------------------------------------------------------- */
.downloads { max-width: 1120px; margin: 110px auto 0; padding: 0 28px; }
.dl-head { margin-bottom: 26px; }
.dl-head h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin-bottom: 8px; }
.dl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

.dl-card {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; transition: border-color .2s, transform .3s var(--ease);
}
.dl-card:hover { border-color: var(--line-2); transform: translateY(-3px); }
/* The platform the visitor is actually on, picked out so they do not have to
   read three cards to find their own. */
.dl-card.yours { border-color: rgba(201,242,74,.45); background: linear-gradient(180deg, rgba(201,242,74,.05), var(--ink-2)); }
.dl-card.yours::after {
  content: "your platform"; position: absolute; top: 16px; right: 18px;
  font-size: .68em; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
.dl-card.absent { opacity: .72; }

.dl-os { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05em; }
.dl-os svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.dl-arch { font-family: var(--mono); font-size: .78em; color: var(--faint); }
.dl-size { font-size: .84em; color: var(--muted); font-variant-numeric: tabular-nums; }
.dl-card .btn { align-self: flex-start; margin-top: 4px; }
.dl-why { font-size: .86em; color: var(--muted); }
.dl-hint { font-family: var(--mono); font-size: .74em; color: var(--faint); word-break: break-all; line-height: 1.6; }
.dl-sum {
  font-family: var(--mono); font-size: .7em; color: var(--faint);
  word-break: break-all; padding-top: 10px; border-top: 1px solid var(--line);
}
.dl-sum b { color: var(--muted); font-weight: 500; }

.dl-source { margin-top: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--ink-2); }
.dl-source summary { padding: 16px 22px; cursor: pointer; font-weight: 600; font-size: .95em; list-style: none; }
.dl-source summary::-webkit-details-marker { display: none; }
.dl-source summary::before { content: "+ "; color: var(--accent); font-weight: 700; }
.dl-source[open] summary::before { content: "- "; }
.dl-source > p, .dl-source > pre { margin: 0 22px 18px; }
.dl-source pre { padding: 14px 16px; background: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-s); overflow-x: auto; font-size: .8em; line-height: 1.6; color: #d7dbe6; }

.foot { max-width: 1120px; margin: 90px auto 40px; padding: 26px 28px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .9em; }

/* ==========================================================================
   Badges and timeline (shared by landing demo and the real history)
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; padding: .18em .6em; border-radius: 999px;
  font-size: .74em; font-weight: 600; letter-spacing: .02em; line-height: 1.5;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.kind { background: var(--surface-2); color: var(--muted); border-color: var(--line); font-family: var(--mono); font-weight: 500; }
.badge.conf.declared { background: var(--accent); color: var(--accent-ink); }
.badge.conf.direct   { background: rgba(255,255,255,.08); color: var(--text); border-color: var(--line-2); }
.badge.conf.inferred { background: transparent; color: var(--sky); border-color: rgba(125,211,252,.45); }
.badge.conf.unknown  { background: transparent; color: var(--warn); border: 1px dashed rgba(251,191,36,.5); }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.timeline li {
  position: relative; padding: 12px 14px 12px 22px; border-radius: var(--radius-s);
  background: var(--ink-2); border: 1px solid var(--line);
  transition: border-color .2s, background .2s;
}
.timeline li:hover { border-color: var(--line-2); background: var(--surface); }
.timeline li::before {
  content: ""; position: absolute; left: 9px; top: 18px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint);
}
.timeline li.declared::before { background: var(--accent); box-shadow: 0 0 0 4px rgba(201,242,74,.15); }
.timeline li.inferred::before { background: var(--sky); }
.timeline li.unknown::before  { background: var(--warn); }
.tl-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.who { font-weight: 600; font-size: .92em; }
.who.human { color: var(--muted); }
.when { margin-left: auto; color: var(--faint); font-size: .8em; font-variant-numeric: tabular-nums; }
.msg { margin-top: 6px; color: var(--muted); font-size: .92em; }
.paths { display: block; margin-top: 6px; color: var(--faint); font-size: .78em; }
.timeline.demo li { cursor: default; }
.tl-id { font-family: var(--mono); color: var(--faint); font-size: .78em; }

/* ==========================================================================
   Auth
   ========================================================================== */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 28px; gap: 28px; grid-auto-rows: max-content; align-content: center; }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 30px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.auth-card h2 { font-size: 1.5em; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: .86em; color: var(--muted); font-weight: 500; }
.auth-card input {
  padding: .7em .85em; border-radius: var(--radius-s); border: 1px solid var(--line-2);
  background: var(--ink); color: var(--text); font-size: 1rem;
  transition: border-color .15s, box-shadow .15s;
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201,242,74,.15); }
.error { color: var(--danger); font-size: .88em; padding: .6em .8em; background: rgba(251,113,133,.08); border-radius: var(--radius-s); }
.auth-card .center a { color: var(--accent); font-weight: 600; }

/* ==========================================================================
   App
   ========================================================================== */
#view-app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 12px 22px;
  border-bottom: 1px solid var(--line); background: rgba(10,12,16,.7); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 5;
}
.topbar-spacer { flex: 1; }
.account-chip {
  display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 6px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); transition: border-color .2s;
}
.account-chip:hover { border-color: var(--line-2); }
.chip-text { display: flex; flex-direction: column; line-height: 1.2; font-size: .86em; font-weight: 500; }
.ring { width: 30px; height: 30px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.5; }
.ring-bg { stroke: var(--line-2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset .8s var(--ease); }

.app-body { flex: 1; display: grid; grid-template-columns: 260px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--line); padding: 18px 12px; background: var(--ink-2); }
.side-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 10px 10px; font-size: .78em; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ws-list li a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border-radius: var(--radius-s); color: var(--text);
  transition: background .15s;
}
.ws-list li a:hover { background: var(--surface); }
.ws-list li a.active { background: var(--surface-2); }
.ws-list .ws-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-list .ws-n { font-family: var(--mono); font-size: .75em; color: var(--faint); }
.side-hint { padding: 12px 10px; line-height: 1.6; }
.side-hint code { display: block; margin-top: 6px; color: var(--muted); white-space: pre-wrap; word-break: break-all; }

.content { padding: 26px 30px; min-width: 0; overflow: auto; }
.empty-state { display: grid; place-items: center; min-height: 40vh; }
.ws-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.ws-head h2 { font-size: 1.4em; font-family: var(--mono); font-weight: 600; }
.tabs { margin-left: auto; display: flex; gap: 4px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tabs a { padding: .35em .95em; border-radius: 999px; font-size: .88em; font-weight: 500; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.tabs a.active { background: var(--surface-2); color: var(--text); }

.files-split { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: 18px; min-height: 50vh; }
.tree { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; overflow: auto; font-size: .9em; }
.tree ul { padding-left: 16px; }
.tree li { list-style: none; }
.tree .row {
  display: flex; align-items: center; gap: 7px; padding: 4px 8px; border-radius: 6px; cursor: pointer;
  color: var(--muted); user-select: none; white-space: nowrap;
}
.tree .row:hover { background: var(--surface); color: var(--text); }
.tree .row.active { background: var(--surface-2); color: var(--text); }
.tree .row .chev { width: 10px; display: inline-block; color: var(--faint); font-size: .75em; transition: transform .15s; }
.tree .row.open .chev { transform: rotate(90deg); }
.tree .row .ico { width: 14px; height: 14px; flex: none; opacity: .8; }
.tree .row .name { font-family: var(--mono); font-size: .92em; }
.tree .row .size { margin-left: auto; color: var(--faint); font-size: .75em; font-variant-numeric: tabular-nums; }
.tree .row.exec .name::after { content: "*"; color: var(--accent); }

.file-pane { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.file-pane > p { padding: 20px; }
.file-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: .82em; color: var(--muted); }
.file-head .size { margin-left: auto; color: var(--faint); }
.file-body { margin: 0; padding: 16px; overflow: auto; font-size: .82em; line-height: 1.55; color: #d7dbe6; tab-size: 4; flex: 1; max-height: 70vh; }
.file-body .ln { display: inline-block; width: 3.5em; color: var(--faint); user-select: none; text-align: right; padding-right: 1.2em; }
.file-binary { padding: 40px 20px; text-align: center; color: var(--muted); }

.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; max-width: 900px; }
.card { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card.span { grid-column: 1 / -1; }
.card h4 { font-size: .8em; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.card .btn { margin-top: 14px; }
.quota-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.quota-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 999px; transition: width .9s var(--ease); }
.quota-fill.warn { background: linear-gradient(90deg, #f59e0b, var(--warn)); }
.quota-fill.full { background: linear-gradient(90deg, #e11d48, var(--danger)); }
.quota-text { margin-top: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.quota-text .muted { font-weight: 400; }
.token-list li { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-top: 1px solid var(--line); }
.token-list li:first-child { border-top: 0; }
.token-list .tok { font-family: var(--mono); font-size: .9em; }
.token-list .lbl { color: var(--muted); font-size: .86em; }
.token-list .used { margin-left: auto; color: var(--faint); font-size: .8em; }

/* --- Toast --------------------------------------------------------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 20;
  padding: .7em 1.1em; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line-2);
  font-size: .9em; box-shadow: var(--shadow); animation: rise .3s var(--ease);
}
.toast.err { border-color: rgba(251,113,133,.4); color: var(--danger); }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; min-height: auto; margin-top: 20px; }
  .hero-card { transform: none; }
  .pillars, .steps { grid-template-columns: 1fr; }
  .app-body { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .files-split { grid-template-columns: 1fr; }
  .account-grid { grid-template-columns: 1fr; }
  .nav-links a:not(.btn) { display: none; }
}
