@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/InstrumentSans-Variable.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/Fraunces-Variable.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #14110e;
  --bg-soft: #1c1814;
  --card: #231e19;
  --card-2: #2b241e;
  --line: rgba(243, 234, 219, 0.1);
  --text: #f3eadb;
  --muted: #b5a894;
  --gold: #e6c56a;
  --gold-dim: #8d7340;
  --in-tune: #7dce9a;
  --flat: #7eafd6;
  --sharp: #e07a5f;
  --danger: #d45d4c;
  --ok: #7dce9a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: calc(72px + var(--safe-bottom));
  --tone: var(--gold);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(230, 197, 106, 0.12), transparent 55%),
    radial-gradient(800px 400px at 100% 100%, rgba(224, 122, 95, 0.08), transparent 50%),
    var(--bg);
  transition: background-color 0.4s ease;
}

body.in-tune {
  --tone: var(--in-tune);
}

body.flat {
  --tone: var(--flat);
}

body.sharp {
  --tone: var(--sharp);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

a {
  color: var(--gold);
}

img {
  max-width: 100%;
}

.app {
  width: min(560px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 18px var(--nav-h);
  position: relative;
}

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

.brand {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.brand strong {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.brand span {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.mic-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.mic-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b6258;
}

.mic-status.is-live .dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(212, 93, 76, 0.2);
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(212, 93, 76, 0.4); }
  100% { box-shadow: 0 0 0 8px rgba(212, 93, 76, 0); }
}

.tuner {
  margin: 8px 0 18px;
  background:
    radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--tone) 16%, transparent), transparent 58%),
    linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 10px 14px 16px;
  box-shadow: var(--shadow);
}

.gauge-wrap {
  position: relative;
  width: min(100%, 300px);
  margin: 0 auto;
  aspect-ratio: 2 / 1;
}

.gauge {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.gauge-arc {
  fill: none;
  stroke: rgba(243, 234, 219, 0.28);
  stroke-width: 12;
  stroke-linecap: round;
}

.gauge-good {
  fill: none;
  stroke: var(--in-tune);
  stroke-width: 12;
  stroke-linecap: round;
  opacity: 1;
}

.needle-origin {
  transition: transform 80ms linear;
}

.needle-origin.is-active line,
.needle-origin.is-active circle {
  stroke: var(--tone);
  fill: var(--tone);
}

.needle-line {
  stroke: var(--gold);
  stroke-width: 3.5;
  stroke-linecap: round;
}

.needle-hub {
  fill: var(--gold);
  stroke: #14110e;
  stroke-width: 3;
}

.note-block {
  position: absolute;
  left: 0;
  right: 0;
  top: 26%;
  text-align: center;
  pointer-events: none;
}

.note-name {
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(3.6rem, 17vw, 5rem);
  font-weight: 560;
  line-height: 0.85;
  letter-spacing: -0.05em;
  margin: -8px 0 4px;
  text-align: center;
}

.note-octave {
  display: inline-block;
  margin-left: 0.08em;
  font-size: 0.38em;
  font-weight: 500;
  vertical-align: 0.55em;
  color: var(--muted);
}

.freq {
  margin: 0 0 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  text-align: center;
}

.cents-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  min-height: 3.2rem;
}

.cents-value {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.95rem;
}

.cents-label {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: var(--muted);
}

.cents-label.is-in-tune { color: var(--in-tune); }
.cents-label.is-flat { color: var(--flat); }
.cents-label.is-sharp { color: var(--sharp); }

.ticks {
  display: flex;
  justify-content: space-between;
  width: min(70%, 250px);
  margin: 0 auto;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.vu {
  height: 6px;
  margin: 16px 18px 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.vu span {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--gold-dim), var(--tone));
  transition: transform 80ms linear;
}

.panel {
  display: none;
  animation: fade 0.25s ease;
}

