/*
 * The playground: the look of the walkthrough (walkthrough.css), with the editor on
 * the left, the network on the right, and the layers of the stack listed over it.
 */
:root {
  --pg-panel-width: clamp(380px, 40vw, 620px);
  --pg-error: #b71c1c;
  --pg-glide: 520ms cubic-bezier(0.32, 0.72, 0, 1);
}

:root[data-theme="dark"] {
  --pg-error: #ff8a80;
}

.pg-title {
  color: var(--wt-muted);
  font-size: 13.5px;
  font-weight: 500;
}

.pg-bar-end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.pg-examples {
  position: relative;
}

.pg-examples-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 18rem;
  padding: 0.3rem 0.55rem 0.3rem 0.7rem;
  border: 1px solid var(--wt-line);
  border-radius: 8px;
  background: var(--wt-raised);
  color: var(--wt-ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.pg-examples-button:hover,
.pg-examples-button[aria-expanded="true"] {
  border-color: color-mix(in srgb, var(--wt-accent) 45%, transparent);
}

.pg-examples-label {
  color: var(--wt-muted);
}

.pg-examples-button strong {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pg-examples-button svg {
  flex: none;
  width: 14px;
  height: 14px;
  color: var(--wt-muted);
}

/* The panel of the examples, under the button: the search, then the groups. */
.pg-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(26rem, calc(100vw - 2rem));
  max-height: min(34rem, calc(100vh - var(--wt-bar-height) - 2rem));
  border: 1px solid var(--wt-line);
  border-radius: 12px;
  background: var(--wt-raised);
  box-shadow: var(--wt-shadow);
}

.pg-menu[hidden] {
  display: none;
}

.pg-search {
  margin: 0.6rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--wt-line);
  border-radius: 8px;
  background: var(--wt-bg);
  color: var(--wt-ink);
  font: inherit;
  font-size: 13.5px;
}

.pg-search:focus {
  outline: 2px solid var(--wt-accent);
  outline-offset: -1px;
}

.pg-menu-list {
  overflow-y: auto;
  padding: 0 0.4rem 0.5rem;
}

