:root {
  --bg: #f6f1e7;
  --panel: #fffaf0;
  --ink: #2b2420;
  --muted: #6d625a;
  --line: #e3d8c6;
  --accent: #c8541c;
  --accent-ink: #fff;
  --error: #b3261e;
  --pad-a: #3d6fd8;
  --pad-b: #2f9e4f;
  --pad-z: #7a7a86;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --panel: #221e17;
    --ink: #f1e9dc;
    --muted: #b2a594;
    --line: #3a3328;
    --accent: #e8743a;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }

.stage { position: relative; }
#screen {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000;
}
.pad { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.pad button {
  width: 52px; height: 52px; border-radius: 50%;
  border: none; color: #fff; font-weight: 700; font-size: 1.1rem;
  touch-action: none; user-select: none; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.pad .pad-a { background: var(--pad-a); }
.pad .pad-b { background: var(--pad-b); }
.pad .pad-z { background: var(--pad-z); border-radius: 12px; width: 64px; }
.pad button.down { transform: translateY(3px); box-shadow: none; filter: brightness(1.15); }

#status { min-height: 1.4em; margin: 10px 0; color: var(--muted); }
#status.error { color: var(--error); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-top: 12px;
}
summary { cursor: pointer; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }
select, textarea, input[type="text"], input[type="number"] {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
textarea { width: 100%; resize: vertical; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button { font: inherit; }
.actions button {
  padding: 8px 18px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.actions button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; margin-top: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.note { color: var(--muted); margin: 4px 0 0; font-size: 0.9em; }

.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 32px; margin-bottom: 6px; }
.picker-head > span:first-child { font-weight: 600; }
.picker-head small { font-weight: 400; color: var(--muted); }
.picker-sel { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.picker-label { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.picker .tile.selected { border-color: var(--accent); background: var(--panel); }
.add {
  padding: 4px 12px; border-radius: 6px; cursor: pointer; font-weight: 600;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
.hint-touch { display: none; }
@media (hover: none) {
  .hint-hover { display: none; }
  .hint-touch { display: inline; }
}
.picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
}
.picker-wrap { position: relative; margin-bottom: 14px; }
.gate {
  position: absolute; inset: -4px; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  backdrop-filter: blur(3px) grayscale(0.6);
  color: var(--muted);
}
.gate[hidden] { display: none; }
.gate button {
  padding: 10px 28px; border-radius: 999px; cursor: pointer;
  font-size: 1.1rem; font-weight: 700; letter-spacing: 0.04em;
  border: none; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  animation: gate-pulse 1.6s ease-in-out infinite;
}
.gate button:active { transform: translateY(3px); box-shadow: none; }
@keyframes gate-pulse { 50% { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .gate button { animation: none; } }
.tile {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease;
}
.tile:hover, .tile:focus-visible {
  transform: scale(1.18) translateY(-2px);
  border-color: var(--accent);
  background: var(--panel);
  position: relative; z-index: 1;
  outline: none;
}
.tile:active { transform: scale(1.05); }
.face {
  display: block;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

footer { max-width: 980px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: 0.85em; }
footer p { margin: 4px 0; }
footer a { color: inherit; }

/* Phones: a swipeable strip of faces, thumb-sized pad, Play kept in reach. */
@media (max-width: 640px) {
  main { padding-top: 12px; }
  .pad { justify-content: center; gap: 18px; }
  .pad button { width: 64px; height: 64px; font-size: 1.25rem; }
  .pad .pad-z { width: 76px; }
  .picker-head { flex-wrap: wrap; }
  .picker {
    grid-template-columns: none;
    grid-template-rows: repeat(3, 52px);
    grid-auto-flow: column;
    grid-auto-columns: 52px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    padding: 2px 2px 8px;
    margin: 0 -14px;
    padding-inline: 14px;
    scroll-padding-inline: 14px;
  }
  .tile { scroll-snap-align: start; }
  .tile:hover, .tile:focus-visible { transform: none; }
  .actions {
    position: sticky; bottom: 0; z-index: 2;
    margin: 0 -14px -14px; padding: 10px 14px;
    background: var(--panel);
    border-top: 1px solid var(--line);
    border-radius: 0 0 10px 10px;
  }
}

pre {
  margin: 10px 0; padding: 10px 12px; overflow-x: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  font-size: 0.85em; line-height: 1.5;
}
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.note code { font-size: 0.95em; }
.note a { color: inherit; }
