/* 🐉 CMRA — Premium Glassmorphic Theme */
:root {
  --bg: #0e0c0b;
  --bg-2: #131110;
  --panel: rgba(24, 22, 20, 0.65);
  --border: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(192, 90, 32, 0.3);
  --accent: #c05a20;
  --accent-2: #d4844a;
  --text: #c8bdb5;
  --muted: #8b7d76;
  --code-bg: rgba(18, 14, 12, 0.8);
  --scroll-track: rgba(21, 17, 15, 0.95);
  --scroll-thumb: linear-gradient(180deg, #b85c2f 0%, #8f4423 100%);
  --scroll-thumb-hover: linear-gradient(180deg, #d27645 0%, #b3542c 100%);
}

* {
  box-sizing: border-box;
}

html {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(ellipse at 50% -20%, #2f1d16 0%, #0e0c0b 60%);
  background-attachment: fixed;
  min-height: 100vh;
}

/* Themed scrollbar for webpage surfaces (keeps code editors untouched). */
html,
body,
pre,
#output-pane,
.variables-list {
  scrollbar-width: thin;
  scrollbar-color: #a7542d var(--scroll-track);
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
pre::-webkit-scrollbar,
#output-pane::-webkit-scrollbar,
.variables-list::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

html::-webkit-scrollbar-track,
body::-webkit-scrollbar-track,
pre::-webkit-scrollbar-track,
#output-pane::-webkit-scrollbar-track,
.variables-list::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 10px;
}

html::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb,
pre::-webkit-scrollbar-thumb,
#output-pane::-webkit-scrollbar-thumb,
.variables-list::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 10px;
  border: 2px solid var(--scroll-track);
}

html::-webkit-scrollbar-thumb:hover,
body::-webkit-scrollbar-thumb:hover,
pre::-webkit-scrollbar-thumb:hover,
#output-pane::-webkit-scrollbar-thumb:hover,
.variables-list::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

/* ── Header ── */
header {
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}

header h1 {
  margin: 0 0 0.2rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent-2);
  letter-spacing: -0.5px;
}

.tagline {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.github-link {
  margin: 0;
}

.github-link a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  transition: border-color 0.2s, color 0.2s;
  display: inline-block;
}

.github-link a:hover {
  border-color: var(--accent);
  color: var(--accent-2);
}

/* Try it Live Button */
.try-live-btn-header {
  background: var(--accent);
  color: #fff !important;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  border-radius: 5px;
  padding: 0.4rem 1rem;
  text-decoration: none;
  transition: background 0.2s, opacity 0.2s;
  display: inline-block;
}

.try-live-btn-header:hover {
  background: var(--accent-2);
}

/* ── Navigation ── */
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.3rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.875rem;
  transition: color 0.2s, border-color 0.2s;
}

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

/* ── Main ── */
main {
  max-width: 900px;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
}

/* ── Sections ── */
section {
  margin: 1.5rem 0;
  padding: 1.75rem 2rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.03);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

section:hover {
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.05);
}

section.hero {
  border-color: var(--border-glow);
  background: rgba(30, 18, 12, 0.7);
}

/* ── Typography ── */
h2 {
  margin: 0 0 0.9rem;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent-2);
}

h3 {
  margin: 1rem 0 0.6rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: #c07048;
}

h4 {
  margin: 0.75rem 0 0.5rem;
  font-size: 1rem;
  color: #a85e30;
}

p,
li {
  color: var(--text);
  margin-bottom: 0.7rem;
}

p.note,
p.equivalence {
  background: rgba(192, 90, 32, 0.07);
  border-left: 3px solid var(--accent);
  padding: 0.65rem 0.9rem;
  margin: 0.9rem 0;
  border-radius: 3px;
  font-size: 0.9rem;
}

strong {
  color: #c8bdb5;
}

em {
  color: var(--muted);
  font-style: italic;
}

/* ── Dragon / Wisdom Cards ── */
.dragon-card {
  background: #131110;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

.wisdom-card {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  background: transparent;
}

.wisdom-card h3 {
  margin-top: 0;
  font-size: 1rem;
}

/* ── Code ── */
code,
pre {
  font-family: Consolas, Monaco, "Courier New", monospace;
}

code {
  background: var(--code-bg);
  color: var(--accent-2);
  padding: 0.12rem 0.38rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-size: 0.88em;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: #c8a882;
  font-size: 0.88rem;
}

/* ── Table ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.9rem 0;
  border-radius: 6px;
  overflow: hidden;
}

th,
td {
  border: 1px solid var(--border);
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: #161210;
  color: var(--accent-2);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.4px;
}

tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

tr:hover {
  background: rgba(192, 90, 32, 0.05);
}

/* ── Lists ── */
ul,
ol {
  margin: 0.75rem 0 0.75rem 1.4rem;
}

li {
  margin-bottom: 0.45rem;
}

ul ul {
  margin-top: 0.35rem;
}

/* ── Links ── */
a {
  color: var(--accent-2);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s;
}

a:hover {
  color: #e0a070;
}

/* GitHub icon */
a[href*="github.com"]::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.3em;
  vertical-align: -0.15em;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38C13.71 14.53 16 11.54 16 8c0-4.42-3.58-8-8-8z'/%3E%3C/svg%3E") no-repeat center / contain;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38C13.71 14.53 16 11.54 16 8c0-4.42-3.58-8-8-8z'/%3E%3C/svg%3E") no-repeat center / contain;
}

