@property --ink {
  syntax: "<color>";
  inherits: true;
  initial-value: #161614;
}
@property --grey {
  syntax: "<color>";
  inherits: true;
  initial-value: #e8e8e4;
}
@property --grey-mid {
  syntax: "<color>";
  inherits: true;
  initial-value: #8a8a84;
}
@property --grey-dark {
  syntax: "<color>";
  inherits: true;
  initial-value: #4a4a46;
}
@property --room {
  syntax: "<color>";
  inherits: true;
  initial-value: #f7f7f4;
}
@property --lime {
  syntax: "<color>";
  inherits: true;
  initial-value: #c6e000;
}
@property --lime-hot {
  syntax: "<color>";
  inherits: true;
  initial-value: #d4f020;
}
@property --blue {
  syntax: "<color>";
  inherits: true;
  initial-value: #6a96c4;
}
@property --blue-deep {
  syntax: "<color>";
  inherits: true;
  initial-value: #3d6f9c;
}
@property --orange {
  syntax: "<color>";
  inherits: true;
  initial-value: #ff9966;
}
@property --glass {
  syntax: "<color>";
  inherits: true;
  initial-value: #ffffffc7;
}
@property --glass-border {
  syntax: "<color>";
  inherits: true;
  initial-value: #0000000f;
}
@property --rail {
  syntax: "<color>";
  inherits: true;
  initial-value: #0000001f;
}
@property --load-track {
  syntax: "<color>";
  inherits: true;
  initial-value: #0000000f;
}
@property --btn-active-bg {
  syntax: "<color>";
  inherits: true;
  initial-value: #161614;
}
@property --btn-active-fg {
  syntax: "<color>";
  inherits: true;
  initial-value: #ffffff;
}
@property --hover-fill {
  syntax: "<color>";
  inherits: true;
  initial-value: #0000000d;
}
@property --room-spot {
  syntax: "<color>";
  inherits: true;
  initial-value: #ffffff;
}
@property --room-wash-a {
  syntax: "<color>";
  inherits: true;
  initial-value: #c6e00012;
}
@property --room-wash-b {
  syntax: "<color>";
  inherits: true;
  initial-value: #6a96c414;
}
@property --room-base-top {
  syntax: "<color>";
  inherits: true;
  initial-value: #fafaf7;
}
@property --room-base-bottom {
  syntax: "<color>";
  inherits: true;
  initial-value: #f0f0eb;
}

:root,
[data-theme="light"] {
  --lime: #c6e000;
  --lime-hot: #d4f020;
  --grey: #e8e8e4;
  --grey-mid: #8a8a84;
  --grey-dark: #4a4a46;
  --ink: #161614;
  --blue: #6a96c4;
  --blue-deep: #3d6f9c;
  --orange: #ff9966;
  --room: #f7f7f4;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(0, 0, 0, 0.06);
  --rail: rgba(0, 0, 0, 0.12);
  --load-track: rgba(0, 0, 0, 0.06);
  --btn-active-bg: #161614;
  --btn-active-fg: #ffffff;
  --hover-fill: rgba(0, 0, 0, 0.05);
  --room-spot: #ffffff;
  --room-wash-a: rgba(198, 224, 0, 0.07);
  --room-wash-b: rgba(106, 150, 196, 0.08);
  --room-base-top: #fafaf7;
  --room-base-bottom: #f0f0eb;
  --theme-color: #c6e000;
  --theme-duration: 0.45s;
  --theme-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --chrome-h: 56px;
  --edge: 8px;
  /* Shared L/R for chrome, tracks, footer; footer gets a touch more below */
  --inset: clamp(10px, 2vmin, 16px);
  --inset-footer: calc(var(--inset) + 6px);
  color-scheme: light;
}

