/* ==========================================================================
   Tokens (light / dark)
   ========================================================================== */
:root {
  color-scheme: light dark;
  --bg: #f3f3ef;
  --bg-glow: #ffffff;
  --surface-alt: #ebebe5;
  --card: #ffffff;
  --card-edge: rgba(20, 20, 30, 0.08);
  --text: #15161a;
  --muted: #62646d;
  --faint: #dcdde2;
  --chip: #e6e6e0;
  --good: #16a34a;
  --good-glow: rgba(22, 163, 74, 0.18);
  --link: #15803d;
  --off: #ea580c;
  --off-glow: rgba(234, 88, 12, 0.14);
  --accent: #15161a;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 16px 40px -16px rgba(20, 20, 40, 0.22);
  --scrim: rgba(12, 14, 18, 0.35);
  --header-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e11;
    --bg-glow: #171b22;
    --surface-alt: #111418;
    --card: #15181d;
    --card-edge: rgba(255, 255, 255, 0.08);
    --text: #f2f3f5;
    --muted: #979ca6;
    --faint: #2a2f38;
    --chip: #1d2129;
    --good: #34d399;
    --good-glow: rgba(52, 211, 153, 0.16);
    --link: #34d399;
    --off: #fb923c;
    --off-glow: rgba(251, 146, 60, 0.14);
    --accent: #f2f3f5;
    --accent-text: #0c0e11;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 24px 48px -24px rgba(0, 0, 0, 0.9);
    --scrim: rgba(0, 0, 0, 0.55);
  }
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); scrollbar-gutter: stable; }
/* While a modal (the tuning sheet) is open, the page behind it stays put. */
html:has(dialog[open]) { overflow: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--good); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.02em; }
h1 { margin: 0; font-size: clamp(2.1rem, 5.2vw, 3.5rem); letter-spacing: -0.035em; }
h2 { margin: 0 0 16px; font-size: clamp(1.5rem, 3vw, 2.1rem); }
h3 { margin: 0 0 6px; font-size: 1.1rem; }
p { margin: 0 0 16px; }
sub { font-size: 0.7em; }

