/* Playground layout. Colors come from the tokens in ../assets/style.css. */
body.pg {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.pg-title {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- toolbar ---------- */
.pg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.pg-toolbar .spacer { flex: 1; }
.pg-field { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--fg-muted); }
.pg-field select {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
}
.pg-btn {
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
.pg-btn:hover:not(:disabled) { border-color: var(--accent); }
.pg-btn:disabled { opacity: 0.5; cursor: default; }
.pg-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* ---------- panes ---------- */
.pg-main {
  /* Override the docs stylesheet's generic <main> padding and max-width. */
  max-width: none;
  width: 100%;
  padding: 0;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.pg-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pg-editor { border-right: 1px solid var(--border); }

.pg-tabs {
  display: flex;
  gap: 2px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}
.pg-tabs button {
  font: inherit;
  font-size: 14px;
  color: var(--fg-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 12px 7px;
  cursor: pointer;
}
.pg-tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pg-tabs .count { font-size: 12px; color: var(--fg-muted); font-weight: 400; }

.pg-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pg-panel[hidden] { display: none; }

/* ---------- code editor ---------- */
.pg-code {
  flex: 1;
  min-height: 0;
  display: flex;
  background: var(--bg-code);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 20px;
}
.pg-gutter {
  margin: 0;
  padding: 12px 8px 12px 12px;
  min-width: 44px;
  text-align: right;
  color: var(--comment);
  background: var(--bg-code);
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
  user-select: none;
  font: inherit;
  line-height: inherit;
}
.pg-code textarea {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: none;
  outline: none;
  resize: none;
  color: var(--fg);
  background: transparent;
  font: inherit;
  line-height: inherit;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

/* ---------- images tab ---------- */
.pg-files { padding: 16px; overflow: auto; font-size: 14px; }
.pg-files p { margin: 0 0 12px; }
.pg-files ul { list-style: none; margin: 0 0 14px; padding: 0; border: 1px solid var(--border); border-radius: 8px; }
.pg-files li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.pg-files li:last-child { border-bottom: none; }
.pg-files li img { width: 40px; height: 28px; object-fit: contain; background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.pg-files li code { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pg-files li small { color: var(--fg-muted); white-space: nowrap; }
.pg-files li button { font: inherit; font-size: 13px; color: var(--fg-muted); background: none; border: none; cursor: pointer; }
.pg-files li button:hover { color: var(--fg); }
.pg-files li.empty { color: var(--fg-muted); }
.pg-upload { cursor: pointer; }
.pg-hint { color: var(--fg-muted); font-size: 13px; margin-top: 12px !important; }

/* ---------- preview ---------- */
.pg-preview { background: var(--bg-soft); }
.pg-status {
  padding: 9px 16px;
  font-size: 13px;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
}
.pg-error {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 12px 16px 0;
  padding: 10px 14px;
  border: 1px solid var(--warn-border);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--warn-bg);
  font-size: 14px;
}
.pg-error[hidden] { display: none; }
.pg-error span { flex: 1; min-width: 0; overflow-wrap: anywhere; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.pg-error button {
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 10px;
  cursor: pointer;
}
.pg-pages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transition: opacity 0.15s;
}
.pg-pages.stale { opacity: 0.45; }
.pg-pages canvas, .pg-pages iframe {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.pg-pages iframe { width: 100%; height: 100%; min-height: 480px; }

.pg-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  z-index: 50;
}
.pg-toast[hidden] { display: none; }

/* ---------- phones ---------- */
@media (max-width: 860px) {
  body.pg { height: auto; overflow: visible; }
  .pg-toolbar { padding: 8px 16px; }
  .pg-main { grid-template-columns: minmax(0, 1fr); padding: 0; }
  .pg-editor { border-right: none; border-bottom: 1px solid var(--border); height: 55vh; }
  .pg-pages { overflow: visible; padding: 16px; }
  .topbar a.gh .txt { display: none; }
}

/* ---------- CodeMirror (editor.js) ---------- */
.pg-code.cm-active { display: block; position: relative; }
.pg-code.cm-active > .pg-gutter,
.pg-code.cm-active > textarea { display: none; }
.pg-code.cm-active > .cm-editor { position: absolute; inset: 0; }
@media (max-width: 860px) {
  .pg-code.cm-active > .cm-editor { position: absolute; }
}
