:root {
  --bg: #0e1a30;
  --surface: #172542;
  --text: #fef3e4;
  --muted: #9ab8cc;
  --accent: #ff6b47;
  --accent-dim: #cc4a25;
  --in-tune: #2ecc71;
  --in-tune-ring: rgba(46, 204, 113, 0.45);
  --warm: #ffc13b;
  --flat-color: #ef5350;
  --sharp-color: #26c6da;
  --ring: rgba(255, 107, 71, 0.45);
}

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

body {
  margin: 0;
  min-height: 100dvh;      /* respects iOS dynamic viewport (address bar) */
  min-height: 100vh;       /* fallback for older browsers */
  overscroll-behavior-y: none; /* prevent iOS pull-to-refresh on the outer page */
  font-family: "DM Sans", system-ui, sans-serif;
  /* Tropical sunset sky fading into deep ocean */
  background:
    radial-gradient(ellipse 130% 55% at 10%  0%, rgba(255, 130, 50,  0.55) 0%, transparent 50%),
    radial-gradient(ellipse  90% 50% at 90%  0%, rgba(220,  60, 100, 0.45) 0%, transparent 45%),
    linear-gradient(175deg, #1c1535 0%, #0e1a30 40%, #07101f 100%);
  color: var(--text);
  line-height: 1.5;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.app {
  max-width: 28rem;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.header-title-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.4rem;
}

.hibiscus-icon {
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(255, 107, 71, 0.5));
}

.header h1 {
  margin: 0;
  font-family: "Pacifico", cursive;
  font-size: 1.9rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  /* Warm coral-to-pink gradient text */
  background: linear-gradient(125deg, #ff8c42 0%, #ff6b6b 55%, #ff4fa3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

/* ── How-to steps ────────────────────────────────────────────────────────── */

.steps {
  margin-top: 1.35rem;
  padding: 1rem 1.1rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 200, 150, 0.1);
}

.steps-title {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--warm);
  opacity: 0.8;
}

.steps-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.55;
}

.steps-list li {
  margin-bottom: 0.55rem;
}

.steps-list li:last-child {
  margin-bottom: 0;
}

/* ── Controls ────────────────────────────────────────────────────────────── */

