:root {
  --bg: #111827;
  --card: #1f2937;
  --text: #f9fafb;
  --muted: #9ca3af;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --border: #374151;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #030712;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family:
    Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(31, 41, 55, 0.96), rgba(3, 7, 18, 1)),
    #030712;
  color: var(--text);
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

.tabs,
.app {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 16px;
}

.tabs {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-right: 16px;
  padding-bottom: 8px;
  padding-left: 16px;
}

.app {
  flex: 1 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(14px, 3vw, 20px);
  padding-top: 8px;
  padding-right: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: 16px;
}

.header {
  text-align: center;
}

.header h1 {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 7vw, 3.5rem);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.header p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.92rem, 2.4vw, 1rem);
  line-height: 1.45;
}

.tuner-card {
  border: 2px solid var(--border);
  border-radius: 28px;
  background: rgba(31, 41, 55, 0.88);
  padding: clamp(22px, 4vw, 28px) clamp(14px, 3vw, 20px);
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.tuner-card[data-state="in-tune"] {
  border-color: var(--green);
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.28);
}

.tuner-card[data-state="flat"] {
  border-color: var(--orange);
  box-shadow: 0 0 40px rgba(245, 158, 11, 0.26);
}

.tuner-card[data-state="sharp"] {
  border-color: var(--red);
  box-shadow: 0 0 40px rgba(239, 68, 68, 0.24);
}

.status {
  color: var(--muted);
  font-size: clamp(0.86rem, 2vw, 0.95rem);
  margin-bottom: 12px;
}

.note {
  font-size: clamp(4.25rem, 24vw, 8.75rem);
  font-weight: 800;
  line-height: 0.88;
  letter-spacing: -0.08em;
  min-height: 0.95em;
  overflow-wrap: anywhere;
}

.frequency {
  margin-top: 12px;
  font-size: clamp(1.25rem, 4vw, 1.6rem);
  font-weight: 700;
}

.target,
.cents {
  margin-top: 4px;
  color: var(--muted);
  font-size: clamp(0.9rem, 2.4vw, 1rem);
}

.advice {
  margin-top: 18px;
  font-size: clamp(1rem, 2.8vw, 1.1rem);
  font-weight: 700;
}

.tuner-card[data-state="in-tune"] .note,
.tuner-card[data-state="in-tune"] .advice {
  color: var(--green);
}

.tuner-card[data-state="flat"] .note,
.tuner-card[data-state="flat"] .advice {
  color: var(--orange);
}

.tuner-card[data-state="sharp"] .note,
.tuner-card[data-state="sharp"] .advice {
  color: var(--red);
}

.meter {
  position: relative;
  height: 72px;
  margin: clamp(22px, 4vw, 28px) clamp(0px, 2vw, 8px) 6px;
}

.meter-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 36px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--red),
    var(--orange),
    var(--green),
    var(--orange),
    var(--red)
  );
  opacity: 0.95;
}

.needle {
  position: absolute;
  top: 20px;
  left: 50%;
  width: 4px;
  height: 40px;
  border-radius: 999px;
  background: white;
  transform: translateX(-50%);
  transition: left 80ms linear;
}

.meter-label {
  position: absolute;
  top: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.meter-label.left {
  left: 0;
}

.meter-label.center {
  left: 50%;
  transform: translateX(-50%);
}

.meter-label.right {
  right: 0;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

button {
  border: 0;
  border-radius: 16px;
  min-height: 48px;
  padding: 14px 16px;
  font-size: clamp(0.96rem, 2.6vw, 1rem);
  font-weight: 800;
  cursor: pointer;
  color: #111827;
  background: #f9fafb;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#startBtn {
  background: var(--green);
  color: #052e16;
}

#stopBtn {
  background: #e5e7eb;
}

.legend {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: clamp(0.86rem, 2.2vw, 0.95rem);
  line-height: 1.4;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 8px;
}

.dot.green {
  background: var(--green);
}

.dot.orange {
  background: var(--orange);
}

.dot.red {
  background: var(--red);
}

@media (max-width: 420px) {
  .app {
    padding-top: 8px;
    padding-right: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left: 12px;
  }

  .tuner-card {
    padding: 24px 14px;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}
.tab {
  background: #374151;
  color: var(--text);
}

.tab.active {
  background: var(--green);
  color: #052e16;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.metronome-card {
  border: 2px solid var(--border);
  border-radius: 28px;
  background: rgba(31, 41, 55, 0.88);
  padding: clamp(22px, 4vw, 28px) clamp(14px, 3vw, 20px);
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.metronome-label {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bpm-value {
  margin-top: 8px;
  font-size: clamp(3.5rem, 18vw, 8rem);
  font-weight: 900;
  line-height: 1;
}

.bpm-slider {
  width: 100%;
  margin: 28px 0 16px;
}

.metronome-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.beat-config {
  display: grid;
  gap: 8px;
  margin: 20px 0;
  color: var(--muted);
}

.beat-config select {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 12px;
  min-height: 48px;
  font-size: clamp(0.96rem, 2.6vw, 1rem);
}

.beat-indicator {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 24px 0;
  min-height: 24px;
}

.beat-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #4b5563;
}

.beat-dot.active {
  background: var(--green);
  box-shadow: 0 0 24px rgba(34, 197, 94, 0.8);
}

.beat-dot.accent {
  background: var(--orange);
  box-shadow: 0 0 24px rgba(245, 158, 11, 0.8);
}

#metronomeStartBtn {
  width: 100%;
  background: var(--green);
  color: #052e16;
}

@media (max-width: 420px) {
  .tabs,
  .app {
    width: min(100%, 100%);
    padding-left: 12px;
    padding-right: 12px;
  }

  .tabs {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .app {
    justify-content: flex-start;
    padding-top: 8px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .tuner-card,
  .metronome-card {
    border-radius: 24px;
  }

  .note {
    font-size: clamp(3.8rem, 25vw, 6.8rem);
  }

  .meter {
    margin-top: 22px;
  }

  .actions,
  .metronome-controls {
    gap: 10px;
  }

  .legend {
    gap: 6px;
  }
}

@media (min-width: 1024px) {
  .app {
    padding-top: 24px;
    padding-bottom: 24px;
  }
}
