/* ============================================================
   Code Playground — inline "Try It" editor for study pages
   ============================================================ */

/* "Try It" button overlaid on code blocks */
.cp-try-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--code-text);
  background: rgba(74, 144, 217, 0.85);
  border: 1px solid rgba(74, 144, 217, 0.5);
  border-radius: 0.375rem;
  cursor: pointer;
  z-index: 5;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  line-height: 1.4;
}

.cp-try-btn:hover {
  background: rgba(74, 144, 217, 1);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(74, 144, 217, 0.4);
}

.cp-try-btn:active {
  transform: translateY(0);
}

/* Playground container */
.cp-container {
  border: 1px solid rgba(74, 144, 217, 0.4);
  border-radius: 0.75rem;
  overflow: hidden;
  margin: 0.75rem 0;
  background: var(--bg-secondary);
  opacity: 0;
  max-height: 0;
  transition: opacity 0.25s ease, max-height 0.35s ease;
}

.cp-container.cp-active {
  opacity: 1;
  max-height: 2000px;
}

.cp-container.cp-closing {
  opacity: 0;
  max-height: 0;
  transition: opacity 0.2s ease, max-height 0.25s ease;
}

/* Toolbar */
.cp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  background: rgba(74, 144, 217, 0.12);
  border-bottom: 1px solid rgba(74, 144, 217, 0.25);
  gap: 0.5rem;
  flex-wrap: wrap;
}

.cp-lang-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: 'Space Grotesk', sans-serif;
}

.cp-btn-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Buttons */
.cp-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  background: var(--bg-primary);
  color: var(--text-main);
}

.cp-btn:hover {
  border-color: rgba(148, 163, 184, 0.5);
  background: rgba(148, 163, 184, 0.1);
}

.cp-btn-run {
  background: rgba(34, 197, 94, 0.15);
  color: var(--status-success-text);
  border-color: rgba(34, 197, 94, 0.35);
}

.cp-btn-run:hover {
  background: rgba(34, 197, 94, 0.25);
  border-color: rgba(34, 197, 94, 0.5);
}

.cp-btn-copy {
  background: rgba(74, 144, 217, 0.12);
  color: var(--status-info-text);
  border-color: rgba(74, 144, 217, 0.3);
}

.cp-btn-copy:hover {
  background: rgba(74, 144, 217, 0.22);
  border-color: rgba(74, 144, 217, 0.5);
}

.cp-btn-fiddle {
  background: rgba(168, 85, 247, 0.12);
  color: var(--xp-purple);
  border-color: rgba(168, 85, 247, 0.3);
}

.cp-btn-fiddle:hover {
  background: rgba(168, 85, 247, 0.22);
  border-color: rgba(168, 85, 247, 0.5);
}

.cp-btn-reset {
  color: var(--text-muted);
}

.cp-btn-close {
  color: var(--text-muted);
}

.cp-btn-close:hover {
  color: var(--status-error-text);
  border-color: rgba(248, 113, 113, 0.4);
}

/* Editor textarea */
.cp-editor {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 1rem;
  margin: 0;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--code-text);
  background: var(--code-editor-bg);
  border: none;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  resize: vertical;
  outline: none;
  tab-size: 2;
  white-space: pre;
  overflow-x: auto;
}

.cp-editor:focus {
  box-shadow: inset 0 0 0 2px rgba(74, 144, 217, 0.3);
}

/* Output panel */
.cp-output {
  padding: 0.5rem 0.75rem 0.75rem;
  background: rgba(0, 0, 0, 0.25);
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
}

.cp-output.cp-hidden {
  max-height: 0;
  padding: 0 0.75rem;
  overflow: hidden;
}

.cp-output-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  font-family: 'Space Grotesk', sans-serif;
}

.cp-output-content {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  margin: 0;
  padding: 0.5rem;
  border-radius: 0.375rem;
  background: rgba(0, 0, 0, 0.3);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  color: var(--code-text);
}

.cp-output-success {
  color: var(--status-success-text);
  border-left: 3px solid var(--status-success);
}

.cp-output-error {
  color: var(--status-error-text);
  border-left: 3px solid var(--status-error);
}

.cp-output-muted {
  color: var(--text-secondary);
  font-style: italic;
}

/* ---- Print: hide playground UI ---- */
@media print {
  .cp-try-btn,
  .cp-container {
    display: none !important;
  }
}
