/* ==========================================================================
   Raylings WebAssembly Playground Stylesheet
   Responsive Split-Pane Layout, Curriculum Syllabus Tree & Terminal Styling
   Standardized with Kubelings Architecture & Material MkDocs Theme
   ========================================================================== */

:root {
  --pg-bg: #ffffff;
  --pg-card-bg: #ffffff;
  --pg-sidebar-bg: #f8fafc;
  --pg-header-bg: #f8fafc;
  --pg-border: #e2e8f0;
  --pg-border-focus: #0284c7;
  --pg-text: #0f172a;
  --pg-text-muted: #64748b;
  --pg-accent: #0284c7;
  --pg-accent-hover: #0369a1;
  --pg-accent-fg: #ffffff;
  --pg-btn-bg: #f1f5f9;
  --pg-btn-hover: #e2e8f0;
  --pg-btn-active: #cbd5e1;
  --pg-btn-text: #1e293b;
  --pg-term-bg: #0b0f19;
  --pg-term-header-bg: #111827;
  --pg-term-text: #f1f5f9;
  --pg-term-border: #1f2937;
  --pg-term-dim: #64748b;
  --pg-success-bg: #dcfce7;
  --pg-success-text: #166534;
  --pg-success-border: #86efac;
  --pg-error-bg: #fee2e2;
  --pg-error-text: #991b1b;
  --pg-error-border: #fca5a5;
  --pg-warning-bg: #fef3c7;
  --pg-warning-text: #92400e;
  --pg-warning-border: #fcd34d;
  --pg-info-bg: #e0f2fe;
  --pg-info-text: #075985;
  --pg-info-border: #7dd3fc;
  --pg-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  --pg-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --pg-radius: 8px;
  --pg-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

[data-md-color-scheme="slate"],
[data-theme="dark"],
html[data-theme="dark"] {
  --pg-bg: #1e1e2e;
  --pg-card-bg: #181825;
  --pg-sidebar-bg: #11111b;
  --pg-header-bg: #11111b;
  --pg-border: #313244;
  --pg-border-focus: #89b4fa;
  --pg-text: #cdd6f4;
  --pg-text-muted: #9399b2;
  --pg-accent: #89b4fa;
  --pg-accent-hover: #b4befe;
  --pg-accent-fg: #11111b;
  --pg-btn-bg: #313244;
  --pg-btn-hover: #45475a;
  --pg-btn-active: #585b70;
  --pg-btn-text: #cdd6f4;
  --pg-term-bg: #0f0f17;
  --pg-term-header-bg: #181825;
  --pg-term-text: #cdd6f4;
  --pg-term-border: #27273a;
  --pg-term-dim: #6c7086;
  --pg-success-bg: rgba(34, 197, 94, 0.15);
  --pg-success-text: #86efac;
  --pg-success-border: rgba(34, 197, 94, 0.35);
  --pg-error-bg: rgba(239, 68, 68, 0.15);
  --pg-error-text: #fca5a5;
  --pg-error-border: rgba(239, 68, 68, 0.35);
  --pg-warning-bg: rgba(245, 158, 11, 0.15);
  --pg-warning-text: #fcd34d;
  --pg-warning-border: rgba(245, 158, 11, 0.35);
  --pg-info-bg: rgba(56, 189, 248, 0.15);
  --pg-info-text: #7dd3fc;
  --pg-info-border: rgba(56, 189, 248, 0.35);
  --pg-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Main Container & Split Layout
   ========================================================================== */

.raylings-playground,
.kubelings-playground {
  display: flex;
  flex-direction: column;
  background: var(--pg-card-bg);
  color: var(--pg-text);
  border: 1px solid var(--pg-border);
  border-radius: var(--pg-radius);
  box-shadow: var(--pg-shadow);
  margin: 0;
  overflow: hidden;
  font-family: var(--pg-font-sans);
  box-sizing: border-box;
  width: 100%;
  height: 100%;
}

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

.playground-split-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 650px;
  height: calc(100vh - 56px);
  max-height: 100vh;
}

@media (max-width: 1024px) {
  .playground-split-layout {
    grid-template-columns: 280px 1fr;
  }
}

@media (max-width: 768px) {
  .playground-split-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    max-height: none;
  }
}

