/* --------------------------------------------------------------------------
   C and C++ Browser Compiler Playground Styles
   -------------------------------------------------------------------------- */

:root {
  /* Comp-specific tier colors & dot styling */
  --tier1: #22a06b;
  --tier2: #e0a112;
  --tier3: #e5533c;
  --tier4: #8b2fd6;
  --dot-off: #434c5e;
  --block-bg: #181b21;
  --block-fg: #eceff4;
}

[data-theme="light"] {
  --dot-off: #cbd5e1;
}

[hidden] {
  display: none !important;
}

.icon-sprite,
.compiler-question-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.compiler-shell {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 80px;
  color: var(--fg);
}

/* --- Hero & Context Header --- */
.compiler-intro {
  margin-bottom: 20px;
}

.intro-eyebrow-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.eyebrow-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font: 600 0.72rem/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--accent-dim);
}

.eyebrow-icon {
  color: var(--accent);
}

.compiler-intro h1 {
  margin: 0 0 8px;
  color: var(--heading);
  font-size: clamp(1.75rem, 3.5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.intro-desc {
  margin: 0 0 16px;
  max-width: 720px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.eyebrow-separator {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}

/* --- Difficulty dots (1-to-1 with /comp/) --- */
.dots {
  font-family: monospace;
  font-size: 1.05rem;
  letter-spacing: 0.14em;
  white-space: nowrap;
}
.dot-off { color: var(--dot-off); }

.dot-on {
  animation: dot-pulse 2.4s ease-in-out infinite;
}
.tier-1 .dot-on {
  color: var(--tier1);
  text-shadow: 0 0 4px rgba(34, 160, 107, 0.55), 0 0 9px rgba(34, 160, 107, 0.35);
}
.tier-2 .dot-on {
  color: var(--tier2);
  text-shadow: 0 0 4px rgba(224, 161, 18, 0.6), 0 0 10px rgba(224, 161, 18, 0.4);
}
.tier-3 .dot-on {
  color: var(--tier3);
  text-shadow: 0 0 5px rgba(229, 83, 60, 0.65), 0 0 12px rgba(229, 83, 60, 0.45);
}
.tier-4 .dot-on {
  color: var(--tier4);
  text-shadow: 0 0 6px rgba(139, 47, 214, 0.7), 0 0 14px rgba(139, 47, 214, 0.5),
               0 0 22px rgba(139, 47, 214, 0.3);
}

@keyframes dot-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

@media (prefers-reduced-motion: reduce) {
  .dot-on { animation: none; }
}

/* --- Question Details Card --- */
.question-preview {
  margin: 0 0 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.question-preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 6px 14px 6px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.question-nav-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-kicker {
  color: var(--accent);
  font: 600 0.72rem/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.question-nav-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  font: 500 0.75rem/1.2 "IBM Plex Sans", sans-serif;
  cursor: pointer;
  transition: all 0.14s ease;
}

.btn-nav:hover:not(:disabled) {
  color: var(--fg);
  background: var(--surface-2);
}

.btn-nav.btn-nav-select {
  font-family: "IBM Plex Mono", monospace;
  color: var(--fg);
  font-weight: 600;
  gap: 6px;
}

.btn-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.question-preview-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-text-link,
.icon-text-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 3px 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font: 500 0.76rem/1.2 "IBM Plex Sans", sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.14s ease;
}

.icon-text-link:hover,
.icon-text-button:hover {
  color: var(--fg);
  background: var(--surface);
  border-color: var(--border);
  text-decoration: none;
}

.icon-text-link svg,
.icon-text-button svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.collapse-icon { transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
.question-preview.is-collapsed .collapse-icon { transform: rotate(180deg); }

.question-preview-bar {
  transition: border-bottom-color 0.22s ease;
}

.question-preview.is-collapsed .question-preview-bar {
  border-bottom-color: transparent;
  border-bottom: 0;
}

#question-content {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  opacity: 1;
}

.question-preview.is-collapsed #question-content {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

#question-content > * {
  min-height: 0;
  overflow: hidden;
  transition: padding 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.question-preview.is-collapsed #question-content > * {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border: 0 !important;
  margin: 0 !important;
}

.question-preview section.question {
  position: relative;
  margin: 0;
  padding: 1.6rem 1.8rem 1.8rem;
  color: var(--fg);
  background: var(--surface);
}

.question-preview section.question h2 {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.question-preview section.question h2 .qtitle {
  display: block;
  margin-top: 0.15rem;
  color: var(--fg);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  text-transform: none;
}

.question-preview section.question h3 {
  margin-top: 1.4rem;
  padding-bottom: 0.3rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.question-preview section.question p,
.question-preview section.question li {
  line-height: 1.55;
  font-size: 0.92rem;
}

.question-preview section.question ul { padding-left: 1.2rem; }
.question-preview section.question li { margin: 0.2rem 0; }
.question-preview section.question a { color: var(--accent); }
.question-preview section.question code {
  padding: 0.1rem 0.36rem;
  color: var(--code-fg);
  background: var(--code-bg);
  border-radius: 5px;
  font: 0.85em "IBM Plex Mono", monospace;
}

.question-preview section.question pre {
  padding: 0.9rem 1rem;
  overflow-x: auto;
  color: var(--block-fg, var(--code-fg));
  background: var(--block-bg, var(--code-bg));
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  white-space: pre-wrap;
}

.question-preview section.question pre code {
  padding: 0;
  color: inherit;
  background: none;
  font-size: 0.86rem;
}

.question-preview .qmeta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.question-preview p.est-time {
  display: inline-block;
  margin: 0.2rem 0 0.5rem;
  padding: 0.25rem 0.6rem;
  color: var(--muted);
  background: var(--code-bg);
  border-radius: 6px;
  font-size: 0.82rem;
}

.question-preview p.extension,
.question-preview ul.walkthrough {
  margin: 0.6rem 0 0.9rem;
  padding: 0.75rem 1rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.question-preview details.hint {
  margin: 1.3rem 0 0.6rem;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}

.question-preview details.hint summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.question-preview details.hint[open] summary { border-bottom: 1px solid var(--border); }
.question-preview .hint-body { padding: 0.4rem 1rem 0.8rem; }
.question-preview .hint-eyes { display: grid; place-items: center; width: 15px; height: 15px; }
.question-preview .hint-eyes svg {
  grid-area: 1 / 1;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.question-preview .eye-shut { opacity: 1; }
.question-preview .eye-open { opacity: 0; }
.question-preview details.hint[open] .eye-shut { opacity: 0; }
.question-preview details.hint[open] .eye-open { opacity: 1; }

/* --- Table of Contents Popup Modal --- */
.toc-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10, 10, 12, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  opacity: 1;
  transition: opacity 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  animation: modal-fade-in 0.18s ease-out;
}

.toc-modal-overlay.is-closing {
  opacity: 0;
  pointer-events: none;
}

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

.toc-modal-dialog {
  width: min(100%, 740px);
  max-height: min(85vh, 780px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border);
  padding: 1.3rem 1.4rem;
  box-sizing: border-box;
  overflow: hidden;
  transform: scale(1) translateY(0);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  animation: modal-zoom-in 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.toc-modal-overlay.is-closing .toc-modal-dialog {
  transform: scale(0.95) translateY(8px);
}

@keyframes modal-zoom-in {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.toc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.9rem;
  flex-shrink: 0;
}

.toc-modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toc-modal-icon {
  color: var(--accent);
}

.toc-modal-title-wrap h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--heading);
  letter-spacing: -0.01em;
}

.toc-count-badge {
  display: inline-block;
  font: 500 0.72rem "IBM Plex Mono", monospace;
  color: var(--muted);
  padding: 2px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.toc-modal-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toc-esc-hint {
  font: 500 0.7rem "IBM Plex Mono", monospace;
  color: var(--muted);
  padding: 2px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.toc-tools {
  margin-bottom: 0.9rem;
  flex-shrink: 0;
}

#toc-search {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.6rem;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

#toc-search:focus {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.toc-filters {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}

.toc-filters .chip {
  font-family: monospace;
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.22rem 0.55rem;
  cursor: pointer;
  transition: all 0.14s ease;
}

.toc-filters .chip.chip-all {
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  font-weight: 500;
}

.toc-filters .chip:hover {
  color: var(--fg);
  border-color: var(--muted);
}

.toc-filters .chip[data-tier="1"] { color: var(--tier1); text-shadow: 0 0 4px rgba(34, 160, 107, 0.55); }
.toc-filters .chip[data-tier="2"] { color: var(--tier2); text-shadow: 0 0 4px rgba(224, 161, 18, 0.6); }
.toc-filters .chip[data-tier="3"] { color: var(--tier3); text-shadow: 0 0 5px rgba(229, 83, 60, 0.65); }
.toc-filters .chip[data-tier="4"] { color: var(--tier4); text-shadow: 0 0 6px rgba(139, 47, 214, 0.7), 0 0 14px rgba(139, 47, 214, 0.4); }

.toc-filters .chip[aria-pressed="true"] {
  border-color: currentColor;
  background: var(--accent-light);
  font-weight: 600;
}

.toc-filters .chip.chip-all[aria-pressed="true"] {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--accent-light);
}

.compiler-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 4px 8px;
  align-content: start;
}

.compiler-toc-list li {
  margin: 0;
  padding: 0;
}

.compiler-toc-list li a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  border: 1px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.compiler-toc-list li a:hover {
  color: var(--fg);
  background: var(--surface-2);
  border-color: var(--border);
  text-decoration: none;
}

.compiler-toc-list li a.active {
  color: var(--accent);
  background: var(--accent-light);
  border-color: var(--accent-dim);
  font-weight: 600;
}

.compiler-toc-list .toc-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compiler-toc-list .dots {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.toc-loading,
.toc-empty {
  grid-column: 1 / -1;
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

/* --- Main Layout Grid --- */
.compiler-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 1fr);
  gap: 18px;
  align-items: stretch;
}

/* --- Editor Window Panel --- */
.editor-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 620px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.editor-panel:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 2px var(--accent-light), 0 4px 20px rgba(0, 0, 0, 0.2);
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.editor-tab-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font: 500 0.78rem "IBM Plex Mono", monospace;
  color: var(--fg);
}

.tab-icon {
  color: var(--accent);
}

.editor-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-select-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.lang-label-text {
  font-weight: 500;
}

.custom-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.dropdown-trigger {
  min-height: 28px;
  padding: 3px 26px 3px 10px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: 500 0.78rem "IBM Plex Mono", monospace;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  position: relative;
  transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.dropdown-trigger:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.dropdown-trigger:focus-visible,
.custom-dropdown.is-open .dropdown-trigger {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.dropdown-chevron {
  position: absolute;
  right: 8px;
  pointer-events: none;
  color: var(--muted);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), color 0.18s ease;
}

.custom-dropdown.is-open .dropdown-chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(0.97);
  transition: opacity 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.18s ease;
  pointer-events: none;
}

.custom-dropdown.is-open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 5px 8px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--fg);
  font: 500 0.76rem "IBM Plex Mono", monospace;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
  text-align: left;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--surface-2);
  color: var(--accent);
  outline: none;
}

