:root {
  --bg-deep: #07080d;
  --bg-card: rgba(22, 26, 36, 0.72);
  --bg-card-solid: #161a24;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f1f4fa;
  --muted: #94a3b8;
  --accent: #5eead4;
  --accent-2: #38bdf8;
  --accent-glow: rgba(94, 234, 212, 0.45);
  --warn: #fcd34d;
  --danger: #fb7185;
  --chord-finger: #c084fc;
  --chord-finger-text: #1a0524;
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.55;
}

.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(56, 189, 248, 0.18), transparent 55%),
    radial-gradient(700px 480px at 88% 12%, rgba(94, 234, 212, 0.12), transparent 50%),
    radial-gradient(600px 400px at 50% 100%, rgba(192, 132, 252, 0.08), transparent 45%),
    linear-gradient(180deg, #0a0c12 0%, #07080d 100%);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.25rem 1.25rem 3.5rem;
  position: relative;
}

.header .eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.header h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(2rem, 5.5vw, 2.65rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(120deg, #fff 0%, #cbd5e1 45%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0;
  max-width: 40rem;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 400;
}

.tagline strong {
  color: var(--text);
  font-weight: 600;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.25rem;
  margin: 2rem 0 1.25rem;
}

.btn {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.8rem 1.5rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

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

.btn-primary {
  position: relative;
  background: linear-gradient(135deg, #2dd4bf 0%, #0d9488 55%, #0f766e 100%);
  color: #021c18;
  box-shadow: 0 6px 32px var(--accent-glow);
}

.btn-primary:hover {
  box-shadow: 0 10px 40px rgba(94, 234, 212, 0.55);
}

.btn-primary[aria-pressed="true"] {
  background: var(--bg-card-solid);
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  border-color: rgba(94, 234, 212, 0.45);
  color: var(--accent);
}

.btn-secondary:disabled,
.btn-ghost:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--muted);
}

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

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--accent);
}

.card {
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.freq-card {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
}

.freq-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.freq-card-hint {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.freq-viz-hz {
  font-size: 1rem;
  font-weight: 500;
  color: var(--accent);
}

.freq-rail-wrap {
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}

.freq-rail-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 72px;
}

.freq-ticks text {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
}

.freq-ticks line {
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 1;
}

.freq-needle {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0.95;
}

.freq-dot {
  fill: var(--accent-2);
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1.5;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.55));
}

.freq-marker {
  transition: opacity 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  .freq-marker,
  .stability-fill,
  .btn,
  .history-item {
    transition: none !important;
  }
}

.live-panel.hidden {
  display: none;
}

.live-panel {
  margin-bottom: 1rem;
}

.live-reading {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.92rem;
  color: var(--text);
}

.stability-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.stability-time {
  color: var(--accent);
  font-size: 0.75rem;
}

.stability-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.stability-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.08s linear;
}

.label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.meters {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
}

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

