/* Playground shell — everything every project shares.
 *
 * Design tokens, the reset, and the project bar. A project's own stylesheet is loaded
 * when it mounts and removed when it leaves, so two projects may use the same class
 * names without colliding; only these rules are present for all of them.
 */

/* Cortex navigation shell — sidebar + tabs. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --rail-bg: #14161c;
  --rail-fg: #9aa1ae;
  --rail-fg-strong: #e8eaee;
  --rail-hover: rgba(255, 255, 255, .05);
  --rail-sel-bg: rgba(255, 255, 255, .08);
  --rail-line: rgba(255, 255, 255, .08);
  --rail-active-bg: var(--accent-soft);
  --rail-active-fg: #b6abff;
  --rail-avatar-bg: #3a4050;
  --rail-edge: transparent;
  --accent: #6d5cf5;
  --accent-soft: rgba(109, 92, 245, .16);
  --text: #171a20;
  --muted: #676e7d;
  --line: #e3e6ec;
  --radius: 10px;
  --rail-w: 68px;
  --topbar-h: 53px;
  --control-h: 34px;   /* every control in the header stands the same height */
  --warn: #b4690e;
  --warn-soft: rgba(180, 105, 14, .14);
}

/* Resolved by app/theme.js and always written to data-theme, which is why the dark
   values appear once here rather than twice — a media query for the system and a copy
   of it for an explicit choice. */
:root[data-theme="dark"] {
  --bg: #0e1014;
  --surface: #171a21;
  --rail-bg: #0a0c10;
  --text: #e9ebf0;
  --muted: #949cad;
  --line: #262b35;
  --accent: #8f81ff;
  --accent-soft: rgba(143, 129, 255, .18);
  --warn: #e0a458;
  --warn-soft: rgba(224, 164, 88, .16);
}

/* Set by the shell on .page, so the choice made in one project is still in force in the
   one it hands you to — and so a project re-rendering its own root cannot drop it. */
.rail-light .app, .app.rail-light {
  --rail-bg: var(--surface);
  --rail-fg: var(--muted);
  --rail-fg-strong: var(--text);
  --rail-hover: var(--bg);
  --rail-sel-bg: var(--line);
  --rail-line: var(--line);
  --rail-active-fg: var(--accent);
  /* --bg is barely distinguishable from the rail's own ground; the avatar needs a
     fill that actually reads as a disc. */
  --rail-avatar-bg: var(--line);
  --rail-edge: var(--line);
}
* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.icon { width: 20px; height: 20px; flex: none; }

/* Names in the markup for screen readers, on hover for everyone else. */
.vh {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------- project bar */

.topbar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}

.project-picker { position: relative; }
.project-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px; border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.project-btn:hover, .project-btn[aria-expanded="true"] {
  background: var(--bg); border-color: var(--line);
}
.project-caret { width: 15px; height: 15px; color: var(--muted); transform: rotate(90deg); }

/* The shared project picker must work without any project stylesheet loaded. */
.popover.popover-project {
  position: absolute; top: calc(100% + 8px); bottom: auto; left: 0;
  width: 268px; max-width: calc(100vw - 32px); max-height: 62vh;
  overflow-y: auto; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .28); z-index: 20;
}
.popover-project .pop-label { margin: 0; font-size: 12px; font-weight: 650; }
/* Negative margins cancel the popover's own 12px padding, so the rule meets both inner
   edges rather than floating inset from them. */
.popover-project .pop-divider { height: 1px; background: var(--line); margin: 8px -12px; }
.project-option {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  text-decoration: none; color: var(--text); font-size: 13px; font-weight: 550;
}
.project-option + .project-option { margin-top: 2px; }
.project-option:hover { background: var(--bg); }
.project-option.is-active { background: var(--accent-soft); color: var(--accent); }
.project-check { width: 16px; height: 16px; margin-left: auto; color: var(--accent); }
.project-empty {
  margin: 0; padding: 14px 8px; text-align: center;
  font-size: 12px; color: var(--muted);
}

/* The page frame: header, then whatever the project renders. */
.page { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 100vh; }

/* The slot a project fills with its own controls. */
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* The project styles this element itself — the shell must not out-specify it with an id
   selector, so nothing here sets display, and the row simply stretches to fill. */
#project-root { min-width: 0; min-height: 0; }

.project-loading {
  padding: 60px 20px; text-align: center; color: var(--muted); font-size: 13px;
}

/* ---------------------------------------------------------------- variants
 * A study offers layouts to compare; the shell owns how that choice is presented, so
 * every study offers it the same way and in the same place. A project declares its
 * variants through ctx.setVariants and never draws the button or the panel itself.
 */
/* One box for both header controls, so the theme button cannot drift out of step with
   the one beside it. Height is stated rather than left to padding and line-height, which
   is what let them differ by 4px the first time. The theme button is that box, squared. */