.panel.is-active {
  display: block;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.card h2 {
  margin: 0 0 6px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.4rem;
  font-weight: 550;
  letter-spacing: -0.03em;
}

.card p,
.hint,
.empty-hint {
  margin: 0 0 10px;
  color: var(--muted);
}

.hint {
  font-size: 0.92rem;
}

.warn {
  background: rgba(224, 122, 95, 0.12);
  border: 1px solid rgba(224, 122, 95, 0.28);
  color: #f0c2b4;
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 0.9rem;
  margin: 12px 0 16px;
}

.latency {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.latency strong {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.8rem;
  letter-spacing: -0.03em;
  color: var(--gold);
}

.latency small,
.field span {
  color: var(--muted);
  font-size: 0.8rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #14110e;
  box-shadow: 0 0 0 1px var(--gold-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 560;
}

.btn.primary {
  background: var(--gold);
  color: #1a140c;
  border-color: transparent;
}

.btn.ghost {
  background: transparent;
}

.btn.danger,
.btn.ghost.danger {
  color: #f0a59a;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.toggle {
  width: 100%;
  min-height: 56px;
  border-radius: 16px;
  background: #2a241e;
  border: 1px solid var(--line);
  font-size: 1.05rem;
}

.toggle.is-on {
  background: color-mix(in srgb, var(--in-tune) 18%, var(--card));
  border-color: color-mix(in srgb, var(--in-tune) 45%, transparent);
  color: var(--in-tune);
}

.rec-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 8px 0 4px;
}

.rec-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #3a201c;
  border: 4px solid var(--danger);
  position: relative;
}

.rec-btn::after {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  background: var(--danger);
  transition: border-radius 0.15s ease, inset 0.15s ease;
}

.rec-btn.is-recording::after {
  inset: 24px;
  border-radius: 8px;
}

.rec-timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
  letter-spacing: 0.06em;
}

.take {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.take-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.take-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.take-actions .btn {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.9rem;
}

select {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  background: #2a241e;
  border: 1px solid var(--line);
  padding: 0 12px;
}

.scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.scale-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  border-radius: 16px;
  background: #2a241e;
  border: 1px solid var(--line);
  padding: 8px 4px;
}

.scale-note .solfege {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.15rem;
}

.scale-note .concert {
  font-size: 0.75rem;
  color: var(--muted);
}

.scale-note.is-current {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(230, 197, 106, 0.25);
  background: color-mix(in srgb, var(--gold) 14%, #2a241e);
}

.scale-note.is-done {
  border-color: color-mix(in srgb, var(--in-tune) 50%, transparent);
  background: color-mix(in srgb, var(--in-tune) 16%, #2a241e);
}

.exercise-status {
  min-height: 3.2em;
  color: var(--muted);
}

.exercise-status.is-ok { color: var(--in-tune); }
.exercise-status.is-sing { color: var(--text); }
.exercise-status.is-listen { color: var(--gold); }

.exercise-score {
  margin-top: 8px;
  color: var(--in-tune);
  font-weight: 560;
}

.nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 560;
  border-radius: 12px;
  padding: 6px 4px;
}

.tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active {
  color: var(--gold);
  background: rgba(230, 197, 106, 0.08);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 7, 0.72);
  backdrop-filter: blur(10px);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px 20px calc(24px + var(--safe-bottom));
}

.overlay[hidden] {
  display: none !important;
}

.overlay-card {
  width: min(520px, 100%);
  background: linear-gradient(180deg, #2a231c, #1a1612);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px 24px 22px;
  box-shadow: var(--shadow);
}

.overlay-card h1 {
  font-family: "Fraunces", Georgia, serif;
  font-size: 2.1rem;
  letter-spacing: -0.04em;
  margin: 0 0 8px;
}

.overlay-card p {
  color: var(--muted);
  margin: 0 0 16px;
}

.overlay-card .btn {
  width: 100%;
  min-height: 54px;
  font-size: 1.05rem;
}

.kicker {
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 700px) {
  .app {
    padding-top: 32px;
  }
}

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


.app.is-compact .tuner {
  padding: 6px 12px 12px;
  margin: 4px 0 12px;
}

.app.is-compact .gauge-wrap {
  width: min(100%, 240px);
  aspect-ratio: 2.1 / 1;
}

.app.is-compact .note-name {
  font-size: clamp(2.4rem, 12vw, 3rem);
  margin: -6px 0 0;
}

.app.is-compact .note-block {
  top: 22%;
}

.app.is-compact .freq {
  margin: 0 0 2px;
  font-size: 0.84rem;
}

.app.is-compact .cents-row {
  min-height: 0;
  margin-top: 0;
}

.app.is-compact .cents-label {
  font-size: 1.1rem;
}

.app.is-compact .vu {
  margin-top: 8px;
}

.latency {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.toggle.is-on {
  background: #2c3a30;
}

.scale-note.is-current {
  background: #3a3324;
}

.scale-note.is-done {
  background: #24332a;
}

@media (max-height: 760px) {
  .gauge-wrap {
    width: min(100%, 260px);
    aspect-ratio: 2 / 1;
  }
  .note-name {
    font-size: clamp(3rem, 15vw, 4rem);
  }
}

#exercise-start { width: 100%; margin-top: 4px; margin-bottom: 8px; }

.note-block { display: none; }
