﻿/* ============================================================
   code-runner.css â€” Embedded "Edit & Run" widget styles
   Plugs into the existing .button-backdrop / .code-container.
   ============================================================ */

/* ── Collapse / Expand toggle button ── */
.code-collapse-btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  margin: 0;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.5) !important;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.code-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.8) !important;
  border-color: rgba(255, 255, 255, 0.22);
}
.code-collapse-btn svg {
  display: block;
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor !important;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-origin: 50% 50%;
  transition: transform 0.2s;
}

/* Force icon parity inside code header controls */
.code-container .button-backdrop .code-theme-btn svg,
.code-container .button-backdrop .code-collapse-btn svg {
  width: 12px !important;
  height: 12px !important;
}
/* Rotate chevron when collapsed */
.code-container--collapsed .code-collapse-btn svg {
  transform: rotate(180deg);
}

/* Guard against global button utility overrides in dark mode */
.code-container:not(.code-container--light) .button-backdrop .code-collapse-btn {
  background: rgba(255, 255, 255, 0.07) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  color: rgba(255, 255, 255, 0.5) !important;
}
.code-container:not(.code-container--light) .button-backdrop .code-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.14) !important;
  border-color: rgba(255, 255, 255, 0.22) !important;
  color: rgba(255, 255, 255, 0.8) !important;
}

/* Collapsed state */
.code-container--collapsed > pre,
.code-container--collapsed > .cr-runner-body {
  display: none !important;
}
/* Round all corners of header when collapsed */
.code-container--collapsed .button-backdrop {
  border-radius: 14px !important;
  border-bottom: none !important;
}

/* ── Light / Dark theme toggle button ── */
.code-theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.code-theme-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.22);
}

/* Light theme overrides on the container */
.code-container--light .button-backdrop {
  background: #e8e8f0 !important;
  border-bottom-color: rgba(0, 0, 0, 0.08) !important;
}
.code-container--light .button-backdrop p {
  color: rgba(0, 0, 0, 0.45) !important;
}
.code-container--light .copy-button {
  background: rgba(0, 0, 0, 0.07) !important;
  color: rgba(0, 0, 0, 0.5) !important;
  border-color: rgba(0, 0, 0, 0.14) !important;
}
.code-container--light .copy-button:hover {
  background: rgba(0, 0, 0, 0.12) !important;
  color: rgba(0, 0, 0, 0.75) !important;
}
.code-container--light .code-theme-btn,
.code-container--light .code-collapse-btn {
  background: rgba(0, 0, 0, 0.07);
  border-color: rgba(0, 0, 0, 0.14);
  color: rgba(0, 0, 0, 0.5) !important;
}
.code-container--light .code-theme-btn:hover,
.code-container--light .code-collapse-btn:hover {
  background: rgba(0, 0, 0, 0.12);
  color: rgba(0, 0, 0, 0.8) !important;
  border-color: rgba(0, 0, 0, 0.22);
}
.code-container--light .cr-try-btn {
  background: rgba(0, 0, 0, 0.07);
  border-color: rgba(0, 0, 0, 0.14);
  color: rgba(0, 0, 0, 0.5);
}
.code-container--light .cr-try-btn:hover {
  background: rgba(240, 154, 15, 0.15);
  color: #a06800;
  border-color: rgba(240, 154, 15, 0.4);
}
.code-container--light .hljs {
  background: #f5f5fa !important;
  color: #383a42 !important;
}
/* Light theme scrollbar */
.code-container--light pre::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.04);
}
.code-container--light pre::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
}
.code-container--light pre::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}
/* Rounded collapsed state in light mode */
.code-container--light.code-container--collapsed .button-backdrop {
  border-radius: 14px !important;
}

/* Light theme: show more / show less bar */
.code-container--light .gl-code-toggle {
  background: #dde1e7 !important;
  color: rgba(0, 0, 0, 0.55) !important;
  border-top-color: rgba(0, 0, 0, 0.10) !important;
}
.code-container--light .gl-code-toggle:hover {
  color: #a06800 !important;
}
/* Fix fade gradient for light code background */
.code-container--light.gl-code-collapsed pre::after {
  background: linear-gradient(transparent, #f5f5fa) !important;
}

/* Light theme: override dracula token colors for legibility */
.code-container--light .hljs,
.code-container--light .hljs-subst {
  color: #383a42 !important;
}
/* built_in / selector-tag / section / link - cyan → teal */
.code-container--light .hljs-built_in,
.code-container--light .hljs-selector-tag,
.code-container--light .hljs-section,
.code-container--light .hljs-link {
  color: #0184bc !important;
}
/* keyword → magenta/pink → strong red-pink */
.code-container--light .hljs-keyword {
  color: #c91b76 !important;
}
/* title / attr / meta-keyword - green → dark green */
.code-container--light .hljs-title,
.code-container--light .hljs-attr,
.code-container--light .hljs-meta-keyword {
  color: #1a8b2e !important;
}
/* string / variable / template - yellow (#f1fa8c) → deep amber */
.code-container--light .hljs-string,
.code-container--light .hljs-meta,
.code-container--light .hljs-name,
.code-container--light .hljs-type,
.code-container--light .hljs-symbol,
.code-container--light .hljs-bullet,
.code-container--light .hljs-addition,
.code-container--light .hljs-variable,
.code-container--light .hljs-template-tag,
.code-container--light .hljs-template-variable {
  color: #986801 !important;
}
/* comment - muted purple → readable grey-blue */
.code-container--light .hljs-comment,
.code-container--light .hljs-quote,
.code-container--light .hljs-deletion {
  color: #6a737d !important;
}
/* literal / number - purple → rich purple */
.code-container--light .hljs-literal,
.code-container--light .hljs-number {
  color: #6f42c1 !important;
}

/* ── "Edit & Run" button in the .button-backdrop bar ── */
.cr-try-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  flex-shrink: 0;
}