.controls {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.btn {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 0.65rem;
  padding: 0.85rem 1.2rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  -webkit-tap-highlight-color: transparent; /* remove grey flash on iOS tap */
  touch-action: manipulation;               /* eliminate 300ms tap delay */
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(145deg, #ff8c42, var(--accent));
  color: #1a0800;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 22px var(--ring);
}

.btn-primary:hover {
  box-shadow: 0 6px 30px var(--ring);
}

.btn-primary[aria-pressed="true"] {
  background: rgba(255, 107, 71, 0.1);
  color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

/* ── String selector ─────────────────────────────────────────────────────── */

.strings {
  margin-top: 1.75rem;
}

.strings-label {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.string-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.string-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 0.55rem;
  padding: 0.75rem 0.4rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 2px solid rgba(255, 255, 255, 0.08);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.string-btn:hover {
  border-color: rgba(255, 140, 66, 0.5);
  background: rgba(255, 140, 66, 0.08);
}

.string-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(255, 107, 71, 0.15);
  box-shadow: 0 0 12px rgba(255, 107, 71, 0.2);
}

.string-btn .name {
  display: block;
  font-weight: 700;
  font-size: 1.15rem;
}

.string-btn .hz {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

/* ── Meter card ──────────────────────────────────────────────────────────── */

.meter-card {
  margin-top: 1.75rem;
  padding: 1.35rem 1.1rem 1.15rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 1rem;
  border: 1px solid rgba(255, 200, 150, 0.1);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.meter-card.is-holding {
  border-color: rgba(255, 107, 71, 0.4);
  box-shadow: 0 0 0 1px rgba(255, 107, 71, 0.12);
}

.meter-card.is-in-tune {
  border-color: rgba(46, 204, 113, 0.6);
  animation: in-tune-pulse 1.8s ease-in-out infinite;
}

@keyframes in-tune-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(46, 204, 113, 0.2), 0 0 24px rgba(46, 204, 113, 0.12); }
  50%       { box-shadow: 0 0 0 1px rgba(46, 204, 113, 0.4), 0 0 40px rgba(46, 204, 113, 0.25); }
}

.freq-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.freq {
  font-size: 1.05rem;
  color: var(--muted);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.note-block {
  margin-top: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.note {
  font-size: 4rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.cents {
  font-size: 1.1rem;
  color: var(--warm);
}

.cents.in-tune {
  color: var(--in-tune);
}

.tune-direction {
  margin: 0.85rem 0 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

.tune-direction.is-empty {
  display: none;
}

.tune-direction.ok {
  color: var(--in-tune);
}

.tune-direction.flat {
  color: #ffb347;
}

.tune-direction.sharp {
  color: #48dbfb;
}

/* ── Needle meter ────────────────────────────────────────────────────────── */

.needle-wrap {
  margin-top: 1.25rem;
}

.needle-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 0.25rem;
  margin-bottom: 0.35rem;
}

.tick.center {
  color: var(--in-tune);
  font-weight: 600;
}

.needle-track {
  position: relative;
  height: 0.55rem;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(239, 83, 80,  0.5) 0%,
    rgba(46,  204, 113, 0.4) 50%,
    rgba(38,  198, 218, 0.5) 100%
  );
  overflow: hidden;
}

.needle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.65rem;
  height: 1.35rem;
  margin: 0;
  background: var(--text);
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  transition: left 0.08s ease-out;
}

.needle-legend {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0.75rem 0 0;
  padding: 0;
}

.needle-legend-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.needle-legend-item dt {
  font-size: 1rem;
  font-weight: 700;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}

.needle-legend-item dd {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.needle-legend-symbol.flat-color  { color: var(--flat-color); }
.needle-legend-symbol.in-tune     { color: var(--in-tune); }
.needle-legend-symbol.sharp-color { color: var(--sharp-color); }

.target-line {
  margin: 1rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.25em;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.footer {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(255, 200, 150, 0.08);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.footer-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.55;
}

.footer-links {
  margin: 0;
}

.footer-link {
  font-size: 0.8rem;
  color: rgba(255, 140, 66, 0.7);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

.footer-mahalo {
  margin: 0;
  font-family: "Pacifico", cursive;
  font-size: 0.95rem;
  font-weight: 400;
  background: linear-gradient(125deg, #ff8c42, #ff6b6b, #ff4fa3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0.75;
}

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.tab-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid rgba(255, 200, 150, 0.12);
  padding: 0.45rem 0 env(safe-area-inset-bottom, 0.45rem);
  z-index: 100;
  margin-top: 2rem;
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.22rem;
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 0;
  min-height: 52px;          /* minimum iOS tap target */
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: color 0.15s ease;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.tab-btn[aria-selected="true"] {
  color: var(--accent);
}

/* ── Panel layout ────────────────────────────────────────────────────────── */

.panel {
  /* Extra bottom padding ensures content scrolls clear of the sticky tab bar
     (tab bar ≈ 60–70 px tall + safe-area-inset-bottom on notched phones). */
  padding-bottom: 5.5rem;
}

.panel-title {
  margin: 0 0 0.25rem;
  font-family: "Pacifico", cursive;
  font-size: 1.55rem;
  font-weight: 400;
  background: linear-gradient(125deg, #ff8c42 0%, #ff6b6b 55%, #ff4fa3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding-top: 1.5rem;
}

.panel-subtitle {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── Secondary button ────────────────────────────────────────────────────── */

.btn-secondary {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid rgba(255, 200, 150, 0.18);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 200, 150, 0.38);
}

/* ── Chord practice ──────────────────────────────────────────────────────── */

.chord-legend {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0 0 1.1rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 200, 150, 0.1);
  border-radius: 0.65rem;
}

.chord-legend-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chord-legend-item dt {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  flex-shrink: 0;
}

.chord-legend-item dd {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.chord-grid {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.chord-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.45rem;
}

.chord-section-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.chord-chip {
  font: inherit;
  cursor: pointer;
  border-radius: 0.55rem;
  padding: 0.55rem 0.3rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 2px solid rgba(255, 255, 255, 0.08);
  font-weight: 700;
  font-size: 1rem;
  transition: border-color 0.15s ease, background 0.15s ease;
  text-align: center;
}

.chord-chip:hover {
  border-color: rgba(255, 140, 66, 0.45);
  background: rgba(255, 140, 66, 0.08);
}

.chord-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(255, 107, 71, 0.15);
}

.chord-detail {
  margin-top: 1.25rem;
  padding: 1.1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 200, 150, 0.12);
  border-radius: 0.85rem;
}

.chord-detail-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;  /* wraps SVG above info on very narrow phones */
}

.chord-detail-info {
  flex: 1;
  min-width: 140px; /* don't crush below this on narrow screens */
}

.chord-detail-name {
  margin: 0 0 0.2rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.chord-detail-tones {
  margin: 0 0 0.8rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.chord-practice-area {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 200, 150, 0.1);
}

.string-dots-row {
  display: flex;
  justify-content: space-around;
  margin-bottom: 0.85rem;
}

.string-dot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}

.string-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.15);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.string-dot.active {
  background: var(--warm);
  border-color: var(--warm);
  box-shadow: 0 0 8px rgba(255, 193, 59, 0.5);
}

.string-dot.pass {
  background: var(--in-tune);
  border-color: var(--in-tune);
}

.string-dot.fail {
  background: var(--flat-color);
  border-color: var(--flat-color);
}

.string-dot.muted {
  background: rgba(255, 255, 255, 0.03);
  border-style: dashed;
}

.practice-instruction {
  font-size: 0.88rem;
  color: var(--text);
  margin: 0 0 0.4rem;
  min-height: 1.4em;
}

.practice-feedback {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
  min-height: 1.4em;
}

.practice-result {
  margin-top: 0.75rem;
  padding: 0.85rem;
  border-radius: 0.65rem;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.85rem;
}

.practice-result-row {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.practice-result-row:last-child {
  border-bottom: none;
}

/* ── Rhythm trainer ──────────────────────────────────────────────────────── */

.rhythm-stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.rhythm-stat-block {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 200, 150, 0.1);
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  text-align: center;
}

.rhythm-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--warm);
  margin-bottom: 0.25rem;
}

.rhythm-stat {
  display: block;
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.beat-trail-canvas {
  display: block;
  width: 100%;
  height: 48px;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 1.25rem;
}

.metronome-section {
  padding: 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 200, 150, 0.08);
  border-radius: 0.75rem;
  margin-bottom: 1rem;
}

.section-label {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--warm);
  opacity: 0.8;
}

.metronome-presets {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.preset-btn {
  flex: 1;
  font: inherit;
  cursor: pointer;
  border-radius: 0.45rem;
  padding: 0.65rem 0;    /* taller for 44px minimum touch target */
  min-height: 44px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.preset-btn:hover,
.preset-btn.active {
  background: rgba(255, 107, 71, 0.15);
  color: var(--accent);
  border-color: var(--accent);
}

.metronome-slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.metronome-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.metronome-bpm-label {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 4rem;
  text-align: right;
}

.rhythm-hint {
  text-align: center;
}

/* ── Record & review ─────────────────────────────────────────────────────── */

.record-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.btn-record {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: linear-gradient(145deg, #ff4444, #cc2020);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 4px 22px rgba(255, 64, 64, 0.35);
  border: none;
}

.btn-record:hover {
  box-shadow: 0 6px 28px rgba(255, 64, 64, 0.5);
}

.btn-record[aria-pressed="true"] {
  background: rgba(255, 64, 64, 0.12);
  color: #ff4444;
  box-shadow: inset 0 0 0 2px #ff4444;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.btn-record[aria-pressed="true"] .rec-dot {
  animation: record-pulse 1s ease-in-out infinite;
}

@keyframes record-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.record-timer {
  font-size: 0.9rem;
  color: var(--muted);
}

.waveform-canvas {
  display: block;
  width: 100%;
  height: 72px;
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.04);
  margin-bottom: 0.85rem;
}

.playback-controls {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.record-save-link {
  text-decoration: none;
  text-align: center;
}

.analysis-card {
  padding: 1rem 1.1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 200, 150, 0.12);
  border-radius: 0.85rem;
  margin-bottom: 1rem;
}

.analysis-title {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--warm);
  opacity: 0.8;
}

.analysis-bar-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.analysis-bar-label {
  font-size: 0.8rem;
  color: var(--muted);
  width: 6rem;
  flex-shrink: 0;
}

.analysis-bar-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.analysis-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--flat-color), var(--warm), var(--in-tune));
  transition: width 0.4s ease;
}

.analysis-bar-pct {
  font-size: 0.8rem;
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  width: 2.5rem;
  text-align: right;
  flex-shrink: 0;
}

.analysis-detail {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
}

.record-hint {
  text-align: center;
}