.dropdown-item.is-selected {
  background: var(--accent-dim);
  color: var(--fg);
  font-weight: 600;
}

.dropdown-item .item-tag {
  font-size: 0.68rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
}

.editor-body {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  background: var(--code-bg);
  min-height: 520px;
}

.editor-gutter {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 44px;
  padding: 16px 8px 16px 0;
  box-sizing: border-box;
  font: 400 0.92rem/1.6 "IBM Plex Mono", monospace;
  color: var(--muted);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  text-align: right;
  user-select: none;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
  opacity: 0.65;
  z-index: 2;
}

.source-highlight,
#source-code {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 520px;
  padding: 16px 18px 16px 56px;
  margin: 0;
  border: 0;
  border-radius: 0;
  font: 400 0.92rem/1.6 "IBM Plex Mono", monospace;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

.source-highlight {
  position: absolute;
  inset: 0;
  height: 100%;
  color: var(--code-fg);
  background: var(--code-bg);
  pointer-events: none;
}

#source-code {
  position: relative;
  color: transparent;
  background: transparent;
  outline: none;
  resize: vertical;
  caret-color: var(--accent);
  -webkit-text-fill-color: transparent;
}

#source-code::selection {
  background: var(--accent);
  color: #000 !important;
  -webkit-text-fill-color: #000 !important;
  text-shadow: none;
}

