:root {
  --bg: #050608;
  --bg-soft: #101318;
  --panel: #151a22;
  --panel-soft: #1b2230;
  --panel-stroke: rgba(255, 255, 255, 0.08);
  --text: #f7f7f6;
  --muted: #b5bcc7;
  --key-text: #1a1c1f;
  --accent: #f3efe7;
  --accent-strong: #ffcf66;
  --primary: #f4f4f2;
  --success: #5bd38d;
  --warning: #ffbf69;
  --danger: #ff7a7a;
  --shadow: 0 20px 54px rgba(0, 0, 0, 0.38);
  --white-key-width: 68px;
  --black-key-width: 42px;
  --font-sans: "Avenir Next", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-display: "Avenir Next Condensed", "Hiragino Kaku Gothic ProN", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top center, rgba(255, 255, 255, 0.05), transparent 32%),
    radial-gradient(circle at bottom left, rgba(255, 198, 88, 0.08), transparent 26%),
    linear-gradient(180deg, #050608, #090b10);
  color: var(--text);
  font-family: var(--font-sans);
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(1480px, calc(100vw - 1.2rem));
  margin: 0 auto;
  padding: 0.8rem 0 1.5rem;
}

.piano-stage {
  padding: 1rem;
  border: 1px solid var(--panel-stroke);
  border-radius: 1.8rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #0c1016, #040507);
  box-shadow: var(--shadow);
}

