/* ============================================================
   Design tokens
   ============================================================ */
:root {
  /* Surfaces & backgrounds */
  --color-bg:             #1a1a1a;
  --color-surface:        #2a2a2a;
  --color-surface-2:      #333;
  --color-surface-3:      #444;
  --color-surface-dim:    #232323;
  --color-surface-hover:  #414141;
  --color-code-bg:        #0d0d0d;

  /* Text */
  --color-text:           #d4d4d4;
  --color-text-bright:    #f5f5f5;
  --color-text-secondary: #aaa;
  --color-text-dim:       #8c8c8c;
  --color-text-faintest:  #737373;

  /* Accent & semantic */
  --color-primary:        #e6c07b;
  --color-accent:         #7c9ef8;
  --color-error:          #ff8a8a;
  --color-success:        #98c379;
  --color-purple:         #b294bb;
  --color-terminal:       #abb2bf;

  /* Borders */
  --color-border:         #444;
  --color-border-dim:     #3c3c3c;
  --color-border-dark:    #222;

  /* Scrollbar */
  --color-scrollbar:       #404040;
  --color-scrollbar-track: #525252;

  /* Overlays & shadows */
  --color-overlay:        #000000b3;
  --color-overlay-heavy:  #1e1e1ef2;
  --color-shadow:         #171717;
  --color-shadow-deep:    #00000066;
  --color-selection:      #264f78;

  /* Toggle */
  --color-toggle-on:      #3b82f6;

  /* Syntax highlighting — Dark+ (VS Code default dark) */
  --syntax-keyword:          #569cd6;
  --syntax-builtin:          #dcdcaa;
  --syntax-symbol:           #9cdcfe;
  --syntax-number:           #b5cea8;
  --syntax-string:           #ce9178;
  --syntax-punctuation:      #d4d4d4;
  --syntax-comment:      #6a9955;
  --syntax-error:            #f44747;
  --syntax-effect:           #e6b455;
  --syntax-effect-construct: #e06c9f;

  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Roboto', sans-serif;
  --font-size-xs:   0.75rem;
  --font-size-sm:   0.875rem;
  --font-size-base: 1rem;
  --font-size-lg:   1.25rem;
  --font-size-xl:   1.75rem;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --radius-sm: 4px;
  --radius-md: 8px;
  --sidebar-default-width: 350px;
}

/* ============================================================
   Reset / base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  background-color: var(--color-bg);
  color: var(--color-text);
}

body.no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

div {
  box-sizing: border-box;
}

h1, h2, h3, h4 {
  margin: 0;
  padding: 0;
}

pre {
  font-family: var(--font-mono);
  font-size: var(--font-size-base);
  margin: 0;
}

textarea {
  outline: none;
  background-color: var(--color-code-bg);
  width: 100%;
  resize: none;
  padding: var(--space-2);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  box-sizing: border-box;
  overflow-x: auto;
  white-space: nowrap;
}

input {
  outline: none;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 0.2rem;
  color: var(--color-text);
  font-size: var(--font-size-base);
  box-sizing: border-box;
}

label {
  display: block;
  margin-top: var(--space-6);
  font-weight: bold;
}

table {
  border-collapse: collapse;
  margin-left: -3px;
}

::-moz-selection {
  background: var(--color-scrollbar-track);
}

::selection {
  background: var(--color-scrollbar-track);
}

/* ============================================================
   Links
   ============================================================ */
a,
a:link,
a:visited,
a:hover,
a:active {
  color: var(--color-text-secondary);
  text-decoration: none;
  cursor: pointer;
}

a:hover {
  color: var(--color-text-bright);
}

a.disabled {
  color: var(--color-border);
  cursor: default;
}

/* Links inside prose content areas get underlines — but not structural/nav links */
.content a,
.content a:link,
.content a:visited,
.content a:hover,
.doc-page__description a,
.doc-page__description a:link,
.doc-page__description a:visited,
.book-page__content a,
.book-page__content a:link,
.book-page__content a:visited {
  text-decoration: underline;
}

/* Structural links inside book-page__content should NOT have underlines */
.book-page__content .example-card__link,
.book-page__content .example-card__link:link,
.book-page__content .example-card__link:visited,
.book-page__content .ref-card,
.book-page__content .ref-card:link,
.book-page__content .ref-card:visited,
.book-page__content .ref-index__link,
.book-page__content .ref-index__link:link,
.book-page__content .ref-index__link:visited,
.book-page__content .chapter-subtoc__link,
.book-page__content .chapter-subtoc__link:link,
.book-page__content .chapter-subtoc__link:visited {
  text-decoration: none;
}

/* ============================================================
   Scrollbars
   ============================================================ */
.fancy-scroll-background::-webkit-scrollbar-track {
  background-color: var(--color-code-bg);
}
.fancy-scroll-background::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.fancy-scroll-background::-webkit-scrollbar-thumb {
  background-color: var(--color-scrollbar);
  cursor: default;
  border: none;
}
.fancy-scroll-background::-webkit-scrollbar-corner {
  background-color: transparent;
}

.fancy-scroll::-webkit-scrollbar-track {
  background-color: transparent;
}
.fancy-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.fancy-scroll::-webkit-scrollbar-thumb {
  background-color: var(--color-scrollbar);
  cursor: default;
  border: none;
}
.fancy-scroll::-webkit-scrollbar-corner {
  background-color: transparent;
}

/* ============================================================
   Layout — main panel + sidebar
   ============================================================ */
#main-panel {
  box-sizing: border-box;
  position: fixed;
  left: calc(var(--sidebar-default-width) + 5px);
  top: 0;
  bottom: 0; /* overridden by applyLayout; ensures overflow-y works before JS */
  padding-top: var(--space-4);
  right: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  z-index: 1;
}

#sidebar {
  box-sizing: border-box;
  position: fixed;
  left: 0;
  width: var(--sidebar-default-width);
  top: 0;
  padding-top: var(--space-4);
  padding-left: var(--space-4);
  white-space: nowrap;
  overflow-y: scroll;
  padding-right: var(--space-4);
}

#resize-sidebar {
  position: fixed;
  width: 5px;
  cursor: col-resize;
  background-color: var(--color-scrollbar-track);
  top: 0;
  z-index: 10;
}

/* ============================================================
   Sidebar BEM component
   ============================================================ */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar__logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--space-4);
}

.sidebar__logo img {
  max-width: 120px;
  width: 100%;
  cursor: pointer;
}

.sidebar__search-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-1) var(--space-2);
  margin-bottom: var(--space-4);
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: none;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  text-align: left;
}

.sidebar__search-btn:hover {
  color: var(--color-text-bright);
}

.sidebar__search-kbd {
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

.sidebar__nav {
  list-style: none;
  margin: 0 0 var(--space-4) 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar__nav-item {
  display: block;
}

.sidebar__nav-item--active .sidebar__link {
  color: var(--color-text-bright);
}

.sidebar__link {
  color: var(--color-text-secondary);
  text-decoration: none;
  cursor: pointer;
  display: block;
}

.sidebar__link:hover,
.sidebar__link--active {
  color: var(--color-text-bright);
}

.sidebar__section {
  margin-bottom: var(--space-2);
}

.sidebar__section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: var(--space-1) 0;
  font-size: var(--font-size-xs);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-dim);
}

