/* ==========================================================================
   Code Playground — Minimalist Light Mode Stylesheet
   Crisp off-white/white surfaces, 1px hairline dividers, sky-blue accent,
   structured Desktop & 3-row Mobile toolbar, IDE autocomplete popup.
   ========================================================================== */

:root {
  --surface: #FFFFFF;
  --surface-subtle: #F8FAFC;
  --surface-hover: #F1F5F9;
  --surface-active: #E0F2FE;

  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;

  --accent: #0284C7;
  --accent-hover: #0369A1;
  --accent-soft: #F0F9FF;
  --accent-border: #BAE6FD;

  --danger: #DC2626;
  --danger-soft: #FEF2F2;
  --danger-border: #FECACA;

  --success: #0F766E;
  --success-soft: #F0FDFA;

  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --editor-font-size: 14px;
  --editor-line-height: 22px;
  --divider-size: 14px;
  --app-height: 100dvh;

  /* Syntax Highlighting (Clean Light Theme) */
  --tok-comment: #64748B;
  --tok-keyword: #0284C7;
  --tok-type: #0369A1;
  --tok-string: #0F766E;
  --tok-number: #C2410C;
  --tok-function: #1D4ED8;
  --tok-meta: #6D28D9;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background-color: var(--surface-subtle);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[hidden] {
  display: none !important;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

/* ==========================================================================
   App Shell
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: var(--app-height);
  min-height: 0;
  background-color: var(--surface);
}

/* ==========================================================================
   Top Navigation Bar — Desktop (>= 768px) & 3-Row Mobile (< 768px)
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 50px;
  padding: 7px 12px;
  background-color: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 30;
}

.tb-item,
.tb-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.tb-brand {
  margin-right: 4px;
}

.tb-back {
  margin-left: auto;
}

/* Hairline vertical dividers between toolbar visual groups on desktop */
.tb-sep {
  display: inline-block;
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background-color: var(--border-strong);
  flex-shrink: 0;
}

/* Invisible responsive row-break helpers */
.tb-break {
  display: none;
  flex: 0 0 100%;
  height: 0;
  margin: 0;
  padding: 0;
}

/* App Brand */
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.015em;
  white-space: nowrap;
  user-select: none;
}

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

/* Back Link (Far-right top corner on desktop; Row 1 right on mobile) */
.back-link {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: color 130ms ease, background-color 130ms ease, border-color 130ms ease;
}

.back-link:hover {
  color: var(--accent);
  background-color: var(--surface-hover);
  border-color: var(--border);
}

/* Clean Minimalist Language Dropdown */
.lang-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.lang-select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: none;
  height: 32px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--surface);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 30px;
  cursor: pointer;
  transition: border-color 130ms ease, background-color 130ms ease, color 130ms ease;
}

.lang-select::picker-icon {
  display: none;
}

.lang-select::-ms-expand {
  display: none;
}

.lang-select:hover {
  border-color: var(--border-strong);
  background-color: var(--surface-hover);
}

.lang-select:focus {
  border-color: var(--accent);
}

.lang-select-chevron {
  position: absolute;
  right: 8px;
  pointer-events: none;
  color: var(--text-muted);
}

/* Uniform Height Toolbar Buttons */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 120ms ease, opacity 140ms ease;
}

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

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

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

.btn-run {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
  padding: 0 11px;
}

.btn-run:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-stop:not(:disabled) {
  background-color: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-stop:hover:not(:disabled) {
  background-color: #FEE2E2;
  border-color: #FCA5A5;
}

.btn-subtle.is-active {
  background-color: var(--surface-active);
  border-color: var(--accent-border);
  color: var(--accent-hover);
}

.btn-subtle.is-active:hover:not(:disabled) {
  background-color: #CFEBFD;
  border-color: #7DD3FC;
}

.btn-icon {
  width: 32px;
  padding: 0;
  color: var(--text-secondary);
}

.btn-icon:hover:not(:disabled) {
  color: var(--text-primary);
}

.btn-icon.is-active {
  color: var(--accent-hover);
}

.btn-history:disabled {
  opacity: 0.36;
  cursor: default;
  pointer-events: none;
}

/* Tactile Micro-Animations for State-Reactive Controls */
.icon-anim,
.icon-swap {
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), opacity 140ms ease;
}

