/*
 * Motif shell chrome. This is the Storybook-style DOM frame around the demos;
 * the demos themselves are canvas islands mounted in sandboxed iframes (Task 7).
 * Dark violet->cyan identity, shared with the VectoJS gallery redesign.
 */
:root {
  --void: #06070a;
  --ground: #0b0d12;
  --panel: #0f1218;
  --raised: #14171f;
  --raised-2: #1b1f29;
  --rule: rgba(255, 255, 255, 0.08);
  --rule-bright: rgba(255, 255, 255, 0.16);
  --text: #f4f6f8;
  --text-dim: #9aa3b0;
  --text-faint: #5a6472;
  --brand-a: #7c5cff;
  --brand-b: #22d3ee;
  --accent: #e0a458;
  --ok: #22c55e;
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --font-mono:
    ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

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

html,
body {
  height: 100%;
  background: var(--void);
  color: var(--text);
  font-family: var(--font-sans);
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.shell {
  display: grid;
  grid-template-columns: 248px 1fr 420px;
  grid-template-rows: 52px 1fr;
  grid-template-areas:
    "top top  top"
    "nav main code";
  height: 100vh;
}
.shell > .topbar {
  grid-area: top;
}
.shell > .left-nav {
  grid-area: nav;
}
.shell > .center-stage {
  grid-area: main;
}
.shell > .code-panel {
  grid-area: code;
}
/* Drawer toggle: a hidden checkbox (in Shell, before .left-nav) driven by the
   topbar hamburger <label>. Only surfaces < 920px; on desktop the nav is a
   static grid column and the toggle is display:none. */
.nav-toggle,
.nav-toggle-btn {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: linear-gradient(180deg, var(--ground), var(--void));
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  box-shadow: 0 4px 16px rgba(124, 92, 255, 0.4);
}
.brand-name {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.5px;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  margin-left: 2px;
}
.top-search {
  margin-left: 18px;
  flex: 0 0 260px;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 9px;
  padding: 7px 12px;
  color: var(--text-faint);
  font-size: 12.5px;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: text;
}
.top-search kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--raised-2);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 1px 6px;
}
.top-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.top-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 4px 11px;
}
.top-pill.gpu {
  color: var(--ok);
  border-color: rgba(34, 197, 94, 0.3);
}

.left-nav {
  background: var(--ground);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  padding: 16px 10px;
}
.nav-group {
  margin-bottom: 18px;
}
.nav-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-faint);
  padding: 0 10px 7px;
  display: flex;
  align-items: center;
}
.nav-label .count {
  margin-left: auto;
  opacity: 0.6;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
}
.nav-item:hover {
  background: var(--raised);
  color: var(--text);
}
.nav-item.active {
  background: linear-gradient(90deg, rgba(124, 92, 255, 0.16), transparent);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--brand-a);
}
.nav-item .chip {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--raised-2);
  color: var(--text-faint);
}

