/* Whisker Playground, scoped to .playground-page so it sits inside the site's header and footer.
   Colours are chosen for WCAG AA against their backgrounds. */

.playground-page {
  background: var(--color-bg-hero);
  color: #e0ecee;
  padding: 2rem 0 3rem;
}

.playground-intro h1 {
  font-size: 2rem;
  color: #fff;
}

.playground-intro p {
  color: #b8cfd2;
  margin: 0.5rem 0 1.25rem;
  max-width: 760px;
}

.playground-intro a {
  color: var(--color-primary-light);
}

.playground-intro code {
  background: rgba(255, 255, 255, 0.08);
  color: #e0ecee;
}

.playground-page .toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.playground-page .toolbar select {
  padding: 0.5rem 0.75rem;
  background: #16343a;
  color: #e0ecee;
  border: 1px solid #2c4c52;
  border-radius: 4px;
  font-size: 0.9rem;
  min-width: 240px;
}

.playground-page .toolbar button {
  padding: 0.5rem 1.25rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.playground-page .toolbar button:hover:not(:disabled) {
  background: #13a09e;
}

.playground-page .toolbar button.secondary {
  background: transparent;
  border: 1px solid #2c4c52;
  color: #e0ecee;
  font-weight: 500;
}

.playground-page .toolbar button.secondary:hover {
  background: #16343a;
}

.playground-page .toolbar button:disabled {
  background: #4b5b5e;
  cursor: not-allowed;
}

#status {
  color: #b8cfd2;
  font-size: 0.85rem;
}

#status.is-ready { color: #6ee7a0; }
#status.is-busy { color: #ffc46b; }
#status.is-error { color: #ff9a8f; }

.editor-panel {
  display: flex;
  gap: 1rem;
  min-height: 460px;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid #2c4c52;
  border-radius: 6px;
  overflow: hidden;
  min-width: 0;
}

.panel-header {
  background: #16343a;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-primary-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#output {
  flex: 1;
  background: #0a1a1e;
  color: #d6e4e6;
  border: none;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
}

/* The editor is a transparent textarea laid over a <pre> that holds the same
   text in colour. Everything that decides where a glyph falls is shared, so
   the two stay aligned; the textarea does not wrap, so there is no soft wrap
   to disagree about. */
.editor-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #0a1a1e;
}

#editor,
#highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 1rem;
  border: none;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: normal;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

#highlight {
  overflow: hidden;
  pointer-events: none;
  color: #d6e4e6;
  background: transparent;
}

#highlight code {
  font: inherit;
  white-space: inherit;
}

#editor {
  resize: none;
  overflow: auto;
  outline: none;
  background: transparent;
  color: #d6e4e6;
}

/* Hidden only once the script has drawn the coloured copy, so the text is
   never invisible when it fails to run. */
.editor-wrap.is-highlighted #editor {
  color: transparent;
  caret-color: #e0ecee;
}

.editor-wrap.is-highlighted #editor::selection {
  background: rgba(127, 216, 207, 0.35);
}

/* Colours are chosen for WCAG AA against #0a1a1e. */
#highlight .hl-kw { color: #ff8fcf; }
#highlight .hl-fn { color: #6ee7a0; }
#highlight .hl-str { color: #f1fa8c; }
#highlight .hl-num,
#highlight .hl-const { color: #c4a7ff; }
#highlight .hl-type { color: #8be9fd; }
#highlight .hl-op { color: #ffb86c; }
#highlight .hl-cm { color: #8a9fb5; font-style: italic; }

#editor:focus {
  outline: 2px solid var(--color-primary-light);
  outline-offset: -2px;
}

#editor::placeholder { color: #5b7276; }

#output {
  margin: 0;
  border-radius: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#output.error { color: #ff9a8f; }

/* WASM download indicator. Indeterminate on purpose: the wasm is served
   gzipped, so a byte counter would compare decompressed bytes against a
   compressed content-length. */
#loading {
  background: #0a1a1e;
  padding: 1rem;
  border-bottom: 1px solid #2c4c52;
  color: #d6e4e6;
  font-size: 0.9rem;
  line-height: 1.5;
}

#loading[hidden] { display: none; }

#loading .loading-title {
  font-weight: 700;
  color: #ffc46b;
}

#loading .loading-note {
  color: #b8cfd2;
  font-size: 0.85rem;
  margin-top: 0.35rem;
}

#loading .loading-elapsed { white-space: nowrap; }

.loading-track {
  position: relative;
  height: 6px;
  margin-bottom: 0.75rem;
  border-radius: 3px;
  background: #16343a;
  overflow: hidden;
}

.loading-track::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--color-primary-light), var(--color-accent));
  animation: loading-slide 1.4s ease-in-out infinite;
}

@keyframes loading-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-track::after {
    animation: loading-pulse 2s ease-in-out infinite;
    width: 100%;
    transform: none;
  }

  @keyframes loading-pulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 1; }
  }
}

.playground-keys {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #b8cfd2;
}

@media (max-width: 768px) {
  .playground-page { padding: 1.25rem 0 2rem; }

  .playground-page .toolbar select {
    flex: 1 1 100%;
    min-width: 0;
  }

  .editor-panel {
    flex-direction: column;
    min-height: 0;
    gap: 0.5rem;
  }

  .editor-panel > .panel:first-child { min-height: 40vh; }
  .editor-panel > .panel:nth-child(2) { min-height: 20vh; }

  /* 16px keeps iOS Safari from zooming in when the textarea is focused. */
  #editor,
  #highlight,
  #output {
    font-size: 16px;
    padding: 0.75rem;
  }
}