.wrap { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 20px; }
.wrap.narrow { max-width: 780px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 12px; z-index: 100; padding: 8px 14px; border-radius: 10px; background: var(--card); }
.muted { color: var(--muted); }

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--card-edge);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 750; letter-spacing: -0.01em; text-decoration: none; }
.logo { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; background: var(--good); color: #fff; }
.site-nav ul { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.site-nav a {
  display: block;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 150ms, color 150ms;
}
.site-nav a:hover, .site-nav a[aria-current="page"] { background: var(--chip); color: var(--text); }
.menu-toggle { display: none; width: 42px; height: 42px; place-items: center; border: 0; border-radius: 12px; background: var(--chip); }
@media (max-width: 719px) {
  .menu-toggle { display: grid; }
  .site-nav {
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    display: none;
    padding: 8px 12px 16px;
    border-bottom: 1px solid var(--card-edge);
    background: var(--bg);
    box-shadow: 0 16px 32px -20px rgba(0, 0, 0, 0.4);
  }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; }
  .site-nav a { padding: 12px 14px; font-size: 1.05rem; }
}

.breadcrumbs { padding-top: 18px; color: var(--muted); font-size: 0.9rem; }
.breadcrumbs ol { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.breadcrumbs li + li::before { content: "/"; margin-right: 6px; opacity: 0.6; }
.breadcrumbs a { text-decoration: none; }
.breadcrumbs a:hover { color: var(--text); }

/* ==========================================================================
   Hero (home + tuning pages)
   ========================================================================== */
.hero { padding: 28px 0 56px; background: radial-gradient(70% 70% at 75% 0%, var(--bg-glow), transparent 70%); }
.hero-grid { display: grid; gap: 20px; grid-template-areas: "title" "tool" "copy"; }
.hero-title { grid-area: title; }
.hero-tool { grid-area: tool; width: 100%; max-width: 440px; justify-self: center; }
.hero-copy { grid-area: copy; }
.eyebrow { margin: 0 0 10px; color: var(--good); font-size: 0.8rem; font-weight: 750; letter-spacing: 0.1em; text-transform: uppercase; }
.lead { max-width: 34em; color: var(--muted); font-size: 1.2rem; line-height: 1.55; }
.checks { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.checks li { display: flex; gap: 12px; align-items: baseline; font-weight: 550; }
.checks li::before { content: "✓"; color: var(--good); font-weight: 800; }
@media (min-width: 900px) {
  .hero { padding: 64px 0 88px; }
  .hero-grid {
    grid-template-columns: minmax(0, 1fr) 420px;
    grid-template-areas: "title tool" "copy tool";
    grid-template-rows: auto 1fr;
    gap: 24px 72px;
    align-items: start;
  }
  .hero-title { align-self: end; padding-top: 48px; }
  .hero-tool { justify-self: end; }
}

/* ==========================================================================
   Sections & content
   ========================================================================== */
.section { padding: 64px 0; }
.section.tight { padding-top: 16px; }
.section.alt { background: var(--surface-alt); }
.section-lead { max-width: 62ch; margin-bottom: 28px; color: var(--muted); }
.section a:not(.card-link):not(.button), .answer a { color: var(--link); text-underline-offset: 3px; }
.page-head { padding: 40px 0 24px; }
.page-head .lead { margin-top: 16px; }
.more { margin: 24px 0 0; font-weight: 600; }

.prose { max-width: 70ch; }
.prose h2 { margin-top: 44px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { margin-top: 24px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 1.3em; }
.prose li { margin: 8px 0; padding-left: 4px; }
.prose .table-wrap { margin: 8px 0 20px; }

.steps { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { padding: 24px; border: 1px solid var(--card-edge); border-radius: 20px; background: var(--card); counter-increment: step; }
.steps li::before {
  content: counter(step);
  width: 34px; height: 34px;
  display: grid; place-items: center;
  margin-bottom: 14px;
  border-radius: 50%;
  background: var(--good-glow);
  color: var(--good);
  font-weight: 800;
}
.steps p { margin: 0; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--card-edge); border-radius: 16px; background: var(--card); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--card-edge); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
td.note { font-size: 1.1rem; font-weight: 800; }
td.note sub { color: var(--muted); font-weight: 600; }
.change-none { color: var(--muted); }
.change-down, .change-up { font-weight: 600; }
.change-down { color: var(--off); }
.change-up { color: var(--link); }
@media (max-width: 560px) {
  th, td { padding: 10px 10px; font-size: 0.92rem; white-space: normal; }
  th { font-size: 0.7rem; }
}

.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); margin: 0; padding: 0; list-style: none; }
.card-link {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px;
  border: 1px solid var(--card-edge);
  border-radius: 20px;
  background: var(--card);
  text-decoration: none;
  transition: transform 200ms ease, box-shadow 200ms ease, border-color 200ms;
}
.card-link:hover { transform: translateY(-2px); border-color: var(--good); box-shadow: var(--shadow); }
.card-link h3 { margin: 0; }
.card-link p { margin: 0; color: var(--muted); font-size: 0.95rem; line-height: 1.5; }
.card-notes { color: var(--good); font-size: 0.85rem; font-weight: 750; letter-spacing: 0.1em; }

.faq { display: grid; gap: 10px; }
.faq details { padding: 0 20px; border: 1px solid var(--card-edge); border-radius: 16px; background: var(--card); }
.faq summary { display: flex; justify-content: space-between; gap: 16px; padding: 18px 0; font-weight: 650; cursor: pointer; list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--muted); font-size: 1.4rem; line-height: 1; transition: transform 200ms; }
.faq details[open] summary::after { transform: rotate(45deg); }
.answer { padding-bottom: 18px; color: var(--muted); }
.answer p { margin: 0; }

.cta { text-align: center; }
.cta h2 { margin-bottom: 20px; }
.button, .start {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.02rem;
  font-weight: 650;
  text-decoration: none;
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.45);
  transition: transform 150ms ease, opacity 150ms;
}
.button:hover, .start:hover { transform: translateY(-1px); }
.button:active, .start:active { transform: scale(0.97); }
.button.secondary { background: var(--chip); color: var(--text); box-shadow: none; }
.button-row { display: flex; flex-wrap: wrap; gap: 12px; }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer { padding: 56px 0 28px; border-top: 1px solid var(--card-edge); color: var(--muted); font-size: 0.95rem; }
.footer-grid { display: grid; gap: 32px; grid-template-columns: 1.6fr 1fr 1fr; }
.footer-about p { max-width: 34ch; margin-top: 14px; }
.footer-about .brand { color: var(--text); }
.site-footer h2 { margin: 0 0 14px; color: var(--text); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; }
.site-footer ul { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.site-footer nav a { text-decoration: none; }
.site-footer nav a:hover { color: var(--text); }
.footer-bottom { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--card-edge); font-size: 0.85rem; }
@media (max-width: 719px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-about { grid-column: 1 / -1; }
}