.sidebar__section-header:hover {
  color: var(--color-text-bright);
}

.sidebar__section-chevron {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: var(--font-size-xs);
}

.sidebar__section-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-left: var(--space-3);
  margin-top: 0;
  transition: max-height 0.25s ease-in-out, opacity 0.2s ease-in-out, margin-top 0.2s ease-in-out;
}

.sidebar__section-content.expanded {
  opacity: 1;
  margin-top: var(--space-2);
}

.sidebar__group {
  margin-bottom: var(--space-2);
}

.sidebar__group-header {
  font-size: var(--font-size-xs);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-dim);
  margin-bottom: var(--space-1);
  padding: var(--space-1) 0;
}

/* Old sidebar classes (used in shell.ts inline HTML — kept for compatibility) */
#sidebar .sidebar-collapsible-header {
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-1) 0;
  font-size: var(--font-size-base);
  user-select: none;
}

#sidebar .sidebar-collapsible-header:hover {
  color: var(--color-text-bright);
}

#sidebar .sidebar-category-label {
  font-size: var(--font-size-xs);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-dim);
  margin-top: var(--space-3);
  margin-bottom: var(--space-1);
}

#sidebar .sidebar-category-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

#sidebar .sidebar-collapsible-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-left: var(--space-3);
  margin-top: 0;
  font-size: var(--font-size-base);
  transition: max-height 0.25s ease-in-out, opacity 0.2s ease-in-out, margin-top 0.2s ease-in-out;
}

#sidebar .sidebar-collapsible-content.expanded {
  opacity: 1;
  margin-top: 0;
  margin-bottom: var(--space-2);
}

#sidebar .active-sidebar-entry {
  color: var(--color-text-bright);
}

#sidebar .active-sidebar-entry a {
  color: var(--color-text-bright);
}

/* ============================================================
   Content area (legacy — used by settings/saved/snapshot pages)
   ============================================================ */
.content {
  display: none;
  padding: 0 var(--space-3);
  max-width: 60rem;
  margin-left: auto;
  margin-right: auto;
}

.content.active-content {
  display: block;
}

.content .example {
  box-shadow: 1px 1px 3px var(--color-shadow);
}

.content .example:hover svg:not(.example-action-btn svg) {
  color: white;
  font-size: 4rem;
}

/* ============================================================
   Content page (BEM — used by corePage, modulesPage, etc.)
   ============================================================ */
.content-page {
  padding: 0 var(--space-3) var(--space-8);
  max-width: 60rem;
  margin-left: auto;
  margin-right: auto;
}

.content-page__header {
  margin-bottom: var(--space-6);
}

.content-page__header h1 {
  font-size: var(--font-size-xl);
  font-weight: bold;
}

.content-page__title {
  font-size: var(--font-size-xl);
  font-weight: bold;
  color: var(--color-text);
  margin: 0 0 1rem 0;
  text-align: left;
}

.content-page__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.content-page__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.content-page__group-title {
  font-size: var(--font-size-lg);
  font-weight: bold;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-2);
}

.content-page__entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.content-page__entry {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.content-page__entry-link {
  color: var(--color-accent);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  text-decoration: none;
}

.content-page__entry-link:hover {
  color: var(--color-text-bright);
  text-decoration: underline;
}

.content-page__entry-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
}

/* ============================================================
   About page
   ============================================================ */
.about-intro {
  max-width: 600px;
  margin: 0 auto var(--space-16);
  text-align: center;
}

.about-intro__text {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  line-height: 1.6;
}


.about-section-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-bright);
  text-align: center;
  margin-bottom: var(--space-4);
}

.about-features {
  margin-bottom: var(--space-16);
}

.about-features__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  max-width: 700px;
  margin: 0 auto;
}

.about-feature-card {
  background: var(--color-surface);
  border-radius: 8px;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.about-feature-card__icon {
  color: var(--color-accent);
  font-size: 1.25rem;
}

.about-feature-card__icon svg {
  width: 1em;
  height: 1em;
}

.about-feature-card__title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-bright);
  margin: 0;
}

.about-feature-card__desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: 0;
  line-height: 1.5;
}

.about-feature-card--clickable {
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.about-feature-card--clickable:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.about-stats {
  margin-bottom: var(--space-12);
}

.about-stats__grid {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.about-stat-card {
  background: var(--color-surface);
  border-radius: 8px;
  padding: var(--space-4) var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  min-width: 120px;
}

.about-stat-card__icon {
  color: var(--color-accent);
  font-size: 1.5rem;
}

.about-stat-card__icon svg {
  width: 1em;
  height: 1em;
}

.about-stat-card__value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--color-text-bright);
}

.about-stat-card__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* ============================================================
   Start page
   ============================================================ */
.start-page__header {
  padding-top: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.start-page__logo {
  max-width: 400px;
  width: 100%;
  height: auto;
  margin-bottom: var(--space-2);
}

.start-page__tagline {
  font-size: var(--font-size-lg);
  font-style: italic;
  color: var(--color-text);
  margin: 0 0 var(--space-1) 0;
}

.start-page__subtitle {
  font-size: var(--font-size-base);
  color: var(--color-text-dim);
  margin: 0 0 var(--space-6) 0;
}

.start-page__nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-16);
  margin-bottom: var(--space-12);
}

.start-page__nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--font-size-lg);
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.15s;
}

.start-page__nav-link:hover {
  color: var(--color-text-bright);
}

.start-page__nav-icon {
  width: 5rem;
  height: 5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.start-page__nav-icon svg {
  width: 100%;
  height: 100%;
}

.start-page__example-section {
  max-width: 60rem;
  width: 100%;
  margin: 0 auto;
}

.start-page__example-label {
  font-size: var(--font-size-base);
  color: var(--color-text-dim);
  margin-bottom: var(--space-2);
}

.start-page__example-try {
  color: var(--color-text-dim);
  text-decoration: underline;
  cursor: pointer;
}

.start-page__example-try:hover {
  color: var(--color-text-bright);
}

/* ============================================================
   Doc page
   ============================================================ */
.doc-page {
  padding: 0 var(--space-3);
  max-width: 60rem;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: var(--space-8);
}

.doc-page__title {
  font-size: var(--font-size-xl);
  font-family: var(--font-mono);
  font-weight: bold;
  margin-bottom: var(--space-1);
}

.doc-page__category {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-4);
}

.doc-page__section {
  margin-bottom: var(--space-6);
}

.doc-page__section-title {
  font-size: var(--font-size-sm);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-dim);
  margin-bottom: var(--space-2);
}

.doc-page__signature {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.doc-page__signature-variant {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-surface);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.doc-page__signature-label {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--space-3);
  margin-bottom: var(--space-1);
}

.doc-page__description {
  line-height: 1.6;
}

.doc-page__description p {
  margin: 0 0 var(--space-3) 0;
}