#source-code::-moz-selection {
  background: var(--accent);
  color: #000 !important;
  text-shadow: none;
}

/* Syntax Highlighting Tokens */
.tok-comment { color: #7f9183; font-style: italic; }
.tok-keyword { color: #d08770; font-weight: 500; }
.tok-number { color: #b48ead; }
.tok-string { color: #a3be8c; }
.tok-preprocessor { color: #81a1c1; }

[data-theme="light"] .tok-comment { color: #66746a; font-style: italic; }
[data-theme="light"] .tok-keyword { color: #b05a3c; font-weight: 500; }
[data-theme="light"] .tok-number { color: #9c6895; }
[data-theme="light"] .tok-string { color: #3a7a40; }
[data-theme="light"] .tok-preprocessor { color: #3b6ea5; }

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--muted);
  box-sizing: border-box;
}

.editor-footer-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.draft-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
  animation: pulse-glow 2.5s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.75; }
}

.line-stats {
  font-family: "IBM Plex Mono", monospace;
}

.editor-footer-buttons {
  display: flex;
  align-items: center;
  gap: 5px;
}

.btn-mini {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  font: 500 0.74rem/1.2 "IBM Plex Sans", sans-serif;
  cursor: pointer;
  transition: all 0.14s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.btn-mini:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--accent);
  transform: translateY(-1px);
}

.btn-mini:active {
  transform: translateY(0) scale(0.98);
}

/* --- Right Side Column (Controls, Stdin, Output) --- */
.io-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 620px;
}

.control-card {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  flex-shrink: 0;
}

.run-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.14s cubic-bezier(0.2, 0.8, 0.2, 1),
              background-color 0.14s ease,
              border-color 0.14s ease,
              box-shadow 0.14s ease,
              color 0.14s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

/* Primary Run Button */
.button.primary {
  position: relative;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: none;
}

.button.primary .btn-svg {
  color: var(--accent);
  transition: color 0.14s ease;
}

.button.primary:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--accent);
  transform: translateY(-1px);
}

.button.primary:hover:not(:disabled) .btn-svg {
  color: var(--accent);
}

.button.primary:active:not(:disabled) {
  background: var(--surface-2);
  transform: translateY(0) scale(0.98);
}

/* Secondary Button: Clean surface matching site design */
.button.secondary {
  position: relative;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.button.secondary:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--fg);
}

/* Danger Button: Subtle Ruby tone */
.button.danger {
  color: #f87171;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.28);
}

.button.danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.22);
  border-color: #dc2626;
  color: #ffffff;
}

