/* ══ Playground layout ══ */

html:has(.playground-container),
html:has(.playground-container) body {
  overflow: hidden;
  height: 100vh;
  margin: 0;
  overscroll-behavior: none;
}

.playground-toolbar {
  position: relative;
  margin-top: var(--nav-h, 3.5rem);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.playground-toolbar-spacer {
  flex: 1;
}

.playground-container {
  display: flex;
  height: calc(100vh - var(--nav-h, 3.5rem) - 2.5rem);
  min-height: 400px;
  overflow: hidden;
}

/* ══ Editor pane ══ */
.playground-editor {
  flex: none;
  width: 50%;
  min-width: 200px;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
}

.playground-editor iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ══ Preview pane ══ */
.playground-preview-pane {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
}

/* ══ Toolbar buttons ══ */
.playground-run,
.playground-btn {
  padding: 0.35rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.2;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  white-space: nowrap;
}

.playground-run {
  border-color: rgba(254, 174, 52, 0.35);
  color: var(--edg-gold);
}
[data-theme="light"] .playground-run {
  border-color: rgba(13, 121, 144, 0.3);
  color: var(--edg-gold);
}

.playground-btn:hover {
  border-color: var(--purple);
  color: var(--text);
  background: var(--glow);
}

.playground-run:hover {
  border-color: var(--edg-gold);
  color: var(--edg-gold);
  background: rgba(254, 174, 52, 0.08);
}
[data-theme="light"] .playground-run:hover {
  border-color: var(--edg-gold);
  color: var(--edg-gold);
  background: rgba(13, 121, 144, 0.06);
}

.playground-run.running {
  opacity: 0.7;
}

/* ══ Step-mode toggle (iOS-style switch) ══ */
.playground-step-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.playground-step-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.playground-step-track {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--border);
  transition: background 0.2s;
  flex-shrink: 0;
}

.playground-step-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.playground-step-toggle input:checked + .playground-step-track {
  background: var(--purple);
}

.playground-step-toggle input:checked + .playground-step-track .playground-step-thumb {
  transform: translateX(14px);
}

.playground-step-label {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim, var(--text));
  line-height: 1.2;
}

.playground-step-toggle input:checked ~ .playground-step-label {
  color: var(--text);
}

/* ══ Click-to-continue indicator ══ */
.playground-click-prompt {
  display: inline-block;
  margin-left: 0.6rem;
  color: var(--text-dim, var(--text));
  font-size: 0.6rem;
  line-height: 1;
  transform: scaleX(1.4) scaleY(0.8);
  position: relative;
  top: -2px;
  animation: clickPromptBlink 1s step-end infinite;
  cursor: pointer;
  user-select: none;
}

@keyframes clickPromptBlink {
  0%, 50% { opacity: 0.85; }
  50.01%, 100% { opacity: 0; }
}

/* ══ Sample dropdown ══ */
.playground-samples {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 0.35rem 1.6rem 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.2;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

.playground-samples:hover {
  border-color: var(--purple);
  background-color: var(--glow);
}

.playground-samples:focus {
  outline: none;
  border-color: var(--purple);
}

.playground-samples option {
  background: var(--bg-elevated);
  color: var(--text);
}

/* ══ Filename input ══ */
.playground-filename {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.2;
  font-weight: 500;
  width: 10rem;
  max-width: 14rem;
  transition: border-color 0.2s, background-color 0.2s;
}

.playground-filename:hover {
  border-color: var(--purple);
  background-color: var(--glow);
}

.playground-filename:focus {
  outline: none;
  border-color: var(--purple);
}

/* ══ Drag handle ══ */
.playground-drag-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20px;
  left: calc(50% - 10px);
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  touch-action: none;
}

.playground-drag-handle-grip {
  display: flex;
  gap: 3px;
  height: 18px;
  transition: opacity 0.2s;
}

.playground-drag-handle-grip::before,
.playground-drag-handle-grip::after {
  content: '';
  width: 2px;
  height: 100%;
  border-radius: 1px;
  background: var(--border);
  transition: background 0.2s;
}

.playground-drag-handle:hover .playground-drag-handle-grip::before,
.playground-drag-handle:hover .playground-drag-handle-grip::after,
.playground-drag-handle.dragging .playground-drag-handle-grip::before,
.playground-drag-handle.dragging .playground-drag-handle-grip::after {
  background: var(--text-dim, var(--text));
}

/* ══ Output ══ */
.playground-output {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem 15vh;
  font-size: 1.05rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ══ Scroll-stable table layout ══ */
.playground-output-table {
  display: table;
  width: 100%;
}

.playground-output-content {
  display: table-cell;
  width: 100%;
  vertical-align: top;
}

.playground-output-keeper-cell {
  display: table-cell;
  width: 0;
  padding: 0;
}

.playground-output-keeper {
  width: 0;
  overflow: hidden;
}

/* ══ Preview overrides ══ */
.playground-output .preview-choice.selected {
  margin-bottom: 1.2rem;
}

/* ══ Empty-state play prompt ══ */
.playground-empty-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.playground-empty-play {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  opacity: 0.65;
}

.playground-empty-play:hover {
  opacity: 1;
  border-color: var(--purple);
  background: var(--glow);
  transform: scale(1.03);
}

.playground-empty-play svg {
  opacity: 0.7;
}

/* ══ Light theme overrides ══ */
[data-theme="light"] .playground-editor {
  background: #faf8f4;
}
[data-theme="light"] .playground-preview-pane {
  background: #ffffff;
}
[data-theme="light"] .playground-toolbar {
  background: #f8f5f0;
  border-bottom-color: #e8e3da;
}

/* ══ Theme transitions ══ */
.playground-container,
.playground-editor,
.playground-preview-pane,
.playground-toolbar,
.playground-output,
.playground-run,
.playground-btn,
.playground-step-track,
.playground-samples,
.playground-filename,
.playground-drag-handle-grip {
  transition: background 0.35s ease, border-color 0.35s ease, color 0.25s ease;
}

/* ══ Responsive ══ */
@media (max-width: 900px) {
  .playground-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .playground-toolbar::-webkit-scrollbar {
    display: none;
  }

  .playground-container {
    flex-direction: column;
    height: calc(100vh - var(--nav-h, 3.5rem) - 2.5rem);
    min-height: 0;
  }

  .playground-editor {
    width: auto !important;
    flex: 1;
    height: 100%;
    min-height: 0;
    border-right: none;
  }

  .playground-preview-pane {
    display: none;
  }

  /* When preview is active, swap panes */
  .playground-container.preview-active .playground-editor {
    display: none;
  }

  .playground-container.preview-active .playground-preview-pane {
    display: flex;
    flex: 1;
    height: 100%;
    min-height: 0;
  }

  .playground-drag-handle {
    display: none !important;
  }

  .playground-btn span,
  .playground-btn svg + br {
    display: none;
  }
}
