:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #191b20;
  --panel-soft: #20242b;
  --line: #323743;
  --text: #f3f6f8;
  --muted: #a9b0bc;
  --accent: #2fd1a6;
  --accent-strong: #62e6c3;
  --danger: #ff6b6b;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(47, 209, 166, 0.09), transparent 240px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
output {
  font: inherit;
}

button,
.fileButton {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button:hover,
.fileButton:hover {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #07120f;
  border-color: var(--accent);
  font-weight: 700;
}

.modeToggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111419;
}

.modeToggle button {
  min-height: 34px;
  border-color: transparent;
  padding: 0 12px;
}

.modeToggle button.active {
  background: var(--accent);
  color: #07120f;
  font-weight: 700;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  margin: 8px 0 0;
}

.fileButton input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.transport,
.details {
  background: rgba(25, 27, 32, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  flex-wrap: wrap;
}

.speedControl,
.timbreControl {
  flex: 1 1 280px;
  display: grid;
  grid-template-columns: auto minmax(130px, 1fr) 58px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.timbreControl {
  flex: 0 1 240px;
  grid-template-columns: auto minmax(130px, 1fr);
}

.timbreControl select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 8px;
}

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

.timeReadout {
  min-width: 132px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.timeline {
  padding: 12px 2px 10px;
}

.overlayControls {
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.overlayControls label {
  width: min(340px, 100%);
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) 48px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.hotkeyHint {
  color: var(--muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.sideDrawer {
  --drawer-tab-width: 46px;
  --drawer-tab-top: 16px;
  position: fixed;
  z-index: 20;
  top: 88px;
  right: 0;
  bottom: 24px;
  width: clamp(320px, 32vw, 680px);
  transform: translateX(calc(100% - var(--drawer-tab-width)));
  transition: transform 180ms ease;
  pointer-events: none;
}

.sideDrawer.open {
  transform: translateX(0);
}

body.drawerOpen .sideDrawer.collapsed {
  transform: translateX(0);
}

.sideDrawer.collapsed .drawerPanel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sideDrawer.open .drawerPanel {
  opacity: 1;
  visibility: visible;
}

.appearanceDrawer {
  --drawer-tab-top: 156px;
  z-index: 22;
}

.midiLibrary {
  --drawer-tab-top: 16px;
  z-index: 21;
}

.drawerTab {
  position: absolute;
  z-index: 2;
  left: 0;
  top: var(--drawer-tab-top);
  width: var(--drawer-tab-width);
  min-height: 132px;
  padding: 10px 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  border-radius: 8px 0 0 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #07120f;
  font-weight: 800;
  pointer-events: auto;
}

.drawerPanel {
  height: 100%;
  margin-left: var(--drawer-tab-width);
  overflow: auto;
  background: rgba(17, 20, 25, 0.96);
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  backdrop-filter: blur(10px);
}

.presetBar,
.customPresetBar {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 12px;
  padding: 14px 14px 0;
  flex-wrap: wrap;
}

.customPresetBar {
  justify-content: flex-start;
  padding-top: 12px;
}

.presetBar label,
.customPresetBar label {
  min-width: min(260px, 100%);
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.presetBar select,
.customPresetBar input {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 8px;
}

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

.appearanceGrid label {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.appearanceGrid label:has(input[type="range"]) {
  grid-template-columns: 1fr minmax(92px, 1.4fr) 48px;
  align-items: center;
}

.appearanceGrid input[type="color"] {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 3px;
}

.appearanceGrid select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 8px;
}

.appearanceGrid output {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.visualizer {
  position: relative;
  display: grid;
  grid-template-columns: 66px 1fr;
  height: min(68vh, 720px);
  min-height: 520px;
  background: #0d0f12;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.visualizer.fallingMode {
  grid-template-columns: 1fr;
  background: #000;
}

.visualizer.fallingMode .keyboard {
  display: none;
}

.keyboard {
  position: relative;
  background: #15181d;
  border-right: 1px solid var(--line);
  min-height: 520px;
}

.keyLabel {
  position: absolute;
  left: 0;
  width: 100%;
  transform: translateY(-50%);
  color: #d8dde5;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  padding-right: 8px;
  text-align: right;
  pointer-events: none;
}

.keyLabel.black {
  color: #788292;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: 520px;
  display: block;
}

.libraryPanel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
  padding: 12px;
}

.libraryHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.libraryHeader strong,
.libraryHeader span {
  display: block;
}

.libraryHeader span {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#libraryFolderInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.librarySearch {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 10px;
}

.libraryList {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.librarySong {
  width: 100%;
  min-height: 44px;
  margin: 0 0 6px;
  justify-content: flex-start;
  gap: 8px;
  border-radius: 8px;
  padding: 7px 10px;
  text-align: left;
}

.librarySong.active {
  background: rgba(47, 209, 166, 0.16);
  border-color: var(--accent);
}

.librarySongText {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.librarySongTitle,
.librarySongPath,
.libraryEmpty {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.librarySongTitle {
  color: var(--text);
  font-weight: 700;
}

.librarySongPath,
.libraryEmpty {
  color: var(--muted);
  font-size: 0.8rem;
}

.libraryEmpty {
  padding: 16px 8px;
}

.emptyState {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  padding: 24px;
}

.emptyState strong {
  color: var(--text);
  font-size: 1.2rem;
}

.emptyState.hidden {
  display: none;
}

.details {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
}

.details > div {
  background: rgba(32, 36, 43, 0.72);
  padding: 16px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.details strong {
  font-size: 1.05rem;
}

@media (max-width: 760px) {
  .app {
    width: min(100vw - 20px, 1180px);
    padding: 14px 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .fileButton {
    width: 100%;
  }

  .transport {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modeToggle {
    grid-column: 1 / -1;
    width: 100%;
  }

  .modeToggle button {
    flex: 1;
  }

  .speedControl,
  .timbreControl,
  .timeReadout {
    grid-column: 1 / -1;
  }

  .timeReadout {
    justify-content: flex-start;
  }

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

  .presetBar,
  .customPresetBar {
    align-items: stretch;
    flex-direction: column;
  }

  .sideDrawer {
    top: 72px;
    bottom: 12px;
    width: calc(100vw - 8px);
  }

  .visualizer {
    grid-template-columns: 48px 1fr;
    min-height: 430px;
  }

  .keyboard,
  canvas {
    min-height: 430px;
  }

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

}

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