:root {
  --bg: #0a0b10;
  --bg-2: #11131c;
  --card: rgba(255, 255, 255, 0.035);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #eef0f6;
  --muted: #8b91a7;
  --accent: #ffb454;
  --accent-2: #7c6cff;
  --good: #57e39b;
  --warn: #ffd166;
  --bad: #ff6b6b;
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(124, 108, 255, 0.16), transparent 60%),
    radial-gradient(1000px 600px at 95% 0%, rgba(255, 180, 84, 0.11), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 22px 60px;
  display: grid;
  gap: 16px;
}

/* ------------------------------------------------------------------ hero */

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 6px 4px 10px;
}

.home-link {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-decoration: none;
  transition: color 0.15s ease;
}
.home-link:hover { color: var(--accent); }

h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.02em;
  font-weight: 650;
}

h1 .arrow { color: var(--accent); font-weight: 400; }

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.11); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }

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

.btn-primary {
  background: linear-gradient(180deg, #ffc978, var(--accent));
  border-color: transparent;
  color: #24160a;
  box-shadow: 0 8px 24px -10px rgba(255, 180, 84, 0.9);
}

.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffd79a, #ffbe6a); }

.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); }

.btn-small { padding: 6px 12px; font-size: 13px; }

.btn.recording {
  background: rgba(255, 107, 107, 0.16);
  border-color: rgba(255, 107, 107, 0.5);
  color: #ffb3b3;
}

.status {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status.ok { color: var(--good); border-color: rgba(87, 227, 155, 0.28); background: rgba(87, 227, 155, 0.08); }
.status.error { color: #ffb3b3; border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.1); }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(12px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
}

.hint { font-size: 12.5px; color: var(--muted); }

kbd {
  font: 11px var(--mono);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  margin: 0 1px;
}

/* ------------------------------------------------------------------ stage */

.stage {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.35fr);
  gap: 16px;
}

@media (max-width: 860px) {
  .stage { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ tuner */

.tuner { display: grid; gap: 18px; }

.tuner-note { display: flex; align-items: baseline; gap: 14px; }

.note-name {
  font-size: 62px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-width: 2.4ch;
  background: linear-gradient(180deg, #fff, #b9c0d8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

body.tracking .note-name {
  background: linear-gradient(180deg, #fff2dd, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
}

.note-meta { display: grid; gap: 2px; }
.note-freq { font: 13px var(--mono); color: var(--muted); }

.note-cents {
  font: 15px var(--mono);
  font-weight: 600;
  color: var(--muted);
}

.note-cents[data-quality="good"] { color: var(--good); }
.note-cents[data-quality="ok"] { color: var(--warn); }
.note-cents[data-quality="off"] { color: var(--bad); }

.needle-track {
  position: relative;
  height: 34px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--card-border);
  overflow: hidden;
}

.needle-track::before,
.needle-track::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.07);
}
.needle-track::before { left: 25%; }
.needle-track::after { right: 25%; }

.needle-center {
  position: absolute;
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 2px;
}

.needle {
  position: absolute;
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 5px;
  margin-left: -2.5px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 0 16px -2px var(--accent);
  transition: transform 0.07s linear;
}

.level { display: flex; align-items: center; gap: 10px; }

.level-track {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  overflow: hidden;
  border: 1px solid var(--card-border);
}

.level-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4aa3ff, var(--good));
  transition: width 0.06s linear, background 0.2s ease;
}

.level-bar[data-zone="hot"] { background: linear-gradient(90deg, var(--warn), var(--bad)); }

.level-db { font: 12px var(--mono); color: var(--muted); min-width: 5ch; text-align: right; }

/* ------------------------------------------------------------- pitch view */

.panel-view { display: flex; flex-direction: column; }

.pitch-canvas {
  width: 100%;
  height: 240px;
  display: block;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--card-border);
}

.debug-body {
  display: none;
  margin-top: 12px;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  font-size: 12px;
}

.debug-body[data-visible="true"] { display: grid; }

.debug-body span { color: var(--muted); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.debug-body b { font: 13px var(--mono); font-weight: 500; }

/* --------------------------------------------------------------- keyboard */

.keyboard {
  position: relative;
  height: 168px;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--card-border);
  padding: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  scrollbar-width: thin;
}

/* Keys are absolutely positioned with percentage widths inside .keyboard-inner,
   which is allowed to grow wider than the container so the board can scroll. */
.keyboard-inner {
  position: relative;
  height: 100%;
  min-height: 100%;
}

.key {
  position: absolute;
  top: 0;
  cursor: pointer;
  transition: background 0.06s ease, transform 0.06s ease;
}

.key-white {
  bottom: 0;
  background: linear-gradient(180deg, #fbfbfd, #dfe2ec);
  border-right: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 0 0 5px 5px;
  z-index: 1;
}

.key-white span {
  position: absolute;
  bottom: 7px;
  left: 0;
  right: 0;
  text-align: center;
  font: 10px var(--mono);
  color: #8b90a3;
  pointer-events: none;
}

.key-black {
  background: linear-gradient(180deg, #3a3d4a, #101219);
  border-radius: 0 0 4px 4px;
  height: 62%;
  z-index: 2;
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.8);
}

.key-white.pressed { background: linear-gradient(180deg, #ffe0b0, #f0b566); }
.key-black.pressed { background: linear-gradient(180deg, #8a6a2f, #4a3413); }

.key-white.hum {
  background: linear-gradient(180deg, #fff3e0, #ffcf94);
  box-shadow: inset 0 -18px 26px -14px var(--accent);
}

.key-black.hum {
  background: linear-gradient(180deg, #7a5a20, #3a2a0c);
  box-shadow: 0 0 14px -2px rgba(255, 180, 84, 0.7);
}

.key-white.flash { background: linear-gradient(180deg, #d9d2ff, #a99cff); }
.key-black.flash { background: linear-gradient(180deg, #6b5ce0, #3d2fa8); }

/* --------------------------------------------------------------- controls */

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px 22px;
}

.ctrl { display: grid; gap: 6px; grid-template-columns: 1fr auto; align-items: center; }

.ctrl-label {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 550;
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: space-between;
}

.ctrl-label em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 400;
}

.ctrl output { font: 12px var(--mono); color: var(--muted); min-width: 6ch; text-align: right; }

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff, #c9cee0);
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.9);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

.ctrl-toggles { grid-template-columns: 1fr; gap: 10px; }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; }
.toggle input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.toggle span { display: grid; }
.toggle em { font-style: normal; font-size: 11.5px; color: var(--muted); }

/* --------------------------------------------------------------- recorder */

.record-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.rec-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  max-height: 128px;
  overflow-y: auto;
}

.chip {
  font: 11.5px var(--mono);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 7px;
  padding: 3px 7px;
  display: inline-flex;
  gap: 5px;
}

.chip b { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------- tips */

.tips { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13.5px; display: grid; gap: 7px; }
.tips strong { color: var(--text); }
.tips em { color: var(--accent); font-style: normal; }

/* ----------------------------------------------------------------- footer */

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: #5f6478;
  font-size: 12px;
  padding: 4px;
}

.footer a { color: #7d8399; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