.doc-page__description code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-surface);
  padding: 0.1em 0.3em;
  border-radius: var(--radius-sm);
}

.doc-page__description pre {
  background: var(--color-surface);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.doc-page__example {
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  overflow: hidden;
  border-left: 3px solid var(--color-primary);
  background: var(--color-code-bg);
  box-shadow: 1px 1px 3px var(--color-shadow);
}

.doc-page__example-code {
  display: block;
  margin: 0;
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-code-bg);
  color: var(--color-text);
  white-space: pre-wrap;
  overflow-x: auto;
}

.doc-page__example-code code {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  padding: 0;
}

.doc-page__example-output {
  background: var(--color-code-bg);
  border-top: 1px solid var(--color-border-dark);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: pre-wrap;
}

.doc-page__example-output .output-arrow {
  color: var(--color-text-dim);
}

.doc-page__example-output--error {
  color: var(--color-error);
}

.doc-page__example-code-wrap {
  position: relative;
}

.doc-page__example-lang {
  position: absolute;
  bottom: var(--space-1);
  right: var(--space-2);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

.doc-page__example-action-bar {
  display: flex;
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  flex-direction: row;
  align-items: center;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

/* Hover on the whole block (including output) fades in the action bar */
.doc-page__example:hover .doc-page__example-action-bar {
  opacity: 1;
  pointer-events: auto;
}

.doc-page__example-action-btn {
  background: none;
  border: none;
  color: var(--color-text-dim);
  cursor: pointer;
  padding: var(--space-1);
  font-size: 1rem;
  line-height: 1;
  transition: color 0.15s ease;
}

.doc-page__example-action-btn:hover {
  color: var(--color-text-bright);
}

.doc-page__example-use-btn {
  font-size: 0.8rem;
  font-family: var(--font-sans, sans-serif);
  white-space: nowrap;
  border: 1px solid var(--color-text-faintest);
  border-radius: 4px;
  padding: 0.3em 0.8em;
}

.doc-page__example-use-btn:hover {
  border-color: var(--color-text-secondary);
}

.doc-page__see-also {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.doc-page__see-also-link {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--color-accent);
  text-decoration: none;
}

.doc-page__see-also-link:hover {
  color: var(--color-text-bright);
  text-decoration: none;
}

.doc-page__not-found {
  color: var(--color-text-dim);
}

/* ============================================================
   Book chapter page
   ============================================================ */
/* --- Chapter sticky header --- */

.chapter-header {
  position: sticky;
  top: -1rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  background: var(--color-surface-dim);
  border-bottom: 1px solid var(--color-border-dim);
  margin: 0 calc(-1 * var(--space-3));
}

.chapter-header__title {
  font-weight: bold;
  font-size: 1.5rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  padding-left: var(--space-2);
}

.chapter-header__breadcrumbs {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
}

.chapter-header__breadcrumb-link {
  color: var(--color-text-secondary);
  text-decoration: none;
  font-weight: normal;
  font-size: 1.1rem;
}

.chapter-header__breadcrumb-link:hover {
  color: var(--color-text-bright);
}

.chapter-header__breadcrumb-sep {
  color: var(--color-text-dim);
  font-weight: normal;
  font-size: 1.1rem;
}

.chapter-header__breadcrumb-current {
  color: var(--color-text);
}

.chapter-header__actions {
  display: flex;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}

.chapter-header__nav-group {
  display: flex;
  align-items: center;
  margin-left: var(--space-1);
}

.chapter-header__toc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8em;
  height: 1.8em;
  flex-shrink: 0;
  border: none;
  background: none;
  border-radius: 4px;
  color: var(--color-text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.chapter-header__toc-btn:hover {
  color: var(--color-text-bright);
  background: var(--color-surface);
}

.chapter-toc-dropdown {
  position: fixed;
  z-index: 300;
  background: var(--color-surface-dim);
  border: 1px solid var(--color-border-dim);
  border-radius: 4px;
  padding: var(--space-1) 0;
  min-width: 14rem;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.chapter-toc-dropdown__section {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--space-1);
}

.chapter-toc-dropdown__item {
  display: flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-toc-dropdown__item:hover {
  color: var(--color-text-bright);
  background: var(--color-surface);
}

.chapter-toc-dropdown__check {
  display: inline-block;
  width: 1.2em;
  flex-shrink: 0;
  color: var(--color-brand);
}

.chapter-toc-dropdown__item--active {
  color: var(--color-text-bright);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.07);
}

.chapter-toc-dropdown__subitem--active {
  padding-left: var(--space-3);
  color: var(--color-text-bright);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.07);
}

.chapter-toc-dropdown__item--overview {
  font-weight: 600;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border-dim);
  margin-bottom: var(--space-1);
}

.chapter-toc-dropdown__subitem {
  display: flex;
  align-items: center;
  padding: var(--space-1) var(--space-3) var(--space-1) calc(var(--space-3) + 1rem);
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-toc-dropdown__subitem:hover {
  color: var(--color-text-bright);
  background: var(--color-surface);
}


.chapter-search-dropdown {
  position: fixed;
  z-index: 300;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  width: 28rem;
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.chapter-search-input {
  border: none;
  border-bottom: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-bright);
  font-size: var(--font-size-sm);
  padding: var(--space-2) var(--space-3);
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.chapter-search-input::placeholder {
  color: var(--color-text-dim);
}

.chapter-search-results {
  overflow-y: auto;
  flex: 1;
}

.chapter-search-result {
  display: flex;
  flex-direction: column;
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  gap: 1px;
}

.chapter-search-results:not(.keyboard-nav) .chapter-search-result:hover,
.chapter-search-result--active {
  background: var(--color-surface);
}

.chapter-search-result--section {
  padding-left: calc(var(--space-3) + 1rem);
}

.chapter-search-result--content {
  padding-left: calc(var(--space-3) + 1rem);
}

.chapter-search-separator {
  height: 1px;
  background: var(--color-border-dim);
  margin: var(--space-1) 0;
}

.chapter-search-group-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-dim);
  padding: var(--space-1) var(--space-3) 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chapter-search-result--content .chapter-search-result__label {
  color: var(--color-text-secondary);
  font-style: italic;
}

.chapter-search-result--code {
  padding-left: calc(var(--space-3) + 1rem);
}

.chapter-search-result--code .chapter-search-result__label {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-search-result__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-search-result__context {
  font-size: var(--font-size-xs);
  color: var(--color-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-search-empty {
  padding: var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  text-align: center;
}

.chapter-header__nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8em;
  height: 1.8em;
  border-radius: 4px;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 1.4rem;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.chapter-header__nav-btn:hover {
  color: var(--color-text-bright);
  background: var(--color-surface);
}

.chapter-header__nav-btn--disabled {
  opacity: 0.25;
  pointer-events: none;
}

/* --- Book chapter page --- */

.book-page {
  padding: 0 var(--space-3);
  max-width: 60rem;
  margin-top: -1rem;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: var(--space-8);
}

.book-page__content {
  line-height: 1.7;
  margin-top: var(--space-4);
}

.book-page__content h1,
.book-page__content h2,
.book-page__content h3 {
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
  scroll-margin-top: 5rem;
}

.book-page__content h1 {
  font-size: var(--font-size-xl);
}

.book-page__content h2 {
  font-size: var(--font-size-lg);
}

.book-page__content p {
  margin: 0 0 var(--space-3) 0;
}

.book-page__content code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-surface);
  padding: 0.1em 0.3em;
  border-radius: var(--radius-sm);
}

.book-page__content pre {
  background: var(--color-surface);
  border-left: 3px solid var(--color-primary);
  padding: var(--space-3);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  overflow-x: auto;
}

.book-page__content .doc-page__example pre {
  border-left: none;
  border-radius: 0;
  background: var(--color-code-bg);
}

.book-page__content pre code {
  background: none;
  padding: 0;
  font-size: var(--font-size-sm);
}

.book-page__content ul,
.book-page__content ol {
  margin: 0 0 var(--space-3) 0;
  padding-left: var(--space-6);
}

.book-page__content blockquote {
  border-left: 3px solid var(--color-border-dim);
  margin: 0 0 var(--space-3) 0;
  padding-left: var(--space-3);
  color: var(--color-text-dim);
}

.book-page__content table th,
.book-page__content table td {
  padding: 0.35em 0.75em;
}

/* --- Book chapter page sub-TOC (h2 section links) --- */

.chapter-subtoc {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-8);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border-left: 2px solid var(--color-brand);
}

.chapter-subtoc__link {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.chapter-subtoc__link:hover {
  color: var(--color-text-bright);
}

/* --- Book overview TOC --- */

.book-toc__header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-4);
}

.book-toc__download {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-dim);
  border-radius: var(--radius-sm);
  padding: 0.3em 0.8em;
}