.pg-menu-heading {
  margin: 0.6rem 0.5rem 0.25rem;
  color: var(--wt-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pg-option {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--wt-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pg-option:hover,
.pg-option.is-active {
  background: color-mix(in srgb, var(--wt-accent) 12%, transparent);
}

.pg-option-title {
  font-size: 13.5px;
  font-weight: 600;
}

.pg-option-summary {
  color: var(--wt-muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.pg-option-uses {
  color: var(--wt-accent);
  font: 11.5px var(--wt-font-mono);
}

.pg-menu-empty {
  margin: 0.75rem 0.6rem;
  color: var(--wt-muted);
  font-size: 13px;
}

.pg .wt-bar .wt-button {
  padding: 0.3rem 0.9rem;
}

/* The panel: the program, what the playground says, and what the program prints. */
.pg .wt-panel {
  gap: 0.75rem;
  padding: 1rem 1.25rem 1.1rem;
}

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

.pg-summary {
  flex-basis: 100%;
  margin: 0.2rem 0 0;
  color: var(--wt-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.pg-summary:empty {
  display: none;
}

/*
 * The editor: a transparent textarea over the highlighted code. Both share font,
 * size and padding, so that the text lines up to the pixel.
 */
.pg-editor {
  position: relative;
  flex: 1;
  min-height: 14rem;
  overflow: hidden;
  border: 1px solid var(--wt-line);
  border-radius: 12px;
  background: var(--wt-code-bg);
}

.pg-editor:focus-within {
  outline: 2px solid var(--wt-accent);
  outline-offset: 1px;
}

.pg-editor textarea,
.pg-layer-text {
  box-sizing: border-box;
  margin: 0;
  padding: 0.9rem 1rem;
  border: 0;
  font-family: var(--wt-font-mono);
  font-size: 13px;
  font-variant-ligatures: none;
  line-height: 1.65;
  letter-spacing: normal;
  tab-size: 4;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.pg-editor textarea {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  background: transparent;
  color: transparent;
  caret-color: var(--wt-ink);
  outline: none;
  resize: none;
}

.pg-editor textarea::selection {
  background: color-mix(in srgb, var(--wt-accent) 28%, transparent);
  color: transparent;
}

.pg-highlight,
.pg-marks {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

/* Under the code, the watched expressions; deeper in nested watches, underlined in front. */
.pg-marks .pg-layer-text {
  color: transparent;
}

.pg-mark {
  border-radius: 3px;
  background: color-mix(in srgb, var(--wt-accent) 13%, transparent);
}

.pg-mark[data-depth="2"] {
  background: color-mix(in srgb, var(--wt-accent) 22%, transparent);
}

.pg-mark[data-depth="3"] {
  background: color-mix(in srgb, var(--wt-accent) 31%, transparent);
}

.pg-mark.is-focused {
  box-shadow: inset 0 -2px 0 var(--wt-accent);
}

.pg-layer-text {
  color: var(--wt-ink);
  will-change: transform;
}

/* The names that complete the code, under the caret. */
.pg-complete {
  position: absolute;
  z-index: 2;
  min-width: 12rem;
  max-width: 24rem;
  max-height: 14rem;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  border: 1px solid var(--wt-line);
  border-radius: 8px;
  background: var(--wt-raised);
  box-shadow: var(--wt-shadow);
  font: 12.5px/1.6 var(--wt-font-mono);
  list-style: none;
}

.pg-complete li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.05rem 0.65rem;
  white-space: nowrap;
  cursor: pointer;
}

.pg-complete li[aria-selected="true"] {
  background: color-mix(in srgb, var(--wt-accent) 16%, transparent);
}

.pg-complete small {
  color: var(--wt-muted);
  font-size: 11px;
}

.pg-status {
  margin: 0;
  color: var(--wt-muted);
  font-size: 13px;
}

.pg-console {
  max-height: 30%;
  margin: 0;
  overflow: auto;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  background: var(--wt-code-bg);
  font-family: var(--wt-font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.pg-stderr {
  color: var(--pg-error);
}

/* The layers, from the top of the stack down, each with the value of the inspected device. */
.pg-layers {
  width: 17rem;
  pointer-events: auto;
}

.pg-layers-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.45rem;
  color: var(--wt-muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pg-solo {
  padding: 0.05rem 0.45rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--wt-muted);
  font-size: 11px;
  letter-spacing: normal;
  text-transform: none;
  cursor: pointer;
}

.pg-solo:hover {
  color: var(--wt-ink);
}

.pg-solo[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--wt-accent) 45%, transparent);
  color: var(--wt-ink);
}

.pg-layer + .pg-layer {
  margin-top: 0.5rem;
}

.pg-layer.is-hidden .pg-layer-name,
.pg-layer.is-hidden .pg-layer-value {
  opacity: 0.45;
}

.pg-layer-eye {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.2rem;
  height: 1.2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--wt-muted);
  cursor: pointer;
}

.pg-layer-eye svg {
  width: 0.85rem;
  height: 0.85rem;
}

.pg-layer-eye:hover {
  color: var(--wt-ink);
}

.pg-layer-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.pg-layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  background: none;
  color: var(--wt-muted);
  font-family: var(--wt-font-mono);
  font-size: 12px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.pg-layer-name:hover {
  color: var(--wt-ink);
}

.pg-layer.is-focused .pg-layer-name {
  color: var(--wt-ink);
  font-weight: 600;
}

.pg-layer-value {
  padding: 0 0.4em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--wt-ink) 8%, transparent);
  color: var(--wt-ink);
  font-family: var(--wt-font-mono);
  font-size: 11.5px;
  white-space: nowrap;
}

.pg-layer-value:empty {
  display: none;
}

.pg-layer-move {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.2rem;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--wt-muted);
  cursor: pointer;
}

.pg-layer-move svg {
  width: 0.8rem;
  height: 0.8rem;
}

.pg-layer-move:hover:not(:disabled) {
  background: color-mix(in srgb, var(--wt-ink) 10%, transparent);
  color: var(--wt-ink);
}

.pg-layer-move:disabled {
  opacity: 0.3;
  cursor: default;
}

.pg-layer-remove {
  width: 1.2rem;
  height: 1.2rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--wt-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.pg-layer-remove:hover {
  background: color-mix(in srgb, var(--wt-ink) 10%, transparent);
  color: var(--wt-ink);
}

.pg-layer .wt-legend-bar {
  margin-top: 0.35rem;
}

.pg-categories {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

/* How the layer in front is drawn: its colour map and how high it rises. */
.pg-look {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.45rem;
  font-size: 11.5px;
}

.pg-look select {
  padding: 0.1rem 0.25rem;
  border: 1px solid var(--wt-line);
  border-radius: 6px;
  background: var(--wt-raised);
  color: var(--wt-ink);
  font: 500 11.5px var(--wt-font-mono);
}

.pg-height {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--wt-muted);
  font-family: var(--wt-font-mono);
}

.pg-height input {
  width: 4.5rem;
  accent-color: var(--wt-accent);
}

.pg-height output {
  min-width: 2.4em;
  color: var(--wt-ink);
  text-align: right;
}

/* From above, the map would only repeat the stage. */
.is-flat .wt-map {
  display: none;
}

/* Above the rounds, which take the bottom of the stage and would run into it. */
.pg .wt-hint {
  bottom: 4.6rem;
}

/* The right of the stage: the tools, then the device inspected and its sensors, which the reader switches. */
.pg-side {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
  max-width: calc(100% - 19rem);
}

.pg-side .wt-tools {
  position: static;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pg-device {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  font-size: 12px;
}

.pg-sensors {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.3rem;
}

.pg-speed {
  margin-right: 0.35rem;
  padding: 0.15rem 0.3rem;
  border: 1px solid var(--wt-line);
  border-radius: 999px;
  background: var(--wt-raised);
  color: var(--wt-ink);
  font: 500 12px var(--wt-font-mono);
  cursor: pointer;
}

/* What to show: the program, both, or the network. A pill slides under the choice. */
.pg-layout {
  --pg-shown: 1;
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 2px;
  border: 1px solid var(--wt-line);
  border-radius: 8px;
  background: var(--wt-raised);
}

.pg[data-layout="code"] .pg-layout {
  --pg-shown: 0;
}

.pg[data-layout="network"] .pg-layout {
  --pg-shown: 2;
}

.pg-layout::before {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc((100% - 4px) / 3);
  border-radius: 6px;
  background: color-mix(in srgb, var(--wt-accent) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--wt-accent) 35%, transparent);
  content: "";
  transform: translateX(calc(var(--pg-shown) * 100%));
  transition: transform var(--pg-glide);
}

.pg-layout button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border: 0;
  background: none;
  color: var(--wt-muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: color 200ms;
}

.pg-layout button:hover,
.pg-layout button[aria-checked="true"] {
  color: var(--wt-ink);
}

.pg-layout svg {
  width: 14px;
  height: 14px;
}

.pg-layout button[aria-checked="true"] svg {
  color: var(--wt-accent);
}

/*
 * The program and the network share the width: the one that goes folds away as it fades,
 * and the one that stays widens into its place.
 */
.pg .wt-panel,
.pg .wt-stage {
  transition: opacity 220ms ease 160ms, transform var(--pg-glide), visibility 0s;
}

.pg[data-layout="code"] .wt-stage,
.pg[data-layout="network"] .wt-panel {
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, transform var(--pg-glide), visibility 0s 520ms;
}

.pg[data-layout="code"] .wt-stage {
  transform: translateX(3rem);
}

.pg[data-layout="network"] .wt-panel {
  transform: translateX(-3rem);
}

@keyframes pg-arrive {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

@media (width > 1000px) {
  .pg .wt-main {
    grid-template-columns: var(--pg-panel-width) minmax(0, 1fr);
    transition: grid-template-columns var(--pg-glide);
  }

  .pg[data-layout="code"] .wt-main {
    grid-template-columns: 100% minmax(0, 1fr);
  }

  .pg[data-layout="network"] .wt-main {
    grid-template-columns: 0% minmax(0, 1fr);
  }

  /* Alone, the program keeps to a column that reads well, in the middle. */
  .pg .wt-panel {
    transition: opacity 220ms ease 160ms, transform var(--pg-glide), visibility 0s, padding var(--pg-glide);
  }

  .pg[data-layout="code"] .wt-panel {
    padding-inline: max(1.5rem, calc((100% - 64rem) / 2));
  }

  .pg .wt-panel {
    overflow: hidden;
    border-right: 1px solid var(--wt-line);
    border-left: 0;
  }
}

@media (max-width: 1000px) {
  .pg .wt-panel {
    border-top: 0;
    border-bottom: 1px solid var(--wt-line);
  }

  .pg-editor {
    flex: none;
    height: 24rem;
  }

  /* One above the other, the one that goes leaves the page, and the one that stays fills it. */
  .pg[data-layout="code"] .wt-stage,
  .pg[data-layout="network"] .wt-panel {
    display: none;
  }

  .pg[data-layout] .wt-panel,
  .pg[data-layout] .wt-stage {
    animation: pg-arrive 380ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  .pg[data-layout="code"] .pg-editor {
    height: max(24rem, calc(100vh - var(--wt-bar-height) - 14rem));
  }

  .pg[data-layout="network"] .wt-stage {
    height: calc(100vh - var(--wt-bar-height));
  }
}

@media (max-width: 640px) {
  .pg-title,
  .pg-examples-label,
  .pg-layout span {
    display: none;
  }

  /* The tools and the device take the top, the layers go above the rounds, and the map, which the 3D view repeats, goes. */
  .pg-side {
    top: 0.75rem;
    right: 0.75rem;
    left: 0.75rem;
    align-items: flex-start;
    max-width: none;
  }

  .pg-side .wt-tools,
  .pg-sensors {
    justify-content: flex-start;
  }

  .pg-device {
    align-items: flex-start;
  }

  /* Over the stack, which a small screen cannot keep clear of it: on a veil, and scrolling. */
  .pg .wt-legend {
    top: auto;
    bottom: 4.25rem;
    left: 0.75rem;
    max-height: 40%;
    overflow-y: auto;
    padding: 0.5rem 0.65rem;
    border-radius: 10px;
    background: color-mix(in srgb, var(--wt-stage) 88%, transparent);
  }

  .pg .wt-stage {
    height: 80vh;
  }

  .pg .wt-map {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pg-layout::before,
  .pg .wt-main,
  .pg .wt-panel,
  .pg .wt-stage {
    animation: none;
    transition: none;
  }
}