.btn-interactive.is-swapping .icon-swap {
  transform: rotate(180deg);
}

.btn-interactive.is-pulsing .icon-anim {
  transform: scale(0.86);
}

/* Examples Dropdown */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 280px;
  max-width: min(340px, calc(100vw - 24px));
  padding: 6px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.1), 0 2px 6px rgba(15, 23, 42, 0.05);
  z-index: 60;
}

.dropdown-header {
  padding: 4px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.dropdown-divider {
  height: 1px;
  margin: 4px 6px;
  background-color: var(--border);
}

.dropdown-item {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background-color: var(--accent-soft);
}

.dropdown-item-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dropdown-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropdown-item-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background-color: var(--surface-active);
  color: var(--accent-hover);
}

.dropdown-item:hover .dropdown-item-title {
  color: var(--accent-hover);
}

.dropdown-item-desc {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   Separate Pages Switcher Bar (Single Page Mode)
   ========================================================================== */

.page-switcher {
  display: flex;
  align-items: stretch;
  background-color: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.page-tab {
  appearance: none;
  flex: 1;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  transition: color 130ms ease, border-color 130ms ease, background-color 130ms ease;
}

.page-tab:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
}

.page-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background-color: var(--surface);
}

/* ==========================================================================
   Two-Pane Workspace & Split / Swap / Single-Page Layout Engine
   ========================================================================== */

.workspace {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: var(--surface);
}

.workspace[data-mode="split"][data-direction="horizontal"] {
  flex-direction: row;
}

.workspace[data-mode="split"][data-direction="vertical"] {
  flex-direction: column;
}

.workspace[data-mode="split"][data-swapped="false"] .code-pane {
  order: 1;
  flex: 0 0 calc(var(--split-ratio, 50%) - (var(--divider-size) / 2));
}

.workspace[data-mode="split"][data-swapped="false"] .output-pane {
  order: 3;
  flex: 1 1 0;
}

.workspace[data-mode="split"][data-swapped="true"] .output-pane {
  order: 1;
  flex: 0 0 calc(var(--split-ratio, 50%) - (var(--divider-size) / 2));
}

.workspace[data-mode="split"][data-swapped="true"] .code-pane {
  order: 3;
  flex: 1 1 0;
}

.workspace[data-mode="split"] .pane-divider {
  order: 2;
}

.workspace[data-mode="single"] .pane-divider {
  display: none;
}

.workspace[data-mode="single"] .pane {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
}

.workspace[data-mode="single"][data-active-page="code"] .output-pane {
  display: none;
}

.workspace[data-mode="single"][data-active-page="output"] .code-pane {
  display: none;
}

.workspace.is-resizing .preview-frame {
  pointer-events: none;
}

.workspace.is-resizing {
  user-select: none;
}

/* ==========================================================================
   Pane Common Styles
   ========================================================================== */

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background-color: var(--surface);
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  background-color: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

.pane-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.pane-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pane-filename {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.pane-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
}