.book-toc__download:hover {
  color: var(--color-text-bright);
  border-color: var(--color-text-dim);
}

.book-toc {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.book-toc__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.book-toc__group-title {
  font-size: var(--font-size-sm);
  font-weight: bold;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.book-toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.book-toc__item > a {
  font-size: var(--font-size-base);
  color: var(--color-text);
  display: block;
  padding: 0.2em 0;
}

.book-toc__item > a:hover {
  color: var(--color-text-bright);
}

.book-toc__sublist {
  list-style: none;
  padding: 0;
  margin: 0;
  padding-left: var(--space-4);
  border-left: 1px solid var(--color-border-dim);
  margin-left: 0.2em;
  margin-bottom: var(--space-2);
}

.book-toc__subitem a {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  display: block;
  padding: 0.15em 0;
}

.book-toc__subitem a:hover {
  color: var(--color-text-bright);
}


/* ============================================================
   Example page
   ============================================================ */
.example-page__entry {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  border-left: 3px solid var(--color-border-dim);
}

.example-page__details {
  list-style: none;
}

.example-page__summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.example-page__summary::-webkit-details-marker {
  display: none;
}

.example-page__summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.example-page__details[open] .example-page__summary {
  margin-bottom: var(--space-2);
}

.example-page__entry-title {
  font-weight: bold;
  font-size: var(--font-size-base);
}

.example-page__entry-btn {
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.example-page__entry-btn:hover {
  background: var(--color-surface-3);
  color: var(--color-text-bright);
}

.example-page__entry-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  margin: 0 0 var(--space-2) 0;
}

.example-page__code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-bg);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

.example-page__code code {
  font-family: inherit;
  font-size: inherit;
  color: var(--color-text);
  background: none;
  padding: 0;
}

/* ============================================================
   Example cards (categorized index page)
   ============================================================ */
.example-category {
  margin-bottom: var(--space-5);
}

.example-category__title {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--color-text);
  margin: 0 0 var(--space-3) 0;
}

.example-category__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
}

.example-card {
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-dim);
  transition: border-color 0.15s, box-shadow 0.15s;
  overflow: hidden;
}

.example-card:hover {
  border-color: var(--color-border);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.example-card__link,
.example-card__link:link,
.example-card__link:visited,
.example-card__link:hover,
.example-card__link:active,
.book-page__content .example-card__link,
.book-page__content .example-card__link:link,
.book-page__content .example-card__link:visited {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  text-decoration: none;
  color: inherit;
  flex: 1;
  cursor: pointer;
}

.example-card__title {
  font-weight: bold;
  font-size: var(--font-size-base);
  color: var(--color-text);
}

.example-card__desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
}

.example-card__play {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.8em;
  height: 1.8em;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--color-text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, opacity 0.15s;
  opacity: 0.5;
}

.example-card:hover .example-card__play {
  opacity: 1;
}

.example-card__play:hover {
  color: var(--color-text-bright);
  background: var(--color-surface-3);
}

.example-header__load-btn svg {
  width: 1.4rem;
  height: 1.4rem;
  flex-shrink: 0;
}

/* Load-in-playground button in example detail header */
.example-header__load-btn {
  font-size: var(--font-size-base) !important;
  width: auto !important;
  padding: 0 var(--space-2) !important;
  white-space: nowrap;
  display: inline-flex !important;
  align-items: center;
  gap: 0.4em;
}

/* Hidden card/category during search filtering */
.example-card--hidden {
  display: none;
}

.example-category--hidden {
  display: none;
}

/* ============================================================
   Reference card grid (top-level /ref page)
   ============================================================ */
.ref-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-3);
}

.ref-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-dim);
  padding: var(--space-4);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.ref-card:hover {
  border-color: var(--color-border);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.book-page__content .ref-card,
.book-page__content .ref-card:link,
.book-page__content .ref-card:visited {
  text-decoration: none;
  color: inherit;
}

.ref-card__title {
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--color-text);
}

.ref-card__desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
}

.ref-card__count {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-top: auto;
}

/* ============================================================
   Reference section listing page
   ============================================================ */
.ref-index__section {
  margin-bottom: var(--space-5);
}

.ref-index__section-title {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--color-text);
  margin: 0 0 var(--space-3) 0;
}

.ref-index__group {
  margin-bottom: var(--space-4);
}

.ref-index__group-title {
  font-size: 1rem;
  font-weight: bold;
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-2) 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: var(--font-size-sm);
}

