/* Themes. Every colour is a token: dark values here (the default), light
   values in the two blocks below. Light applies when the device prefers it
   (System mode) or when the header toggle sets data-theme="light"; an
   explicit data-theme="dark" wins over a light device. theme.js and
   theme-init.js keep --bg's two values for iOS's theme-color. */
:root {
  --bg: #0f1115;
  --panel: #181b22;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #7c5cff;
  --accent-soft: #7c5cff26;
  --on-accent: #ffffff;
  --link: #a996ff;
  --danger: #ff8a8a;
  --danger-line: #ff8a8a66;
  --danger-soft: #ff8a8a1a;
  --backdrop: #000000aa;
  --backdrop-strong: #000000cc;
  --shadow: #00000088;
  /* Google's sign-in button, light theme (Google Identity branding guidelines). */
  --google-bg: #ffffff;
  --google-bg-hover: #f2f2f2;
  --google-text: #1f1f1f;
  --google-line: #747775;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f6fa;
    --panel: #ffffff;
    --line: #d4d7e1;
    --text: #16181d;
    --muted: #5b6372;
    --accent: #6646e6;
    --accent-soft: #6646e61f;
    --link: #5a3fd6;
    --danger: #c62828;
    --danger-line: #c6282866;
    --danger-soft: #c628281a;
    --backdrop: #10121866;
    --backdrop-strong: #101218aa;
    --shadow: #1018282e;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f6f6fa;
  --panel: #ffffff;
  --line: #d4d7e1;
  --text: #16181d;
  --muted: #5b6372;
  --accent: #6646e6;
  --accent-soft: #6646e61f;
  --link: #5a3fd6;
  --danger: #c62828;
  --danger-line: #c6282866;
  --danger-soft: #c628281a;
  --backdrop: #10121866;
  --backdrop-strong: #101218aa;
  --shadow: #1018282e;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

header {
  padding: 1.5rem 1.25rem 0.5rem; max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 0.5rem 1rem;
}
header h1 { margin: 0; font-size: 1.6rem; }
header p { margin: 0.25rem 0 0; color: var(--muted); }
header .app-version { font-size: 0.8rem; }
header .app-version a { color: var(--muted); }
header .app-version a:hover { color: var(--text); }

main {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 1.25rem;
  padding: 1rem 1.25rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; padding-bottom: 6rem; }  /* room for the bottom bar */
  /* Phone order follows the page: Routine, Style, Difficulty, Moves, then the routine. */
  fieldset { min-width: 0; }
}

/* On wide screens the routine stays in view while you scroll the settings and move list. */
@media (min-width: 761px) {
  #result {
    position: sticky;
    top: 1rem;
    align-self: start;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}

[hidden] { display: none !important; }

fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  margin: 0 0 1rem;
  padding: 0.75rem 1rem 1rem;
}
legend { padding: 0 0.4rem; font-weight: 600; }