.control-topbar,
.stage-summary,
.panel-head,
.test-progress-head,
.sensitivity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.control-topbar {
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.mode-switch,
.chip-group,
.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.mode-switch {
  padding: 0.24rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.mode-button,
.focus-chip,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.2rem;
  min-height: 3.2rem;
  padding: 0.78rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
  transition:
    transform 140ms ease,
    background 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease;
}

.mode-button {
  min-width: 6.7rem;
  min-height: 3rem;
  padding-inline: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.mode-button.is-active,
.focus-chip.is-active,
.icon-button:hover,
.icon-button:focus-visible,
.mode-button:hover,
.focus-chip:hover {
  color: #111214;
  background: var(--accent);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.8),
    0 12px 24px rgba(255, 255, 255, 0.08);
}

.control-caption,
.brand-eyebrow,
.panel-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.control-caption {
  color: rgba(255, 255, 255, 0.85);
}

.octave-controls {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex: 1 1 20rem;
  justify-content: center;
}

.focus-chip {
  min-width: 3rem;
  min-height: 3rem;
  padding: 0.7rem;
  font-weight: 800;
}

.icon-button {
  width: 3.3rem;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 400;
}

.stage-summary {
  align-items: stretch;
  margin-bottom: 1rem;
}

.brand-card,
.target-card {
  padding: 1.2rem 1.3rem;
  border-radius: 1.45rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-card {
  flex: 1.2;
}

.target-card {
  flex: 0.95;
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.brand-eyebrow {
  color: #f3c76f;
}

.brand-card h1,
.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: -0.03em;
}

.brand-card h1 {
  font-size: clamp(2.4rem, 6vw, 4.3rem);
  line-height: 0.94;
}

.brand-copy,
.support-copy,
.feedback-text,
.steps {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}

.mode-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 2.1rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 800;
}

.mode-pill {
  color: #111214;
  background: var(--accent);
}

.stage-message {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.7;
  color: #ececec;
}

.target-note-card {
  padding: 1rem 1.1rem;
  border-radius: 1.25rem;
  background: rgba(255, 255, 255, 0.05);
}

.target-note-label,
.target-note-meta {
  margin: 0;
}

.target-note-label {
  font-size: clamp(2.6rem, 8vw, 4.9rem);
  line-height: 0.95;
  font-family: var(--font-display);
  font-weight: 800;
}

.target-note-meta {
  margin-top: 0.4rem;
  color: #d7d7d7;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.keyboard-stage {
  padding: 0.85rem;
  border-radius: 1.55rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)),
    rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.keyboard-guide {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.keyboard-shell {
  overflow-x: auto;
  padding: 0 0 0.5rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.keyboard {
  --shadow-line: rgba(18, 18, 18, 0.26);

  position: relative;
  min-width: 100%;
  height: 24rem;
  padding-top: 0.18rem;
}

.keyboard-white-layer {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.keyboard-black-layer {
  position: absolute;
  top: 0;
  left: 0;
  height: 14.3rem;
  pointer-events: none;
}

.piano-key {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.piano-key:hover {
  transform: translateY(-1px);
}

.piano-key:active {
  transform: translateY(0);
}

.white-key {
  position: relative;
  width: var(--white-key-width);
  min-width: var(--white-key-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0.4rem 1rem;
  border-right: 1px solid rgba(32, 32, 32, 0.12);
  border-left: 1px solid rgba(255, 255, 255, 0.52);
  border-bottom: 6px solid rgba(12, 12, 12, 0.12);
  border-radius: 0 0 0.9rem 0.9rem;
  background:
    linear-gradient(180deg, #ffffff 0%, #f5f2ee 65%, #ddd8cf 100%);
  color: var(--key-text);
  box-shadow:
    inset -4px 0 8px rgba(0, 0, 0, 0.07),
    inset 1px 0 0 rgba(255, 255, 255, 0.8);
}

.white-key:first-child {
  border-left-color: rgba(0, 0, 0, 0.18);
}

.black-key {
  position: absolute;
  top: 0;
  width: var(--black-key-width);
  height: 14rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 0.2rem 0.9rem;
  border-radius: 0 0 0.55rem 0.55rem;
  background:
    linear-gradient(180deg, #1c1f25 0%, #050608 66%, #5b5d62 100%);
  color: #f7f7f6;
  box-shadow:
    inset 0 -18px 18px rgba(255, 255, 255, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 14px 22px rgba(0, 0, 0, 0.38);
  pointer-events: auto;
  z-index: 2;
}

.piano-key.is-active.white-key {
  background:
    linear-gradient(180deg, #fff8db 0%, #f3e0a4 72%, #d0ab52 100%);
  box-shadow:
    inset -4px 0 8px rgba(0, 0, 0, 0.08),
    0 8px 18px rgba(255, 208, 102, 0.26);
}

.piano-key.is-active.black-key {
  background:
    linear-gradient(180deg, #7f6929 0%, #332603 70%, #ffcf66 100%);
  color: #111214;
}

.key-solfege,
.key-alias,
.key-scientific {
  display: block;
  text-align: center;
}

.key-solfege {
  font-size: 0.94rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.key-alias {
  margin-top: auto;
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0.85;
  letter-spacing: 0.04em;
}

.key-scientific {
  margin-top: 0.18rem;
  font-size: 0.86rem;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.3);
}

.black-key .key-scientific {
  color: rgba(255, 255, 255, 0.46);
}

.dashboard {
  display: grid;
  grid-template-columns: 1.02fr 0.98fr 0.88fr;
  gap: 1rem;
  margin-top: 1rem;
}

.panel {
  padding: 1.15rem;
  border-radius: 1.5rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    var(--panel);
  border: 1px solid var(--panel-stroke);
  box-shadow: var(--shadow);
}

.panel-head {
  align-items: flex-start;
  margin-bottom: 1rem;
}

.panel-head h2 {
  font-size: 1.8rem;
}

.panel-label {
  color: rgba(255, 255, 255, 0.58);
}

.control-block {
  display: grid;
  gap: 0.8rem;
}

.primary-button,
.secondary-button,
.accent-button {
  min-height: 3.4rem;
  padding: 0.92rem 1.1rem;
  border-radius: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 120ms ease,
    opacity 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.accent-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active,
.accent-button:active {
  transform: translateY(0);
}

.primary-button {
  color: #111214;
  background: var(--accent);
}

.secondary-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
}

.accent-button {
  color: #111214;
  background: #ffcf66;
}

.primary-button[disabled],
.secondary-button[disabled],
.accent-button[disabled] {
  opacity: 0.46;
  cursor: not-allowed;
  transform: none;
}

.test-progress-card,
.sensitivity-card {
  margin-top: 0.2rem;
  padding: 0.95rem 1rem;
  border-radius: 1.15rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.metric-label {
  margin: 0 0 0.4rem;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-value {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text);
}

.support-copy {
  margin-top: 0.55rem;
  font-size: 0.92rem;
}

.sensitivity-range {
  width: 100%;
  accent-color: #ffcf66;
}

.feedback-text {
  margin-top: 0.95rem;
  color: #f0f0ef;
}

.error-text {
  margin: 0.85rem 0 0;
  color: #ff8f8f;
  line-height: 1.66;
}

.meter-wrap {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.82rem;
  font-weight: 700;
}

.meter-track {
  position: relative;
  height: 1.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.meter-center {
  position: absolute;
  top: 0.13rem;
  bottom: 0.13rem;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 255, 255, 0.74);
  border-radius: 999px;
}

.meter-thumb {
  position: absolute;
  top: 0.11rem;
  left: calc(50% - 0.62rem);
  width: 1.24rem;
  height: 1.24rem;
  border-radius: 999px;
  background: #98a2b3;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card {
  padding: 0.95rem;
  border-radius: 1.1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.steps {
  margin-top: 1rem;
  padding-left: 1.1rem;
}

.progress-track {
  position: relative;
  height: 0.72rem;
  margin-top: 0.7rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f4f4f2, #ffcf66);
  transition: width 100ms linear;
}

.status-pill {
  color: #d1d5db;
  background: rgba(148, 163, 184, 0.16);
}

.status-waiting {
  color: #d1d5db;
  background: rgba(148, 163, 184, 0.16);
}

.status-listening {
  color: #06141f;
  background: rgba(125, 211, 252, 0.92);
}

.status-playing {
  color: #06141f;
  background: rgba(250, 204, 21, 0.88);
}

.status-low {
  color: #26190c;
  background: rgba(255, 191, 105, 0.92);
}

.status-intune {
  color: #071610;
  background: rgba(91, 211, 141, 0.92);
}

.status-high {
  color: #22090c;
  background: rgba(255, 122, 122, 0.92);
}

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

  .test-panel {
    grid-column: span 2;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 0.8rem, 56rem);
    padding-top: 0.45rem;
  }

  .stage-summary {
    flex-direction: column;
  }

  .keyboard {
    height: 19.5rem;
  }

  .keyboard-black-layer {
    height: 11.7rem;
  }

  .black-key {
    height: 11.4rem;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .test-panel {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 0.55rem, 46rem);
    padding-bottom: 1rem;
  }

  .piano-stage,
  .panel {
    padding: 0.9rem;
    border-radius: 1.35rem;
  }

  .control-topbar {
    gap: 0.8rem;
  }

  .mode-switch,
  .octave-controls,
  .zoom-controls {
    width: 100%;
    justify-content: center;
  }

  .octave-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.7rem;
  }

  .chip-group {
    flex-wrap: wrap;
    justify-content: center;
  }

  .mode-button {
    flex: 1 1 0;
    min-width: 0;
  }

  .brand-card h1 {
    font-size: clamp(2.1rem, 12vw, 3.2rem);
  }

  .target-note-label {
    font-size: clamp(2.4rem, 15vw, 4rem);
  }

  .keyboard-guide {
    flex-direction: column;
    align-items: flex-start;
  }

  .keyboard {
    height: 16rem;
  }

  .keyboard-black-layer {
    height: 9.8rem;
  }

  .white-key {
    padding-top: 0.75rem;
    padding-bottom: 0.85rem;
  }

  .black-key {
    height: 9.5rem;
    padding-top: 0.65rem;
    padding-bottom: 0.75rem;
  }

  .key-solfege {
    font-size: 0.84rem;
  }

  .key-alias {
    font-size: 0.68rem;
  }

  .key-scientific {
    font-size: 0.78rem;
  }

  .compact-grid {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .app-shell {
    width: min(100vw - 0.8rem, 86rem);
  }

  .piano-stage {
    padding: 0.85rem;
  }

  .stage-summary {
    margin-bottom: 0.8rem;
  }

  .brand-card,
  .target-card,
  .panel {
    padding: 0.9rem 1rem;
  }

  .keyboard {
    height: 14.2rem;
  }

  .keyboard-black-layer {
    height: 8.8rem;
  }

  .black-key {
    height: 8.55rem;
  }

  .dashboard {
    grid-template-columns: 1.08fr 0.92fr 0.82fr;
  }

  .brand-copy,
  .feedback-text,
  .support-copy,
  .steps,
  .stage-message {
    line-height: 1.5;
  }
}
