:root {
  color-scheme: dark;
  --ink: #e6f5e8;
  --muted: #9fc3a5;
  --accent: #3ddc62;
  --accent-ink: #021006;
  --panel: rgba(6, 30, 12, 0.78);
  --line: rgba(61, 220, 98, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #010802;
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  background:
    radial-gradient(ellipse at 70% 30%, rgba(0, 120, 40, 0.35), transparent 60%),
    radial-gradient(ellipse at 20% 80%, rgba(0, 70, 90, 0.3), transparent 55%),
    #010802;
  background-attachment: fixed;
}

/* --- launch page ------------------------------------------------------------------------- */

#launch-page {
  max-width: 44rem;
  margin: 0 auto;
  padding: max(2rem, env(safe-area-inset-top)) 1.25rem 3rem;
  text-align: center;
}

h1 {
  margin: 1rem 0 0.5rem;
  font-size: clamp(2rem, 7vw, 3.25rem);
  letter-spacing: 0.02em;
  color: var(--accent);
}

.lead {
  color: var(--muted);
  margin: 0 auto 2rem;
  max-width: 36rem;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  min-height: 2.75rem;
  min-width: 2.75rem;
  margin: 0.15rem;
}

button:hover {
  background: rgba(61, 220, 98, 0.15);
}

button:focus-visible,
#fractal-canvas:focus-visible {
  outline: 3px solid #ffd54a;
  outline-offset: 2px;
}

button[aria-pressed="true"] {
  background: rgba(61, 220, 98, 0.28);
}

kbd {
  font: 0.85em ui-monospace, "SF Mono", Consolas, monospace;
  padding: 0.05em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 0.3em;
  background: rgba(255, 255, 255, 0.06);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

button.launch {
  font-size: 1.35rem;
  font-weight: 600;
  padding: 0.8rem 2.4rem;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 2rem rgba(61, 220, 98, 0.35);
}

button.launch:hover {
  background: #63ef83;
}

.escape-times {
  color: var(--muted);
  margin: 1.25rem 0 2.5rem;
}

table.controls {
  margin: 0 auto;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  overflow: hidden;
  text-align: left;
  font-size: 0.95rem;
}

table.controls caption {
  font-weight: 600;
  padding-bottom: 0.5rem;
  color: var(--accent);
}

table.controls th,
table.controls td {
  padding: 0.45rem 0.9rem;
  border-top: 1px solid var(--line);
}

table.controls thead th {
  border-top: none;
  color: var(--muted);
  font-weight: 500;
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 1.5rem;
}

/* --- the fractal ---------------------------------------------------------------------------- */

body.exploring {
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  background: #000;
}

#fractal-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#box {
  position: absolute;
  border: 2px dashed #fff;
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

#readout {
  position: absolute;
  left: max(0.75rem, env(safe-area-inset-left));
  top: max(0.5rem, env(safe-area-inset-top));
  margin: 0;
  padding: 0.2rem 0.7rem;
  border-radius: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  font: 0.8rem/1.4 ui-monospace, "SF Mono", Consolas, monospace;
  max-width: calc(100% - 1.5rem);
  overflow-wrap: anywhere;
  pointer-events: none;
}

#toast {
  position: absolute;
  left: 50%;
  top: 3.5rem;
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 2rem);
  padding: 0.4rem 1rem;
  border-radius: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--accent);
  text-align: center;
}

#toolbar {
  position: absolute;
  left: 50%;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15rem;
  width: max-content;
  max-width: calc(100% - 1rem);
  padding: 0.2rem;
  border-radius: 1.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

#toolbar button {
  margin: 0;
  padding: 0.3rem 0.8rem;
  background: transparent;
  border-color: transparent;
}

#toolbar button:hover {
  background: rgba(61, 220, 98, 0.2);
}

#help {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.72);
  overflow-y: auto;
}

.help-card {
  width: min(34rem, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 1rem 1.25rem 1.25rem;
  border-radius: 0.9rem;
  background: #06180b;
  border: 1px solid var(--accent);
}

.help-card h2 {
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.help-card dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.35rem 1rem;
  margin: 0 0 1rem;
}

.help-card dt {
  font-weight: 600;
}

.help-card dd {
  margin: 0;
  color: var(--muted);
}

#drawing {
  position: absolute;
  left: 50%;
  top: calc(max(0.5rem, env(safe-area-inset-top)) + 3.6rem);
  transform: translateX(-50%);
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  pointer-events: none;
}

/* ?embed=1: the host page provides fullscreen and there is nothing to exit to. */
.embed [data-action='exit'],
.embed [data-action='fullscreen'] {
  display: none;
}

@media (max-width: 30rem) {
  table.controls th,
  table.controls td {
    padding: 0.4rem 0.5rem;
  }

  #toolbar {
    gap: 0;
  }

  #toolbar button {
    padding: 0.2rem 0.45rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
    font-size: 0.9rem;
  }

  .help-card dl {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

  .help-card dd {
    margin-bottom: 0.4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
