/* ============================================================
   Metronome — styles
   Maroon-based theme. Light + dark via prefers-color-scheme.
   Phone-first: every control is at least 56px tall, with no
   sliders, drags, or small steppers (tremor-friendly).
   ============================================================ */

/* ---- Theme tokens ---------------------------------------- */
:root {
  --bg:            #fbf6f1;   /* warm cream page */
  --surface:       #ffffff;
  --surface-alt:   #f4ebe4;
  --text:          #2a0f12;   /* near-black maroon, ~15:1 on cream */
  --text-muted:    #6b4448;   /* ~7:1 on cream */
  --border:        #dcc7c0;
  --border-strong: #a86f72;

  --maroon:        #800000;   /* primary brand */
  --maroon-hover:  #660000;
  --maroon-deep:   #4a0006;   /* pressed + header ink */
  --on-maroon:     #ffffff;   /* ~11:1 on --maroon */

  --accent:        #b5294a;   /* downbeat rose, dots only */
  --dot-off:       #e4d2ca;
  --dot-on:        #800000;

  --target:        #2f6b3a;   /* "target reached" green, text ~6:1 */

  /* Ramp-mode flames (decorative) and the panel's warm ramp border. */
  --flame-outer:   #9d0208;
  --flame-mid:     #e85d04;
  --flame-core:    #ffba08;
  --ramp-border:   #e85d04;
  --focus-ring:    #d4a017;   /* gold ring: visible on cream and maroon */

  --shadow:        0 2px 4px rgba(74, 0, 6, .08),
                   0 8px 24px rgba(74, 0, 6, .10);
  --radius:        14px;
  --radius-sm:     10px;
  --min-target:    56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #1a0d0f;
    --surface:       #2a1417;
    --surface-alt:   #351a1e;
    --text:          #f6e9e6;
    --text-muted:    #d4b5b0;
    --border:        #5a3136;
    --border-strong: #8d5a5f;

    --maroon:        #9b1c24;
    --maroon-hover:  #b3262f;
    --maroon-deep:   #6e0f15;
    --on-maroon:     #ffffff;

    --accent:        #f07a95;
    --dot-off:       #4a2a2e;
    --dot-on:        #e0606f;

    --target:        #7fd193;
    --focus-ring:    #f5c542;
    --shadow:        0 2px 4px rgba(0, 0, 0, .4);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

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

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 2rem; color: var(--maroon); }
@media (prefers-color-scheme: dark) { h1 { color: var(--text); } }
h2 { font-size: 1.25rem; margin-bottom: 8px; }

.app-header { padding: 8px 4px 0; }
.subtitle, .hint, .footer-note { color: var(--text-muted); margin: 4px 0 0; }
.hint { font-size: 0.95rem; margin-bottom: 12px; }
.footer-note { text-align: center; font-size: 0.9rem; padding-bottom: 24px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 4px solid var(--focus-ring);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

/* ---- Tempo display -------------------------------------- */
.tempo-panel {
  position: relative;
  overflow: hidden;
  text-align: center;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  transition: padding .25s ease, border-color .25s ease, box-shadow .25s ease;
}

/* ---- Ramp mode: flames on both sides of the tempo block ---------- */
/* app.js toggles .ramp-active on #tempo-panel; everything here is
   decorative (the text "Ramp mode" in #rung-info carries the meaning).
   The side padding grows so the flames never sit under the number or a
   wide row of beat dots. */
.tempo-panel.ramp-active {
  padding-inline: 64px;
  border-color: var(--ramp-border);
  box-shadow: 0 0 0 1px var(--ramp-border), 0 6px 22px rgba(232, 93, 4, .25);
}

.flame-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.ramp-flames {
  position: absolute;
  bottom: 0;
  width: 56px;
  height: 117px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
}
.ramp-flames.left  { left: 4px; }
.ramp-flames.right { right: 4px; transform: scaleX(-1); }
.tempo-panel.ramp-active .ramp-flames { opacity: 1; }

.flame { transform-box: fill-box; transform-origin: 50% 100%; }

@media (prefers-reduced-motion: no-preference) {
  .tempo-panel.ramp-active .flame    { animation: flame-flicker 1.1s ease-in-out infinite; }
  .tempo-panel.ramp-active .flame.f2 { animation-duration: .9s;  animation-delay: -.3s; }
  .tempo-panel.ramp-active .flame.f3 { animation-duration: 1.3s; animation-delay: -.6s; }
}

@media (max-width: 380px) {
  .tempo-panel.ramp-active { padding-inline: 46px; }
  .ramp-flames { width: 40px; height: 84px; }
}

@keyframes flame-flicker {
  0%, 100% { transform: scale(1, 1)     skewX(0deg); }
  25%      { transform: scale(.94, 1.07) skewX(-3deg); }
  50%      { transform: scale(1.05, .93) skewX(2deg); }
  75%      { transform: scale(.97, 1.04) skewX(-1deg); }
}

.tempo-readout {
  margin: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}

.bpm {
  font-size: clamp(5rem, 22vw, 7.5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--maroon);
}
@media (prefers-color-scheme: dark) { .bpm { color: var(--dot-on); } }

/* The big number is a tap target that opens a native select. The select
   covers the whole picker with opacity 0, so a tap lands on it and iOS
   shows its wheel picker. Its font-size stays at 16px, because iOS zooms
   the page when a smaller field is focused. */
.tempo-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.tempo-picker:has(#tempo-select:focus-visible) {
  outline: 4px solid var(--focus-ring);
  outline-offset: 3px;
}
.picker-chevron {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
}
#tempo-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.bpm-unit {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.term {
  margin: 6px 0 0;
  font-size: 1.6rem;
  font-style: italic;
  color: var(--text);
}

