/* prepstack-app-shell v0.5.0 */
:root,
:root[data-prepstack-theme="light"] {
  color-scheme: light;
  --ps-page: #f7f8fb;
  --ps-surface: #ffffff;
  --ps-surface-soft: #f1f3f7;
  --ps-surface-raised: #ffffff;
  --ps-ink: #171b26;
  --ps-muted: #626b7c;
  --ps-line: #dfe3eb;
  --ps-line-strong: #c8ceda;
  --ps-accent: #4f46e5;
  --ps-accent-hover: #4338ca;
  --ps-accent-soft: #eef0ff;
  --ps-violet: #6d5bd0;
  --ps-success: #16856a;
  --ps-warning: #a35c00;
  --ps-danger: #b83a4b;
  --ps-code: #111521;
  --ps-code-ink: #edf3ff;
  --ps-shadow-sm: 0 1px 2px rgb(20 26 40 / 6%);
  --ps-shadow: 0 .8rem 2.5rem rgb(20 26 40 / 10%);
  --ps-radius-sm: .5rem;
  --ps-radius: .75rem;
  --ps-radius-lg: 1rem;
  --page: var(--ps-page);
  --background: var(--ps-page);
  --surface: var(--ps-surface);
  --surface-soft: var(--ps-surface-soft);
  --ink: var(--ps-ink);
  --foreground: var(--ps-ink);
  --muted: var(--ps-muted);
  --muted-foreground: var(--ps-muted);
  --line: var(--ps-line);
  --border: var(--ps-line);
  --accent: var(--ps-accent);
  --accent-soft: var(--ps-accent-soft);
  --primary: var(--ps-accent);
  --card: var(--ps-surface);
  --code: var(--ps-code);
  --code-ink: var(--ps-code-ink);
  --radius: var(--ps-radius);
}

:root[data-prepstack-theme="dark"] {
  color-scheme: dark;
  --ps-page: #0d0f14;
  --ps-surface: #151820;
  --ps-surface-soft: #1d212b;
  --ps-surface-raised: #1a1e27;
  --ps-ink: #eef0f5;
  --ps-muted: #a6adbb;
  --ps-line: #303641;
  --ps-line-strong: #454c5a;
  --ps-accent: #a8a4ff;
  --ps-accent-hover: #c2bfff;
  --ps-accent-soft: #28264a;
  --ps-violet: #c1b8ff;
  --ps-success: #69d7b7;
  --ps-warning: #f0bd70;
  --ps-danger: #ff94a3;
  --ps-code: #090b10;
  --ps-code-ink: #eff4ff;
  --ps-shadow-sm: 0 1px 2px rgb(0 0 0 / 24%);
  --ps-shadow: 0 .8rem 2.5rem rgb(0 0 0 / 32%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-prepstack-theme="light"]) {
    color-scheme: dark;
    --ps-page: #0d0f14;
    --ps-surface: #151820;
    --ps-surface-soft: #1d212b;
    --ps-surface-raised: #1a1e27;
    --ps-ink: #eef0f5;
    --ps-muted: #a6adbb;
    --ps-line: #303641;
    --ps-line-strong: #454c5a;
    --ps-accent: #a8a4ff;
    --ps-accent-hover: #c2bfff;
    --ps-accent-soft: #28264a;
    --ps-violet: #c1b8ff;
    --ps-success: #69d7b7;
    --ps-warning: #f0bd70;
    --ps-danger: #ff94a3;
    --ps-code: #090b10;
    --ps-code-ink: #eff4ff;
    --ps-shadow-sm: 0 1px 2px rgb(0 0 0 / 24%);
    --ps-shadow: 0 .8rem 2.5rem rgb(0 0 0 / 32%);
  }
}

