/* =============================================
   METRONOME — Styles
   ============================================= */

/* === Theme Variables === */
:root {
  --bg: #101010;
  --surface: #1a1a1a;
  --surface-hover: #232323;
  --border: #2e2e2e;
  --text: #eeeeee;
  --text-secondary: #929292;
  --text-muted: #5e5e5e;
  --accent: #ec7630;
  --accent-hover: #f49050;
  --accent-glow: #ec763017;
  --accent-2: #ef4444;
  --accent-2-glow: rgba(239, 68, 68, 0.3);
  --dot-bg: #2e2e2e;
  --dot-active: #f49050;
  --dial-track: #2e2e2e;
  --dial-active: #ec7630;
  --knob: #eeeeee;
  --btn-bg: #1d1d1d;
  --btn-hover: #282828;
  --active-text: #fff;
  --radius: 12px;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-hover: #ececec;
  --border: #d4d4d4;
  --text: #1a1a1a;
  --text-secondary: #6e6e6e;
  --text-muted: #a0a0a0;
  --accent: #ec7630;
  --accent-hover: #f49050;
  --accent-glow: rgba(236, 118, 48, 0.25);
  --accent-2: #ef4444;
  --accent-2-glow: rgba(239, 68, 68, 0.3);
  --dot-bg: #d4d4d4;
  --dot-active: #f49050;
  --dial-track: #d4d4d4;
  --dial-active: #ec7630;
  --knob: #1a1a1a;
  --btn-bg: #e8e8e8;
  --btn-hover: #dddddd;
  --active-text: #1a1a1a;
}

/* === Reset & Base === */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  transition:
    background var(--transition),
    color var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === App Shell === */