[data-theme="dark"] {
  --lime: #d4f020;
  --lime-hot: #e7ff4a;
  --grey: #2c2c28;
  --grey-mid: #9a9a92;
  --grey-dark: #c8c8c0;
  --ink: #f3f3ee;
  --blue: #7aa8d4;
  --blue-deep: #9ec4e6;
  --orange: #ffb086;
  --room: #121210;
  --glass: rgba(28, 28, 26, 0.82);
  --glass-border: rgba(255, 255, 255, 0.08);
  --rail: rgba(255, 255, 255, 0.14);
  --load-track: rgba(255, 255, 255, 0.08);
  --btn-active-bg: #f3f3ee;
  --btn-active-fg: #121210;
  --hover-fill: rgba(255, 255, 255, 0.08);
  --room-spot: rgba(255, 255, 255, 0.06);
  --room-wash-a: rgba(212, 240, 32, 0.08);
  --room-wash-b: rgba(122, 168, 212, 0.1);
  --room-base-top: #161614;
  --room-base-bottom: #0e0e0c;
  --theme-color: #1a1a16;
  color-scheme: dark;
}

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

html {
  transition:
    --ink var(--theme-duration) var(--theme-ease),
    --grey var(--theme-duration) var(--theme-ease),
    --grey-mid var(--theme-duration) var(--theme-ease),
    --grey-dark var(--theme-duration) var(--theme-ease),
    --room var(--theme-duration) var(--theme-ease),
    --lime var(--theme-duration) var(--theme-ease),
    --lime-hot var(--theme-duration) var(--theme-ease),
    --blue var(--theme-duration) var(--theme-ease),
    --blue-deep var(--theme-duration) var(--theme-ease),
    --orange var(--theme-duration) var(--theme-ease),
    --glass var(--theme-duration) var(--theme-ease),
    --glass-border var(--theme-duration) var(--theme-ease),
    --rail var(--theme-duration) var(--theme-ease),
    --load-track var(--theme-duration) var(--theme-ease),
    --btn-active-bg var(--theme-duration) var(--theme-ease),
    --btn-active-fg var(--theme-duration) var(--theme-ease),
    --hover-fill var(--theme-duration) var(--theme-ease),
    --room-spot var(--theme-duration) var(--theme-ease),
    --room-wash-a var(--theme-duration) var(--theme-ease),
    --room-wash-b var(--theme-duration) var(--theme-ease),
    --room-base-top var(--theme-duration) var(--theme-ease),
    --room-base-bottom var(--theme-duration) var(--theme-ease);
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: "Outfit", "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 450;
  letter-spacing: -0.01em;
  background: var(--room);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  -webkit-font-smoothing: antialiased;
  transition:
    background-color var(--theme-duration) var(--theme-ease),
    color var(--theme-duration) var(--theme-ease);
}

body.hide-system-cursor,
body.hide-system-cursor * {
  cursor: none !important;
}

/* Keep a real pointer on chrome / footer so controls stay usable */
body.hide-system-cursor .chrome,
body.hide-system-cursor .chrome *,
body.hide-system-cursor .footer,
body.hide-system-cursor .footer a {
  cursor: auto !important;
}

body.hide-system-cursor .chrome .ctrl,
body.hide-system-cursor .chrome .ctrl-text,
body.hide-system-cursor .chrome button {
  cursor: pointer !important;
}

a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 160ms ease, color 160ms ease;
}

a:hover {
  border-bottom-color: currentColor;
}

#room {
  position: relative;
  isolation: isolate;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    var(--room-base-top) 0%,
    var(--room-base-bottom) 100%
  );
  transition: background var(--theme-duration) var(--theme-ease);
}

/* Slow ambient radial wash — drifts on a long ease cycle */
#room::before {
  content: "";
  position: absolute;
  inset: -35%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 42% 38% at 50% 42%, var(--room-spot) 0%, transparent 55%),
    radial-gradient(ellipse 55% 48% at 72% 88%, var(--room-wash-a) 0%, transparent 52%),
    radial-gradient(ellipse 40% 36% at 18% 78%, var(--room-wash-b) 0%, transparent 48%);
  transform: translate3d(0, 0, 0) scale(1.05);
  animation: room-wash-drift 96s ease-in-out infinite alternate;
  will-change: transform;
}