.rung-info { margin: 4px 0 0; color: var(--text-muted); }

.beats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
  min-height: 28px;
}

.beat-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--dot-off);
  border: 2px solid transparent;
}
.beat-dot.downbeat { border-color: var(--accent); }
.beat-dot.active { background: var(--dot-on); }
.beat-dot.active.downbeat { background: var(--accent); }

/* Only animate the flash when the user has not asked for less motion. */
@media (prefers-reduced-motion: no-preference) {
  .beat-dot { transition: background-color 60ms linear; }
}

/* ---- Buttons --------------------------------------------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--min-target);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--maroon);
  color: var(--on-maroon);
}
.btn-primary:hover:not(:disabled) { background: var(--maroon-hover); }
.btn-primary:active:not(:disabled) { background: var(--maroon-deep); }

.btn-huge {
  width: 100%;
  min-height: 96px;
  font-size: 2rem;
  letter-spacing: 0.04em;
}
.btn-huge[aria-pressed="true"] {
  background: var(--maroon-deep);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, .35);
}

.btn-step {
  flex: 1 1 0;
  min-height: 80px;
  flex-direction: column;
  font-size: 1.2rem;
  background: var(--surface);
  color: var(--maroon);
  border-color: var(--maroon);
}
@media (prefers-color-scheme: dark) { .btn-step { color: var(--text); } }
.btn-step:hover:not(:disabled) { background: var(--surface-alt); }
.step-sign { font-size: 2.2rem; line-height: 1; font-weight: 800; }

.btn-secondary {
  flex: 1 1 0;
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--maroon); }

.controls { display: grid; gap: 16px; }
.step-row, .button-row { display: flex; gap: 12px; }
.button-row { margin-top: 12px; }

/* ---- Forms ----------------------------------------------- */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field { display: block; border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
.field-label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  padding: 0;
}
legend.field-label { padding: 0; }

.select-big {
  width: 100%;
  min-height: var(--min-target);
  padding: 10px 14px;
  font: inherit;
  font-size: 1.15rem;
  color: var(--text);
  background: var(--surface-alt);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--min-target);
}
.checkbox-field input {
  width: 30px; height: 30px;
  margin: 0;
  accent-color: var(--maroon);
  flex: 0 0 auto;
}
.checkbox-field label { font-size: 1.1rem; }

/* Radio groups become big segmented buttons. The real input stays
   in the DOM so keyboard and screen-reader behavior is native. */
.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}
.choice {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-target);
  padding: 10px 8px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}
.choice input {
  position: absolute;
  opacity: 0;
  width: 1px; height: 1px;
  margin: 0;
  pointer-events: none;
}
.choice:has(input:checked) {
  background: var(--maroon);
  color: var(--on-maroon);
  border-color: var(--maroon);
}
.choice:has(input:focus-visible) {
  outline: 4px solid var(--focus-ring);
  outline-offset: 3px;
}

/* ---- Recent tempi and ramp buttons ----------------------- */
.btn-wide {
  width: 100%;
  min-height: 80px;
  font-size: 1.4rem;
  margin-top: 4px;
}

.recent { margin-top: 4px; }
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
}
.recent-btn {
  appearance: none;
  min-height: var(--min-target);
  padding: 10px 8px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.recent-btn:hover { border-color: var(--maroon); }
.recent-btn[aria-pressed="true"] {
  background: var(--maroon);
  color: var(--on-maroon);
  border-color: var(--maroon);
}
.recent-empty { grid-column: 1 / -1; margin: 0; }

/* ---- Practice ramp status -------------------------------- */
.ramp-status { margin-top: 4px; }

progress#ramp-progress {
  width: 100%;
  height: 22px;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}
progress#ramp-progress::-webkit-progress-bar { background: var(--surface-alt); border-radius: 999px; }
progress#ramp-progress::-webkit-progress-value { background: var(--maroon); border-radius: 999px; }
progress#ramp-progress::-moz-progress-bar { background: var(--maroon); border-radius: 999px; }

.ramp-text { margin: 10px 0 0; font-size: 1.05rem; }
.ramp-text.reached { color: var(--target); font-weight: 700; }

/* ---- Small screens and wider screens -------------------- */
@media (max-width: 380px) {
  .step-sign { font-size: 1.8rem; }
  .field-row { grid-template-columns: 1fr; }
  .step-row, .button-row { flex-direction: column; }
}

@media (min-width: 760px) {
  .app { max-width: 680px; }
}