.variant-btn, .theme-btn {
  display: flex; align-items: center; gap: 8px;
  height: var(--control-h); padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 550; cursor: pointer;
}
.variant-btn:hover, .variant-btn[aria-expanded="true"] { background: var(--bg); }
.variant-btn-icon { width: 15px; height: 15px; color: var(--muted); }

.theme-btn { width: var(--control-h); padding: 0; justify-content: center; }
.theme-btn:hover { background: var(--bg); }
.theme-btn-icon { width: 17px; height: 17px; color: var(--muted); }
.theme-btn:hover .theme-btn-icon { color: var(--text); }

.scrim { position: fixed; inset: 0; background: rgba(15, 18, 25, .3); z-index: 50; }

.slideover {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 51;
  width: min(360px, 88vw); display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -20px 0 44px rgba(0, 0, 0, .16);
  animation: slideover-in .18s ease;
}
@keyframes slideover-in { from { transform: translateX(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .slideover { animation: none; } }

.slideover-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 14px; border-bottom: 1px solid var(--line);
}
.slideover-head h2 { margin: 0; font-size: 15px; }
.slideover-close {
  display: grid; place-items: center; width: 30px; height: 30px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.slideover-close:hover { background: var(--bg); color: var(--text); }
.slideover-close .icon { width: 16px; height: 16px; }

.slideover-body { display: flex; flex-direction: column; gap: 8px; padding: 16px; overflow-y: auto; }

.variant-card {
  display: flex; flex-direction: column; gap: 5px;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.variant-card:hover { background: var(--bg); }
.variant-card.is-active { border-color: var(--accent); background: var(--accent-soft); }
.variant-card-head {
  display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14px;
}
.variant-card.is-active .variant-card-head { color: var(--accent); }
.variant-card-check { width: 16px; height: 16px; margin-left: auto; color: var(--accent); }
.variant-card-desc { font-size: 12.5px; line-height: 1.5; color: var(--muted); }

/* What the variant costs, kept visually secondary to what it is. */
.variant-card-trade {
  margin-top: 4px; padding-top: 9px; border-top: 1px solid var(--line);
  font-size: 12px; line-height: 1.5; color: var(--muted);
}
.variant-card.is-active .variant-card-trade { border-top-color: rgba(109, 92, 245, .25); }
.variant-card-trade-label {
  display: block; margin-bottom: 2px;
  font-size: 10.5px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--warn);
}

/* -------------------------------------------------------------------- rail
 * The icon rail is the app's own chrome, not one study's. Both the navigation study and
 * the admin area inside it draw the same one, so it is defined once here and themed by
 * the --rail-* tokens above. What goes in it stays each project's business.
 */
.rail {
  display: flex; flex-direction: column; align-items: center;
  background: var(--rail-bg); color: var(--rail-fg);
  padding: 14px 10px; gap: 6px;
  min-height: 0;
  border-right: 1px solid var(--rail-edge);
}

/* Names live in the markup for screen readers and appear on hover for everyone else. */
.vh {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  padding: 5px 9px; border-radius: 7px;
  background: var(--text); color: var(--surface);
  font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .12s ease;
  z-index: 60;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; }

.rail-item {
  display: grid; place-items: center;
  width: 48px; height: 48px; padding: 0; border-radius: 12px;
  color: var(--rail-fg); text-decoration: none;
}
.rail-item:hover { background: var(--rail-hover); color: var(--rail-fg-strong); }
.rail-item.is-active { background: var(--rail-active-bg); color: var(--rail-active-fg); }
.rail-item.is-active .icon { color: var(--rail-active-fg); }

.rail-glyph { display: grid; place-items: center; }

/* zone 1 — app identity */
.rail-identity { padding: 4px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #3fc6d8);
  color: #fff; font-weight: 700; font-size: 14px;
}
.brand-name { display: none; }

.rail-utility {
  margin-top: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}

/* Admin is the last thing in the rail, so it sits at the foot of it rather than 22px
   below whatever happens to precede it — which differs by variant. */
.rail-admin { margin-top: auto; padding-top: 22px; }

/* A persistent route back to the project index. The picker still owns project switching. */
.topbar-left { display: flex; align-items: center; gap: 18px; min-width: 0; }
.home-link { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600; white-space: nowrap; }
.home-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.home-mark { display: block; width: 32px; height: 32px; flex: none; }
.topbar-home { --topbar-h: 64px; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.topbar-home .topbar-left { grid-column: 2; }
.topbar-home .topbar-right { grid-column: 3; justify-self: end; }
@media (max-width: 620px) {
  .topbar-left { gap: 6px; }
  .home-wordmark { display: none; }
  .topbar-left:not(:has(.project-picker)) .home-wordmark { display: inline; }
  .project-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 420px) {
  .topbar-home { padding: 0 12px; gap: 10px; }
  .topbar-home .home-wordmark { font-size: 12px; }
}