.button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* Keyboard Shortcut Tooltip — floats smoothly above the button on hover */
.kbd-pill {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  opacity: 0;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 3px 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  z-index: 20;
  transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.kbd-pill::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--border-strong);
}

.kbd-pill kbd {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--fg);
  font: 500 0.65rem/1.2 "IBM Plex Mono", monospace;
  white-space: nowrap;
}

.button:hover:not(:disabled) .kbd-pill {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.diag-link {
  color: var(--accent);
  text-decoration: underline dotted var(--accent);
  cursor: pointer;
  border-radius: 2px;
  padding: 0 2px;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.diag-link:hover {
  background-color: var(--accent-dim);
  color: var(--fg);
  text-decoration: underline solid var(--accent);
}

.btn-icon-only {
  padding: 3px 5px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.compiler-progress {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  font-size: 0.78rem;
  color: var(--fg);
}

.progress-status-text {
  font-weight: 500;
}

progress {
  display: block;
  width: 100%;
  height: 5px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

progress::-webkit-progress-bar {
  background: var(--surface);
}

progress::-webkit-progress-value {
  background: var(--accent);
  transition: width 0.2s ease;
}

progress::-moz-progress-bar {
  background: var(--accent);
}

.toolchain-info-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 2px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
}

.toolchain-status-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.toolchain-badge {
  font: 500 0.72rem/1.2 "IBM Plex Mono", monospace;
  color: var(--muted);
}

.btn-ghost-mini {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  font: 500 0.74rem/1.2 "IBM Plex Sans", sans-serif;
  cursor: pointer;
  transition: all 0.14s ease;
}

.btn-ghost-mini:hover {
  color: var(--fg);
  background: var(--surface);
  border-color: var(--border);
}

/* --- Input & Output Panels --- */
.io-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
}

.output-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

.input-bar, .output-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.input-bar h2, .output-bar h2 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--heading);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.heading-icon {
  color: var(--muted);
}

.output-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font: 500 0.72rem/1.2 "IBM Plex Mono", monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  transition: all 0.2s ease;
}

.status-pill .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
  transition: all 0.2s ease;
}

.status-pill.status-running {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-light);
}

.status-pill.status-running .status-dot {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(208, 135, 112, 0.6);
  animation: pulse-glow 1s infinite ease-in-out;
}

.status-pill.status-success {
  color: #10b981;
  border-color: #059669;
  background: rgba(16, 185, 129, 0.12);
}

