/* Playground page: the editor (CodeMirror, see playground-editor/), the rendered specification, the console
   (the report of the checker) and the colours of the code. Light and dark follow the theme.
   This file is only loaded on that page, so it can reshape the theme's page around the playground: the
   header bar stays, the playground takes all the rest of the window and nothing else is shown. */

/* --- The page around the playground ----------------------------------------------------------- */

.bd-header-article,   /* breadcrumbs and the link to the Markdown version */
.prev-next-footer,
.bd-footer,
.ablog__blog_comments {
  display: none;
}

.bd-container__inner.bd-page-width {
  max-width: none;
}

/* The theme sets these with three classes and loads after this file: match it, and win with `html body` */
html body .bd-main .bd-content .bd-article-container {
  max-width: none;
  padding: 0;
  overflow: visible;
}

html body .bd-main .bd-content .bd-article-container .bd-article {
  padding: 0;
}

/* The title stays for the page structure and screen readers, not for the eye */
.bd-article h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.pg {
  /* Colours of the code, used by the editor (playground-editor/src/index.js) */
  --pg-kw: var(--pst-color-primary);
  --pg-str: var(--pst-color-success);
  --pg-inf: var(--pst-color-text-muted);
  --pg-ref: var(--pst-color-primary);
  --pg-tag: color-mix(in srgb, var(--pst-color-warning) 60%, var(--pst-color-text-base));
  --pg-lit: var(--pst-color-info);
  --sev-syntax: var(--pst-color-danger);
  --sev-critical: var(--pst-color-danger);
  /* darker than the brand orange: it has to be 3:1 against the white of the light theme */
  --sev-severe: color-mix(in srgb, var(--orange) 75%, var(--pst-color-text-base));
  --sev-moderate: var(--pst-color-warning);
  --sev-light: var(--pst-color-info);
  /* All the window under the header bar (--pg-top is its measured height, set by playground.js) */
  box-sizing: border-box;
  height: calc(100vh - var(--pg-top, 5rem));
  height: calc(100dvh - var(--pg-top, 5rem));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.75rem;
}

/* display: grid above would otherwise win over the hidden attribute */
.pg[hidden],
.pg-fallback[hidden] {
  display: none;
}

/* --- Toolbar ------------------------------------------------------------------------------ */

.pg-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.pg-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pg-toolbar select,
.pg-toolbar button {
  min-height: 2.5rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--pst-color-border);
  border-radius: 0.375rem;
  background: var(--pst-color-background);
  color: var(--pst-color-text-base);
  font: inherit;
}

.pg-toolbar button {
  cursor: pointer;
}

.pg-toolbar button:hover {
  background: var(--pst-color-surface);
}

.pg-toolbar select {
  max-width: 100%;
}

.pg-note,
.pg-hint {
  min-height: 1.5em;
  margin: 0;
  color: var(--pst-color-text-muted);
  font-size: var(--pst-font-size-milli);
}

/* A small admonition: what is written here stays in the browser. Wraps to a row of its own on a narrow screen. */
.pg-privacy {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-sizing: border-box;
  /* as tall as the select and the buttons beside it, so the row reads as one line */
  min-height: 2.5rem;
  max-width: 100%;
  margin: 0;
  padding: 0.25rem 0.75rem;
  border-left: 3px solid var(--pst-color-primary);
  border-radius: 0 0.375rem 0.375rem 0;
  background: var(--pst-color-surface);
  color: var(--pst-color-text-muted);
  font-size: var(--pst-font-size-milli);
  line-height: 1.35;
}

.pg-privacy-icon {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  color: var(--pst-color-primary);
}

/* How to leave the editor with the keyboard, shown while it has the focus (Tab indents in it) */
.pg-hint {
  margin-left: auto;
  visibility: hidden;
}

.pg-editing .pg-hint {
  visibility: visible;
}

/* On a narrow screen the hint would take a row of its own, and it is for a keyboard (it is still read aloud) */
@media (max-width: 40rem) {
  .pg-hint {
    display: none;
  }
}

/* --- Editor ---------------------------------------------------------------------------------------- */

/* Half the window for the code, half for the specification and the console: side by side, one above the
   other on a narrow screen. Every pane scrolls inside itself, the page does not. */
.pg-main {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.pg-side {
  display: grid;
  gap: 0.75rem;
  grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

@media (max-width: 62rem) {
  .pg-main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1.5fr);
  }
}

.pg-editor {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--pst-color-border);
  border-radius: 0.375rem;
  background: var(--pst-color-background);
}

.pg-editor:focus-within {
  outline: 2px solid var(--pst-color-primary);
  outline-offset: 1px;
}

.pg-editor .cm-editor {
  position: absolute;
  inset: 0;
}

/* Underlines of the diagnostics. Wavy for what is wrong, dotted for what is only worth a look, so the
   difference does not rest on the colour alone. These replace the zigzag images of CodeMirror. */