@keyframes room-wash-drift {
  0% {
    transform: translate3d(-3.5%, -2.5%, 0) scale(1.04);
  }
  50% {
    transform: translate3d(2%, 3.5%, 0) scale(1.1);
  }
  100% {
    transform: translate3d(4%, -1.5%, 0) scale(1.06);
  }
}

.room-edge {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--edge);
  background: var(--lime);
  z-index: 8;
  padding-top: var(--safe-top);
}

/* —— chrome —— */
.chrome {
  position: absolute;
  top: calc(var(--edge) + var(--safe-top));
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--chrome-h);
  padding: var(--inset) var(--inset) 0;
  pointer-events: none;
}

.chrome > * {
  pointer-events: auto;
}

.chrome-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
  opacity: 1;
  transition: opacity 0.55s ease;
}

.brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.45em;
  font-size: clamp(1.15rem, 3.2vw, 1.55rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
}

.brand-ver {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0.12em 0.42em;
  border-radius: 999px;
  background: var(--grey);
  font-size: 0.55em;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: 0.15em;
}

body[data-screen="start"] .brand {
  font-size: clamp(1.45rem, 5vw, 2.35rem);
}

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

.hud-controls[hidden] {
  display: none !important;
}

.status {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--grey-dark);
  min-width: 4.5rem;
  text-align: right;
}

.control-cluster {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.theme-cycle .ctrl-text {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-width: 5.5rem;
  justify-content: center;
}

.theme-icon {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: currentColor;
  position: relative;
  flex: 0 0 auto;
  opacity: 0.85;
  transition:
    background var(--theme-duration) var(--theme-ease),
    box-shadow var(--theme-duration) var(--theme-ease),
    opacity 160ms ease;
}

.brand,
.brand-ver,
.control-cluster,
.ctrl,
.ctrl-text,
.footer,
.footer a,
.about,
.start-hint,
#start-btn,
.status,
.track-guide,
.track-beat,
.track-ring,
.track-meta,
.track-name,
.track-rail,
.load-track,
#load-bar,
#load-label,
#load-detail,
.room-edge {
  transition:
    background-color var(--theme-duration) var(--theme-ease),
    background var(--theme-duration) var(--theme-ease),
    color var(--theme-duration) var(--theme-ease),
    border-color var(--theme-duration) var(--theme-ease),
    box-shadow var(--theme-duration) var(--theme-ease),
    fill var(--theme-duration) var(--theme-ease);
}

[data-theme-mode="auto"] .theme-icon {
  background: conic-gradient(from 180deg, var(--ink) 0 50%, var(--grey-mid) 50% 100%);
  box-shadow: inset 0 0 0 1px var(--glass-border);
}

[data-theme-mode="light"] .theme-icon {
  background: #f0c419;
  box-shadow: 0 0 0 2px rgba(240, 196, 25, 0.35);
}

[data-theme-mode="dark"] .theme-icon {
  background: radial-gradient(circle at 68% 32%, var(--room-base-top) 0 40%, #d7dde8 42%);
  box-shadow: none;
}

.ctrl {
  appearance: none;
  width: 40px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--grey-dark);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ctrl svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.ctrl:hover {
  background: var(--hover-fill);
  color: var(--ink);
}

.ctrl.is-active {
  background: var(--btn-active-bg);
  color: var(--btn-active-fg);
}

.ctrl-label {
  padding: 0 4px 0 10px;
  font-size: 0.72rem;
  font-weight: 550;
  color: var(--grey-mid);
  user-select: none;
}

.ctrl-text {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--grey-dark);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 550;
  padding: 0 12px;
  height: 36px;
  cursor: pointer;
}

.ctrl-text:hover {
  color: var(--ink);
}

.ctrl-text.is-active {
  background: var(--btn-active-bg);
  color: var(--btn-active-fg);
}

/* —— footer —— */
.footer {
  position: absolute;
  left: var(--inset);
  right: var(--inset);
  bottom: calc(var(--inset-footer) + var(--safe-bottom));
  z-index: 10;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--grey-mid);
  font-size: clamp(0.65rem, 1.55vw, 0.85rem);
  font-weight: 450;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.55s ease;
}