/* ==========================================================================
   Sidebar: Curriculum Syllabus & State Explorer
   ========================================================================== */

.playground-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--pg-sidebar-bg);
  border-right: 1px solid var(--pg-border);
  overflow: hidden;
  height: 100%;
}

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--pg-border);
  background: var(--pg-header-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--pg-text);
}

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

.sidebar-icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--pg-text-muted);
  transition: all 0.15s ease;
}

.sidebar-icon-btn:hover {
  background: var(--pg-btn-hover);
  border-color: var(--pg-border);
  color: var(--pg-text);
}

.sidebar-icon-danger:hover {
  background: var(--pg-error-bg);
  border-color: var(--pg-error-border);
  color: var(--pg-error-text);
}

/* Global Progress Bar in Sidebar */
.sidebar-progress-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-progress-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: var(--pg-text-muted);
}

.sidebar-progress-pct {
  color: var(--pg-accent);
}

.sidebar-progress-track {
  height: 6px;
  background: var(--pg-btn-bg);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--pg-border);
}

.sidebar-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--pg-accent), #22c55e);
  transition: width 0.3s ease;
}

/* Search and Filter Tabs */
.sidebar-search-row {
  width: 100%;
}

.sidebar-search-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--pg-border);
  border-radius: 6px;
  background: var(--pg-card-bg);
  color: var(--pg-text);
  outline: none;
  transition: border-color 0.15s ease;
}

.sidebar-search-input:focus {
  border-color: var(--pg-border-focus);
}

.sidebar-filter-tabs {
  display: flex;
  background: var(--pg-btn-bg);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.filter-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 4px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--pg-text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.filter-tab:hover {
  color: var(--pg-text);
}

.filter-tab.active {
  background: var(--pg-card-bg);
  color: var(--pg-accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Syllabus Chapter Tree */
.sidebar-syllabus-tree {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.sidebar-loading-placeholder,
.sidebar-empty {
  padding: 20px 14px;
  font-size: 12px;
  color: var(--pg-text-muted);
  text-align: center;
}

.chapter-group {
  border-bottom: 1px solid var(--pg-border);
}

.chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  background: var(--pg-sidebar-bg);
  transition: background 0.15s ease;
  user-select: none;
}

.chapter-header:hover {
  background: var(--pg-btn-hover);
}

.chapter-header-title {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  flex: 1;
}

.chapter-chevron {
  font-size: 10px;
  color: var(--pg-text-muted);
  transition: transform 0.2s ease;
  display: inline-block;
}

.chapter-group.expanded .chapter-chevron {
  transform: rotate(90deg);
}

.chapter-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--pg-text-muted);
}

.chapter-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--pg-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-badge-count {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--pg-btn-bg);
  color: var(--pg-text-muted);
  border: 1px solid var(--pg-border);
  white-space: nowrap;
}

.chapter-badge-count.complete {
  background: var(--pg-success-bg);
  color: var(--pg-success-text);
  border-color: var(--pg-success-border);
}

.chapter-exercise-list {
  display: none;
  flex-direction: column;
  background: var(--pg-card-bg);
}

.chapter-group.expanded .chapter-exercise-list {
  display: flex;
}

.exercise-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 26px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  font-size: 12px;
}

.exercise-item:hover {
  background: var(--pg-btn-hover);
}

.exercise-item.active {
  background: var(--pg-info-bg);
  border-left-color: var(--pg-accent);
}

.exercise-status-icon {
  font-size: 11px;
  font-weight: 700;
  width: 14px;
  text-align: center;
}

.exercise-item.status-done .exercise-status-icon {
  color: #22c55e;
}

.exercise-item.status-progress .exercise-status-icon {
  color: #f59e0b;
}

.exercise-item.status-unstarted .exercise-status-icon {
  color: var(--pg-text-muted);
}