/* ==========================================================================
   Tuner widget
   ========================================================================== */
.tuner { display: flex; flex-direction: column; gap: 14px; }
/* Mode switch */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--chip);
}
.mode {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  transition: background 200ms ease, color 200ms ease, box-shadow 200ms ease;
}
.mode span { overflow: hidden; text-overflow: ellipsis; }
.mode[aria-pressed="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 12px -6px rgba(0, 0, 0, 0.2);
}
.mode svg { flex: none; opacity: 0.7; }

/* Main card */
.card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 18px 16px 26px;
  border: 1px solid var(--card-edge);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.card::before, .card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0;
  transition: opacity 350ms ease;
}
.card::before { background: radial-gradient(70% 60% at 50% 62%, var(--good-glow), transparent 70%); }
.card::after { background: radial-gradient(70% 60% at 50% 62%, var(--off-glow), transparent 70%); }
[data-state="in-tune"] .card::before { opacity: 1; }
[data-state="flat"] .card::after, [data-state="sharp"] .card::after { opacity: 1; }

.gauge { display: block; width: 100%; height: auto; overflow: visible; }
.track { fill: none; stroke: var(--faint); stroke-width: 6; stroke-linecap: round; }
.zone { fill: none; stroke: var(--good); stroke-width: 6; stroke-linecap: round; opacity: 0.35; transition: opacity 250ms; }
[data-state="in-tune"] .zone { opacity: 1; }
#ticks line { stroke: var(--faint); stroke-width: 2; stroke-linecap: round; }
#ticks line.major { stroke: var(--muted); }
.gauge-label { fill: var(--muted); font-size: 18px; font-weight: 600; text-anchor: middle; }
.needle { transform-origin: 150px 160px; }
.needle line { stroke: var(--muted); stroke-width: 4; stroke-linecap: round; transition: stroke 200ms; }
.needle circle { fill: var(--card); stroke: var(--muted); stroke-width: 4; transition: stroke 200ms; }
[data-state="in-tune"] .needle line, [data-state="in-tune"] .needle circle { stroke: var(--good); }
[data-state="flat"] .needle line, [data-state="flat"] .needle circle,
[data-state="sharp"] .needle line, [data-state="sharp"] .needle circle { stroke: var(--off); }
[data-state="off"] .needle, [data-state="off"] #ticks { opacity: 0.4; }