html { background: var(--ps-page); }
html { scroll-behavior: smooth; }
body.ps-embedded-view {
  min-width: 0;
  color: var(--ps-ink);
  background: var(--ps-page);
}
body.ps-shell-active {
  display: block !important;
  min-width: 20rem;
  margin: 0 !important;
  padding: 0 !important;
  color: var(--ps-ink);
  background: var(--ps-page);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", "PingFang SC", sans-serif;
  font-feature-settings: "kern" 1, "liga" 1;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.ps-shell-active,
body.ps-shell-active *,
body.ps-shell-active *::before,
body.ps-shell-active *::after { box-sizing: border-box; }

body.ps-shell-active a { color: var(--ps-accent); text-underline-offset: .18em; }
body.ps-shell-active a:hover { color: var(--ps-accent-hover); }
body.ps-shell-active h1,
body.ps-shell-active h2,
body.ps-shell-active h3 { text-wrap: balance; }
body.ps-shell-active button,
body.ps-shell-active input,
body.ps-shell-active select,
body.ps-shell-active textarea { font: inherit; }

.ps-skip-link,
body.ps-shell-active > .skip-link {
  position: fixed;
  z-index: 100;
  inset: .65rem auto auto .65rem;
  padding: .55rem .72rem;
  border-radius: var(--ps-radius-sm);
  color: var(--ps-surface) !important;
  background: var(--ps-ink);
  text-decoration: none;
  transform: translateY(-180%);
}
.ps-skip-link:focus,
body.ps-shell-active > .skip-link:focus { transform: translateY(0); }

body.ps-shell-active :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--ps-accent) 72%, transparent);
  outline-offset: 2px;
}

.ps-app-shell {
  display: grid;
  width: 100%;
  min-height: 100vh;
  grid-template-columns: 13rem 16rem minmax(0, 1fr);
  align-items: start;
}

.ps-app-shell.ps-shell-no-context {
  grid-template-columns: minmax(11.5rem, 13.5rem) minmax(0, 1fr);
}

.ps-global-rail,
.ps-context-pane {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  overflow: auto;
  border-inline-end: 1px solid var(--ps-line);
  background: var(--ps-surface);
}

.ps-global-rail {
  display: flex;
  padding: 1rem .75rem;
  flex-direction: column;
  gap: 1rem;
}

.ps-brand {
  display: grid;
  gap: .12rem;
  padding: .4rem .55rem .85rem;
  color: var(--ps-ink) !important;
  text-decoration: none;
}