.status-pill.status-success .status-dot {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.status-pill.status-error {
  color: #f87171;
  border-color: #dc2626;
  background: rgba(239, 68, 68, 0.12);
}

.status-pill.status-error .status-dot {
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.status-icon {
  width: 12px;
  height: 12px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-icon-running,
.status-icon-success,
.status-icon-error { display: none; fill: none; }
.status-running .status-icon-ready { display: none; }
.status-running .status-icon-running { display: block; animation: status-spin 0.85s linear infinite; transform-origin: center; }
.status-success .status-icon-ready { display: none; }
.status-success .status-icon-success { display: block; }
.status-error .status-icon-ready { display: none; }
.status-error .status-icon-error { display: block; }

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

#stdin {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 90px;
  padding: 10px 14px;
  margin: 0;
  color: var(--code-fg);
  background: var(--code-bg);
  border: 0;
  border-radius: 0;
  outline: none;
  resize: vertical;
  font: 400 0.86rem/1.55 "IBM Plex Mono", monospace;
}

#stdin::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

/* Prevent Shiki wrapper styling leaks into output */
.output-panel .codeblock {
  margin: 0 !important;
  border: 0 !important;
  background: transparent !important;
}

.output-panel .code-head {
  display: none !important;
}

#program-output {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 200px;
  max-height: 480px;
  flex: 1 1 auto;
  margin: 0 !important;
  padding: 12px 14px !important;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--code-fg);
  background: var(--code-bg) !important;
  border: 0 !important;
  border-radius: 0 !important;
  font: 400 0.86rem/1.6 "IBM Plex Mono", monospace;
}

/* --- Scrollbars --- */
#source-code::-webkit-scrollbar,
#stdin::-webkit-scrollbar,
#program-output::-webkit-scrollbar,
.compiler-toc-list::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#source-code::-webkit-scrollbar-track,
#stdin::-webkit-scrollbar-track,
#program-output::-webkit-scrollbar-track,
.compiler-toc-list::-webkit-scrollbar-track {
  background: var(--code-bg);
}

#source-code::-webkit-scrollbar-thumb,
#stdin::-webkit-scrollbar-thumb,
#program-output::-webkit-scrollbar-thumb,
.compiler-toc-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

#source-code::-webkit-scrollbar-thumb:hover,
#stdin::-webkit-scrollbar-thumb:hover,
#program-output::-webkit-scrollbar-thumb:hover,
.compiler-toc-list::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* --- Accessibility Focus States --- */
:where(textarea, select, button, summary, pre):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Responsive Breakpoints --- */
@media (max-width: 940px) {
  .compiler-grid {
    grid-template-columns: 1fr;
  }
  #source-code {
    min-height: 380px;
  }
  .compiler-toc-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .compiler-shell {
    width: min(100% - 24px, 1440px);
    padding: 16px 0 60px;
  }
  .compiler-intro h1 {
    font-size: 1.6rem;
  }
  .question-preview-bar {
    align-items: flex-start;
    flex-direction: column;
    padding: 10px 14px;
    gap: 8px;
  }
  .question-preview-actions {
    width: 100%;
    justify-content: space-between;
  }
  .question-preview section.question {
    padding: 1.2rem 1rem 1.4rem;
  }
  .run-actions {
    flex-direction: column;
  }
  .run-actions .button {
    width: 100%;
    min-height: 44px;
  }
  .editor-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 14px;
  }
  .editor-footer-buttons {
    width: 100%;
    justify-content: flex-end;
  }
  #source-code {
    min-height: 300px;
  }
  .toc-modal-dialog {
    padding: 1rem;
    max-height: 90vh;
  }
  .compiler-toc-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .compiler-page * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* --- Light Mode Styling --- */
[data-theme="light"] .status-pill.status-success {
  color: #047857;
  border-color: #059669;
  background: rgba(16, 185, 129, 0.14);
}

[data-theme="light"] .status-pill.status-error {
  color: #b91c1c;
  border-color: #dc2626;
  background: rgba(239, 68, 68, 0.14);
}

[data-theme="light"] .eyebrow-tag {
  color: var(--accent-dim);
  background: rgba(176, 106, 85, 0.12);
  border-color: rgba(176, 106, 85, 0.3);
}

[data-theme="light"] .editor-panel,
[data-theme="light"] .control-card,
[data-theme="light"] .io-panel,
[data-theme="light"] .output-panel,
[data-theme="light"] .question-preview,
[data-theme="light"] .toc-modal-dialog {
  box-shadow: 0 2px 12px rgba(46, 52, 64, 0.08);
}

[data-theme="light"] #source-code::placeholder,
[data-theme="light"] #stdin::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

[data-theme="light"] .kbd-pill {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--fg);
}

/* --- Touch-Target Sizing for Mobile --- */
@media (pointer: coarse) {
  .btn-mini,
  .btn-ghost-mini,
  .btn-nav,
  .icon-text-button,
  .icon-text-link {
    min-height: 44px;
    padding: 10px 14px;
  }
}