.app {
  max-width: 440px;
  margin: 0 auto;
  padding: 0 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* === Header === */
.header {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  height: 1.2em;
  width: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon {
  width: 20px;
  height: 20px;
}

/* Theme toggle: show sun in dark mode (switch to light), moon in light mode (switch to dark) */
[data-theme="dark"] .icon-sun {
  display: block;
}
[data-theme="dark"] .icon-moon {
  display: none;
}
[data-theme="light"] .icon-sun {
  display: none;
}
[data-theme="light"] .icon-moon {
  display: block;
}

/* === Main Content === */
.main {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

/* === Page Title === */
.page-title {
  text-align: center;
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 48px;
}

.page-title h1 {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-title p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* === Dial === */
.dial-wrapper {
  position: relative;
  width: 100%;
  max-width: 300px;
  touch-action: none;
}

.dial-svg {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}

.dial-track {
  fill: none;
  stroke: var(--dial-track);
  stroke-width: 8;
  stroke-linecap: round;
}

.dial-active {
  fill: none;
  stroke: var(--dial-active);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 565.49;
  stroke-dashoffset: 565.49; /* hidden until JS updates */
  transition: stroke-dashoffset 0.06s linear;
}

.dial-knob {
  fill: var(--knob);
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
  cursor: grab;
  transition: r 0.15s ease;
}

.dial-knob:hover {
  r: 12;
}

.dial-wrapper.dragging .dial-knob {
  r: 13;
  cursor: grabbing;
}

/* BPM Display (overlaid on dial center) */
.bpm-center {
  position: absolute;
  top: 52%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.bpm-value {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: center;
  width: 4.5ch;
  outline: none;
  pointer-events: auto;
  caret-color: var(--accent);
  border-bottom: 2px solid transparent;
  padding-bottom: 2px;
  transition:
    border-color var(--transition),
    color var(--transition);
  font-family: inherit;
}

.bpm-value:focus {
  border-bottom-color: var(--accent);
}

/* Hide number input spinners */
.bpm-value::-webkit-inner-spin-button,
.bpm-value::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.bpm-value {
  -moz-appearance: textfield;
}

.bpm-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-top: 4px;
}

/* === Dial Row (stepper − | dial | stepper +) === */
.dial-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

/* === Tempo Marking === */
.tempo-marking {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
}

/* === BPM Stepper === */
.stepper-btn {
  min-width: 46px;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stepper-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.stepper-btn:active {
  transform: scale(0.92);
}

/* === Beat Dots === */
.beat-dots {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  min-height: 28px;
}

.beat-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--dot-bg);
  transition:
    background 0.08s ease,
    box-shadow 0.08s ease;
  transform: scale(1);
}

.beat-dot.active {
  background: var(--dot-active);
  box-shadow: 0 0 14px var(--accent-glow);
  animation: dot-pop 0.12s ease-out;
}

.beat-dot.accent {
  background: var(--accent-2);
  box-shadow: 0 0 18px var(--accent-2-glow);
  animation: dot-pop 0.12s ease-out;
}

@keyframes dot-pop {
  0% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

/* === Action Buttons === */
.action-row {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

.btn-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.hidden {
  display: none !important;
}

.btn-start {
  background: var(--accent);
  color: #1a1400;
}

.btn-start:hover {
  background: var(--accent-hover);
}

.btn-start:active {
  transform: scale(0.97);
}

.btn-start.playing {
  background: var(--accent-2);
}

.btn-start.playing:hover {
  background: #f87171;
}

.btn-tap {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  max-width: 100px;
  flex: 0 0 auto;
  width: 100px;
}

.btn-tap:hover {
  background: var(--btn-hover);
}

.btn-tap:active,
.btn-tap.tapped {
  transform: scale(0.94);
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* === Settings === */
.settings {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: left;
}

.seg-control {
  display: flex;
  flex: 1;
  gap: 6px;
  background: none;
  border-radius: 8px;
}

.seg-control button {
  flex: 1;
  padding: 9px 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.seg-control button:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.seg-control button.active {
  color: var(--active-text);
  background: var(--accent-glow);
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px var(--accent-glow);
}

/* === Timer Display === */
.timer-display {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: center;
}

.timer-display.warning {
  color: var(--accent-2);
}

/* === Keyboard Shortcuts Hint === */
.shortcuts {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
}

.shortcuts kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.68rem;
  margin: 0 1px;
  vertical-align: baseline;
}

/* === Responsive === */
@media (max-width: 480px) {
  .app {
    padding: 16px 16px;
  }

  .page-title {
    padding: 32px 20px 32px;
  }

  .page-title h1 {
    font-size: 2rem;
  }

  .page-title p {
    font-size: 1rem;
  }

  .bpm-value {
    font-size: 3.6rem;
  }

  .dial-wrapper {
    max-width: 260px;
  }

  .stepper-btn {
    min-width: 40px;
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .action-row {
    max-width: 100%;
  }

  .settings {
    max-width: 100%;
  }

  .beat-dots {
    gap: 8px;
  }

  .beat-dot {
    width: 14px;
    height: 14px;
  }

  .content {
    padding: 48px 20px 64px;
  }

  .content-nav a {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  .tempo-table {
    font-size: 0.85rem;
  }

  .tempo-table th,
  .tempo-table td {
    padding: 8px 10px;
  }
}

@media (max-width: 360px) {
  .page-title h1 {
    font-size: 1.7rem;
  }

  .bpm-value {
    font-size: 3rem;
  }

  .dial-wrapper {
    max-width: 190px;
  }

  .stepper-btn {
    min-width: 36px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .seg-control button {
    padding: 8px 2px;
    font-size: 0.75rem;
  }

  .seg-control {
    gap: 4px;
  }

  .tempo-table {
    font-size: 0.8rem;
  }

  .tempo-table th,
  .tempo-table td {
    padding: 7px 6px;
  }
}

/* === Page Content === */
.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 64px 24px 80px;
}

.content-inner {
  border-top: 1px solid var(--border);
  padding-top: 48px;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

.content-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.content-nav a {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.content-nav a:hover {
  color: var(--text);
  border-color: var(--accent);
}

.content-section {
  display: flex;
  flex-direction: column;
  scroll-margin-top: 24px;
}

.content h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.content h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 4px;
  margin-top: 24px;
}

.content p {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.content strong {
  color: var(--text);
  font-weight: 600;
}

.content p a {
  color: var(--text);
  text-decoration: underline;
}

/* === Tempo Table === */
.tempo-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 0.95rem;
}

.tempo-table th,
.tempo-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.tempo-table thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.tempo-table tbody td {
  color: var(--text-secondary);
}

.tempo-table tbody td:first-child {
  color: var(--text);
  font-weight: 600;
}

.tempo-table tbody tr:last-child td {
  border-bottom: none;
}

/* === Footer === */
.footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.footer-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-copy {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}

.footer-link:hover {
  color: var(--text);
}

/* === Accessibility: Focus Visible === */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* === Tempo Nav Dropdown === */
.tempo-nav {
  position: relative;
}

.tempo-nav__trigger {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tempo-nav__trigger:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.tempo-nav__chevron {
  width: 14px;
  height: 14px;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.tempo-nav__dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  list-style: none;
  padding: 6px;
  display: none;
  z-index: 100;
  margin: 0;
}

.tempo-nav.open .tempo-nav__dropdown {
  display: block;
}

.tempo-nav.open .tempo-nav__chevron {
  transform: rotate(180deg);
}

.tempo-nav__dropdown li {
  margin: 0;
}

.tempo-nav__dropdown a {
  display: block;
  padding: 8px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  border-radius: 6px;
  transition: all var(--transition);
  white-space: nowrap;
}

.tempo-nav__dropdown a:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* === Popular Tempos Section === */
.tempo-links {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

.tempo-links__inner {
  border-top: 1px solid var(--border);
  padding-top: 40px;
}

.tempo-links h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.tempo-links__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tempo-links__grid a {
  display: inline-block;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
}

.tempo-links__grid a:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--accent);
}

/* === Neighbor Tempo Links (BPM pages) === */
.neighbor-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.neighbor-links a {
  display: inline-block;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.neighbor-links a:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--accent);
}

@media (max-width: 480px) {
  .tempo-links {
    padding: 0 20px 48px;
  }

  .footer {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

/* === Selection === */
::selection {
  background: var(--accent);
  color: #fff;
}
