:root {
  --bg: #0a0d12;
  --bg-elevated: #121722;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-strong: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f3f6fb;
  --text-muted: #8b97ab;
  --green: #00e676;
  --amber: #ffb300;
  --red: #ff4d5a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  touch-action: manipulation;
  user-select: none;
}

.mono {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  padding-top: calc(8px + var(--safe-top));
  padding-bottom: calc(8px + var(--safe-bottom));
  overflow: hidden;
}

.ambient-glow {
  position: absolute;
  inset: -10% -20% auto -20%;
  height: 55%;
  pointer-events: none;
  background: radial-gradient(circle at 50% 42%, rgba(0, 230, 118, 0.09), transparent 65%);
  transition: background 0.35s ease;
  z-index: 0;
}

.ambient-glow.state-warn {
  background: radial-gradient(circle at 50% 42%, rgba(255, 179, 0, 0.11), transparent 65%);
}

.ambient-glow.state-off {
  background: radial-gradient(circle at 50% 42%, rgba(255, 77, 90, 0.12), transparent 65%);
}

.ambient-glow.state-intune {
  background: radial-gradient(circle at 50% 42%, rgba(0, 230, 118, 0.22), transparent 65%);
}

/* Header */
.top-bar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 14px 8px;
}

.brand-cluster {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(0, 230, 118, 0.14);
  color: var(--green);
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-name span {
  color: var(--green);
}

.tuning-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tuning-pill:hover {
  color: var(--text);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.auto-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.auto-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.auto-switch input,
.setting-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.2s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

input:checked + .switch-track {
  background: var(--green);
}

input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Seismograph Stage */
.seismo-stage {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 210px;
  margin: 0 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(16, 21, 30, 0.72) 0%, rgba(10, 13, 18, 0.94) 100%);
  border: 1px solid rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

#seismoCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.accidental-markers {
  position: absolute;
  top: 10px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.42);
  font-weight: 700;
}

.accidental {
  font-size: 1.25rem;
  line-height: 1;
}

.scale-center {
  font-size: 0.7rem;
  opacity: 0.45;
  letter-spacing: 0.05em;
}

.tracker-hud {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  height: 46px;
  pointer-events: none;
}

.direction-pill {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(18, 23, 34, 0.88);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: color 0.15s ease, border-color 0.15s ease, opacity 0.2s ease, transform 0.15s ease;
}

.direction-pill.is-intune {
  color: var(--green);
  border-color: rgba(0, 230, 118, 0.45);
}

.direction-pill.is-warn {
  color: var(--amber);
  border-color: rgba(255, 179, 0, 0.4);
}

.direction-pill.is-off {
  color: var(--red);
  border-color: rgba(255, 77, 90, 0.4);
}

.cents-bubble {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%) scale(0.92);
  opacity: 0;
  min-width: 38px;
  height: 30px;
  padding: 0 9px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: #141a24;
  border: 2px solid var(--green);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.cents-bubble.is-visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.cents-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--bubble-color, var(--green));
}

.note-orb-wrap {
  position: absolute;
  top: 54%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.note-orb {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 24, 34, 0.84);
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.note-orb.is-intune {
  border-color: var(--green);
  box-shadow: 0 0 26px rgba(0, 230, 118, 0.42);
  transform: scale(1.06);
}

.note-orb.is-warn {
  border-color: var(--amber);
}

.note-orb.is-off {
  border-color: var(--red);
}

.note-orb-letter {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(10, 13, 18, 0.72);
  font-size: 0.74rem;
  color: var(--text-muted);
}

.dot-sep {
  opacity: 0.45;
}

.chromatic-hint {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(255, 179, 0, 0.14);
  border: 1px solid rgba(255, 179, 0, 0.32);
  color: #ffd166;
}

.mic-level-bar {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 8px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  pointer-events: none;
}

.mic-level-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #00e676);
  transition: width 0.07s linear;
}

/* Mic Activation Overlay */
.mic-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  background: rgba(10, 13, 18, 0.76);
  backdrop-filter: blur(6px);
  text-align: center;
}

.mic-start-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-radius: 999px;
  border: 1px solid rgba(0, 230, 118, 0.55);
  background: linear-gradient(135deg, #00e676 0%, #00c853 100%);
  color: #07140d;
  font-size: 0.96rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 230, 118, 0.28);
}

.mic-start-btn:active {
  transform: scale(0.97);
}

.mic-pulse-ring {
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  border: 2px solid rgba(0, 230, 118, 0.45);
  animation: pulseRing 2.1s infinite ease-out;
  pointer-events: none;
}

@keyframes pulseRing {
  0% { transform: scale(0.98); opacity: 0.8; }
  100% { transform: scale(1.14, 1.35); opacity: 0; }
}

.mic-helper {
  margin: 0;
  max-width: 280px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* Headstock Stage */
.headstock-stage {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  padding: 8px 10px 0;
  height: clamp(235px, 36dvh, 295px);
  flex-shrink: 0;
}

.peg-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  height: 78%;
  margin-bottom: 18px;
}

.peg-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.peg-col-right .peg-item {
  flex-direction: row-reverse;
}

.peg-btn {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: #171c26;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.peg-btn:active {
  transform: scale(0.93);
}

.peg-note {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
}

.peg-sub {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

.peg-check {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--green);
  color: #05140b;
  font-size: 0.65rem;
  font-weight: 900;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.peg-btn.is-tuned .peg-check {
  display: flex;
}

.peg-btn.is-tuned {
  border-color: rgba(0, 230, 118, 0.55);
}

.peg-btn.is-selected {
  background: #ffffff;
  color: #0b0e14;
  border-color: #ffffff;
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.28);
}

.peg-btn.is-selected .peg-sub {
  color: #475569;
}

.peg-btn.is-selected.is-in-tune {
  background: var(--green);
  border-color: #b9f6ca;
  box-shadow: 0 0 24px rgba(0, 230, 118, 0.55);
}

.peg-ear-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.peg-ear-btn:hover,
.peg-ear-btn:active {
  color: var(--green);
  border-color: rgba(0, 230, 118, 0.4);
}

.headstock-svg-host {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

.headstock-svg {
  width: 100%;
  max-width: 248px;
  height: 100%;
}

.svg-peg-cap {
  transition: fill 0.18s ease, stroke 0.18s ease;
}

.svg-peg-cap.is-selected {
  fill: #ffffff;
  stroke: #00e676;
  stroke-width: 1.8;
}

.svg-string-path.is-selected {
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.45));
}

.svg-string-path.is-in-tune {
  stroke: var(--green);
  filter: drop-shadow(0 0 6px rgba(0, 230, 118, 0.7));
}

/* Bottom Status Bar */
.bottom-bar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 2px;
  font-size: 0.76rem;
  color: var(--text-muted);
  background: #0a0d12;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #475569;
}

.live-dot.is-live {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.tuned-counter {
  font-weight: 700;
  color: var(--text-muted);
}

/* Bottom Sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.bottom-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + var(--safe-bottom));
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.sheet-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.tuning-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tuning-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.tuning-option.is-active {
  border-color: var(--green);
  background: rgba(0, 230, 118, 0.1);
}

.tuning-opt-name {
  font-size: 0.94rem;
  font-weight: 700;
}

.tuning-opt-notes {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
}

.setting-col {
  flex-direction: column;
  align-items: stretch;
}

.setting-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
}

.setting-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.setting-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.stepper button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.stepper span {
  min-width: 54px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.setting-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.reset-tuned-btn {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
