:root {
  color-scheme: light;
  --ink: #1f2528;
  --muted: #68747a;
  --line: #d9e1e3;
  --paper: #f6f4ef;
  --panel: #ffffff;
  --green: #2f8f6f;
  --blue: #2376d1;
  --amber: #d49b29;
  --red: #c44949;
  --key-black: #151719;
  --shadow: 0 22px 70px rgba(29, 35, 38, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(115deg, rgba(47, 143, 111, 0.18), transparent 36%),
    linear-gradient(245deg, rgba(35, 118, 209, 0.16), transparent 42%),
    var(--paper);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid rgba(31, 37, 40, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand,
.connection-panel,
.stage-header,
.log-header,
.meter-copy {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
}

.mark {
  display: grid;
  grid-template-columns: repeat(3, 10px);
  gap: 4px;
  align-items: end;
  width: 48px;
  height: 48px;
  padding: 10px;
  border-radius: 8px;
  background: #202629;
}

.mark span {
  display: block;
  border-radius: 4px;
  background: #fff;
}

.mark span:nth-child(1) {
  height: 18px;
}

.mark span:nth-child(2) {
  height: 28px;
  background: #74d6b5;
}

.mark span:nth-child(3) {
  height: 22px;
  background: #8cbdf0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 2.3vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p,
.device-card p,
.hint-box {
  color: var(--muted);
  line-height: 1.5;
}

.connection-panel {
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #9aa4a9;
}

.status-pill[data-state="ready"] .status-dot {
  background: var(--green);
}

.status-pill[data-state="error"] .status-dot {
  background: var(--red);
}

.primary-button,
.ghost-button,
.text-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
}

.primary-button {
  padding: 0 18px;
  color: #fff;
  background: var(--blue);
  box-shadow: 0 10px 26px rgba(35, 118, 209, 0.25);
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.link-button {
  text-decoration: none;
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  background: transparent;
  color: var(--blue);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.side-panel,
.piano-stage {
  border: 1px solid rgba(31, 37, 40, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.panel-group {
  display: grid;
  gap: 8px;
}

label,
.card-label,
.meter-copy span,
.panel-grid span,
.eyebrow,
.log-header {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.device-card,
.hint-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfc;
}

.device-card strong {
  display: block;
  margin: 6px 0;
  font-size: 1.35rem;
}

.meter-block {
  display: grid;
  gap: 10px;
}

.meter-copy {
  justify-content: space-between;
}

.meter-copy strong {
  font-size: 1.4rem;
}

.velocity-meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef0;
}

.velocity-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
  transition: width 120ms ease;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.panel-grid div {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.panel-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 1.45rem;
}

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

.piano-stage {
  display: grid;
  grid-template-rows: auto minmax(250px, 1fr) minmax(150px, 210px);
  min-width: 0;
  overflow: hidden;
}

.stage-header {
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.stage-header h2 {
  margin-top: 3px;
  font-size: clamp(1.5rem, 3vw, 2.8rem);
  letter-spacing: 0;
}

.piano-wrap {
  display: grid;
  align-items: end;
  min-width: 0;
  padding: 22px 18px;
  background:
    linear-gradient(180deg, rgba(237, 243, 242, 0.8), rgba(255, 255, 255, 0.2)),
    #f8faf9;
}

.keyboard {
  position: relative;
  width: 100%;
  min-width: 720px;
  height: clamp(230px, 35vw, 360px);
  border: 1px solid #b7c1c5;
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 -18px 32px rgba(31, 37, 40, 0.08);
}

.key {
  position: absolute;
  user-select: none;
  touch-action: none;
  transition:
    transform 70ms ease,
    background 70ms ease,
    box-shadow 70ms ease;
}

.key.white {
  z-index: 1;
  bottom: 0;
  height: 100%;
  border-right: 1px solid #c9d1d4;
  background: linear-gradient(180deg, #fff, #f2f4f4);
}

.key.white:first-child {
  border-bottom-left-radius: 8px;
}

.key.white:last-child {
  border-bottom-right-radius: 8px;
}

.key.black {
  z-index: 3;
  top: 0;
  height: 62%;
  border: 1px solid #000;
  border-radius: 0 0 5px 5px;
  background: linear-gradient(180deg, #282d30, #090a0b);
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.26);
}

.key.active.white {
  background: linear-gradient(180deg, #def5eb, #a9dfc7);
  transform: translateY(3px);
}

.key.active.black {
  background: linear-gradient(180deg, #276d5d, #0f2c28);
  transform: translateY(2px);
}

.key-label {
  position: absolute;
  right: 4px;
  bottom: 8px;
  color: #7a858a;
  font-size: clamp(0.64rem, 0.9vw, 0.78rem);
  font-weight: 700;
  writing-mode: vertical-rl;
}

.log-panel {
  min-height: 0;
  border-top: 1px solid var(--line);
  background: #fff;
}

.log-header {
  justify-content: space-between;
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

#eventLog {
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  height: calc(100% - 45px);
  margin: 0;
  padding: 10px 14px;
  overflow: auto;
  list-style: none;
}

#eventLog li {
  display: grid;
  grid-template-columns: 72px 1fr 48px;
  gap: 10px;
  align-items: center;
  min-height: 28px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
}

#eventLog strong {
  color: var(--ink);
}

@media (max-width: 880px) {
  .topbar,
  .stage-header {
    align-items: stretch;
    flex-direction: column;
  }

  .connection-panel {
    justify-content: stretch;
  }

  .primary-button,
  .ghost-button {
    flex: 1;
  }

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

  .piano-wrap {
    overflow-x: auto;
  }

  .keyboard {
    width: 860px;
  }
}

@media (max-width: 540px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    margin: 10px auto;
  }

  .topbar,
  .side-panel,
  .stage-header {
    padding: 14px;
  }

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