label { display: block; margin: 0.5rem 0; }
select, input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
.radio-row label, .check { margin: 0.35rem 0; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  margin: 0;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.hint { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0.5rem; }

/* Listen: under the Song BPM field. */
.listen-buttons, .listen-octave { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.listen-buttons button { min-height: 44px; }
.listen .hint:empty { display: none; }

/* Moves panel: one row when closed, the full list when open. */
#moves-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
}
#moves-panel summary::-webkit-details-marker { display: none; }
#moves-panel summary::after { content: "Show ▾"; color: var(--muted); }
#moves-panel[open] summary::after { content: "Hide ▴"; }
.moves-tools { display: flex; gap: 0.5rem; margin: 0.25rem 0 0.5rem; }
.moves-tools button { min-height: 44px; }

.move-list { list-style: none; margin: 0; padding: 0; }
.move-list li { border-top: 1px solid var(--line); padding: 0.4rem 0; }
.move-list li:first-child { border-top: 0; }
.move-list label { margin: 0; cursor: pointer; }
.move-list .desc { margin: 0.15rem 0 0 1.6rem; color: var(--muted); font-size: 0.85rem; }
.move-list li.filtered { opacity: 0.4; }
.move-list li.variant { margin-left: 1.4rem; border-top-style: dashed; }

.move-name { font-weight: 600; }
.meta { display: block; color: var(--muted); font-size: 0.85rem; }
.move-list .meta { margin-left: 1.6rem; }

.result-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.result-head h2 { margin: 0; }
.actions { display: flex; gap: 0.5rem; }

button {
  /* Quick repeated taps are taps, not iOS double-tap zoom (pinch zoom still works). */
  touch-action: manipulation;
  font: inherit;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
button:disabled { opacity: 0.5; cursor: default; }
.actions button { white-space: nowrap; }

/* Bottom bar: phones only. */
.action-bar { display: none; }
@media (max-width: 760px) {
  #shuffle, #play { display: none; }  /* the bar has Shuffle again and Play */
  .action-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .bar-summary { flex: 1; min-width: 0; line-height: 1.25; }
  .bar-summary strong { display: block; }
  .bar-summary span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .action-bar button { min-height: 44px; white-space: nowrap; }
}

.routine { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.routine .move {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  margin: 0.35rem 0;
}
.routine .beats { display: block; color: var(--muted); font-size: 0.8rem; }
/* A move outside its BPM sweet spot: still allowed, just flagged. */
.tempo-tag {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.8rem;
}
.move-list li.off-tempo .meta::after { content: " · outside sweet spot"; color: var(--text); }
.routine .connector { color: var(--muted); font-size: 0.9rem; padding: 0.1rem 0 0.1rem 1rem; }

/* Account (sign-in) area, top right of the header. */
.account { position: relative; }
.account .signin { white-space: nowrap; min-height: 40px; }
.account-notice {
  grid-column: 1 / -1; margin: 0; padding: 0.5rem 0.75rem; font-size: 0.9rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text);
}

.account-menu > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 0.5rem;
  min-height: 40px; padding: 0.25rem 0.6rem 0.25rem 0.3rem;
  border: 1px solid var(--line); border-radius: 999px;
}
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu[open] > summary { border-color: var(--accent); }
.account-menu .avatar,
.account-menu .avatar-fallback { width: 28px; height: 28px; border-radius: 50%; flex: none; }
.account-menu .avatar-fallback {
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
  background: var(--accent-soft); color: var(--text);
}
.account-menu .avatar-fallback[hidden],
.account-menu .avatar[hidden] { display: none; }
.account-name { max-width: 10ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.account-panel {
  position: absolute; right: 0; top: calc(100% + 0.4rem); z-index: 20; min-width: 15rem;
  display: grid; gap: 0.5rem; padding: 0.75rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px var(--shadow);
}
.account-who { margin: 0 0 0.25rem; display: grid; font-size: 0.9rem; }
.account-who span { color: var(--muted); overflow-wrap: anywhere; }
.account-panel button { min-height: 40px; width: 100%; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger-line); }
button.danger:hover { background: var(--danger-soft); }

@media (max-width: 760px) {
  .account-name { display: none; }
  .account-menu > summary { padding: 0.25rem; }
}

/* Signed out: landing panel, and the banner over a shared routine. */
.landing {
  grid-column: 1 / -1; max-width: 640px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.5rem;
}
.landing h2 { margin-top: 0; }
.landing-points { padding-left: 1.2rem; color: var(--muted); }
.landing-points li { margin: 0.25rem 0; }
.landing button { min-height: 44px; }

/* Continue with Google: Google's standard light button, the brightest thing on
   a dark page on purpose. The logo keeps its own colours. */
button.google-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 48px; padding: 0 18px 0 14px;
  background: var(--google-bg); color: var(--google-text);
  border: 1px solid var(--google-line); border-radius: 6px;
  font-weight: 600; font-size: 1rem; letter-spacing: 0.01em;
}
button.google-button:hover { background: var(--google-bg-hover); }
button.google-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.google-g { width: 20px; height: 20px; flex: none; }
.sprite { position: absolute; } /* the logo's <symbol> holder; takes no space */

/* Header: the theme button (and, in the app, the account control). */
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
button.theme-toggle {
  display: inline-grid; place-items: center; padding: 0;
  width: 44px; height: 44px; border-radius: 999px;
  background: transparent; color: var(--text); border: 1px solid var(--line);
}
button.theme-toggle:hover { border-color: var(--accent); }
button.theme-toggle svg { width: 20px; height: 20px; }

main.shared-only { grid-template-columns: 1fr; max-width: 760px; }
.shared-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin: 0.5rem 0 1rem; padding: 0.75rem 1rem;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px;
}
.shared-banner p { margin: 0; flex: 1 1 16rem; }
.shared-banner[hidden] { display: none; }

#result[aria-busy="true"] .routine { opacity: 0.55; transition: opacity 0.15s; }

.account-actions, .landing-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.account-actions button { white-space: nowrap; min-height: 40px; }
@media (max-width: 760px) {
  /* Phones: the header is tight. Keep Sign in for returning users; new
     visitors get Create account on the landing panel. */
  .account-actions .create-account { display: none; }
}