.ps-brand strong { font-size: 1.08rem; letter-spacing: -.025em; line-height: 1.1; }
.ps-brand small { color: var(--ps-violet); font-size: .69rem; font-weight: 700; letter-spacing: .015em; }
.ps-global-links { display: grid; gap: .2rem; }
.ps-global-link {
  display: grid;
  min-width: 0;
  min-height: 2.75rem;
  padding: .56rem .62rem;
  grid-template-columns: 1.55rem minmax(0, 1fr);
  align-items: center;
  gap: .42rem;
  border-radius: .6rem;
  color: var(--ps-muted) !important;
  font-size: .84rem;
  font-weight: 650;
  text-decoration: none;
}
.ps-global-link:hover { color: var(--ps-ink) !important; background: var(--ps-surface-soft); }
.ps-global-link[aria-current="page"] {
  color: var(--ps-accent) !important;
  background: var(--ps-accent-soft);
  box-shadow: inset 3px 0 0 var(--ps-accent);
}
.ps-global-icon { color: var(--ps-accent); text-align: center; }
.ps-global-icon svg { display: block; width: 1.05rem; height: 1.05rem; margin: auto; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.ps-rail-actions {
  display: grid;
  gap: .4rem;
  margin-top: auto;
}
.ps-notes-launcher {
  display: grid;
  min-height: 2.65rem;
  padding: .5rem .62rem;
  grid-template-columns: 1.55rem minmax(0, 1fr);
  align-items: center;
  gap: .42rem;
  border: 1px solid var(--ps-line);
  border-radius: .6rem;
  color: var(--ps-ink);
  background: var(--ps-surface);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 650;
  text-align: start;
}
.ps-notes-launcher:hover { border-color: var(--ps-line-strong); background: var(--ps-surface-soft); }
.ps-notes-launcher-icon { color: var(--ps-accent); text-align: center; }
.ps-locale-link {
  display: inline-grid;
  min-height: 2.35rem;
  padding: .35rem .6rem;
  place-items: center;
  border: 1px solid var(--ps-line);
  border-radius: .55rem;
  color: var(--ps-muted) !important;
  background: var(--ps-surface);
  font-size: .72rem;
  font-weight: 800;
  text-decoration: none;
}
.ps-locale-link:hover { color: var(--ps-accent) !important; background: var(--ps-surface-soft); }

.ps-theme-control {
  display: grid;
  gap: .4rem;
  padding: .48rem;
  border: 1px solid var(--ps-line);
  border-radius: var(--ps-radius);
  background: var(--ps-surface-soft);
}
.ps-theme-control > span { color: var(--ps-muted); font-size: .67rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.ps-theme-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .2rem; }
.ps-theme-button {
  min-height: 2rem;
  padding: .3rem .22rem;
  border: 1px solid transparent;
  border-radius: .42rem;
  color: var(--ps-muted);
  background: transparent;
  cursor: pointer;
  font-size: .7rem !important;
  font-weight: 700;
}
.ps-theme-button[aria-pressed="true"] { border-color: var(--ps-line); color: var(--ps-ink); background: var(--ps-surface); box-shadow: 0 .15rem .45rem rgb(0 0 0 / 8%); }

.ps-context-pane { padding: .9rem .72rem; }
.ps-context-title { margin: .25rem .45rem .7rem; color: var(--ps-muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.ps-context-search { width: calc(100% - .2rem); min-height: 2.4rem; margin: 0 .1rem .65rem; padding: .48rem .62rem; border: 1px solid var(--ps-line); border-radius: var(--ps-radius-sm); color: var(--ps-ink); background: var(--ps-surface); }
.ps-context-search[hidden] { display: none; }
.ps-context-list { display: grid; gap: .1rem; margin: 0; padding: 0; list-style: none; }
.ps-context-link {
  display: block;
  padding: .5rem .58rem;
  border-radius: .5rem;
  color: var(--ps-muted) !important;
  font-size: .8rem;
  line-height: 1.35;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.ps-context-link:hover,
.ps-context-link.is-active { color: var(--ps-accent) !important; background: var(--ps-accent-soft); }
.ps-context-link[data-level="3"] { padding-inline-start: 1.25rem; font-size: .75rem; }

.ps-reading-pane {
  min-width: 0;
  min-height: 100vh;
  padding: clamp(.75rem, 1.6vw, 1.35rem);
  overflow-x: clip;
}
.ps-reading-pane > .page,
.ps-reading-pane > .collection-page,
.ps-reading-pane > .page-shell,
.ps-reading-pane > main {
  width: min(100%, 78rem);
  margin: 0 auto;
}
.ps-reading-pane.ps-reading-wide > .page,
.ps-reading-pane.ps-reading-wide > .collection-page,
.ps-reading-pane.ps-reading-wide > .page-shell,
.ps-reading-pane.ps-reading-wide > main { width: 100%; max-width: 92rem; }
.ps-reading-pane > .page,
.ps-reading-pane > .collection-page { padding-top: .5rem; }
.ps-reading-pane > .site-nav { display: none; }
.ps-reading-pane > iframe {
  display: block;
  width: 100%;
  max-width: none;
  min-height: calc(100vh - 3rem);
  margin: 0;
  border: 1px solid var(--ps-line);
  border-radius: var(--ps-radius-lg);
  background: var(--ps-surface);
  box-shadow: var(--ps-shadow-sm);
}

body.ps-shell-active .page > .document-header h1 { font-size: clamp(2rem, 4vw, 3rem); }
body.ps-shell-active .page > .document-header,
body.ps-shell-active .page > .prose { max-width: 67ch; }
body.ps-shell-active .hero h1 { font-size: clamp(2.75rem, 6vw, 4.6rem); }

body.ps-shell-active .prepstack-nav,
body.ps-shell-active .collection-toolbar,
body.ps-shell-active .card,
body.ps-shell-active .stat,
body.ps-shell-active .collection-card,
body.ps-shell-active .catalog-item,
body.ps-shell-active .candidate-card,
body.ps-shell-active .family-card,
body.ps-shell-active .feature-card,
body.ps-shell-active .pattern-card,
body.ps-shell-active .pro-panel {
  border-color: var(--ps-line);
  border-radius: var(--ps-radius);
  color: var(--ps-ink);
  background: var(--ps-surface);
  box-shadow: none;
}

body.ps-shell-active .stats { overflow: hidden; border: 1px solid var(--ps-line); border-radius: var(--ps-radius-lg); background: var(--ps-surface); }
body.ps-shell-active .stats .stat { border: 0; border-radius: 0; background: var(--ps-surface); }
body.ps-shell-active .stats .stat + .stat { border-inline-start: 1px solid var(--ps-line); }
body.ps-shell-active .stats .stat strong { color: var(--ps-ink); }
body.ps-shell-active .stats .stat span { color: var(--ps-muted); }

body.ps-shell-active input,
body.ps-shell-active select,
body.ps-shell-active textarea,
body.ps-shell-active button:not(.ps-theme-button) {
  border-color: var(--ps-line);
  border-radius: var(--ps-radius-sm);
  color: var(--ps-ink);
  background-color: var(--ps-surface);
}

body.ps-shell-active .worker-button.primary {
  border-color: transparent;
  color: #ffffff !important;
  background: var(--ps-accent);
}
body.ps-shell-active .worker-button.primary:hover { background: var(--ps-accent-hover); }
body.ps-shell-active .status-tab[aria-pressed="true"] {
  color: var(--ps-accent);
  background: var(--ps-accent-soft);
}

.ps-notes {
  width: min(68rem, calc(100vw - 2rem));
  max-height: min(50rem, calc(100dvh - 2rem));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--ps-line);
  border-radius: var(--ps-radius-lg);
  color: var(--ps-ink);
  background: var(--ps-surface);
  box-shadow: var(--ps-shadow);
}
.ps-notes::backdrop { background: rgb(10 14 24 / 48%); backdrop-filter: blur(3px); }
.ps-notes[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.ps-notes-header {
  display: flex;
  min-height: 4rem;
  padding: .85rem 1rem;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  border-bottom: 1px solid var(--ps-line);
}
.ps-notes-title-group { min-width: 0; }
.ps-notes-header h2 { margin: 0; font-size: 1.05rem; line-height: 1.2; }
.ps-notes-status { display: block; margin-top: .2rem; color: var(--ps-muted); font-size: .72rem; }
.ps-notes-close {
  display: inline-grid;
  width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  place-items: center;
  border: 1px solid var(--ps-line);
  border-radius: .55rem;
  color: var(--ps-muted);
  background: var(--ps-surface);
  cursor: pointer;
  font-size: 1.15rem;
}
.ps-notes-close:hover { color: var(--ps-ink); background: var(--ps-surface-soft); }
.ps-notes-grid {
  display: grid;
  min-height: 0;
  padding: 1rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  overflow: auto;
}
.ps-note-field { display: grid; min-width: 0; min-height: 0; gap: .42rem; }
.ps-note-field > span { color: var(--ps-muted); font-size: .7rem; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
.ps-notes textarea {
  width: 100%;
  min-height: 26rem;
  padding: .9rem;
  resize: none;
  border: 1px solid var(--ps-line);
  color: var(--ps-ink);
  background: var(--ps-surface-soft);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: .84rem;
  line-height: 1.55;
  tab-size: 4;
}
.ps-note-preview {
  min-height: 26rem;
  max-height: calc(100dvh - 9rem);
  padding: .9rem;
  overflow: auto;
  border: 1px solid var(--ps-line);
  border-radius: var(--ps-radius-sm);
  background: var(--ps-surface-soft);
  font-size: .88rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.ps-note-preview > :first-child { margin-top: 0; }
.ps-note-preview pre { overflow: auto; padding: .75rem; border-radius: .55rem; color: var(--ps-code-ink); background: var(--ps-code); }
.ps-note-preview code { font-family: "SFMono-Regular", Consolas, monospace; }

.syntax-keyword { color: #ff7ab2; font-weight: 650; }
.syntax-builtin { color: #82d2ff; }
.syntax-string { color: #a8e66b; }
.syntax-number { color: #d5a6ff; }
.syntax-comment { color: #8b98ad; font-style: italic; }
.syntax-operator { color: #ffd580; }
.syntax-function { color: #78dce8; font-weight: 650; }
.syntax-class { color: #ffd866; font-weight: 650; }
.syntax-call { color: #c7d4ff; }
.syntax-attribute { color: #b4e1ff; }
.syntax-self { color: #ffb86c; font-style: italic; }

@media (max-width: 72rem) {
  .ps-app-shell { grid-template-columns: 4.7rem minmax(13rem, 15rem) minmax(0, 1fr); }
  .ps-app-shell.ps-shell-no-context { grid-template-columns: 4.7rem minmax(0, 1fr); }
  .ps-brand { padding-inline: .25rem; text-align: center; }
  .ps-brand strong { font-size: .74rem; }
  .ps-brand small,
  .ps-global-label,
  .ps-notes-launcher-label { display: none; }
  .ps-global-link { grid-template-columns: 1fr; justify-items: center; padding-inline: .25rem; }
  .ps-notes-launcher { grid-template-columns: 1fr; justify-items: center; padding-inline: .25rem; }
  .ps-theme-control { padding: .35rem; }
  .ps-theme-control > span { display: none; }
  .ps-theme-buttons { grid-template-columns: 1fr; }
}

@media (max-width: 48rem) {
  .ps-app-shell,
  .ps-app-shell.ps-shell-no-context { display: block; }
  .ps-global-rail {
    position: fixed;
    z-index: 60;
    inset: auto 0 0;
    display: flex;
    width: 100%;
    height: calc(4.2rem + env(safe-area-inset-bottom));
    padding: .38rem .45rem calc(.38rem + env(safe-area-inset-bottom));
    overflow: hidden;
    flex-direction: row;
    align-items: center;
    gap: .3rem;
    border: 0;
    border-top: 1px solid var(--ps-line);
    background: color-mix(in srgb, var(--ps-surface) 94%, transparent);
    backdrop-filter: blur(16px);
  }
  .ps-brand { display: none; }
  .ps-global-links { display: grid; min-width: 0; flex: 1 1 auto; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .1rem; }
  .ps-global-link {
    min-width: 0;
    min-height: 3.35rem;
    padding: .35rem .2rem;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: .08rem;
    font-size: .66rem;
  }
  .ps-global-link[aria-current="page"] { box-shadow: inset 0 3px 0 var(--ps-accent); }
  .ps-global-label { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ps-rail-actions { display: flex; margin: 0; flex: 0 0 auto; align-items: center; gap: .2rem; }
  .ps-notes-launcher { width: 2.75rem; min-height: 2.75rem; grid-template-columns: 1fr; justify-items: center; padding: 0; }
  .ps-notes-launcher-label { display: none; }
  .ps-locale-link { min-width: 2.4rem; min-height: 2.4rem; padding: .2rem; }
  .ps-theme-control { display: block; padding: .18rem; flex: 0 0 auto; border: 0; background: transparent; }
  .ps-theme-buttons { display: block; }
  .ps-theme-button { display: none; min-width: 2.7rem; min-height: 2.4rem; padding-inline: .18rem; }
  .ps-theme-button[aria-pressed="true"] { display: block; }
  .ps-context-pane {
    position: static;
    width: 100%;
    height: auto;
    padding: .45rem .55rem;
    overflow-x: auto;
    overflow-y: hidden;
    border: 0;
    border-bottom: 1px solid var(--ps-line);
  }
  .ps-context-title,
  .ps-context-search { display: none; }
  .ps-context-list { display: flex; width: max-content; }
  .ps-context-link { min-width: auto; max-width: 13rem; white-space: nowrap; }
  .ps-reading-pane { min-height: 0; padding: .65rem .65rem calc(5.2rem + env(safe-area-inset-bottom)); }
  .ps-reading-pane > iframe { min-height: 64rem; }
  .ps-notes { width: 100vw; max-width: none; max-height: 100dvh; height: 100dvh; border: 0; border-radius: 0; }
  .ps-notes-grid { grid-template-columns: 1fr; }
  .ps-notes textarea,
  .ps-note-preview { min-height: 18rem; }
  body.ps-shell-active .stats .stat + .stat { border-inline-start: 0; border-top: 1px solid var(--ps-line); }
}

@media (max-width: 31rem) {
  .ps-global-link { min-height: 2.9rem; }
  .ps-theme-button { min-width: 2.35rem; font-size: .62rem !important; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ps-app-shell *, .ps-app-shell *::before, .ps-app-shell *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