.meta-hint {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Multi-File Tabs inside Code Panel (index.html, style.css, script.js) */
.subtabs {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.subtabs::-webkit-scrollbar {
  display: none;
}

.subtab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.subtab:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
}

.subtab.is-active {
  color: var(--accent);
  background-color: var(--surface);
  border-color: var(--border);
  font-weight: 600;
}

/* ==========================================================================
   Slim Dedicated Divider Rail With Strictly Contained Mini Buttons
   ========================================================================== */

.pane-divider {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 var(--divider-size);
  overflow: hidden;
  background-color: var(--surface-subtle);
  touch-action: none;
  z-index: 10;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.workspace[data-direction="horizontal"] .pane-divider {
  width: var(--divider-size);
  flex-direction: column;
  cursor: col-resize;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.workspace[data-direction="vertical"] .pane-divider {
  height: var(--divider-size);
  flex-direction: row;
  cursor: row-resize;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.divider-grip {
  display: none;
}

.pane-divider:hover,
.pane-divider.is-dragging {
  background-color: var(--accent-soft);
  border-color: var(--accent-border);
}

/* Strictly contained, bubble-free inline button container */
.divider-actions {
  position: static;
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  cursor: default;
}

.workspace[data-direction="horizontal"] .divider-actions {
  flex-direction: column;
}

.workspace[data-direction="vertical"] .divider-actions {
  flex-direction: row;
}

.divider-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.divider-btn svg {
  width: 10px;
  height: 10px;
}

.divider-btn:hover,
.divider-btn:focus-visible {
  background-color: rgba(2, 132, 199, 0.12);
  color: var(--accent);
}

.divider-btn:active {
  transform: scale(0.9);
}

.divider-btn.is-active {
  background: transparent;
  color: var(--accent);
}

.divider-btn.is-active:hover,
.divider-btn.is-active:focus-visible {
  background-color: rgba(2, 132, 199, 0.16);
  color: var(--accent-hover);
}

/* ==========================================================================
   Dismissible C++ / C Basic-Code Notice Banner
   ========================================================================== */

.cpp-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  background-color: var(--accent-soft);
  border-bottom: 1px solid var(--accent-border);
  color: #334155;
  font-size: 12.5px;
  line-height: 1.45;
  flex-shrink: 0;
}

.notice-icon {
  color: var(--accent);
  margin-top: 2px;
  flex-shrink: 0;
}

.notice-text {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.notice-close {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-top: -2px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.notice-close:hover {
  background-color: var(--surface-active);
  border-color: var(--accent-border);
  color: var(--accent-hover);
}

/* ==========================================================================
   Code Editor (Synchronized Line Numbers + Highlight Layer + Textarea)
   ========================================================================== */

.editor-shell {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background-color: var(--surface);
  overflow: hidden;
}

.editor-gutter {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 14px 10px 64px 8px;
  background-color: var(--surface-subtle);
  border-right: 1px solid var(--border);
  color: #94A3B8;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: var(--editor-line-height);
  text-align: right;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}

.editor-stack {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: var(--surface);
}

.editor-highlight,
.editor-textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  padding: 14px 16px 64px 14px;
  font-family: var(--font-mono);
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  letter-spacing: 0;
  font-variant-ligatures: none;
  tab-size: 4;
  -moz-tab-size: 4;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  box-sizing: border-box;
}

.editor-highlight {
  z-index: 1;
  pointer-events: none;
  overflow: auto;
  scrollbar-width: none;
  color: var(--text-primary);
  background: transparent;
  padding-right: 40px;
}

.editor-highlight::-webkit-scrollbar {
  display: none;
}

.editor-highlight code {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.editor-textarea {
  z-index: 2;
  overflow: auto;
  resize: none;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text-primary);
}

.editor-textarea::selection {
  background-color: rgba(14, 165, 233, 0.22);
}

/* Syntax Token Colors */
.tok-comment {
  color: var(--tok-comment);
  font-style: italic;
}

.tok-keyword {
  color: var(--tok-keyword);
  font-weight: 500;
}

.tok-type {
  color: var(--tok-type);
}

.tok-string {
  color: var(--tok-string);
}

.tok-number {
  color: var(--tok-number);
}

.tok-function {
  color: var(--tok-function);
}

.tok-meta {
  color: var(--tok-meta);
}

/* ==========================================================================
   IDE Autocomplete / Code Suggestions Popup (Minimalist Light Mode)
   ========================================================================== */

.ac-measure-span {
  position: fixed;
  top: -9999px;
  left: -9999px;
  visibility: hidden;
  pointer-events: none;
  white-space: pre;
  font-variant-ligatures: none;
}

.ac-popup {
  position: fixed;
  z-index: 80;
  min-width: 210px;
  max-width: min(300px, calc(100vw - 16px));
  max-height: 216px;
  overflow-y: auto;
  padding: 4px;
  background-color: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
}

.ac-item {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 5px 8px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.ac-item:hover {
  background-color: var(--surface-hover);
}

.ac-item.is-selected {
  background-color: var(--surface-active);
  color: var(--accent-hover);
}

.ac-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ac-match {
  font-weight: 700;
  color: var(--accent);
}

.ac-item.is-selected .ac-match {
  color: var(--accent-hover);
}

.ac-kind {
  flex-shrink: 0;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 1px 5px;
  border-radius: 4px;
  background-color: var(--surface-hover);
  color: var(--text-muted);
}

.ac-item.is-selected .ac-kind {
  background-color: rgba(2, 132, 199, 0.14);
  color: var(--accent-hover);
}

.ac-kind-kw { color: var(--tok-keyword); }
.ac-kind-fn { color: var(--tok-function); }
.ac-kind-tag { color: var(--tok-keyword); }
.ac-kind-prop { color: var(--tok-type); }
.ac-kind-type { color: var(--tok-type); }
.ac-kind-meta { color: var(--tok-meta); }
.ac-kind-var { color: var(--text-secondary); }

/* ==========================================================================
   Output / Preview Panel Controls & Status
   ========================================================================== */

.pane-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-pill {
  display: inline-block;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.45;
  background-color: var(--surface-hover);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill[data-state="loading"],
.status-pill[data-state="running"] {
  background-color: var(--accent-soft);
  color: var(--accent-hover);
}

.status-pill[data-state="loading"]::before,
.status-pill[data-state="running"]::before {
  content: '';
  display: inline-block;
  vertical-align: -1px;
  margin-right: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-border);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}

.status-pill[data-state="waiting"] {
  background-color: var(--surface-active);
  color: var(--accent-hover);
  font-weight: 600;
}

.status-pill[data-state="waiting"]::before {
  content: '';
  display: inline-block;
  vertical-align: 0;
  margin-right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent);
  animation: pulseDot 1s ease-in-out infinite;
}

.status-pill[data-state="done"] {
  background-color: var(--success-soft);
  color: var(--success);
}

.status-pill[data-state="error"],
.status-pill[data-state="stopped"] {
  background-color: var(--danger-soft);
  color: var(--danger);
}

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

@keyframes pulseDot {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

.mini-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.mini-btn:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
  border-color: var(--border-strong);
}

.mini-btn[aria-expanded="true"] {
  background-color: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-hover);
}

.mini-btn[aria-expanded="true"] .icon-stdin-caret {
  transform: rotate(180deg);
}

.stdin-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent);
}

/* Auto-run Toggle for Preview Languages */
.autorun-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.autorun-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-track {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background-color: var(--border-strong);
  transition: background-color 140ms ease;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background-color: #FFFFFF;
  transition: transform 140ms ease;
}

.autorun-toggle input:checked + .toggle-track {
  background-color: var(--accent);
}

.autorun-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(13px);
}

