:root {
  --bg: #100e0c;
  --panel: #17140f;
  --ink: #f6f1e7;
  --muted: #a3988c;
  --line: rgba(246, 241, 231, 0.08);
  --gold: #e6b15a;
  --ivory: #f6e2b8;
  --flat: #8eb6ff;
  --sharp: #ff8d72;
  --serif: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --kaiti: "KaiTi", "STKaiti", "楷体", var(--serif);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: radial-gradient(rgba(255, 244, 224, 0.16) 0.6px, transparent 0.6px);
  background-size: 3px 3px;
}

button, p { font: inherit; }

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

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.app {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  gap: 18px;
  padding: 22px 28px 18px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--gold);
}

.brand h1 {
  margin: 0;
  font-family: var(--kaiti);
  font-size: 34px;
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1;
  color: var(--ink);
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.14em;
}

.mark {
  width: 34px;
  height: 34px;
  display: block;
}

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

.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
}

.primary {
  background: #f3ecdf;
  color: #1a150f;
}

.primary:hover { background: #fff8ee; }

.ghost {
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(243, 236, 223, 0.22);
}

.ghost:hover { background: rgba(243, 236, 223, 0.06); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d84a32;
  box-shadow: 0 0 0 0 rgba(216, 74, 50, 0.55);
  animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 7px rgba(216, 74, 50, 0); }
}

.level {
  width: 76px;
  height: 6px;
  border-radius: 99px;
  background: rgba(246, 241, 231, 0.12);
  overflow: hidden;
}

.level span {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--gold), #fff1cf);
}

.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 22px;
}

.readout {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: 6px 4px 4px 0;
}

.note {
  font-family: var(--serif);
  font-size: 108px;
  line-height: 0.84;
  letter-spacing: -0.045em;
  white-space: nowrap;
  color: var(--ink);
}

.note.is-idle { color: rgba(246, 241, 231, 0.28); }

.note.in-tune { text-shadow: 0 0 28px rgba(230, 177, 90, 0.28); }

.note.pop { animation: pop 0.18s ease; }

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

.note sup {
  font-family: var(--sans);
  font-size: 0.28em;
  font-weight: 600;
  letter-spacing: 0;
  margin-left: 0.06em;
  position: relative;
  top: -0.95em;
}

.solfege {
  margin: 12px 0 0;
  font-family: var(--sans);
  font-size: 22px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.status {
  margin: 8px 0 0;
  min-height: 1.3em;
  font-size: 22px;
  font-weight: 600;
}

.hz {
  margin: 4px 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.meter { margin-top: 22px; max-width: 280px; }

.meter.is-idle { opacity: 0.4; }

.meter-scale,
.meter-words {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.meter-track {
  position: relative;
  height: 28px;
}

.meter-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 13px;
  height: 2px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--flat), rgba(246, 241, 231, 0.28) 32%, var(--gold) 50%, rgba(246, 241, 231, 0.28) 68%, var(--sharp));
}

.zone {
  position: absolute;
  top: 6px;
  left: 35%;
  width: 30%;
  height: 16px;
  border-radius: 4px;
  background: rgba(230, 177, 90, 0.12);
}

.needle {
  position: absolute;
  top: 3px;
  left: 50%;
  width: 2px;
  height: 22px;
  border-radius: 1px;
  background: var(--ink);
  transform: translateX(-50%);
}

.warn, .error {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.55;
}

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

.error { color: #ffb4a4; }

.device {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.graph {
  position: relative;
  min-height: 280px;
  height: 100%;
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.graph-bar, .now-label, .hint {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.graph-bar {
  top: 12px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ago {
  font-size: 12px;
  color: rgba(246, 241, 231, 0.46);
}

.legend {
  display: flex;
  gap: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(20, 18, 16, 0.72);
  color: rgba(246, 241, 231, 0.72);
  font-size: 12px;
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
}

.swatch.flat { background: var(--flat); }
.swatch.ok { background: var(--gold); }
.swatch.sharp { background: var(--sharp); }

.now-label {
  top: 12px;
  right: 14px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: rgba(246, 241, 231, 0.5);
}

.hint {
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(246, 241, 231, 0.7);
  font-size: 15px;
}

.keyboard-scroll {
  overflow-x: auto;
  border-radius: 16px;
  background: #1c1814;
  border: 1px solid var(--line);
  padding: 10px 10px 8px;
}

.piano {
  position: relative;
  display: flex;
  height: 96px;
  min-width: 720px;
  user-select: none;
}

.white {
  position: relative;
  flex: 1 1 0;
  margin: 0 1px;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(180deg, #f7f1e6, #e4d8c6);
  box-shadow: inset 0 -8px 8px rgba(90, 58, 24, 0.08);
}

.white.on { background: linear-gradient(180deg, #ffe3ad, #e6b15a); }

.white span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 10px;
  color: #8d8173;
  pointer-events: none;
}

.white.on span { color: #4a3414; }

.black {
  position: absolute;
  top: 0;
  height: 61%;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(180deg, #3a342c, #14110e);
  transform: translateX(-50%);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.35);
  z-index: 1;
}

.black.on { background: linear-gradient(180deg, #ffe3ad, #c8892e); }

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

@media (max-width: 860px) {
  .app { padding: 16px; gap: 14px; }
  .stage { grid-template-columns: 1fr; }
  .note { font-size: 84px; }
  .graph { min-height: 300px; }
}

@media (max-height: 760px) {
  .piano { height: 76px; }
  .note { font-size: 84px; }
  .meter { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .dot, .note.pop { animation: none; }
}

::selection { background: rgba(230, 177, 90, 0.28); }