/* Idle: hide controls + footer; title stays put */
body.chrome-idle .chrome-actions,
body.chrome-idle .footer {
  opacity: 0;
}

body.chrome-idle .chrome-actions,
body.chrome-idle .chrome-actions *,
body.chrome-idle .footer a {
  pointer-events: none;
}

.footer-copy {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  min-width: 0;
}

.footer a {
  pointer-events: auto;
  font-weight: 550;
  color: var(--grey-dark);
}

.footer-credit {
  color: var(--grey-dark);
  text-align: right;
  margin-left: auto;
  flex: 0 0 auto;
}

.footer-sep {
  opacity: 0.45;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.screen[hidden] {
  display: none !important;
}

/* —— enter —— */
#screen-start {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.start-body {
  padding:
    calc(var(--chrome-h) + var(--edge) + var(--safe-top) + var(--inset))
    var(--inset)
    calc(2.5rem + var(--inset-footer) + var(--safe-bottom));
  max-width: 36rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.about {
  margin: 0 0 1.5rem;
  color: var(--ink);
  font-size: clamp(1rem, 2.6vw, 1.2rem);
  font-weight: 450;
  line-height: 1.55;
  letter-spacing: -0.015em;
  text-wrap: pretty;
  text-align: center;
  animation: fade-up 700ms ease both;
}

.start-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fade-up 700ms 100ms ease both;
}

#start-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--lime);
  color: #111;
  font: inherit;
  font-size: clamp(0.95rem, 2.4vw, 1.05rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  padding: 0.85rem 1.4rem;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background var(--theme-duration) var(--theme-ease),
    background-color var(--theme-duration) var(--theme-ease);
}

#start-btn:hover {
  background: var(--lime-hot);
  transform: translateY(-2px);
}

#start-btn:disabled {
  opacity: 0.5;
  cursor: wait;
  transform: none;
}

.start-hint {
  margin: 0.75rem 0 0;
  color: var(--grey-mid);
  font-size: 0.88rem;
}

/* —— load —— */
#screen-load {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 clamp(20px, 8vw, 80px);
}

.load-wrap {
  width: min(100%, 360px);
}

.load-track {
  height: 8px;
  border-radius: 999px;
  background: var(--load-track);
  overflow: hidden;
}

#load-bar {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--blue);
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 120ms linear;
}

#load-label,
#load-detail {
  margin-top: 10px;
  color: var(--grey-dark);
  font-size: 0.9rem;
}

/* —— play / tracks —— */
#screen-play {
  pointer-events: none;
}

#tracks {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.track {
  position: absolute;
  left: 0;
  width: 100%;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.track.is-dragging {
  cursor: grabbing;
  z-index: 5;
}

.track-rail {
  position: absolute;
  left: var(--inset);
  right: var(--inset);
  top: 50%;
  height: 0;
  border-top: 1px dotted var(--rail);
}

.track-delay {
  position: absolute;
  left: var(--inset);
  right: var(--inset);
  top: 50%;
  width: auto;
  height: 2px;
  margin-top: -1px;
  border-radius: 999px;
  background: rgba(106, 150, 196, 0.35);
  transform: scaleX(0);
  transform-origin: left center;
  opacity: 0;
  transition: opacity 180ms ease;
}