.autorun-toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Interactive Terminal Console, Inline Input & SQL Tables
   ========================================================================== */

.console-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background-color: var(--surface);
}

.console-output {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 36px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.console-output.is-waiting-input {
  cursor: text;
}

.console-placeholder {
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text-muted);
}

.console-status-line {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--accent-hover);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.console-stderr,
.console-error {
  display: block;
  margin-top: 6px;
  color: var(--danger);
}

.console-info {
  display: block;
  margin-top: 8px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--text-muted);
}

.term-input-echo {
  color: var(--accent-hover);
  font-weight: 500;
}

.term-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  vertical-align: baseline;
  white-space: nowrap;
}

.term-inline-input {
  appearance: none;
  min-width: 10ch;
  max-width: min(36ch, calc(100vw - 90px));
  padding: 1px 6px;
  margin: 0;
  border: 1px solid var(--accent-border);
  border-bottom: 2px solid var(--accent);
  border-radius: 4px;
  background-color: var(--accent-soft);
  color: var(--accent-hover);
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  caret-color: var(--accent);
  outline: none;
}

.term-inline-input:focus {
  border-color: var(--accent);
  background-color: #FFFFFF;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.14);
}

.term-inline-input::placeholder {
  color: #94A3B8;
  font-weight: 400;
}