.center-stage {
  background:
    radial-gradient(
      circle at 70% 20%,
      rgba(124, 92, 255, 0.07),
      transparent 45%
    ),
    var(--void);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stage-head {
  padding: 20px 26px 0;
}
.stage-title {
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -0.5px;
}
.stage-desc {
  color: var(--text-dim);
  font-size: 13.5px;
  margin-top: 6px;
  max-width: 560px;
  line-height: 1.5;
}
.stage-tabs {
  display: flex;
  gap: 4px;
  margin-top: 16px;
  border-bottom: 1px solid var(--rule);
}
.stage-tab {
  font-size: 12.5px;
  padding: 8px 13px;
  color: var(--text-faint);
  border-bottom: 2px solid transparent;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
  cursor: pointer;
}
.stage-tab.active {
  color: var(--text);
  border-bottom-color: var(--brand-a);
}
.viewport {
  flex: 1;
  margin: 22px 26px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: repeating-conic-gradient(
      rgba(255, 255, 255, 0.02) 0% 25%,
      transparent 0% 50%
    )
    50% / 22px 22px;
  position: relative;
  overflow: hidden;
}
.demo-frame {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  border: 0;
  background: transparent;
}
.viewport-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(6, 7, 10, 0.72);
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}
.viewport-status[hidden] {
  display: none;
}
.vs-spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--rule);
  border-top-color: var(--brand-a);
  border-radius: 50%;
  animation: vs-spin 0.8s linear infinite;
}
.vs-spinner[hidden] {
  display: none;
}
@keyframes vs-spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .vs-spinner {
    animation: none;
  }
}
.vs-msg {
  max-width: 40ch;
  margin: 0;
}
.vs-retry {
  padding: 7px 16px;
  border: 1px solid var(--rule-bright, rgba(255, 255, 255, 0.16));
  border-radius: 8px;
  background: transparent;
  color: var(--brand-b);
  font: inherit;
  cursor: pointer;
}
.vs-retry[hidden] {
  display: none;
}
.viewport-note {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 11px;
  color: var(--text-faint, #5a6472);
  background: rgba(6, 7, 10, 0.6);
  padding: 3px 9px;
  border-radius: 6px;
}
.viewport-note[hidden] {
  display: none;
}
.viewport-toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 0 26px 16px;
}
.vp-run {
  margin-left: auto;
  color: var(--brand-b);
  border-color: color-mix(in srgb, var(--brand-b) 40%, transparent);
}
.vp {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 4px 10px;
  background: none;
  cursor: pointer;
}
.vp.active {
  color: var(--text);
  border-color: var(--rule-bright);
}

.code-panel {
  background: var(--panel);
  border-left: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.code-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
}
.code-tab {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 5px 11px;
  border-radius: 7px 7px 0 0;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
}
.code-tab.active {
  background: var(--raised);
  color: var(--text);
}
.code-copy {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-dim);
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 5px 11px;
  background: none;
  font-family: inherit;
  cursor: pointer;
}
.code-run {
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  border: none;
  border-radius: 7px;
  padding: 5px 13px;
  cursor: pointer;
}
.code-body {
  flex: 1;
  overflow: auto;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-dim);
  white-space: pre;
}
.code-copy.copied {
  color: var(--ok);
  border-color: var(--ok);
}
.code-editor {
  height: 100%;
}
.code-editor .cm-editor {
  height: 100%;
  font-size: 12.5px;
  background: transparent;
}
.code-editor .cm-scroller {
  font-family: var(--font-mono);
}
.code-license {
  margin-left: auto;
  opacity: 0.7;
}
.code-panel .code-body {
  padding: 0;
  white-space: normal;
}

.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 100;
}
.search-overlay[hidden] {
  display: none;
}
.search-modal {
  width: min(560px, 92vw);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.search-input {
  width: 100%;
  padding: 16px 18px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--rule);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
.search-results {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 50vh;
  overflow: auto;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.search-result.active,
.search-result:hover {
  background: rgba(124, 92, 255, 0.14);
}
.sr-title {
  color: var(--text);
  font-size: 14px;
}
.sr-cat {
  margin-left: auto;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
}
.search-empty {
  padding: 16px 14px;
  color: var(--text-faint, #5a6472);
  font-size: 13px;
  list-style: none;
}

@media (max-width: 1180px) {
  .shell {
    grid-template-columns: 220px 1fr;
    grid-template-rows: 52px 1fr 40vh;
    grid-template-areas:
      "top  top"
      "nav  main"
      "nav  code";
  }
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr 42vh;
    grid-template-areas:
      "top"
      "main"
      "code";
  }
  .nav-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--rule);
    border-radius: 9px;
    background: var(--raised);
    color: var(--text);
    cursor: pointer;
    font-size: 15px;
  }
  .shell > .left-nav {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: 264px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 24px rgba(0, 0, 0, 0.4);
  }
  .nav-toggle:checked ~ .left-nav {
    transform: translateX(0);
  }
  .nav-scrim {
    display: none;
    position: fixed;
    inset: 52px 0 0 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 30;
  }
  .nav-toggle:checked ~ .nav-scrim {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shell > .left-nav {
    transition: none;
  }
}