.ref-index__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ref-index__item {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.ref-index__link {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  white-space: nowrap;
  flex-shrink: 0;
}

.ref-index__link:hover {
  color: var(--color-text-bright);
}

.ref-index__desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-module__desc {
  font-size: var(--font-size-base);
  color: var(--color-text-dim);
  margin: 0 0 var(--space-4) 0;
  line-height: 1.5;
}

/* ============================================================
   Example detail page
   ============================================================ */
.example-detail__category {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  margin: 0 0 var(--space-2) 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.example-detail__desc {
  font-size: var(--font-size-base);
  color: var(--color-text);
  margin: 0 0 var(--space-4) 0;
  line-height: 1.6;
}

.example-detail__code {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  background: var(--color-bg);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0 0 var(--space-4) 0;
  white-space: pre;
}

.example-detail__code code {
  font-family: inherit;
  font-size: inherit;
  color: var(--color-text);
  background: none;
  padding: 0;
}


/* ============================================================
   Search dialog
   ============================================================ */
.search-dialog {
  background: var(--color-bg);
  border: 3px solid var(--color-surface);
  border-radius: var(--radius-sm);
  width: 800px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.search-dialog__input {
  padding: var(--space-3);
  font-size: 1.1rem;
  background: var(--color-surface);
  border: none;
  color: var(--color-text);
  outline: none;
}

.search-dialog__results {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
}

.search-dialog__entry {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.1s;
}

.search-dialog__entry:hover,
.search-dialog__entry--focused {
  background: var(--color-surface-dim);
}

.search-dialog__entry-title {
  font-family: var(--font-mono);
  font-size: var(--font-size-base);
  color: var(--color-text);
}

.search-dialog__entry-category {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-dim);
}

.search-dialog__entry-desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   Playground panel
   ============================================================ */
#playground {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: transparent;
}

#resize-playground {
  height: 5px;
  background: var(--color-border-dim);
  cursor: row-resize;
}

#panels-container {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: row;
  white-space: nowrap;
}

/* Panel header bars */
#context-panel,
#dvala-panel,
#output-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--space-2);
  height: 1.6rem;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border-dim);
  user-select: none;
  cursor: pointer;
}

.panel-header__title {
  font-size: 1.1rem;
}

.panel-header__actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.panel-header__actions > a,
.panel-header__actions > div > a {
  display: flex;
  align-items: center;
  gap: 0.25em;
}

/* Run button — running state */
.run-btn__busy {
  display: none;
  align-items: center;
  gap: 0.35em;
}

.dvala-running .run-btn__idle { display: none; }
.dvala-running .run-btn__busy { display: inline-flex; }

.spinner {
  width: 0.9em;
  height: 0.9em;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-text-bright);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Panel vertical resize dividers */
#resize-divider-1,
#resize-divider-2 {
  width: 5px;
  height: 100%;
  cursor: col-resize;
  background: var(--color-border-dim);
}

/* Output result area */
#output-result {
  font-family: var(--font-mono);
  background: var(--color-code-bg);
  padding: var(--space-2);
  font-size: var(--font-size-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  height: calc(100% - 1.6rem);
  overflow-y: auto;
}

#output-result .error,
#output-result .warn {
  color: var(--color-error);
  white-space: pre-wrap;
}

#output-result .output {
  color: var(--syntax-string);
  white-space: pre-wrap;
  padding-left: var(--space-2);
}

#output-result .analyze {
  color: var(--syntax-keyword);
  white-space: pre-wrap;
}

#output-result .tokenize {
  color: var(--syntax-symbol);
  white-space: pre-wrap;
}

#output-result .parse {
  color: var(--syntax-number);
  white-space: pre-wrap;
}

#output-result .result {
  color: var(--syntax-symbol);
  white-space: pre-wrap;
  margin-bottom: var(--space-1);
}

#output-result .comment {
  color: var(--syntax-comment);
  white-space: pre-wrap;
}

#output-result a.share-link {
  color: var(--syntax-string);
  white-space: nowrap;
}

#output-result a.share-link:hover {
  color: white;
}

#output-result .separator {
  font-size: var(--font-size-sm);
  border-bottom: solid 1px var(--color-scrollbar-track);
  height: 0;
  margin: 0;
  padding: 0;
  width: 100%;
}

/* ============================================================
   Toast notifications
   ============================================================ */
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.6rem var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-scrollbar-track);
  border-left: 3px solid var(--color-primary);
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  box-shadow: 0 4px 12px var(--color-shadow-deep);
  animation: toast-in 0.25s ease;
  min-width: 16rem;
}

.toast.toast-error {
  border-left-color: var(--color-error);
}

.toast.toast-info {
  border-left-color: var(--color-primary);
}

.toast-close {
  background: none;
  border: none;
  color: var(--color-text-dim);
  font-size: var(--font-size-base);
  cursor: pointer;
  padding: 0 var(--space-1);
  line-height: 1;
  margin-left: auto;
}

.toast-close:hover {
  color: var(--color-text);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-1rem); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-1rem); }
}

/* ============================================================
   Buttons
   ============================================================ */
button:focus {
  outline-color: var(--color-scrollbar-track);
}

.button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  background: var(--color-surface);
  color: var(--color-text-bright);
  border: 1px solid var(--color-border-dim);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  transition: background 0.15s ease, color 0.15s ease;
}

.button:hover {
  background: var(--color-surface-hover);
  color: var(--color-text-bright) !important;
}

.button--primary {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.button--primary:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-text-bright);
  color: var(--color-text-bright);
}

.button--danger {
  border-color: var(--color-error);
  color: var(--color-error);
}

.button--danger:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-error);
  color: var(--color-error);
}

.settings-action-row .button {
  min-width: 7rem;
  flex-shrink: 0;
}

.snapshot-btn:focus {
  outline: none;
}

.snapshot-btn {
  transition: color 0.15s ease;
}

.snapshot-btn:hover {
  color: var(--color-text-bright) !important;
}

.toolbar-btn {
  background: none;
  border: none;
  padding: 4px 8px;
  font-size: var(--font-size-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  transition: color 0.15s ease;
  font-family: inherit;
}

.toolbar-btn:hover {
  color: var(--color-text-bright);
}

/* ============================================================
   Settings
   ============================================================ */
.settings-tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0.4rem 1.25rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
  font-family: inherit;
}

.settings-tab-btn:hover {
  color: var(--color-text);
}

.settings-tab-btn.active {
  color: white;
  border-bottom-color: white;
}

.settings-tab-content {
  display: none;
  flex-direction: column;
  gap: var(--space-2);
}

.settings-tab-content.active {
  display: flex;
}

/* Settings toggle switch */
.settings-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.settings-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.settings-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--color-scrollbar-track);
  border-radius: 24px;
  transition: background-color 0.2s;
}

.settings-toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--color-text-secondary);
  border-radius: 50%;
  transition: transform 0.2s;
}

.settings-toggle input:checked + .settings-toggle-slider {
  background-color: var(--color-toggle-on);
}

.settings-toggle input:checked + .settings-toggle-slider::before {
  transform: translateX(20px);
}

.settings-toggle-disabled .settings-toggle-slider {
  opacity: 0.4;
  cursor: not-allowed;
}

.settings-toggle-row-disabled {
  opacity: 0.5;
}

/* ============================================================
   Dialog / modal overlay
   ============================================================ */
.dialog-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: transparent;
  backdrop-filter: blur(12px);
  animation: fade-in 0.2s ease-in-out;
  z-index: 100;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#add-context-menu,
#more-menu {
  z-index: 10;
}

/* ============================================================
   Code examples (legacy class used in old/inline HTML)
   ============================================================ */