.term-inline-submit {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  min-width: 26px;
  padding: 0 7px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background-color: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.term-inline-submit:hover {
  background-color: var(--accent-hover);
}

/* Minimalist SQL Result Tables */
.sql-results-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-family: var(--font-sans);
  white-space: normal;
}

.sql-result-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sql-result-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.sql-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.sql-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}

.sql-table th,
.sql-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.sql-table th:last-child,
.sql-table td:last-child {
  border-right: none;
}

.sql-table tbody tr:last-child td {
  border-bottom: none;
}

.sql-table thead th {
  background-color: var(--surface-subtle);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.sql-table tbody tr:hover td {
  background-color: var(--accent-soft);
}

.sql-table td.is-num {
  font-family: var(--font-mono);
  text-align: right;
}

.sql-table td.is-null {
  font-family: var(--font-mono);
  font-style: italic;
  color: var(--text-muted);
}

/* Fallback Stdin Drawer */
.stdin-section {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background-color: var(--surface-subtle);
}

.stdin-bar {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 34px;
  padding: 0 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.stdin-bar:hover {
  background-color: var(--surface-hover);
  color: var(--text-primary);
}

.stdin-bar-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stdin-section:not(.is-collapsed) .stdin-chevron {
  transform: rotate(90deg);
}

.stdin-bar-title {
  font-weight: 600;
  color: var(--text-primary);
}

.stdin-summary {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stdin-summary.has-value {
  color: var(--accent);
}

.stdin-bar-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.stdin-body {
  padding: 0 12px 10px;
}

.stdin-textarea {
  display: block;
  width: 100%;
  min-height: 70px;
  max-height: 160px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

.stdin-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ==========================================================================
   Sandboxed Live Preview (HTML & CSS + Markdown)
   ========================================================================== */

.preview-view {
  flex: 1;
  min-width: 0;
  min-height: 0;
  background-color: #FFFFFF;
}

.preview-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background-color: #FFFFFF;
}

/* ==========================================================================
   Responsive Toolbar Breakpoints
   ========================================================================== */

/* Standard Desktop (1161px - 1340px): keep all groups crisp on 1 row */
@media (max-width: 1340px) and (min-width: 1161px) {
  .topbar {
    padding: 7px 10px;
    gap: 5px;
  }

  .tb-group {
    gap: 4px;
  }

  .tb-sep {
    margin: 0 2px;
  }

  .btn {
    padding: 0 8px;
  }

  .btn-icon {
    width: 32px;
    padding: 0;
  }

  .btn-run {
    padding: 0 10px;
  }

  .lang-select {
    padding: 0 24px 0 9px;
  }

  .back-link {
    padding: 0 6px;
    font-size: 12px;
  }
}

/* Compact Desktop / Tablet Landscape (768px - 1160px): clean 2-row header
   Row 1: Brand + Language (Left) ... Back link (Far Right)
   Row 2: [Exec] | [Editor Tools] | [Single Page, Fullscreen] */
@media (max-width: 1160px) and (min-width: 768px) {
  .topbar {
    padding: 7px 12px;
    gap: 7px 6px;
  }

  .tb-brand { order: 1; }
  .tb-lang { order: 2; }
  .tb-back { order: 3; margin-left: auto; }
  .tb-sep-0 { display: none; }
  .tb-break-1 { display: block; order: 4; }
  .tb-exec { order: 5; }
  .tb-sep-1 { order: 6; }
  .tb-tools-primary { order: 7; }
  .tb-tools-history { order: 8; }
  .tb-tools-reset { order: 9; }
  .tb-sep-2 { order: 10; }
  .tb-view-single { order: 11; }
  .tb-view-fs { order: 12; }

  .meta-shortcut {
    display: none;
  }
}

/* Mobile Layout (< 768px): Exact 3-Row Pattern
   Row 1: Code Playground (left) ... <- back to alisadeq.dev (right)
   Row 2: Run, Stop, Examples, Suggest
   Row 3: [Undo] [Redo] [Single Page] [Clear] [Reset] [Fullscreen] (left) ... Language (right) */
@media (max-width: 767px) {
  .workspace[data-direction="vertical"] {
    --divider-size: 18px;
  }

  .workspace[data-direction="horizontal"] {
    --divider-size: 16px;
  }

  .divider-btn {
    width: 15px;
    height: 15px;
  }

  .workspace[data-direction="horizontal"] .divider-btn {
    width: 14px;
    height: 14px;
  }

  .divider-btn svg {
    width: 11px;
    height: 11px;
  }

  .topbar {
    padding: 7px 8px;
    gap: 7px 5px;
  }

  .tb-sep {
    display: none;
  }

  /* Row 1 */
  .tb-brand { order: 1; margin-right: auto; }
  .tb-back { order: 2; margin-left: 0; }

  .tb-break-1 { display: block; order: 3; }

  /* Row 2: Run, Stop, Examples, Suggest */
  .tb-exec { order: 4; gap: 5px; }
  .tb-tools-primary { order: 5; gap: 5px; }

  .tb-break-2 { display: block; order: 6; }

  /* Row 3: Undo, Redo, Single Page, Clear, Reset, Fullscreen + Language on far right */
  .tb-tools-history { order: 7; gap: 5px; }
  .tb-view-single { order: 8; }
  .tb-tools-reset { order: 9; gap: 5px; }
  .tb-view-fs { order: 10; }
  .tb-lang { order: 11; margin-left: auto; min-width: 0; }

  .lang-select-wrap {
    min-width: 0;
    max-width: 100%;
  }

  .tb-view-single .btn-label,
  .tb-tools-reset .btn-label-sm {
    display: none;
  }

  .tb-tools-history .btn,
  .tb-view-single .btn,
  .tb-tools-reset .btn,
  .tb-view-fs .btn {
    width: 31px;
    height: 31px;
    padding: 0;
  }

  .tb-exec .btn,
  .tb-tools-primary .btn {
    height: 31px;
    padding: 0 9px;
  }

  .lang-select {
    height: 31px;
    line-height: 29px;
    font-size: 12.5px;
    padding: 0 26px 0 9px;
    max-width: 168px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .lang-select-chevron {
    right: 8px;
  }

  .brand-title {
    font-size: 13.5px;
  }

  .back-link {
    height: 28px;
    font-size: 12px;
    padding: 0 5px;
  }

  .meta-shortcut,
  .stdin-bar-hint {
    display: none;
  }
}

/* Compact phones (<= 430px, e.g. 390px): keep all 6 Row 3 icons + Language on one clean line */
@media (max-width: 430px) {
  .topbar {
    gap: 7px 4px;
  }

  .tb-exec,
  .tb-tools-primary,
  .tb-tools-history,
  .tb-tools-reset {
    gap: 4px;
  }

  .tb-tools-history .btn,
  .tb-view-single .btn,
  .tb-tools-reset .btn,
  .tb-view-fs .btn {
    width: 28px;
    height: 28px;
    padding: 0;
  }

  .lang-select {
    height: 28px;
    line-height: 26px;
    font-size: 12px;
    padding: 0 23px 0 8px;
    max-width: 158px;
  }

  .lang-select-chevron {
    right: 7px;
  }
}

/* Extra-narrow phone screens (<= 380px, e.g. 360px wide) */
@media (max-width: 380px) {
  .topbar {
    padding: 7px 6px;
    gap: 6px 4px;
  }

  .tb-exec,
  .tb-tools-primary,
  .tb-tools-history,
  .tb-tools-reset {
    gap: 4px;
  }

  .tb-exec .btn,
  .tb-tools-primary .btn {
    height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .tb-tools-history .btn,
  .tb-view-single .btn,
  .tb-tools-reset .btn,
  .tb-view-fs .btn {
    width: 26px;
    height: 26px;
    padding: 0;
  }

  .tb-tools-history .btn .icon,
  .tb-view-single .btn .icon,
  .tb-tools-reset .btn .icon,
  .tb-view-fs .btn .icon {
    width: 13px;
    height: 13px;
  }

  .lang-select {
    height: 26px;
    line-height: 24px;
    font-size: 11.5px;
    padding: 0 21px 0 7px;
    max-width: 146px;
  }

  .lang-select-chevron {
    right: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
