/*
 * gallery PyScript demo — interpreter/stage stylesheet
 *
 * Loaded *in addition to* site.css (shared PyDevices chrome) by micropython.html
 * and pyodide.html. Everything here is specific to the parametric loader's
 * interactive UI (device bezel, canvas, console, run controls) so it stays
 * independent of org-wide chrome updates. index.html (the gallery) does not
 * need this file — it has no stage/console UI.
 */

html {
  scroll-behavior: smooth;
}

/* ---------- Loader page layout ---------- */

.loader-main {
  padding: 30px 0 60px;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 18px;
}

.crumbs a {
  color: var(--ink-soft);
}

.crumbs .sep {
  opacity: 0.5;
}

.loader-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.loader-head h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3.2vw, 2.2rem);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.loader-lede {
  margin: 0 0 26px;
  max-width: 680px;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

.stage-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 26px;
  align-items: start;
}

/* Display left, console right */
.play-area {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr);
  grid-template-rows: auto auto;
  column-gap: 26px;
  row-gap: 12px;
  align-items: start;
  margin-bottom: 26px;
}

.interpreter-page > .site-header,
.interpreter-page > .site-footer,
.interpreter-page .loader-main > :not(.play-area) {
  display: none;
}

.interpreter-page .loader-main {
  width: min(760px, calc(100% - 24px));
  margin: 0 auto;
  padding-top: 0;
  padding-bottom: 0;
}

.interpreter-page .play-area {
  grid-template-columns: minmax(0, auto);
  grid-template-rows: auto auto;
  justify-content: center;
  margin-bottom: 0;
}

.interpreter-page .play-area > .display-column {
  grid-row: 1;
}

.interpreter-page .play-area > .console-panel {
  grid-column: 1;
  grid-row: 2;
  justify-self: center;
}

.interpreter-page {
  min-height: 0;
}

.interpreter-page .device {
  padding: 16px 8px 16px;
}

.interpreter-page .console-panel {
  padding: 16px 9px 6px;
}

.play-area > .stage-controls {
  grid-column: 1;
  grid-row: 1;
}

.play-area > .display-column {
  grid-column: 1;
  grid-row: 2;
}

.play-area > .console-panel {
  grid-column: 2;
  grid-row: 2;
}

.stage-controls {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.run-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: none;
}

.display-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.meta-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

@media (max-width: 880px) {
  .stage-layout {
    grid-template-columns: 1fr;
  }

  .play-area {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .play-area > .stage-controls,
  .play-area > .display-column,
  .play-area > .console-panel {
    grid-column: 1;
  }

  .play-area > .stage-controls {
    grid-row: 1;
  }

  .play-area > .display-column {
    grid-row: 2;
  }

  .play-area > .console-panel {
    grid-row: 3;
  }

  .interpreter-page .play-area {
    grid-template-rows: auto auto;
  }

  .interpreter-page .play-area > .display-column {
    grid-row: 1;
  }

  .interpreter-page .play-area > .console-panel {
    grid-row: 2;
  }
}

@media (min-width: 760px) {
  .interpreter-page.interpreter-standalone .loader-main {
    width: min(760px, calc(100% - 24px));
  }

  .interpreter-page.interpreter-standalone.interpreter-with-console .play-area {
    grid-template-columns: auto auto;
    grid-template-rows: auto;
    column-gap: 18px;
  }

  .interpreter-page.interpreter-standalone.interpreter-with-console .play-area > .display-column {
    grid-column: 1;
    grid-row: 1;
  }

  .interpreter-page.interpreter-standalone.interpreter-with-console .play-area > .console-panel {
    grid-column: 2;
    grid-row: 1;
  }
}

/* Device bezel that frames the canvas */
.stage {
  display: grid;
  place-items: center;
  gap: 16px;
  padding: 30px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    radial-gradient(420px 320px at 50% 0%, rgba(90, 79, 214, 0.08), transparent 70%),
    var(--bg-soft);
}

.run-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: none;
}

.device {
  padding: 16px;
  border-radius: 22px;
  background: linear-gradient(160deg, #262e36, #131a20);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  border: 1px solid #2f3a45;
}

#display_canvas {
  display: block;
  border-radius: 10px;
  background-color: #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  /* Multi-touch gestures (pinch, 2-finger pan) go to the app, not the
     browser's native zoom/scroll — preventDefault() on pointer events alone
     isn't reliable against native touch-action handling. */
  touch-action: none;
}

/* Boot loader over the canvas -- the same spinner and uppercase status line the
   org landing page shows over a hero canvas. Its .hero-canvas-loader,
   .hero-spinner and .hero-canvas-status rules arrive with the shared chrome
   (/assets/chrome/site.css), so only the anchor, the reveal condition and the
   contrast against a black canvas are set here. */
.canvas-stage {
  position: relative;
  line-height: 0;
}

body[data-runtime-state="ready"] .hero-canvas-loader {
  opacity: 0;
  visibility: hidden;
}

/* The bezel is dark in both themes, so --ink-soft would sink into it. */
.canvas-stage .hero-canvas-status {
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.4;
}

.canvas-stage .hero-spinner {
  border-color: rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
}

body[data-runtime-state="failed"] .canvas-stage .hero-spinner {
  animation: none;
  border-top-color: #e5687a;
}

/* Invisible over the black canvas of a booting demo; the reason it is here is
   the failure case, where the app has already painted a bright UI underneath
   and the message would otherwise be unreadable. */
.canvas-stage .hero-canvas-loader {
  background: rgba(8, 12, 16, 0.62);
}

/* Starts 1×1; PSDisplay (lv_multi_display / EncoderEmu) resizes when used. */
#aux_canvas {
  display: block;
  margin-top: 0;
}
#aux_canvas:not([height="1"]):not([height="0"]) {
  margin-top: 8px;
  border-radius: 10px;
  background-color: #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* Side panel */
.aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px 18px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.panel ul {
  margin: 0;
  padding-left: 1.1em;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.panel li + li {
  margin-top: 6px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-soft);
}

.meta-row:last-child {
  border-bottom: 0;
}

.meta-row .k {
  color: var(--muted);
}

.meta-row .v {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

/* Console / stdout panel */
.console-panel {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px 18px;
  overflow: hidden;
}

.device-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-top: 8px;
}

/* A link beside the console toggle, in its look. The header row isn't shown
   when a gallery card opens a demo, so the footer is the one place it's seen. */
.footer-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--panel-2);
  font: 600 0.78rem var(--font);
  text-decoration: none;
}

.footer-link:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.footer-link[hidden] {
  display: none;
}

.console-panel[hidden] {
  display: none;
}

.console-toggle {
  min-height: 30px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--panel-2);
  font: 600 0.78rem var(--font);
  cursor: pointer;
}

.console-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.console-label {
  margin: 0 0 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  flex-shrink: 0;
}

/* Legacy collapsible console (unused by generated pages) */
.console {
  margin-top: 26px;
}

.console summary {
  cursor: pointer;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 4px 0;
  user-select: none;
}

.console summary:hover {
  color: var(--ink-soft);
}

#log,
.log {
  box-sizing: border-box;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #121a22;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  color: #dfeaf2;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Stacked mobile layout: give the log a sensible minimum height */
@media (max-width: 880px) {
  .play-area .console-panel #log {
    min-height: 12rem;
  }
}

/* PyScript loading splash */
.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Hide PyScript's default splashscreen in favour of our own */
py-splashscreen,
mpy-splashscreen {
  display: none !important;
}