/* Play routine: the stage view. Full screen on phones, large on desktop. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.stage {
  --row: clamp(88px, 15dvh, 120px);
  touch-action: manipulation; /* tapping along to the music must never zoom */
  width: min(720px, 100vw); height: min(640px, 100dvh);
  max-width: 100vw; max-height: 100dvh;
  padding: 1rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 16px;
  display: none; flex-direction: column; gap: 1rem;
}
.stage[open] { display: flex; }
.stage::backdrop { background: var(--backdrop-strong); }
.stage-top { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.stage-tempo { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.stage button { min-height: 44px; min-width: 44px; }
.stage-main { flex: 1; position: relative; overflow: hidden; min-height: 0; }
.stage-count { color: var(--muted); font-size: 1.1rem; margin: 0; text-align: center; font-variant-numeric: tabular-nums; }

/* The routine as a falling list: upcoming moves above, the current one on the
   now line, finished ones fading out below. Rows are placed by --i. */
.stage-list {
  position: absolute; inset: 0;
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 90%, transparent);
  mask-image: linear-gradient(transparent, #000 14%, #000 90%, transparent);
}
.stage-track { position: absolute; inset: 0 0 auto 0; will-change: transform; }
.stage-row {
  position: absolute; left: 0.5rem; right: 0.5rem;
  top: calc(var(--i) * var(--row) * -1); height: var(--row);
  display: flex; flex-direction: column; justify-content: center; gap: 0.15rem;
  transform-origin: left center; will-change: transform, opacity;
}
.stage-row-conn { color: var(--muted); font-size: 1rem; min-height: 1.2em; }
.stage-row-name { font-size: clamp(1.8rem, 8vw, 2.6rem); font-weight: 700; line-height: 1.1; }
.stage-row-meta { color: var(--muted); font-size: 0.9rem; }
.stage-row-tag { display: none; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); }
.stage-row.soon .stage-row-tag { display: block; }
.stage-nowline {
  position: absolute; left: 0; right: 0; height: 1px; z-index: 1;
  background: linear-gradient(90deg, transparent, var(--line) 15%, var(--line) 85%, transparent);
}

/* The beat indicator: pinned under the now line, one dot per beat of the move. */
.stage-dots {
  position: absolute; left: 0; right: 0; z-index: 3;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem;
  padding: 0.75rem 0 1rem; background: linear-gradient(var(--bg) 70%, transparent);
}
.stage-dots span {
  width: clamp(18px, 5vw, 26px); height: clamp(18px, 5vw, 26px);
  border-radius: 50%; border: 2px solid var(--line); background: var(--bg);
}
.stage-dots span.done { background: var(--accent-soft); border-color: var(--accent); }
.stage-dots span.now { background: var(--accent); border-color: var(--accent); }

/* Count-in: a big 5 6 7 8 over the list; the dots keep counting below it. */
.stage-countin { position: absolute; inset: 0; z-index: 2; display: grid; place-content: center; text-align: center; background: var(--bg); }
.stage-countin b { font-size: clamp(5rem, 30vw, 9rem); color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.stage-countin small { color: var(--muted); font-size: 1.1rem; }
.stage-controls { display: grid; grid-template-columns: 1fr 2fr; gap: 0.75rem; }
.stage-controls button { min-height: 56px; font-size: 1.1rem; }
.stage-tap { font-weight: 700; }
@media (max-width: 760px) {
  .stage { width: 100vw; height: 100dvh; border-radius: 0; border: none; }
  .stage-controls button { min-height: 64px; }
}

/* Sign-in panel */
.signin-dialog {
  width: min(420px, calc(100vw - 2rem)); padding: 1.25rem;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
}
.signin-dialog::backdrop { background: var(--backdrop); }
.signin-dialog form { display: grid; gap: 0.75rem; }
.signin-dialog label { display: grid; gap: 0.35rem; }
.signin-dialog input {
  font: inherit; padding: 0.6rem 0.7rem; border-radius: 6px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
}
.signin-dialog input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.signin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.signin-head h2 { margin: 0; font-size: 1.3rem; }
button.icon { padding: 0.2rem 0.6rem; font-size: 1.2rem; line-height: 1; }
button.wide { width: 100%; min-height: 44px; }
button.google-button.wide { min-height: 48px; }
button.link { background: none; border: none; padding: 0; color: var(--link); text-decoration: underline; min-height: 0; }
.signin-or { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; margin: 1rem 0; }
.signin-or::before, .signin-or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.signin-links, .signin-alt { font-size: 0.9rem; margin: 0.25rem 0; }
#signin-status.error { color: var(--danger); }

/* Footer and text pages (privacy policy). */
.site-footer { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem 2rem; font-size: 0.85rem; color: var(--muted); }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }
@media (max-width: 760px) {
  .site-footer { padding-bottom: 6rem; }  /* clear of the bottom bar */
}
.home-link { color: inherit; text-decoration: none; }
main.doc { display: block; }
.doc > * { max-width: 720px; }
.doc h2 { font-size: 1.2rem; margin: 1.75rem 0 0.5rem; }
.doc h3 { font-size: 1rem; margin: 1.25rem 0 0.25rem; }
.doc li { margin: 0.35rem 0; }
.doc a { color: var(--link); }