.example-code {
  background-color: var(--color-code-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  border-left: 3px solid var(--color-primary);
}

.example-action-bar {
  display: none;
}

.example-code:hover .example-action-bar {
  display: flex;
}

.example-action-btn {
  color: var(--color-text-secondary);
  transition: color 0.15s ease;
}

.example-action-btn:hover {
  color: var(--color-text-bright);
}

/* Chapter nav links inside .content (legacy) */
.content .chapter-nav-link,
.content .chapter-nav-link:link,
.content .chapter-nav-link:visited,
.content .chapter-nav-link:hover {
  color: var(--color-text-secondary);
  transition: color 0.15s;
  text-decoration: none;
}

.content .chapter-nav-link:hover {
  color: var(--color-text-bright);
}

/* ============================================================
   Syntax overlay (textarea-based code editor)
   Parent-scrolls pattern: container is the only scroll host;
   neither child has its own scrollbar → zero scrollbar mismatch.
   ============================================================ */
.syntax-overlay-container {
  display: grid;
  grid-template-columns: auto 1fr;
  width: 100%;
  overflow: auto;
  background-color: var(--color-code-bg);
}

.syntax-overlay-line-numbers {
  grid-column: 1;
  grid-row: 1;
  padding: var(--space-2) 0.6em var(--space-2) var(--space-2);
  font-family: monospace;
  font-size: var(--font-size-sm);
  line-height: 1.2;
  white-space: pre;
  color: var(--color-text-dim);
  user-select: none;
  border-right: 1px solid var(--color-surface);
  position: sticky;
  left: 0;
  background-color: var(--color-code-bg);
  z-index: 2;
}

/* Shared text-layout properties so caret aligns with highlighted text */
.syntax-overlay-container textarea,
.syntax-overlay-container pre {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  padding: var(--space-2);
  font-family: monospace;
  font-size: var(--font-size-sm);
  line-height: 1.2;
  tab-size: 2;
  white-space: pre;
  box-sizing: border-box;
  border: none;
}

.syntax-overlay-container textarea {
  color: transparent;
  caret-color: white;
  background-color: transparent;
  z-index: 1;
  overflow: hidden;
  resize: none;
  outline: none;
}

.syntax-overlay-container textarea::selection {
  background: var(--color-selection);
}

.syntax-overlay-container textarea::-moz-selection {
  background: var(--color-selection);
}


.syntax-overlay-selection {
  color: transparent;
  pointer-events: none;
  z-index: 1;
}

.syntax-overlay-highlight {
  z-index: 2;
}

.syntax-highlight-range {
  background-color: var(--color-selection);
  border-radius: 2px;
}

.syntax-overlay-container pre {
  color: var(--color-text);
  overflow: visible;
  pointer-events: none;
  height: max-content;
  width: max-content;
  min-height: 100%;
  min-width: 100%;
}

/* ============================================================
   Shell structural classes
   ============================================================ */

/* Search dialog overlay */
#search-dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 200;
}

.search-dialog-overlay__inner {
  display: flex;
  justify-content: center;
  padding-top: 80px;
  max-height: calc(100% - 80px);
}

/* search-intro / no-result messages inside the search dialog */
#search-intro,
#no-search-result {
  padding: var(--space-4);
  text-align: center;
  color: var(--color-text-dim);
}

/* Toast container */
#toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  pointer-events: none;
  height: 20vh;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 30%, transparent 80%);
  -webkit-mask-image: linear-gradient(to bottom, black 30%, transparent 80%);
}

/* Sidebar logo wrapper */
.sidebar-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--space-4);
}

.sidebar-logo-wrap img {
  max-width: 120px;
  width: 100%;
  height: auto;
  cursor: pointer;
}

/* Sidebar search button (legacy inline — shell.ts uses this as a div) */
.sidebar-search-row {
  padding: var(--space-1) var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  cursor: pointer;
  border: 1px solid var(--color-border);
}

.sidebar-search-row:hover {
  color: var(--color-text-bright);
}

.sidebar-search-icon {
  display: flex;
  align-items: center;
  font-size: 1.1em;
  flex-shrink: 0;
}

.sidebar-search-kbd {
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

/* Sidebar nav list */
.sidebar-nav-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.sidebar-nav-list a,
.sidebar-nav-item-row a {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Sidebar nav item with indicator dot */
.sidebar-nav-item-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

/* Nav indicator dots (programs, snapshots) */
.nav-indicator {
  display: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-bright);
  margin-left: 4px;
  flex-shrink: 0;
}

/* Sidebar API reference section label */
.sidebar-section-label {
  font-size: var(--font-size-xs);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2);
  color: var(--color-text-dim);
}

/* Sidebar spacer */
.sidebar-spacer {
  height: var(--space-4);
}

/* Sidebar GitHub link */
.sidebar-github {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-1);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-decoration: none;
  margin-top: var(--space-6);
}

.sidebar-github:hover {
  color: var(--color-text-bright);
}

/* Sidebar version */
.sidebar-version {
  padding: var(--space-1) var(--space-2) var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-align: center;
}

/* ============================================================
   Panel textarea (context + dvala editors)
   ============================================================ */
.panel-textarea {
  height: calc(100% - 1.6rem);
  border: none;
  resize: none;
}

/* ============================================================
   Panel header sub-elements
   ============================================================ */
.panel-header__icon-btn {
  font-size: var(--font-size-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
}

.panel-header__code-title {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  overflow: hidden;
}

.panel-header__debug-icon {
  font-size: var(--font-size-lg);
  color: var(--text-secondary);
  opacity: 0.3;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s;
}
.panel-header__debug-icon:hover {
  opacity: 0.6;
}
.panel-header__debug-icon.active {
  opacity: 1;
  color: var(--color-primary);
}

.panel-header__title-string {
  font-size: 1.1rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-header__title-input {
  font-size: 1.1rem;
  background: transparent;
  border: none;
  outline: none;
  min-width: 8rem;
  max-width: 20rem;
  padding: 0 2px;
  color: inherit;
}

/* Pending / unsaved indicator dot */
.pending-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-bright);
  margin-left: 2px;
  flex-shrink: 0;
}

/* Locked / read-only indicator */
.locked-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  margin-left: 2px;
}

.panel-textarea--locked {
  opacity: 0.7;
  cursor: default;
}

/* ============================================================
   Dropdown menus (add-context-menu, more-menu)
   ============================================================ */
.dropdown-menu {
  position: absolute;
  top: 30px;
  max-width: 20rem;
  padding: var(--space-2);
  border: 1px solid var(--color-border-dim);
  background: var(--color-surface-3);
  z-index: 50;
}

.dropdown-menu__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.dropdown-menu__field-group {
  display: flex;
  flex-direction: column;
}

.dropdown-menu__label {
  font-size: var(--font-size-xs);
  font-weight: bold;
}

.dropdown-menu__label + .dropdown-menu__label {
  margin-top: var(--space-2);
}

.dropdown-menu__input {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.dropdown-menu__textarea {
  border: none;
  color: var(--color-text);
  background: var(--color-surface-2);
}

.dropdown-menu__add-btn {
  margin-top: var(--space-1);
}

.dropdown-menu__error {
  color: var(--color-error);
  font-size: var(--font-size-xs);
}

/* Menu items with icons */
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: 3px;
  white-space: nowrap;
}