.readout { margin-top: -6px; text-align: center; }
.note-wrap {
  display: inline-flex;
  align-items: stretch;
  font-size: clamp(5.25rem, 27vw, 7.5rem);
  line-height: 0.95;
}
.note-wrap.pop { animation: pop 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.note {
  font-family: ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: -0.04em;
  transition: color 200ms;
}
.note-meta {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0.3em;
  margin-left: 0.04em;
  padding: 0.06em 0 0.04em;
  font-size: 0.3em;
  text-align: left;
}
.accidental { font-weight: 700; line-height: 1; }
.octave { color: var(--muted); font-weight: 600; font-size: 0.7em; line-height: 1; }
[data-state="in-tune"] .note, [data-state="in-tune"] .accidental { color: var(--good); }
[data-state="idle"] .note, [data-state="off"] .note { color: var(--faint); }

.cents-row { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 32px; margin-top: 10px; }
.cents {
  min-width: 62px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--chip);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cents:empty { display: none; }
[data-state="flat"] .cents, [data-state="sharp"] .cents { color: var(--off); }
[data-state="in-tune"] .cents { color: var(--good); }
.hint { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
[data-state="in-tune"] .hint { color: var(--good); }
[data-state="idle"] .hint::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good);
  animation: pulse 1.6s ease-in-out infinite;
}
.hz { min-height: 1.2em; margin-top: 8px; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* Start overlay */
.start-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 350ms ease, visibility 350ms;
}
.tuner:not([data-state="off"]) .start-layer { opacity: 0; visibility: hidden; }
.start:disabled { opacity: 0.6; cursor: default; transform: none; }
.start-note { margin: 0; max-width: 260px; color: var(--muted); font-size: 0.85rem; text-align: center; }

/* Strings (tuning mode) */
.strings {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
[data-mode="chromatic"] .strings { display: none; }
.strings li {
  position: relative;
  padding: 12px 0 10px;
  border: 1px solid var(--card-edge);
  border-radius: 16px;
  background: var(--card);
  text-align: center;
  font-weight: 700;
  transition: transform 200ms ease, border-color 200ms, background 200ms, color 200ms;
}
.strings li sub { color: var(--muted); font-size: 0.7em; font-weight: 600; }
.strings li.active { transform: translateY(-3px); border-color: var(--muted); background: var(--chip); }
[data-state="in-tune"] .strings li.active { border-color: var(--good); color: var(--good); }
[data-state="flat"] .strings li.active, [data-state="sharp"] .strings li.active { border-color: var(--off); }
.strings li.tuned::after {
  content: "✓";
  position: absolute;
  top: -7px; right: -5px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  animation: pop 260ms cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.message {
  padding: 14px 16px;
  border: 1px solid var(--off);
  border-radius: 16px;
  background: var(--off-glow);
  line-height: 1.4;
}

/* Tuning sheet */
.sheet {
  width: 100%;
  max-width: 100%;
  max-height: 100dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}
.sheet::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 200ms ease;
}
.sheet[open] .sheet-panel { animation: slide-up 280ms cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet-panel {
  max-width: 440px;
  max-height: 82dvh;
  margin: 0 auto;
  padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain; /* scrolling past the end of the list doesn't move the page */
  border-radius: 24px 24px 0 0;
  background: var(--card);
  box-shadow: 0 -12px 40px -12px rgba(0, 0, 0, 0.35);
}
@media (min-width: 640px) {
  .sheet { margin: auto; }
  .sheet-panel { border-radius: 24px; }
}
.grip { width: 40px; height: 5px; margin: 6px auto 10px; border-radius: 3px; background: var(--faint); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 10px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.sheet-close {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--chip);
}
.sheet-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.sheet-item {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  transition: background 150ms;
}
.sheet-item:hover { background: var(--chip); }
.sheet-item .name { font-weight: 600; }
.sheet-item .notes { color: var(--muted); font-size: 0.9rem; letter-spacing: 0.06em; white-space: nowrap; }
.sheet-item[aria-current="true"] { border-color: var(--good); background: var(--good-glow); }
.sheet-item[aria-current="true"] .notes { color: var(--text); }

.start { padding: 16px 28px; font-size: 1.05rem; }
.start:disabled { opacity: 0.6; cursor: default; transform: none; }

@keyframes pop { from { transform: scale(0.9); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.75); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