.track-guide {
  --guide-size: clamp(36px, 7.6vh, 56px);
  position: absolute;
  top: 50%;
  left: 0;
  width: var(--guide-size);
  height: var(--guide-size);
  margin-top: calc(var(--guide-size) / -2);
  border-radius: 50%;
  background: color-mix(in srgb, var(--blue) 28%, transparent);
  border: 1.5px solid var(--blue);
  box-sizing: border-box;
  display: grid;
  place-items: center;
  transform-origin: center center;
  will-change: transform, opacity;
  pointer-events: none;
}

.track-ring {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--blue-deep) 75%, transparent);
  opacity: 0.85;
  pointer-events: none;
}

.track-beat {
  width: 38%;
  height: 38%;
  border-radius: 50%;
  background: var(--blue-deep);
  transform: scale(1);
  transform-origin: center center;
  z-index: 1;
}

.track-guide.is-replay {
  border-color: var(--orange);
  background: color-mix(in srgb, var(--orange) 22%, transparent);
}

.track-guide.is-replay .track-ring {
  border-color: color-mix(in srgb, var(--orange) 80%, transparent);
}

.track-beat.is-replay {
  background: var(--orange);
}

.track-meta {
  --label-op: 0;
  position: absolute;
  right: var(--inset);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  pointer-events: none;
  color: var(--grey-mid);
  font-size: clamp(0.65rem, 1.5vw, 0.75rem);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

body.show-labels .track-meta {
  opacity: var(--label-op);
}

body.show-labels.chrome-idle .track-meta {
  opacity: 0;
  transition: opacity 0.55s ease;
}

.track-name {
  color: var(--grey-dark);
}

#cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: rgba(198, 224, 0, 0.9);
  pointer-events: none;
  /* Above tracks/screens, below chrome so it never covers buttons */
  z-index: 9;
  transition: opacity 120ms ease;
  will-change: transform;
}

#cursor.is-over-chrome {
  opacity: 0 !important;
}

#cursor .spin {
  position: absolute;
  inset: -5px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 999px;
  animation: spin 2.4s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* —— responsive —— */
@media (max-width: 720px) {
  :root {
    --chrome-h: 52px;
  }

  .status {
    display: none;
  }

  .ctrl {
    width: 36px;
    height: 34px;
  }

  .ctrl-text {
    height: 34px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .footer {
    gap: 0.25rem 0.4rem;
  }
}

@media (max-width: 520px) {
  .chrome {
    align-items: center;
  }

  .brand {
    font-size: 1.05rem;
    max-width: min(52%, 12rem);
  }

  body[data-screen="start"] .brand {
    font-size: clamp(1.25rem, 7vw, 1.8rem);
    max-width: none;
  }

  .chrome-actions {
    max-width: 62%;
    align-items: center;
  }

  .hud-controls {
    gap: 6px;
  }

  .theme-cycle .ctrl-text {
    min-width: 0;
  }

  #theme-label {
    display: none;
  }

  .ctrl-label {
    display: none;
  }

  .ctrl-text {
    padding: 0 9px;
  }

  .footer {
    gap: 0.2rem 0.35rem;
    font-size: clamp(0.58rem, 2.8vw, 0.72rem);
  }

  .about {
    font-size: 1rem;
  }
}

@media (max-width: 420px) {
  .control-cluster.cursor-toggle,
  .control-cluster.labels-toggle {
    display: none;
  }

  .hud-controls {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root,
  [data-theme="light"],
  [data-theme="dark"] {
    --theme-duration: 0.01ms;
  }

  .about,
  .start-panel,
  #cursor .spin,
  #room::before {
    animation: none;
  }

  #room::before {
    transform: none;
    will-change: auto;
  }

  #start-btn:hover {
    transform: none;
  }

  html,
  body,
  #room,
  .brand,
  .brand-ver,
  .control-cluster,
  .ctrl,
  .ctrl-text,
  .footer,
  .theme-icon {
    transition: none;
  }
}