.pg .cm-editor .cm-lintRange {
  padding-bottom: 0;
  background-image: none;
  text-decoration: underline wavy var(--sev, var(--pst-color-danger));
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.pg .cm-editor .cm-lintRange.pg-sev-syntax { --sev: var(--sev-syntax); }
.pg .cm-editor .cm-lintRange.pg-sev-critical { --sev: var(--sev-critical); }
.pg .cm-editor .cm-lintRange.pg-sev-severe { --sev: var(--sev-severe); }
.pg .cm-editor .cm-lintRange.pg-sev-moderate { --sev: var(--sev-moderate); text-decoration-style: dotted; }
.pg .cm-editor .cm-lintRange.pg-sev-light { --sev: var(--sev-light); text-decoration-style: dotted; }

/* Messages and the search panel are added to the page by CodeMirror, outside .pg */
.cm-tooltip {
  border: 1px solid var(--pst-color-border);
  border-radius: 0.375rem;
  background: var(--pst-color-background);
  color: var(--pst-color-text-base);
  font-size: 0.875rem;
}

.cm-panels {
  border-color: var(--pst-color-border);
  background: var(--pst-color-surface);
  color: var(--pst-color-text-base);
}

.cm-panels input,
.cm-panels button {
  font: inherit;
}

/* --- Preview ------------------------------------------------------------------------------------ */

/* The HTML of the export: headings, text, code. Only what is not the theme's own is set here. */
.pg-preview {
  position: relative; /* the offset parent of the headings: where an anchor click scrolls to */
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.25rem 1rem 1rem;
  border: 1px solid var(--pst-color-border);
  border-radius: 0.375rem;
  background: var(--pst-color-background);
}

.pg-preview:focus-visible {
  outline: 2px solid var(--pst-color-primary);
  outline-offset: 1px;
}

html body .pg-preview :is(h2, h3, h4, h5, h6) {
  margin: 1.25rem 0 0.5rem;
  padding: 0;
  border: 0;
  font-weight: 600;
  line-height: 1.3;
}

html body .pg-preview h2 { font-size: 1.4rem; }
html body .pg-preview h3 { font-size: 1.15rem; }
html body .pg-preview h4 { font-size: 1rem; }
html body .pg-preview :is(h5, h6) { font-size: 0.9rem; }

/* Where an anchor click brought the reader, until they go elsewhere */
.pg-preview :is(h2, h3, h4, h5, h6):focus {
  outline: none;
  background: color-mix(in srgb, var(--pst-color-primary) 14%, transparent);
}

.pg-preview p {
  margin: 0 0 0.75rem;
}

.pg-preview pre {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  overflow: auto;
  border: 1px solid var(--pst-color-border);
  border-radius: 0.375rem;
  background: var(--pst-color-surface);
  line-height: 1.5;
}

.pg-preview pre code {
  padding: 0;
  background: none;
  color: var(--pst-color-text-base);
  font-size: 0.875rem;
}

/* The comment of a requirement */
.pg-preview aside.comment {
  margin: 0 0 0.75rem;
  padding-left: 0.75rem;
  border-left: 3px solid var(--pst-color-border);
  color: var(--pst-color-text-muted);
}

/* The highlighting of code (classes of @lezer/highlight, set by highlight() of editor.js) */
.pg-preview .tok-keyword { color: var(--pg-kw); }
.pg-preview .tok-string { color: var(--pg-str); }
.pg-preview .tok-comment { color: var(--pg-inf); font-style: italic; }
.pg-preview .tok-variableName { color: var(--pg-ref); }
.pg-preview .tok-meta { color: var(--pg-tag); }
.pg-preview :is(.tok-number, .tok-atom) { color: var(--pg-lit); }

/* --- Console ------------------------------------------------------------------------------------- */

/* The report of the checker, under the preview: the summary stays in view, the list scrolls */
.pg-console {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--pst-color-border);
  border-radius: 0.375rem;
  background: var(--pst-color-surface);
}

.pg-console-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--pst-color-border);
}

.pg-console-title {
  color: var(--pst-color-text-muted);
  font-size: var(--pst-font-size-milli);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pg-summary {
  margin: 0;
  font-weight: 600;
}

.pg-summary[data-state="ok"] { color: var(--pst-color-success); }
.pg-summary[data-state="issues"] { color: var(--pst-color-text-base); }
.pg-summary[data-state="failed"] { color: var(--pst-color-danger); }

.pg-issues {
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.pg-issue button {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  column-gap: 0.5rem;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.4rem 0.5rem;
  border: 0;
  border-left: 3px solid var(--sev, var(--pst-color-border));
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pg-issue button:hover {
  background: var(--pst-color-surface);
}

.pg-issue button:focus-visible {
  outline: 2px solid var(--pst-color-primary);
  outline-offset: -2px;
}

.pg-issue.pg-sev-syntax { --sev: var(--sev-syntax); }
.pg-issue.pg-sev-critical { --sev: var(--sev-critical); }
.pg-issue.pg-sev-severe { --sev: var(--sev-severe); }
.pg-issue.pg-sev-moderate { --sev: var(--sev-moderate); }
.pg-issue.pg-sev-light { --sev: var(--sev-light); }

.pg-loc,
.pg-sev,
.pg-code {
  color: var(--pst-color-text-muted);
}

.pg-code {
  font-weight: 400;
}

.pg-sev {
  margin-right: 0.5rem;
  font-size: var(--pst-font-size-milli);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pg-msg {
  font-weight: 500;
}

.pg-where {
  grid-column: 2;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--pst-color-text-muted);
  font-size: var(--pst-font-size-milli);
}

.pg-where code {
  padding: 0;
  background: none;
  color: inherit;
}
