:root {
  color-scheme: light;
  --ink: #183034;
  --muted: #678084;
  --line: #dce9e9;
  --panel: rgba(255, 255, 255, 0.92);
  --accent: #19aaa9;
  --accent-dark: #0c7f82;
  --accent-soft: #dff7f5;
  --key-width: 78px;
  --key-height: 310px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #f4fafa;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
  background:
    radial-gradient(circle at 15% 12%, rgba(56, 207, 200, 0.14), transparent 30rem),
    radial-gradient(circle at 88% 90%, rgba(94, 180, 222, 0.12), transparent 28rem),
    #f4fafa;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(42px, 7vh, 78px) 0 44px;
}

.hero {
  margin-bottom: 30px;
  text-align: center;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 7vw, 4.4rem);
  font-weight: 780;
  letter-spacing: -0.06em;
  line-height: 1;
}

.hero p {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.12rem);
}

.instrument {
  overflow: hidden;
  border: 1px solid rgba(208, 228, 228, 0.95);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(51, 105, 110, 0.12);
  backdrop-filter: blur(12px);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.mode-switch {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f3f8f8;
}

.mode-button {
  min-width: 62px;
  padding: 8px 13px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.mode-button.is-selected {
  color: var(--accent-dark);
  background: #fff;
  box-shadow: 0 2px 8px rgba(60, 99, 102, 0.1);
}

.toolbar-actions,
.volume-control {
  display: flex;
  align-items: center;
}

.toolbar-actions {
  gap: 24px;
}

.volume-control {
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.volume-control input {
  width: 128px;
  accent-color: var(--accent);
  cursor: pointer;
}

.volume-control output {
  width: 3.2em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stop-button {
  padding: 10px 15px;
  border: 1px solid #cfe1e1;
  border-radius: 10px;
  color: #3c5b5f;
  background: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.stop-button:hover,
.stop-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: #f6ffff;
}

.piano-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 30px 24px 12px;
  scrollbar-color: #b8d8d7 transparent;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
}

.piano {
  display: flex;
  width: max-content;
  min-width: 100%;
  justify-content: center;
  gap: 5px;
  padding: 9px;
  border-radius: 16px;
  background: #d8e6e6;
  box-shadow: inset 0 2px 6px rgba(41, 78, 82, 0.12);
  user-select: none;
  -webkit-user-select: none;
}

.piano-key {
  position: relative;
  display: flex;
  flex: 0 0 var(--key-width);
  width: var(--key-width);
  height: var(--key-height);
  align-items: flex-end;
  justify-content: center;
  padding: 0 8px 22px;
  overflow: hidden;
  border: 1px solid #c9d6d6;
  border-radius: 8px 8px 12px 12px;
  outline: none;
  color: var(--ink);
  background: linear-gradient(180deg, #fff 0%, #fff 72%, #f4f8f8 100%);
  box-shadow:
    0 7px 0 #bccaca,
    0 10px 14px rgba(47, 81, 83, 0.14);
  cursor: pointer;
  touch-action: pan-x;
  -webkit-touch-callout: none;
  transition: transform 70ms ease, box-shadow 70ms ease, background 100ms ease;
}

.piano-key::before {
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--key-accent, transparent);
  content: "";
  opacity: 0;
  transition: opacity 100ms ease;
}

.piano-key.is-active {
  transform: translateY(6px);
  color: #075d60;
  background: linear-gradient(180deg, #f4ffff 0%, #e0f7f5 100%);
  box-shadow:
    0 1px 0 #afc3c3,
    0 3px 8px rgba(26, 138, 140, 0.18),
    inset 0 0 0 2px rgba(25, 170, 169, 0.23);
}

.piano-key.is-active::before,
.piano-key:focus-visible::before {
  opacity: 1;
}

.piano-key:focus-visible {
  box-shadow:
    0 7px 0 #a7c4c4,
    0 10px 14px rgba(47, 81, 83, 0.14),
    inset 0 0 0 2px var(--accent);
}

.key-labels {
  display: grid;
  justify-items: center;
  gap: 10px;
  pointer-events: none;
}

.note-label {
  min-width: 2.2em;
  font-size: 1.08rem;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.computer-key {
  min-width: 28px;
  padding: 3px 6px;
  border: 1px solid #d3dfdf;
  border-radius: 6px;
  color: #839598;
  background: rgba(255, 255, 255, 0.75);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.2;
}

.instrument-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 52px;
  padding: 10px 24px 16px;
  color: var(--muted);
  font-size: 0.78rem;
}

.instrument-footer p {
  margin: 0;
}

#audio-status[data-state="ready"]::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
  vertical-align: 1px;
}

#audio-status[data-state="error"] {
  color: #b34a4a;
}

noscript {
  display: block;
  margin: 20px 0;
  color: #a33;
  text-align: center;
}

@media (max-width: 760px) {
  :root {
    --key-width: 66px;
    --key-height: 276px;
  }

  .app-shell {
    width: min(100% - 24px, 1180px);
    padding-top: 34px;
  }

  .instrument {
    border-radius: 20px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
  }

  .mode-switch {
    align-self: flex-start;
  }

  .toolbar-actions {
    justify-content: space-between;
    gap: 12px;
  }

  .volume-control {
    flex: 1;
  }

  .volume-control input {
    width: min(32vw, 150px);
  }

  .piano-scroll {
    padding: 24px 14px 12px;
  }

  .piano {
    min-width: max-content;
  }

  .instrument-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
    padding: 10px 16px 16px;
  }

  .keyboard-hint {
    display: none;
  }
}

@media (max-width: 430px) {
  :root {
    --key-width: 62px;
    --key-height: 250px;
  }

  .app-shell {
    width: 100%;
    padding: 28px 0 0;
  }

  .hero {
    padding: 0 18px;
    margin-bottom: 24px;
  }

  .instrument {
    border-right: 0;
    border-left: 0;
    border-radius: 20px 20px 0 0;
  }

  .toolbar-actions {
    align-items: flex-end;
  }

  .volume-control {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 5px 8px;
  }

  .volume-control input {
    order: 3;
    width: 100%;
  }

  .stop-button {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
