:root {
  --stage: #0f0b0a;
  --stage-2: #291a12;
  --brass: #dcb359;
  --ink: #f4ece2;
  --muted: rgba(244, 236, 226, 0.55);
  --primary: rgba(244, 236, 226, 0.92);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-stroke: rgba(255, 255, 255, 0.14);
  --quaternary: rgba(255, 255, 255, 0.08);
  --scrim: rgba(0, 0, 0, 0.28);
  --sheet: rgba(28, 20, 16, 0.82);
  --safe: env(safe-area-inset-bottom, 0px);
  --top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

html.light {
  --stage: #d1bda3;
  --stage-2: #f7f0e0;
  --ink: #1c140e;
  --muted: rgba(28, 20, 14, 0.55);
  --primary: rgba(28, 20, 14, 0.92);
  --glass: rgba(255, 255, 255, 0.46);
  --glass-stroke: rgba(255, 255, 255, 0.55);
  --quaternary: rgba(255, 255, 255, 0.5);
  --scrim: rgba(40, 24, 12, 0.18);
  --sheet: rgba(247, 240, 224, 0.92);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 42%, var(--stage-2) 40px, var(--stage) 640px);
  color: var(--ink);
  font-family: "SF Pro Rounded", "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1120px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + var(--top)) 22px 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img {
  width: 26px; height: 26px;
  border-radius: 6px;
}
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.brand p {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.wave {
  width: 160px;
  height: 28px;
  margin-left: auto;
  flex: 0 0 160px;
}

.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 16px 28px 12px;
}

.row { display: flex; flex-direction: column; gap: 8px; }
.row-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}
.row-bar h2 {
  margin: 0;
  width: 72px;
  flex: 0 0 72px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.voice-static {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.grow { flex: 1; }

.voice-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--quaternary);
  overflow: hidden;
}
.voice-menu .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex: 0 0 7px;
}
.voice-menu .voice-title {
  font-size: 12px;
  font-weight: 600;
}
.voice-menu .chev {
  width: 9px; height: 9px;
  color: var(--muted);
}
.voice-menu select {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  appearance: none;
  border: 0;
  background: none;
}

.step {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.step b {
  min-width: 22px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.mini {
  appearance: none;
  border: 0;
  background: transparent;
  width: 22px;
  height: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  border-radius: 6px;
}
.mini svg { width: 13px; height: 13px; display: block; }
.mini:hover { background: var(--quaternary); }

.pads {
  display: flex;
  gap: 8px;
}
.pad {
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 58px;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--accent, var(--brass)) 35%, transparent);
  background: color-mix(in srgb, var(--accent, var(--brass)) 18%, transparent);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  user-select: none;
  touch-action: none;
  transition: transform 120ms ease-out, background 120ms ease-out, color 120ms ease-out;
}
.pad small {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
}
.pad b {
  font-family: "New York", "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1;
}
.pad.on {
  background: var(--accent, var(--brass));
  border-color: color-mix(in srgb, var(--accent, var(--brass)) 90%, white);
  transform: scale(0.96);
}
.pad.on small,
.pad.on b { color: rgba(255, 255, 255, 0.92); }

.pad.space {
  width: 100%;
  height: 52px;
  border-radius: 16px;
  --accent: #6b5cc7;
}
.pad.space.on { transform: scale(0.985); }