.menu-item:hover {
  background: var(--color-surface-2);
  color: var(--color-text-bright);
}

.menu-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.menu-item:hover svg {
  opacity: 1;
}

.menu-shortcut {
  margin-left: auto;
  opacity: 0.5;
  font-size: var(--font-size-xs);
}

/* ============================================================
   Modal overlay + box
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
}

/* ------------------------------------------------------------------
   Execution Control Bar
   ------------------------------------------------------------------ */
.execution-control-bar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--color-overlay-heavy);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-2) var(--space-4);
  z-index: 300;
  backdrop-filter: blur(4px);
}

.execution-status {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  min-width: 60px;
}

.execution-status--running {
  color: var(--color-success);
}

.execution-status--paused {
  color: var(--color-primary);
}

.execution-status--terminal {
  color: var(--color-terminal);
}

.execution-controls {
  display: flex;
  gap: var(--space-2);
}

.exec-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.exec-btn:hover:not(:disabled) {
  background: var(--color-surface-hover);
  border-color: var(--color-border-bright);
  color: var(--color-text-bright);
}

.exec-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.exec-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.exec-btn svg {
  width: 16px;
  height: 16px;
}

#exec-pause-btn:hover:not(:disabled) {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

#exec-stop-btn:hover:not(:disabled) {
  color: var(--color-error);
  border-color: var(--color-error);
}

#exec-play-btn:hover:not(:disabled) {
  color: var(--color-success);
  border-color: var(--color-success);
}


.modal-box {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-dim);
  border-top: 2px solid var(--color-primary);
  padding: var(--space-6) var(--space-3) var(--space-3);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  background-color: var(--color-surface-dim);
  border-bottom: 1px solid var(--color-border-dim);
  margin: calc(-1 * var(--space-6)) calc(-1 * var(--space-3)) var(--space-4);
  padding: 0.6rem var(--space-3);
}

.modal-header__title {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--color-text-bright);
}

.modal-header__more {
  position: relative;
}

.modal-more-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 210;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  padding: var(--space-2);
  min-width: 8rem;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
}

.modal-more-menu a {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  cursor: pointer;
}

.modal-more-menu a:hover {
  color: var(--color-text-bright);
}

.modal-header__more-btn {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--color-text-dim);
}

.modal-header__more-btn:hover {
  color: var(--color-text-bright);
}

.modal-header__close-btn {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--color-text-dim);
  padding: 0 0.25rem;
  flex-shrink: 0;
  transition: color 0.15s ease;
  line-height: 1;
  margin-left: 0.25rem;
}

.modal-header__close-btn:hover {
  color: var(--color-text-bright);
}

.modal-body-row {
  margin-bottom: var(--space-4);
}

.modal-btn-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.modal-checklist {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.modal-checklist__item {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  font-weight: normal;
}

/* ============================================================
   Effect modal
   ============================================================ */
#effect-modal .modal-box {
  border-top-color: var(--color-error);
}

.effect-modal__nav {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.effect-modal__counter {
  font-size: var(--font-size-sm);
}


.effect-modal__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.effect-modal__field-label {
  font-size: var(--font-size-xs);
  font-weight: bold;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.effect-modal__name {
  font-size: 1rem;
  color: var(--color-purple);
}


.effect-modal__input-label {
  font-size: var(--font-size-sm);
  font-weight: normal;
  margin: 0;
}

.effect-modal__textarea {
  border: 1px solid var(--color-border-dim);
  background: var(--color-bg);
  color: var(--color-text);
  padding: var(--space-1);
  resize: vertical;
}

/* ============================================================
   Println / readline
   ============================================================ */
.println-content {
  background: var(--color-bg);
  padding: var(--space-2);
  overflow-x: auto;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  margin: 0;
}

.println-content.error-content {
  color: var(--color-error);
}

.readline-input {
  width: 100%;
  border: 1px solid var(--color-border-dim);
  background: var(--color-bg);
  color: var(--color-text);
  padding: var(--space-1);
  resize: vertical;
  margin-bottom: var(--space-2);
}

/* ============================================================
   Form error
   ============================================================ */
.form-error {
  color: var(--color-error);
  font-size: var(--font-size-xs);
}

/* ============================================================
   Snapshot panel
   ============================================================ */
#snapshot-panel-container {
  max-width: 860px;
  width: 95%;
  padding: 0;
  position: relative;
  overflow-x: clip;
}

.snapshot-panel__body {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  flex: 1;
}

.snapshot-panel__breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  flex: 1;
  gap: var(--space-1);
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--color-text-bright);
}

.breadcrumb-sep {
  color: var(--color-text-dim);
  margin: 0 0.15rem;
  font-weight: normal;
}

.breadcrumb-item {
  color: var(--color-text);
}

.breadcrumb-item--clickable {
  color: var(--color-text-dim);
  cursor: pointer;
  font-weight: normal;
}

.breadcrumb-item--clickable:hover {
  color: var(--color-text-secondary);
}

.breadcrumb-icon {
  display: inline-flex;
  vertical-align: middle;
  margin-right: 0.4em;
  font-size: 1.3em;
  opacity: 0.8;
}

.snapshot-panel__columns {
  display: flex;
  flex-direction: row;
  gap: var(--space-4);
  min-width: 0;
}

.snapshot-panel__col {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  flex: 1;
  min-width: 0;
}

.snapshot-panel__error {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.snapshot-panel__section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.snapshot-panel__section-label {
  font-size: 0.8rem;
  font-weight: bold;
  text-transform: uppercase;
}

.snapshot-panel__code-block {
  position: relative;
}

.snapshot-panel__code-pre {
  margin: 0;
  padding: var(--space-3);
  overflow-x: auto;
}

.snapshot-panel__use-btn {
  display: none;
}

.snapshot-panel__buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.snapshot-panel__buttons-left {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ============================================================
   Generic modal panel (used by centralized modal stack)
   ============================================================ */
.modal-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100vh - 48px);
  background: var(--color-surface-2);
  overflow: hidden;
}

/* When a modal-panel is inside modal-box, let the panel handle scrolling (sticky header) */
.modal-box:has(> .modal-panel) {
  overflow-y: hidden;
  max-height: calc(100vh - 48px);
  padding: 0;
}

.modal-panel .modal-header {
  margin: 0;
  padding: 0.75rem var(--space-4);
  font-size: 1.1rem;
}

.modal-panel__body {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.modal-panel__body::-webkit-scrollbar-track { background-color: transparent; }
.modal-panel__body::-webkit-scrollbar { width: 8px; height: 8px; }
.modal-panel__body::-webkit-scrollbar-thumb { background-color: var(--color-scrollbar); border: none; }
.modal-panel__body::-webkit-scrollbar-corner { background-color: transparent; }

.modal-panel__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border-dim);
  background-color: var(--color-surface-dim);
}

.println-output {
  position: relative;
}

.println-copy-btn {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--color-text-dim);
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.println-output:hover .println-copy-btn {
  opacity: 1;
}

.println-copy-btn:hover {
  color: var(--color-text-bright);
}

