:root {
  --bg: #f4faf8;
  --surface: #ffffff;
  --text: #1c2b2e;
  --muted: #5d6f72;
  --border: #dbe8e4;
  --hover: rgba(47, 122, 116, 0.08);
  --accent: #2f7a74;
  --accent-text: #ffffff;
  --code-bg: #f1f6f5;
  --shadow: 0 1px 2px rgba(25, 56, 62, 0.06), 0 4px 16px rgba(25, 56, 62, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1c1e;
    --surface: #172a2d;
    --text: #e4efed;
    --muted: #9db3b0;
    --border: #26403f;
    --hover: rgba(108, 195, 185, 0.1);
    --accent: #6cc3b9;
    --accent-text: #0f1c1e;
    --code-bg: #0f1c1e;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1c1e;
  --surface: #172a2d;
  --text: #e4efed;
  --muted: #9db3b0;
  --border: #26403f;
  --hover: rgba(108, 195, 185, 0.1);
  --accent: #6cc3b9;
  --accent-text: #0f1c1e;
  --code-bg: #0f1c1e;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1,
h2,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible,
a:focus-visible,
.code:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.muted {
  color: var(--muted);
}

/* Bar linking back to the main site. */

.demo-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background-color: #19383e;
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}

.demo-bar a {
  color: #c6ebe1;
  font-weight: 600;
  text-decoration: none;
}

.demo-bar a:hover {
  text-decoration: underline;
}

/* Layout */

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: grid;
  gap: 16px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.8rem;
  letter-spacing: -0.02em;
}

.page-header h1 span {
  color: var(--accent);
}

.page-header p {
  color: var(--muted);
}

.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card h2 {
  font-size: 1.05rem;
  margin-bottom: 8px;
}

/* Buttons */

.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s, background-color 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-text);
  min-width: 96px;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: none;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background-color: var(--hover);
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.875rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  background-color: var(--hover);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-btn .icon-sun {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-btn .icon-moon {
    display: none;
  }
}

:root[data-theme="dark"] .theme-btn .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-btn .icon-moon {
  display: none;
}

/* Controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.segmented button {
  border: none;
  background: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.segmented button[aria-checked="true"] {
  background-color: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

.buttons {
  display: flex;
  gap: 8px;
}

.speed {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.speed span {
  margin-right: 4px;
}

.speed button {
  border: 1px solid var(--border);
  background: none;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.speed button.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* The LED board */

.board {
  position: relative;
  border-radius: 18px;
  padding: 28px 20px 24px;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.07) 1px, transparent 0) 0 0 / 16px 16px,
    linear-gradient(160deg, #0f3d36, #0a2a26);
  color: #d9efe9;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), var(--shadow);
}

.board-label {
  position: absolute;
  top: 12px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(217, 239, 233, 0.7);
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #3ddc84;
  box-shadow: 0 0 8px #3ddc84;
}

.paused .chip-dot {
  background-color: #ffc93c;
  box-shadow: 0 0 8px #ffc93c;
}

.leds {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding-top: 16px;
}

.led-slot {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 4px;
}

.led {
  --size: clamp(52px, 13vw, 84px);
  width: var(--size);
  height: calc(var(--size) * 1.15);
  border-radius: 50% 50% 12% 12% / 60% 60% 12% 12%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.35), transparent 40%),
    color-mix(in srgb, var(--led) 28%, #1b1b1b);
  border: 2px solid color-mix(in srgb, var(--led) 35%, #000);
  transition: background-color 40ms, box-shadow 40ms, filter 40ms;
}

.led.on {
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.85), transparent 45%),
    var(--led);
  border-color: color-mix(in srgb, var(--led) 70%, #fff);
  box-shadow:
    0 0 18px 4px color-mix(in srgb, var(--led) 70%, transparent),
    0 0 60px 18px color-mix(in srgb, var(--led) 35%, transparent);
}

.leg {
  width: 30%;
  height: 22px;
  border-left: 3px solid #b8c2c4;
  border-right: 3px solid #b8c2c4;
  opacity: 0.7;
}

.led-slot strong {
  font-size: 0.9rem;
}

.led-note {
  min-height: 2.6em;
  color: rgba(217, 239, 233, 0.7);
  font-size: 0.75rem;
  line-height: 1.3;
}

.beat {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: rgba(217, 239, 233, 0.75);
}

.beat[hidden] {
  display: none;
}

.beat ol {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step -1;
}

.beat li {
  counter-increment: step;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: background-color 60ms;
}

.beat li::before {
  content: counter(step);
}

.beat li.active {
  background-color: #6cc3b9;
  border-color: #6cc3b9;
  color: #0a2a26;
  font-weight: 700;
}

/* Readouts */

.readouts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.readout {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
}

.readout span {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.readout strong {
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.how p {
  color: var(--muted);
}

/* Code */

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.code-head h2 {
  margin: 0;
}

.code-card .muted {
  margin: 6px 0 12px;
  font-size: 0.875rem;
}

.code {
  margin: 0;
  padding: 12px 0;
  max-height: 460px;
  overflow: auto;
  background-color: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.6;
}

.line {
  display: block;
  padding-right: 16px;
  white-space: pre;
  transition: opacity 0.2s;
}

.line.dim {
  opacity: 0.3;
}

.line.flag {
  background-color: var(--hover);
  box-shadow: inset 3px 0 var(--accent);
}

.ln {
  display: inline-block;
  width: 3em;
  padding-right: 1em;
  text-align: right;
  color: var(--muted);
  user-select: none;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.photo {
  margin: 0;
}

.photo h2 {
  text-align: center;
}

.photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
}

.shortcuts {
  flex-basis: 100%;
  text-align: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .readouts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls {
    gap: 12px;
  }

  .segmented {
    width: 100%;
  }

  /* Phones have no keyboard shortcuts to show. */
  .shortcuts {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .led,
  .line {
    transition: none;
  }
}