.exercise-item-content {
  flex: 1;
  overflow: hidden;
}

.exercise-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--pg-text);
}

.exercise-item-id {
  font-family: var(--pg-font-mono);
  font-weight: 600;
  font-size: 11px;
}

/* ==========================================================================
   Main Workspace: Top Bar & Metadata
   ========================================================================== */

.playground-main-workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.workspace-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  background: var(--pg-header-bg);
  border-bottom: 1px solid var(--pg-border);
}

.workspace-meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chapter-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--pg-btn-bg);
  color: var(--pg-text-muted);
  border: 1px solid var(--pg-border);
}

.chapter-badge-link {
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chapter-badge-link:hover {
  background: var(--pg-btn-hover);
  color: var(--pg-accent);
  border-color: var(--pg-accent-border);
}

.nav-btn-guide {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.35);
  color: #38bdf8;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  transition: all 0.15s ease;
}

.nav-btn-guide:hover {
  background: rgba(14, 165, 233, 0.25);
  border-color: #38bdf8;
  color: #ffffff;
}

.playground-btn-guide-tb {
  text-decoration: none;
  color: #38bdf8;
  border-color: rgba(14, 165, 233, 0.3);
  background: rgba(14, 165, 233, 0.08);
}

.playground-btn-guide-tb:hover {
  background: rgba(14, 165, 233, 0.18);
  border-color: #38bdf8;
  color: #ffffff;
}

.sidebar-guide-icon-btn {
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--pg-text-muted);
  text-decoration: none;
  transition: all 0.15s ease;
  opacity: 0.7;
}

.sidebar-guide-icon-btn:hover {
  opacity: 1;
  color: #38bdf8;
  background: var(--pg-btn-hover);
}

.exercise-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--pg-text);
}

.workspace-meta-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-stepper {
  display: flex;
  gap: 4px;
}

.nav-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--pg-btn-bg);
  border: 1px solid var(--pg-border);
  border-radius: 6px;
  color: var(--pg-text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover:not(:disabled) {
  background: var(--pg-btn-hover);
}

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

.playground-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 12px;
  background: var(--pg-btn-bg);
  color: var(--pg-text-muted);
  border: 1px solid var(--pg-border);
}

.playground-status-pill .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background-color: #94a3b8;
}

.playground-status-pill.status-loading .status-dot {
  background-color: #f59e0b;
  animation: pg-pulse 1.2s infinite;
}

.playground-status-pill.status-ready .status-dot {
  background-color: #22c55e;
}

.playground-status-pill.status-running .status-dot {
  background-color: #0284c7;
  animation: pg-pulse 0.8s infinite;
}

.playground-status-pill.status-error .status-dot {
  background-color: #ef4444;
}

@keyframes pg-pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

/* ==========================================================================
   Action Toolbar
   ========================================================================== */

.playground-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--pg-card-bg);
  border-bottom: 1px solid var(--pg-border);
}

.playground-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--pg-border);
  border-radius: 6px;
  background: var(--pg-btn-bg);
  color: var(--pg-btn-text);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.playground-btn:hover:not(:disabled) {
  background: var(--pg-btn-hover);
  border-color: var(--pg-border-focus);
}

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

.playground-btn-primary {
  background: var(--pg-accent);
  color: var(--pg-accent-fg);
  border-color: var(--pg-accent);
}

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

.playground-btn-kbd {
  font-size: 10px;
  font-family: var(--pg-font-mono);
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.15);
  margin-left: 4px;
}

.playground-btn.btn-active {
  background: var(--pg-accent);
  color: var(--pg-accent-fg);
}

/* ==========================================================================
   Hint Drawer
   ========================================================================== */

.playground-hints-card {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px;
  background: var(--pg-warning-bg);
  color: var(--pg-warning-text);
  border-bottom: 1px solid var(--pg-warning-border);
  font-size: 13px;
}

.playground-hints-card.hints-visible {
  display: flex;
}

.playground-hint-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.playground-hint-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

.playground-hint-text {
  flex: 1;
}