.cr-try-btn:hover {
  background: rgba(240, 154, 15, 0.18);
  color: #f09a0f;
  border-color: rgba(240, 154, 15, 0.35);
}

.cr-try-btn--active,
.cr-try-btn--active:hover {
  background: rgba(240, 154, 15, 0.15);
  color: #f09a0f;
  border-color: rgba(240, 154, 15, 0.4);
}

.cr-try-btn svg {
  stroke: currentColor;
  flex-shrink: 0;
}

/* ── Runner body - hidden by default, shown in edit mode ── */
.cr-runner-body {
  background: #1e1e2e;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0 0 14px 14px;
}

/* Light theme: runner body */
.code-container--light .cr-runner-body {
  background: #f5f5fa;
  border-top-color: rgba(0, 0, 0, 0.08);
}
.code-container--light .cr-textarea {
  background: #f5f5fa;
  color: #383a42;
  border-bottom-color: rgba(0, 0, 0, 0.08);
}
.code-container--light .cr-textarea:focus {
  background: #ededf5;
}
.code-container--light .cr-actions {
  background: #e8e8f0;
  border-top-color: rgba(0, 0, 0, 0.06);
  border-bottom-color: rgba(0, 0, 0, 0.06);
}
.code-container--light .cr-btn-reset {
  background: rgba(0, 0, 0, 0.07);
  color: rgba(0, 0, 0, 0.55);
  border-color: rgba(0, 0, 0, 0.14);
}
.code-container--light .cr-btn-reset:hover {
  background: rgba(0, 0, 0, 0.12);
  color: rgba(0, 0, 0, 0.8);
}
.code-container--light .cr-results {
  background: #ededf5;
}
.code-container--light .cr-output {
  background: #e0ffe8;
  color: #1a6b30;
  border-color: rgba(0, 0, 0, 0.08);
}
.code-container--light .cr-error {
  background: #fff0f0;
  color: #c0392b;
  border-color: rgba(0, 0, 0, 0.08);
}

/* â”€â”€ Accessible label (visually hidden) â”€â”€ */
.cr-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* â”€â”€ Editable textarea â”€â”€ */
.cr-textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  padding: 18px 22px;
  font-family: 'Menlo', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 14.5px;
  line-height: 1.75;
  color: #cdd6f4;
  background: #1e1e2e;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  outline: none;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  transition: background 0.15s;
}

.cr-textarea:focus {
  background: #22223a;
  outline: none;
}

/* Custom scrollbar inside textarea â€” matches code block */
.cr-textarea::-webkit-scrollbar { height: 6px; width: 6px; }
.cr-textarea::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); }
.cr-textarea::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); border-radius: 3px; }
.cr-textarea::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

/* â”€â”€ Action row (Run + Reset) â”€â”€ */
.cr-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #16161e;
  border-top: 1px solid rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  flex-wrap: wrap;
}

/* â”€â”€ Buttons â”€â”€ */
.cr-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s;
  white-space: nowrap;
}

.cr-btn:active { transform: scale(0.97); }

.cr-btn-run {
  background: #f09a0f;
  color: #fff;
}

.cr-btn-run:hover { background: #d4870c; }

.cr-btn-reset {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.cr-btn-reset:hover {
  background: rgba(255, 255, 255, 0.13);
  color: rgba(255, 255, 255, 0.85);
}

/* â”€â”€ Results area â”€â”€ */
.cr-results {
  padding: 12px 16px 14px;
  background: #0f0f1a;
  border-radius: 0 0 14px 14px;
}

/* â”€â”€ Output (console) â”€â”€ */
.cr-output {
  margin: 0;
  padding: 10px 14px;
  background: #111;
  color: #00e000;
  border: 1px solid #1a3a1a;
  border-radius: 6px;
  font-family: 'Menlo', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}

/* â”€â”€ Error â”€â”€ */
.cr-error {
  margin: 0;
  padding: 10px 14px;
  background: #1a0a0a;
  color: #ff4d4f;
  border: 1px solid #3a1010;
  border-radius: 6px;
  font-family: 'Menlo', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Hidden iframe (JS mode) ── */
.cr-iframe { display: none !important; }

/* ── HTML preview iframe ── */
.cr-results--preview {
  padding: 12px 16px 14px;
  background: #0f0f1a;
  border-radius: 0 0 14px 14px;
}

.cr-preview {
  display: block;
  width: 100%;
  height: 220px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: #ffffff;
  resize: vertical;
  overflow: auto;
}

/* ── Mobile ── */
@media (max-width: 576px) {
  .cr-try-btn {
    font-size: 10.5px;
    padding: 3px 8px;
  }

  .code-theme-btn svg,
  .code-collapse-btn svg {
    width: 11px !important;
    height: 11px !important;
  }

  .cr-textarea {
    font-size: 0.85em;
    padding: 14px 16px;
  }

  .cr-actions {
    padding: 8px 12px;
    gap: 6px;
  }

  .cr-btn {
    width: 100%;
    justify-content: center;
    font-size: 12px;
  }

  .cr-results {
    padding: 10px 12px 12px;
  }
}
/* playground-specific styles are self-contained in playground.html */
