/* The playground: the two demonstrations and their controls. */

/* ---------- playground ---------- */

.play {
  padding: 44px 0 80px;
  display: grid;
  gap: 28px;
}

.demo {
  border: 1px solid var(--rule);
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.demo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--rule);
}

.demo-head h2 {
  font-size: 1.35rem;
}

.demo-head p {
  margin: 6px 0 0;
  color: var(--ink-2);
  font-size: 14px;
  max-width: 70ch;
}

.demo-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 3px 7px;
  user-select: none;
  white-space: nowrap;
}

.demo-body {
  padding: 22px;
}

.broadcast-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 26px;
  align-items: flex-end;
  margin-bottom: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label,
.field-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  user-select: none;
}

.field select {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule-2);
  border-radius: 2px;
  padding: 7px 30px 7px 10px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 10px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.field select:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.stage-legend {
  display: flex;
  justify-content: flex-start;
  gap: 16px;
  margin: 0 0 8px 2px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  user-select: none;
}

.broadcast-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr) 24px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.operand {
  min-width: 0;
}

.operand-label {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  margin-bottom: 8px;
  min-width: 0;
}

.operand-label .op-name {
  color: var(--ink);
}

.operand-label .op-shape {
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.operator {
  font-family: var(--mono);
  font-size: 18px;
  color: var(--ink-3);
  text-align: center;
  user-select: none;
}

.grid-plain {
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 52px));
  justify-content: start;
  border: 1px solid var(--rule);
  background: var(--rule);
  padding: 3px;
  border-radius: 2px;
}

/* Coordinate frame around an operand: indices on the two axes, a hairline on each. */
.grid-frame {
  display: grid;
  grid-template-columns: 14px auto;
  grid-template-rows: 13px auto;
  gap: 3px;
  width: max-content;
  margin-inline: auto;
}

.grid-frame .axis-cols {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 52px));
  gap: 3px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--rule);
}

.grid-frame .axis-rows {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(var(--rows, 3), minmax(0, 1fr));
  gap: 3px;
  padding-right: 2px;
  border-right: 1px solid var(--rule);
}

.grid-frame .grid-plain {
  grid-column: 2;
  grid-row: 2;
}

.grid-plain.is-empty,
.grid-frame.is-empty {
  display: none;
}

.grid-frame .axis-cols span,
.grid-frame .axis-rows span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1;
  color: var(--ink-3);
}

/* The select is drawn here, not by the browser: the same paper, rule and teal as the rest. */
.picker {
  position: relative;
}

.picker-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-width: 150px;
  padding: calc(0.5em + 0.06em) 10px calc(0.5em - 0.06em) 11px;
  border: 1px solid var(--rule-2);
  border-radius: 2px;
  background: var(--glass-strong);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.picker-button:hover {
  border-color: var(--ink-3);
  background: var(--surface);
}

.picker.open .picker-button {
  border-color: var(--teal);
  background: var(--surface);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--teal) 28%, transparent);
}

.picker-chevron {
  width: 0.875rem;
  height: 0.875rem;
  flex: none;
  transition: transform 160ms ease;
}

.picker.open .picker-chevron {
  transform: rotate(180deg);
}

.picker-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 5px);
  left: 0;
  min-width: 100%;
  max-height: 232px;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--rule-2);
  border-radius: 3px;
  box-shadow: 0 18px 36px -22px rgb(14 36 48 / 55%);
}

html[data-theme="dark"] .picker-menu {
  box-shadow: 0 18px 36px -22px rgb(0 0 0 / 80%);
}

.picker-option {
  position: relative;
  padding: calc(0.42em + 0.05em) 10px calc(0.42em - 0.05em) 12px;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-2);
  cursor: pointer;
  outline: none;
}

.picker-option:hover {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--ink);
}

.picker-option:focus {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--teal) 55%, transparent);
}

.picker-option[aria-selected="true"] {
  color: var(--ink);
  background: color-mix(in srgb, var(--teal) 9%, transparent);
}

.picker-option[aria-selected="true"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--teal);
  clip-path: polygon(0 0, 100% 8%, 100% 92%, 0 100%);
}

@media (width <= 820px) {
  .field {
    flex: 1 1 132px;
  }
  .picker-button {
    min-width: 0;
  }
}

.grid-plain span {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1.35;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  border-radius: 1px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-plain.result span {
  background: color-mix(in srgb, var(--teal) calc(var(--t, 0) * 46%), var(--surface));
}

.demo-message {
  margin-top: 18px;
  min-height: 24px;
  font-size: 14px;
  color: var(--ink-2);
}

.demo-message .err {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--amber);
}

@media (width <= 820px) {
  .stage-legend {
  display: flex;
  justify-content: flex-start;
  gap: 16px;
  margin: 0 0 8px 2px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  user-select: none;
}

.broadcast-stage {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .operator {
    text-align: left;
    padding-left: 2px;
  }
}

.fit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.65fr);
  gap: 24px;
  align-items: start;
}

@media (width <= 820px) {
  .fit-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.fit-canvas {
  width: 100%;
  height: 380px;
  display: block;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper);
  touch-action: none;
  cursor: crosshair;
}

.fit-readout {
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper);
  padding: 16px 18px;
}

.fit-readout dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 16px;
  align-items: baseline;
}

.fit-readout dt {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  user-select: none;
}

.fit-readout dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  overflow-wrap: anywhere;
  text-align: right;
}

.fit-readout .formula {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.fit-hint {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

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

.demo-actions .btn {
  font-size: 13px;
  padding: calc(0.5em + 0.07em) 0.9em calc(0.5em - 0.07em);
}

.engine-warning {
  display: none;
  margin: 0 0 18px;
  padding: 12px 16px;
  border: 1px solid var(--rule-2);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-2);
  font-size: 13.5px;
  color: var(--ink-2);
  position: relative;
}

.engine-warning::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--amber);
  clip-path: polygon(0 0, 100% 10%, 100% 90%, 0 100%);
}

body.no-engine .engine-warning {
  display: block;
}