/* ── Footer ── */
footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 2rem;
}

footer a {
  color: var(--muted);
  text-decoration: none;
}

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

/* ── Responsive ── */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  section {
    padding: 1rem;
  }

  nav a {
    font-size: 0.82rem;
    padding: 0.28rem 0.55rem;
  }
}

/* ═══ PLAYGROUND STYLES ═══ */
#playground {
  background: var(--panel);
  border-color: var(--border);
}

.playground-controls {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.02);
}

.control-row label {
  color: var(--text);
  font-weight: 500;
  font-size: 0.9rem;
}

.control-row select {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.4rem 0.7rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
  min-width: 180px;
}

.control-row select:hover,
.control-row select:focus {
  border-color: var(--accent);
  outline: none;
}

.file-upload-label {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.4rem 0.85rem;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  display: inline-block;
}

.file-upload-label:hover {
  border-color: var(--accent);
  color: var(--accent-2);
}

.action-btn {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 1rem;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(4px);
}

.action-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
  background: rgba(192, 90, 32, 0.15);
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(192, 90, 32, 0.15);
}

.action-btn:active {
  opacity: 0.75;
}

.run-btn {
  background: linear-gradient(135deg, var(--accent), #e87030);
  color: #fff;
  border: none;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(192, 90, 32, 0.3);
  letter-spacing: 0.5px;
}

.run-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #d46828, #f08348);
  box-shadow: 0 6px 16px rgba(192, 90, 32, 0.4);
  transform: translateY(-1px);
}

#editor-container {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-glow);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  height: 440px;
}

#editor-container .CodeMirror {
  height: 100%;
  font-size: 13.5px;
  font-family: Consolas, Monaco, "Courier New", monospace;
}

.output-section {
  margin-top: 1.25rem;
}

.output-section h3 {
  margin-top: 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
}

#output-pane {
  background: var(--code-bg);
  color: #a8f0c3;
  border: 1px solid rgba(255, 107, 53, 0.3);
  border-radius: 8px;
  padding: 1.25rem;
  min-height: 140px;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'Fira Code', Consolas, Monaco, monospace;
  font-size: 1.1rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.loading-status {
  background: rgba(192, 90, 32, 0.07);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Responsive Playground */
@media (max-width: 768px) {
  .control-row {
    flex-direction: column;
    align-items: stretch;
  }

  .control-row select,
  .file-upload-label,
  .action-btn {
    width: 100%;
    text-align: center;
  }

  #editor-container {
    height: 280px !important;
  }
}

.explain-box b,
.explain-box strong {
  color: var(--accent-1);
}

/* --- Layout --- */
.two-column-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.editor-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.debug-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.debug-controls-panel {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3);
}

.timeline-slider-container {
  margin: 1rem 0;
}

.timeline-actions {
  display: flex;
  gap: 0.5rem;
}

.timeline-actions .action-btn {
  flex: 1;
  text-align: center;
}

.step-badge {
  display: inline-block;
  background: rgba(192, 90, 32, 0.2);
  border: 1px solid rgba(255, 107, 53, 0.5);
  color: #ffaa7a;
  border-radius: 20px;
  padding: 0.5rem 1.2rem;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: Consolas, Monaco, monospace;
  margin-top: 1rem;
}


/* Live Variables Pane */
.variables-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3);
  max-height: 400px;
  overflow-y: auto;
}

.var-row {
  display: flex;
  align-items: center;
  background: transparent;
  border: 1px solid rgba(255, 107, 53, 0.4);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-family: Consolas, Monaco, "Courier New", monospace;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.var-row:hover {
  transform: translateX(6px);
  border-color: rgba(255, 107, 53, 0.8);
  box-shadow: 0 0 15px rgba(255, 107, 53, 0.2);
}

.var-name {
  color: #ffaa7a;
  font-weight: 500;
  font-size: 1.25rem;
}

.var-equals {
  color: #8b7d76;
  margin: 0 0.6rem;
  font-size: 1.25rem;
}

.var-value {
  color: #ffffff;
  font-size: 1.25rem;
  word-break: break-all;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
}

.empty-state {
  color: #8b7d76;
  opacity: 0.8;
  font-style: italic;
  font-size: 1.1rem;
  text-align: center;
  padding: 1rem;
}

/* Responsive Playground */
@media (max-width: 1024px) {
  .playground-layout {
    flex-direction: column;
  }

  .debug-col {
    min-width: 100%;
    order: -1;
  }
}

@media (min-width: 1024px) {
  .playground-main {
    max-width: 1400px;
  }
  .two-column-layout.debug-active {
    flex-direction: row;
  }
  .debug-col {
    width: 340px;
    flex-shrink: 0;
  }
}

/* Heatmap Gutter */
.heatmap-gutter-line {
  background: rgba(255, 107, 53, 0.1);
  width: 5px !important;
  margin-left: 2px;
}

#timeline-slider {
  width: 100%;
  appearance: none;
  background: rgba(192, 90, 32, 0.2);
  height: 8px;
  border-radius: 4px;
  outline: none;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

#timeline-slider::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, var(--accent), #f08348);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(192, 90, 32, 0.8);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#timeline-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

@media (max-width: 768px) {
  .control-row {
    flex-direction: column;
    align-items: stretch;
  }

  .control-row select,
  .file-upload-label,
  .action-btn {
    width: 100%;
    text-align: center;
  }

  #editor-container {
    height: 280px !important;
  }
}