/* ==========================================================================
   Editor & Terminal Panes
   ========================================================================== */

.playground-workspace {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  flex: 1;
  overflow: hidden;
  background: var(--pg-card-bg);
}

@media (max-width: 900px) {
  .playground-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 350px 250px;
  }
}

.playground-editor-pane {
  position: relative;
  height: 100%;
  border-right: 1px solid var(--pg-border);
  overflow: hidden;
}

#playground-editor,
#playground-diff-editor {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

#playground-diff-editor {
  display: none;
}

.diff-active #playground-editor {
  display: none;
}

.diff-active #playground-diff-editor {
  display: block;
}

.playground-output-pane {
  display: flex;
  flex-direction: column;
  background: var(--pg-term-bg);
  color: var(--pg-term-text);
  height: 100%;
  overflow: hidden;
}

.playground-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--pg-term-header-bg);
  border-bottom: 1px solid var(--pg-term-border);
  font-size: 11px;
}

.playground-output-tabs {
  display: flex;
  gap: 6px;
}

.playground-output-tab {
  background: transparent;
  border: none;
  color: var(--pg-term-dim);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.playground-output-tab.active {
  background: var(--pg-btn-bg);
  color: var(--pg-accent);
}

.playground-output-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.playground-output-title-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
}

.playground-output-meta {
  color: var(--pg-term-dim);
  font-family: var(--pg-font-mono);
}

#playground-output,
#playground-cluster-view {
  flex: 1;
  margin: 0;
  padding: 12px;
  overflow-y: auto;
  font-family: var(--pg-font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

#playground-cluster-view {
  display: none;
}

/* ANSI & Terminal Styling */
.term-pass { color: #4ade80; }
.term-fail { color: #f87171; }
.term-warn { color: #fbbf24; }
.term-info { color: #38bdf8; }
.term-bold { font-weight: 700; }
.term-dim { color: var(--pg-term-dim); }

.term-banner-pass {
  display: block;
  padding: 4px 8px;
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border-left: 3px solid #22c55e;
  font-weight: 700;
  margin-bottom: 8px;
}

.term-banner-fail {
  display: block;
  padding: 4px 8px;
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border-left: 3px solid #ef4444;
  font-weight: 700;
  margin-bottom: 8px;
}

.term-banner-info {
  display: block;
  padding: 4px 8px;
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border-left: 3px solid #0284c7;
  font-weight: 700;
  margin-bottom: 8px;
}

.term-inline-btn {
  background: var(--pg-accent);
  color: var(--pg-accent-fg);
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  margin-left: 4px;
  transition: opacity 0.15s ease;
}

.term-inline-btn:hover {
  opacity: 0.9;
}

/* Cluster Inspector Cards */
.cluster-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.cluster-stat-card {
  background: var(--pg-term-header-bg);
  border: 1px solid var(--pg-term-border);
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cluster-stat-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--pg-accent);
}

.cluster-stat-lbl {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--pg-term-dim);
}

/* ==========================================================================
   Fullscreen Mode & Full-Bleed Container Overrides
   ========================================================================== */

.raylings-playground:fullscreen,
.raylings-playground:-webkit-full-screen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  background: var(--pg-card-bg) !important;
  z-index: 2147483647 !important;
}

.raylings-playground:fullscreen .playground-split-layout,
.raylings-playground:-webkit-full-screen .playground-split-layout {
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
}

.raylings-playground.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  margin: 0 !important;
  border-radius: 0 !important;
  z-index: 2147483647 !important;
  box-shadow: none !important;
  background: var(--pg-card-bg) !important;
}

.raylings-playground.is-fullscreen .playground-split-layout {
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
}

body:has(#raylings-playground) .md-main__inner,
body:has(#raylings-playground) .md-grid,
body:has(#raylings-playground) .md-content,
body:has(#raylings-playground) .md-content__inner,
body:has(#raylings-playground) .md-typeset,
.md-content:has(#raylings-playground),
.md-typeset:has(#raylings-playground) {
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  width: 100% !important;
}