.value-row {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.value {
  font-size: clamp(1.65rem, 5.5vw, 2.15rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.value.mono {
  font-family: var(--mono);
  font-weight: 500;
}

.note-name {
  font-variant-numeric: tabular-nums;
}

.unit {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
}

.hint,
.cents {
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1.2em;
}

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

.cents.sharp {
  color: var(--warn);
}

.melody-card {
  margin-top: 1.25rem;
  padding: 1.35rem 1.4rem 1.45rem;
}

.melody-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.melody-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.melody-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

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

.melody-empty.hidden {
  display: none;
}

.note-history {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.note-history li {
  margin: 0;
}

.history-li {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.5rem;
  position: relative;
}

.history-li--dragging {
  opacity: 0.65;
}

.history-li--drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.history-drag-handle {
  flex: 0 0 auto;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  min-height: 2.5rem;
  font-size: 0.65rem;
  letter-spacing: -0.12em;
  line-height: 1;
  color: var(--muted);
  cursor: grab;
  user-select: none;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.history-drag-handle:hover {
  color: var(--accent);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
}

.history-drag-handle:active {
  cursor: grabbing;
}

.history-row-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  justify-content: center;
  flex: 0 0 auto;
}

.history-icon-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1;
  font-family: var(--font);
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--accent);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.history-icon-btn:hover:not(:disabled) {
  border-color: var(--accent-dim);
  background: rgba(94, 234, 212, 0.12);
}

.history-icon-btn--danger {
  color: var(--danger);
  font-size: 1.25rem;
}

.history-icon-btn--danger:hover:not(:disabled) {
  border-color: rgba(251, 113, 133, 0.55);
  background: rgba(251, 113, 133, 0.1);
}

.history-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.melody-voicing-hint {
  margin: 0.65rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 42rem;
}

.melody-voicing-hint.hidden {
  display: none;
}

.history-quality-select {
  align-self: center;
  flex: 0 0 auto;
  width: min(36vw, 9.25rem);
  max-width: 100%;
  font-size: 0.78rem;
  padding: 0.45rem 0.4rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  cursor: pointer;
}

.history-quality-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.65rem 0.85rem;
  flex: 1;
  min-width: 0;
  width: auto;
  padding: 0.55rem 0.65rem;
  text-align: left;
  font: inherit;
  color: inherit;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.history-item:hover {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
}

.history-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.history-item.is-selected {
  border-color: rgba(94, 234, 212, 0.55);
  box-shadow: 0 0 0 1px rgba(94, 234, 212, 0.2);
}

.history-item.is-playing {
  border-color: rgba(252, 211, 77, 0.65);
  box-shadow: 0 0 0 1px rgba(252, 211, 77, 0.25);
}

.history-item-index {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 1.5rem;
}

.history-item-note {
  font-weight: 700;
  font-size: 1rem;
}

.history-item-meta {
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 0.12rem;
}

.history-item-thumb {
  width: 112px;
  max-width: 34vw;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
}

.theory-card {
  margin-top: 1.25rem;
  padding: 1.35rem 1.4rem 1.25rem;
}

.theory-card h2 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.theory-grid {
  display: grid;
  gap: 1rem 1.25rem;
  grid-template-columns: 1fr 1fr;
  align-items: end;
}

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

.theory-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.theory-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--muted);
}

.theory-select,
.theory-input {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

.theory-check {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  padding-top: 0.5rem;
}

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

.theory-hint,
.theory-keys {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.theory-keys {
  margin-top: 0.5rem;
}

.gf-capo-banner {
  font-size: 0.58rem;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: rgba(168, 179, 201, 0.72);
  margin: 0 0 0.15rem;
  padding: 0;
  text-transform: none;
}

.chord-section {
  margin-top: 1.25rem;
}

.chord-section h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.chord-hint {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.chord-card-inner {
  padding: 0.15rem 0 0;
}

.chord-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.chord-name {
  font-size: 1.65rem;
  font-weight: 700;
}

.chord-shape-label {
  font-size: 0.84rem;
  color: var(--muted);
}

.fretboard-host {
  user-select: none;
}

/* Guitar grid v2: string | open/mute | frets (open no longer stretches finger cells) */
.gf-board {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--mono);
  font-size: 0.82rem;
  --gf-cell-min: 2rem;
}

.gf-row {
  display: grid;
  align-items: center;
  min-height: var(--gf-cell-min);
  gap: 4px 6px;
}

.gf-row--head {
  min-height: 1.35rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.gf-corner {
  visibility: hidden;
}

.gf-str {
  text-align: center;
  font-weight: 600;
  color: #a8b3c9;
}

.gf-st {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--gf-st);
  height: 1.35rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.gf-st--open {
  color: var(--accent);
  font-size: 0.85rem;
  line-height: 1;
}

.gf-st--mute {
  color: var(--danger);
  font-weight: 700;
  font-size: 0.8rem;
}

.gf-num {
  text-align: center;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.68rem;
}

.gf-num--capo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  line-height: 1;
}

.gf-num--capo .gf-num-fret {
  font-size: 0.62rem;
  opacity: 0.85;
}

.gf-capo-mark {
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(192, 132, 252, 0.75);
  text-transform: none;
}

.gf-board.fretboard--mini .gf-capo-mark {
  font-size: 0.45rem;
}

.gf-cell {
  min-height: calc(var(--gf-cell-min) - 2px);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(15, 18, 28, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-weight: 600;
  font-size: 0.72rem;
}

.gf-cell--dot {
  background: linear-gradient(145deg, rgba(192, 132, 252, 0.95), rgba(124, 58, 237, 0.9));
  color: var(--chord-finger-text);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 12px rgba(124, 58, 237, 0.35);
}

.gf-board.fretboard--mini {
  font-size: 0.62rem;
  --gf-str: 1.05rem;
  --gf-st: 0.85rem;
  --gf-cell-min: 1.35rem;
  gap: 2px;
}

.gf-board.fretboard--mini .gf-row {
  gap: 2px 4px;
}

.gf-board.fretboard--mini .gf-cell {
  border-radius: 5px;
  font-size: 0.58rem;
}

.gf-board.fretboard--mini .gf-st--open {
  font-size: 0.68rem;
}

.footer {
  margin-top: 2.5rem;
  padding-top: 1.35rem;
  border-top: 1px solid var(--border);
}

.footer p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
}
