*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #14161a;
  --fg: #e8e8ea;
  --dim: #5b5e66;
  --accent: #e8734d;
  --panel: #17181a;
  --panel-alt: #232427;

  /* The stage picks a random hue on load; these fall back to the base palette. */
  --stage-bg: var(--bg);
  --stage-fg: var(--fg);
  --stage-panel-alt: var(--panel-alt);

  --slot-width: 3rem;
  --slot-gap: 1.4rem;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

/* Buttons share a flat, chrome-free look. */
#play-pause,
#back-to-top,
.tap-target {
  appearance: none;
  border: none;
  border-radius: 0;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* No ring on click, but keyboard focus stays visible. */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Stage ---------------------------------------------------------------- */

#stage {
  position: relative;
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  padding: 2rem;
  background: var(--stage-bg);
}

#pattern-block {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  row-gap: 0.6rem;
  align-items: center;
  width: 100%;
}

#current-section {
  position: relative;
  grid-row: 1;
  grid-column: 2;
  justify-self: center;
}

#current-highlight {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

#labels-line-container,
#current-line-viewport {
  position: relative;
  z-index: 1;
}

#next-line-container {
  grid-row: 2;
  grid-column: 2;
  justify-self: center;
  opacity: 0.32;
}

/* --- Pattern lines -------------------------------------------------------- */

.pattern-line,
.highlight-row {
  display: flex;
  gap: var(--slot-gap);
}

.slot,
.highlight-cell {
  width: var(--slot-width);
}

.highlight-row,
.highlight-cell {
  height: 100%;
}

.highlight-cell.current {
  background: var(--stage-panel-alt);
}

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem 0.5rem;
}

.slot-label {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--stage-fg);
}

.slot-letter {
  font-size: 1.5rem;
  font-weight: 700;
  min-height: 1.9rem;
  line-height: 1.1;
  color: var(--accent);
}

/* On the slot being played, label and letter trade colours. */
.slot.current .slot-label {
  color: var(--accent);
}

.slot.current .slot-letter {
  color: var(--stage-fg);
}

/* Copy of the retired line, animated out over its old position. */
.swap-ghost {
  position: fixed;
  z-index: 5;
  pointer-events: none;
}

#counter {
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  margin-top: -0.15rem;
  margin-left: 1.5rem;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--dim);
  white-space: nowrap;
}

#counter.hidden {
  display: none;
}

/* --- Transport and navigation --------------------------------------------- */

#play-pause {
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4.6rem;
  height: 2.6rem;
  padding: 0;
}

#play-pause:hover {
  filter: brightness(1.1);
}

#play-pause:active {
  filter: brightness(0.9);
}

#scroll-hint {
  position: absolute;
  bottom: 1.5rem;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  color: var(--dim);
  transition: opacity 0.2s ease;
}

#scroll-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

#scroll-hint .scroll-text {
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

#scroll-hint .arrow {
  display: flex;
  animation: bounce 1.6s infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(6px);
  }
}

#back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel-alt);
  color: var(--fg);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  padding: 0.7rem 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

#back-to-top:hover {
  filter: brightness(1.2);
}

/* --- Options -------------------------------------------------------------- */

#options-mount {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 1.5rem 10rem;
  background: var(--panel);
  overscroll-behavior-y: none;
}

.options {
  width: 100%;
  max-width: 30rem;
  display: flex;
  flex-direction: column;
  gap: 2.2rem;
}

.option-row {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.option-label {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.option-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.option-value {
  min-width: 3rem;
  text-align: right;
  font-size: 1.1rem;
  font-weight: 700;
}

.option-slider {
  flex: 1;
  appearance: none;
  height: 0.5rem;
  background: var(--panel-alt);
}

.option-slider::-webkit-slider-thumb {
  appearance: none;
  width: 1.2rem;
  height: 1.5rem;
  background: var(--accent);
  border-radius: 0;
  cursor: pointer;
}

.option-slider::-moz-range-thumb {
  width: 1.2rem;
  height: 1.5rem;
  background: var(--accent);
  border: none;
  border-radius: 0;
  cursor: pointer;
}

.tap-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tap-target {
  background: var(--panel-alt);
  color: var(--fg);
  font-size: 1rem;
  min-width: 2.6rem;
  padding: 0.6rem 0.5rem;
}

.tap-target:hover {
  filter: brightness(1.2);
}

.tap-target.selected {
  background: var(--accent);
  color: var(--bg);
}

@media (prefers-reduced-motion: reduce) {
  #scroll-hint .arrow {
    animation: none;
  }
}