/* ============================================================
   Settings page
   ============================================================ */
.settings-page__body {
  padding: var(--space-4);
  background: var(--color-surface);
}

.settings-tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.settings-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-1) 0;
}

.settings-toggle-row__labels {
  display: flex;
  flex-direction: column;
}

.settings-toggle-row__label {
  font-size: var(--font-size-base);
}

.settings-toggle-row__desc {
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
  max-width: 32rem;
}

.settings-sub-toggles {
  margin-left: var(--space-4);
  padding-left: var(--space-3);
  border-left: 2px solid var(--color-border-dim);
}

/* Color palette (Developer tab) */
.color-palette__group-title {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-dim);
  margin: var(--space-4) 0 var(--space-2);
}
.color-palette__group-title:first-child {
  margin-top: 0;
}
.color-palette__group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.color-palette__swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  width: 90px;
}
.color-palette__color {
  width: 100%;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  overflow: hidden;
}
.color-palette__color > span {
  display: block;
  width: 100%;
  height: 100%;
}
.color-palette__color--alpha {
  background-image:
    linear-gradient(45deg, var(--color-surface-2) 25%, transparent 25%),
    linear-gradient(-45deg, var(--color-surface-2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--color-surface-2) 75%),
    linear-gradient(-45deg, transparent 75%, var(--color-surface-2) 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}
.color-palette__name {
  font-size: 0.6rem;
  color: var(--color-text-secondary);
  text-align: center;
  word-break: break-all;
}
.color-palette__hex {
  font-size: 0.55rem;
  color: var(--color-text-faintest);
  font-family: monospace;
}
.color-palette__text-preview {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  width: 180px;
}
.color-palette__text-sample {
  font-size: var(--font-size-sm);
  flex: 1;
}
.color-palette__text-preview .color-palette__hex {
  flex-shrink: 0;
}

.settings-tab-content__desc {
  margin: 0 0 var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
}

.settings-action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) 0;
}

.settings-action-row__info {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.settings-action-row__label {
  font-size: var(--font-size-base);
}

.settings-action-row__desc {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  max-width: 32rem;
}

.settings-action-section-header {
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  padding: var(--space-4) 0 var(--space-1);
  border-bottom: 1px solid var(--color-border-dim);
}

.settings-action-row__size {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  font-weight: normal;
  margin-left: var(--space-2);
}

/* ============================================================
   List pages (saved programs, snapshots)
   ============================================================ */
.list-page__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

.list-page__heading {
  font-size: var(--font-size-xl);
}

.list-page__actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.list-page__action-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-dim);
  font-size: var(--font-size-sm);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.15s, color 0.15s;
}

.list-page__action-btn:hover {
  background: var(--color-surface-3);
  color: var(--color-text-bright);
}

.list-page__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

#snapshots-list,
#saved-programs-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-2);
}

#snapshots-list .list-group-label,
#snapshots-list button:not(.snapshot-card),
#saved-programs-list .list-group-label {
  grid-column: 1 / -1;
}

.list-page__empty {
  color: var(--color-text-dim);
  font-style: italic;
}

/* ============================================================
   Misc utilities
   ============================================================ */
h2.discrete {
  color: gray;
}


/* ============================================================
   Mobile overlay
   ============================================================ */
#mobile-overlay {
  display: none;
}

@media (max-width: 768px) {
  #mobile-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    z-index: 9999;
    padding: var(--space-6);
  }

  #main-panel,
  #sidebar,
  #playground,
  #resize-sidebar,
  #resize-playground {
    display: none !important;
  }

  .mobile-overlay__header {
    text-align: center;
    margin-bottom: var(--space-6);
  }

  .mobile-overlay__logo {
    max-width: 220px;
    height: auto;
  }

  .mobile-overlay__tagline {
    font-size: var(--font-size-lg);
    color: var(--color-text-bright);
    margin: var(--space-4) 0 var(--space-2);
  }

  .mobile-overlay__subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    max-width: 300px;
    margin: 0 auto;
  }

  .mobile-overlay__note {
    padding: var(--space-4);
    background: var(--color-surface);
    border-radius: 8px;
    border-left: 3px solid var(--color-accent);
    max-width: 320px;
    text-align: left;
    margin-bottom: var(--space-6);
  }

  .mobile-overlay__note-title {
    font-weight: 600;
    color: var(--color-text-bright);
    margin-bottom: var(--space-2);
  }

  .mobile-overlay__note-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    line-height: 1.5;
  }

  .mobile-overlay__github {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
  }

  .mobile-overlay__github:hover {
    color: var(--color-text-bright);
  }

  .mobile-overlay__github svg {
    width: 1.25em;
    height: 1.25em;
  }
}

/* ============================================================
   AST Tree Viewer
   ============================================================ */

.ast-tree-viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.ast-tree__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ast-tree__search {
  flex: 1;
  min-width: 140px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.ast-tree__search:focus {
  outline: none;
  border-color: var(--color-primary);
}
.ast-tree__search::placeholder {
  color: var(--color-text-dim);
}

.ast-tree__count {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  white-space: nowrap;
}

.ast-tree__btn {
  padding: 3px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.ast-tree__btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.ast-tree {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  padding-bottom: var(--space-4);
}

.ast-tree__node {
  display: flex;
  align-items: baseline;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: default;
  white-space: nowrap;
}
.ast-tree__node:hover {
  background: rgba(255, 255, 255, 0.06);
}
.ast-tree__node--selected {
  background: rgba(86, 156, 214, 0.15);
}
.ast-tree__node--match {
  outline: 1px solid var(--color-primary);
  outline-offset: -1px;
}

.ast-tree__arrow {
  display: inline-block;
  width: 1em;
  text-align: center;
  font-size: 0.65em;
  color: var(--color-text-dim);
  flex-shrink: 0;
  user-select: none;
}
.ast-tree__arrow--open {
  color: var(--color-text-secondary);
}

.ast-tree__label {
  color: var(--color-text-dim);
  margin-right: 0.5ch;
}

.ast-tree__type {
  font-weight: 600;
}

.ast-tree__summary {
  color: var(--color-text-secondary);
  margin-left: 0.5ch;
}

.ast-tree__id {
  color: var(--color-text-dim);
  font-size: 0.75em;
  opacity: 0.5;
  margin-left: 0.75ch;
}

.ast-tree__empty {
  padding: var(--space-4);
  color: var(--color-text-dim);
  text-align: center;
  font-style: italic;
}

.ast-tree__toast {
  position: absolute;
  right: 8px;
  top: -2px;
  background: var(--color-surface-2);
  color: var(--color-text);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  pointer-events: none;
  animation: ast-toast-fade 1.2s ease forwards;
}
@keyframes ast-toast-fade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

.ast-tree__preview {
  border-top: 1px solid var(--color-border);
  padding: var(--space-3);
  min-height: 2.5em;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--color-surface-1);
}

.ast-tree__preview-hint {
  color: var(--color-text-dim);
  font-style: italic;
  font-size: 0.8rem;
}

.ast-tree__preview-code {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

