/* The playground's editor/console/sidebar follow the site-wide light/dark
   theme toggle via the --code-* tokens defined in base.css. The CodeMirror
   syntax theme itself ("dracula" for dark, "default" for light) is switched
   in run.js alongside these, in response to the same toggle. */

.playground-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  background: var(--code-border);
  overflow: hidden;
  min-height: 0;
}

.playground-main.has-sidebar {
  grid-template-columns: 170px minmax(0, 1fr) minmax(0, 1fr);
}

.playground-main.has-sidebar.sidebar-collapsed {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.playground-main.sidebar-collapsed .playground-sidebar {
  display: none;
}

@media (max-width: 800px) {
  .playground-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .playground-main.has-sidebar,
  .playground-main.has-sidebar.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .playground-sidebar {
    display: none;
  }
}

.pane {
  background: var(--code-panel-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane-header {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--code-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pane-header span.pane-title {
  font-weight: 600;
  margin-right: auto;
  color: var(--code-text);
}

.CodeMirror {
  flex: 1;
  height: auto !important;
  font-size: 0.95rem;
}

#status,
#save-status {
  color: var(--code-muted);
  font-size: 0.85rem;
}

#output {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--code-text);
}

.output-error {
  color: var(--code-danger);
}

.output-input {
  outline: none;
  border-bottom: 1px solid var(--code-accent);
  min-width: 1ch;
  display: inline-block;
}

.submit-bar {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--code-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.submit-bar .pane-title {
  font-weight: 600;
  margin-right: auto;
  color: var(--code-text);
}

.explorer-header {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--code-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.explorer-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--code-muted);
  margin-right: auto;
}

.explorer-new {
  color: var(--code-muted);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.explorer-new:hover {
  color: var(--code-text);
}

.snippet-explorer {
  list-style: none;
  margin: 0;
  padding: 0.2rem 0;
  overflow-y: auto;
  flex: 1;
}

.snippet-explorer-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.75rem;
  color: var(--code-text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid transparent;
  font-size: 0.82rem;
  line-height: 1.7;
}

.snippet-explorer-icon {
  flex-shrink: 0;
  font-size: 0.8em;
  opacity: 0.8;
}

.snippet-explorer-item:hover {
  background: var(--code-bg);
}

.snippet-explorer-item.is-active {
  border-left-color: var(--code-accent);
  background: color-mix(in srgb, var(--code-accent) 12%, transparent);
}

.snippet-explorer-empty {
  color: var(--code-muted);
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
}

/* Toolbar buttons (standard small size): an inline SVG icon plus a text label. On
   narrow screens the label is hidden and only the icon remains (each button
   keeps its title/aria-label, so it stays accessible and discoverable). */
.pg-btn {
  gap: 0.35rem;
}

.pg-btn .btn-icon {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
}

.pane-header,
.submit-bar {
  gap: 0.4rem;
}

@media (max-width: 600px) {
  .pg-btn {
    width: 2.5em;
    padding-inline: 0;
    justify-content: center;
  }

  .pg-btn .btn-label {
    display: none;
  }

  .pane-header {
    padding: 0.4rem 0.6rem;
  }

  .submit-bar {
    padding: 0.4rem 0.6rem;
  }
}


/* ---- Pas à pas (trace view) ---- */
.trace-line.CodeMirror-linebackground,
.CodeMirror-linebackground.trace-line {
  background: rgba(255, 193, 7, 0.28);
}

.CodeMirror-linebackground.trace-error-line {
  background: rgba(220, 53, 69, 0.25);
}

#trace-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  color: var(--code-text);
}

#trace-panel[hidden],
.trace-inputs[hidden] {
  display: none !important;
}

.trace-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  flex-wrap: wrap;
}

.trace-counter {
  font-size: 0.85rem;
  color: var(--code-muted);
  min-width: 6.5em;
  text-align: center;
}

.trace-note {
  margin: 0;
  padding: 0 1rem 0.4rem;
  font-size: 0.85rem;
  color: var(--code-muted);
}

.trace-note.is-error {
  color: var(--code-danger);
}

.trace-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 1rem 0.75rem;
}

.trace-vars {
  width: 100%;
  border-collapse: collapse;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.88rem;
}

.trace-vars th,
.trace-vars td {
  text-align: left;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--code-border);
  word-break: break-word;
}

.trace-vars th {
  font-family: inherit;
  color: var(--code-muted);
  font-weight: 600;
}

.trace-vars tr.is-changed td {
  background: rgba(255, 193, 7, 0.22);
  font-weight: 700;
}

.trace-vars tr.is-local td:first-child::after {
  content: " (locale)";
  color: var(--code-muted);
  font-weight: 400;
  font-size: 0.8em;
}

.trace-empty {
  color: var(--code-muted);
  font-style: italic;
}

.trace-out-title {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--code-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.trace-output {
  margin: 0.25rem 0 0;
  padding: 0.5rem 0.6rem;
  min-height: 2.5rem;
  background: transparent;
  border: 1px solid var(--code-border);
  border-radius: 6px;
  color: var(--code-text);
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.trace-inputs {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--code-border);
  font-size: 0.8rem;
  color: var(--code-muted);
}

.trace-inputs textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  background: transparent;
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.88rem;
  padding: 0.35rem 0.5rem;
  resize: vertical;
}

/* Keep the editor toolbar on one line: the filename gives way first. */
#editor-filename {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-header:has(#editor-filename) {
  flex-wrap: nowrap;
}

/* Exercise / challenge statement shown above the editor. Collapsible; it scrolls
   on its own so the editor always keeps most of the pane. */
.statement-panel {
  border-bottom: 1px solid var(--code-border);
  max-height: 40%;
  overflow-y: auto;
  flex-shrink: 0;
  color: var(--code-text);
}

.statement-panel > summary {
  cursor: pointer;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  background: var(--code-panel-bg);
}

.statement-body {
  padding: 0 1rem 0.75rem;
  font-size: 0.9rem;
  color: var(--code-text);
}

.statement-body p,
.statement-body li {
  color: inherit;
}

.statement-body pre {
  white-space: pre-wrap;
  font-size: 0.85rem;
}

/* A pane narrower than 600px (e.g. the editor next to the file explorer on a
   laptop) shows icon-only toolbar buttons, like the phone layout does, so the
   toolbar never spills into the neighbouring pane. */
.pane {
  container-type: inline-size;
}

@container (max-width: 600px) {
  .pg-btn {
    width: 2.5em;
    padding-inline: 0;
    justify-content: center;
  }

  .pg-btn .btn-label {
    display: none;
  }
}