.bottombar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 22px calc(14px + var(--safe));
  flex-wrap: wrap;
}

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-stroke);
  border-radius: 16px;
  backdrop-filter: blur(22px) saturate(1.5);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
}
.cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}
.oct-read {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 36px;
  line-height: 1.05;
}
.oct-read span {
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
}
.oct-read b {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tr-read {
  min-width: 28px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.vol { gap: 8px; }
.speaker { width: 14px; height: 14px; color: var(--brass); flex: 0 0 14px; }
#volume {
  width: 110px;
  accent-color: var(--brass);
}
.sustain {
  font-size: 12px;
  font-weight: 600;
  gap: 8px;
}
.sustain input {
  appearance: none;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: rgba(120, 120, 128, 0.32);
  position: relative;
  cursor: pointer;
}
.sustain input::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 160ms ease-out;
}
.sustain input:checked { background: #34c759; }
.sustain input:checked::after { transform: translateX(14px); }

.tool-row { display: flex; align-items: center; gap: 6px; }
#letter-video { opacity: 0.4; }
#letter-video.on { opacity: 1; }
#midi { opacity: 0.55; }
#midi.on { opacity: 1; }
#solo.on { color: var(--brass); }
.rec-btn .ico-stop { display: none; }
.rec-btn.rec { color: #c43c32; }
.rec-btn.rec .ico-rec { display: none; }
.rec-btn.rec .ico-stop { display: block; }

.glass-icon {
  appearance: none;
  border: 1px solid var(--glass-stroke);
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  padding: 0;
  flex: 0 0 32px;
}
.glass-icon svg { width: 15px; height: 15px; }

.install-hint { font-size: 12px !important; max-width: 280px; }

.stage {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 6;
}
.rec-monitors {
  position: fixed;
  top: calc(14px + var(--top));
  right: 12px;
  z-index: 12;
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.rec-monitors[hidden] { display: none !important; }
.rec-monitors canvas {
  border-radius: 12px;
  border: 1px solid var(--glass-stroke);
  box-shadow: 0 10px 32px rgba(0,0,0,0.45);
  background: #0d0908;
}
#tape { width: 112px; height: 112px; }
#film { width: 200px; height: 112px; }

.modal {
  position: fixed; inset: 0; z-index: 30;
  background: var(--scrim);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.sheet {
  width: min(460px, 100%);
  background: var(--sheet);
  border: 1px solid var(--glass-stroke);
  border-radius: 22px;
  padding: 24px;
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
}
.export-sheet { width: min(420px, 100%); }
.sheet h3 {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 600;
}
.sheet p, .fine {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}
.help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
}
.keychip {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--quaternary);
  white-space: nowrap;
}
.choice {
  display: block; width: 100%; text-align: left;
  margin: 0 0 8px; padding: 10px;
  border-radius: 10px;
  border: 0;
  background: var(--quaternary);
}
.choice b { display: block; font-size: 14px; font-weight: 600; }
.choice span { font-size: 12px; color: var(--muted); }
.sheet-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.glass-btn {
  appearance: none;
  border: 1px solid var(--glass-stroke);
  background: var(--glass);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: inherit;
  text-decoration: none;
  display: inline-block;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 14px;
}
.field select {
  appearance: none;
  background: var(--quaternary);
  border: 1px solid var(--glass-stroke);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.settings-sheet { width: min(460px, 100%); }
.tabs {
  display: flex; gap: 6px; margin: 0 0 16px;
}
.tab {
  appearance: none; border: 0;
  background: var(--quaternary);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.55;
}
.tab.on { opacity: 1; background: var(--glass); border: 1px solid var(--glass-stroke); }
.switch-field {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.switch-field input[type="checkbox"] {
  appearance: none;
  width: 32px; height: 18px; border-radius: 999px;
  background: rgba(120, 120, 128, 0.32);
  position: relative; cursor: pointer;
}
.switch-field input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  transition: transform 160ms ease-out;
}
.switch-field input[type="checkbox"]:checked { background: #34c759; }
.switch-field input[type="checkbox"]:checked::after { transform: translateX(14px); }
#midi-refresh { margin-bottom: 12px; }
@media (display-mode: standalone) {
  .topbar { padding-top: calc(14px + var(--top)); }
}

@media (max-width: 860px) {
  .board { padding: 12px 14px; }
  .topbar, .bottombar { padding-left: 14px; padding-right: 14px; }
  .wave { display: none; }
  #help { margin-left: auto; }
  .row-bar { flex-wrap: wrap; }
  .pads { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pad { flex: 0 0 auto; min-width: 52px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .pad { height: 44px; }
  .pad.space { height: 40px; }
  .board { padding-top: 8px; padding-bottom: 6px; gap: 10px; }
  .brand p { max-width: 28vw; }
}

@media (prefers-reduced-motion: reduce) {
  .pad { transition: none; }
}
