/* ============================================================
   LEITMOTIF STUDIO — noir atelier design system
   ============================================================ */

:root {
  --bg0: #0b0d15;
  --bg1: #10131f;
  --bg2: #161a2a;
  --panel: rgba(22, 26, 42, 0.72);
  --panel-solid: #151928;
  --line: rgba(160, 170, 210, 0.14);
  --line-strong: rgba(160, 170, 210, 0.26);
  --ink: #e9e3d3;
  --ink-dim: #9aa0b4;
  --ink-faint: #6a7085;
  --acc: #d9a84e;
  --acc-bright: #f0c470;
  --acc-soft: rgba(217, 168, 78, 0.14);
  --acc-glow: rgba(217, 168, 78, 0.35);
  --danger: #d96a5e;
  --radius: 14px;
  --font-display: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", Georgia, serif;
  --font-ui: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}

html[data-genre="fantasy"] {
  --bg0: #0a1210;
  --bg1: #0e1815;
  --bg2: #14201c;
  --panel: rgba(19, 31, 27, 0.74);
  --panel-solid: #13201b;
  --line: rgba(150, 210, 185, 0.13);
  --line-strong: rgba(150, 210, 185, 0.26);
  --ink: #e4ecdf;
  --acc: #57c3a0;
  --acc-bright: #7fdec0;
  --acc-soft: rgba(87, 195, 160, 0.13);
  --acc-glow: rgba(87, 195, 160, 0.35);
}

html[data-genre="horror"] {
  --bg0: #100b0e;
  --bg1: #150e12;
  --bg2: #1d1319;
  --panel: rgba(28, 18, 24, 0.76);
  --panel-solid: #1b1218;
  --line: rgba(220, 150, 165, 0.12);
  --line-strong: rgba(220, 150, 165, 0.24);
  --ink: #e8dfe0;
  --acc: #c8515c;
  --acc-bright: #e57782;
  --acc-soft: rgba(200, 81, 92, 0.14);
  --acc-glow: rgba(200, 81, 92, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 75% -10%, var(--acc-soft), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(90, 110, 180, 0.08), transparent 55%),
    linear-gradient(165deg, var(--bg1), var(--bg0) 55%);
  background-attachment: fixed;
  overflow: hidden;
  font-size: 13.5px;
  line-height: 1.55;
  transition: background 0.5s ease;
}

/* film grain + vignette */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="140" height="140"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2"/><feColorMatrix type="saturate" values="0"/></filter><rect width="140" height="140" filter="url(%23n)" opacity="0.5"/></svg>');
  opacity: 0.045;
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 40%, transparent 60%, rgba(0, 0, 0, 0.42));
}

#app { position: relative; z-index: 1; height: 100vh; display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(160, 170, 210, 0.16);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(160, 170, 210, 0.3); }
::-webkit-scrollbar-corner { background: transparent; }

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }

input, select {
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  outline: none;
}
input:focus, select:focus { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }

svg { display: block; }

/* ---------- header ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 12px 22px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.025), transparent);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 13px; }

.brand-mark {
  width: 40px; height: 40px;
  border: 1px solid var(--acc);
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--acc);
  font-size: 19px;
  font-family: var(--font-display);
  box-shadow: 0 0 18px var(--acc-glow), inset 0 0 10px var(--acc-soft);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 19px;
  letter-spacing: 0.22em;
  color: var(--ink);
  font-weight: 600;
}
.brand-text h1 .brand-sub {
  font-size: 11px;
  letter-spacing: 0.34em;
  color: var(--acc);
  margin-left: 8px;
}
.brand-text p { font-size: 10.5px; color: var(--ink-faint); letter-spacing: 0.08em; margin-top: 1px; }

.genre-tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}

.genre-tab {
  padding: 7px 18px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  transition: all 0.22s ease;
}
.genre-tab:hover { color: var(--ink); background: rgba(255, 255, 255, 0.04); }
.genre-tab.active {
  color: var(--acc-bright);
  background: var(--acc-soft);
  box-shadow: inset 0 0 0 1px var(--acc-glow);
  font-weight: 600;
}

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 296px 1fr;
  gap: 14px;
  padding: 14px 18px;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 2px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  font-weight: 600;
}

/* ---------- theme panel ---------- */

#themePanel { padding: 16px 16px 14px; flex: none; }

.theme-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--acc);
  margin-bottom: 5px;
}

.game-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.35;
  text-shadow: 0 0 24px var(--acc-glow);
}

.theme-tagline {
  font-size: 11px;
  color: var(--ink-faint);
  margin: 4px 0 12px;
  font-family: var(--font-display);
  letter-spacing: 0.06em;
}

.motif-box {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.motif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}

.mini-btn {
  width: 24px; height: 24px;
  border-radius: 6px;
  color: var(--acc);
  display: grid; place-items: center;
  border: 1px solid var(--line);
  transition: all 0.18s;
}
.mini-btn:hover { background: var(--acc-soft); border-color: var(--acc); }
.mini-btn svg { width: 13px; height: 13px; }

.motif-svg { width: 100%; height: 58px; color: var(--ink); }

.motif-key { font-size: 11px; color: var(--ink-dim); display: flex; align-items: center; gap: 4px; }
.motif-key input { width: 62px; padding: 2px 6px; font-size: 11px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12.5px;
  letter-spacing: 0.03em;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--acc); background: var(--acc-soft); }
.btn svg { width: 15px; height: 15px; }

.btn-accent {
  border-color: var(--acc);
  color: var(--acc-bright);
  background: var(--acc-soft);
}
.btn-accent:hover { box-shadow: 0 0 16px var(--acc-glow); background: var(--acc-soft); }

.btn-wide { width: 100%; justify-content: center; padding: 10px; }

.theme-note {
  margin-top: 10px;
  font-size: 10.5px;
  color: var(--ink-faint);
  line-height: 1.65;
}

/* ---------- scene panel ---------- */

#scenePanel, #lengthPanel { padding: 13px 12px; flex: none; }
#scenePanel .panel-title, #lengthPanel .panel-title { margin: 0 4px 10px; }

.scene-list { display: flex; flex-direction: column; gap: 6px; }

.scene-card {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.025);
  text-align: left;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.scene-card:hover {
  background: rgba(255, 255, 255, 0.055);
  border-color: var(--line-strong);
  transform: translateX(2px);
}
.scene-card.active {
  border-color: var(--acc);
  background: var(--acc-soft);
  box-shadow: inset 3px 0 0 var(--acc), 0 4px 18px rgba(0, 0, 0, 0.3);
}

.scene-icon {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 9px;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  transition: all 0.2s;
}
.scene-icon svg { width: 18px; height: 18px; }
.scene-card.active .scene-icon { color: var(--acc-bright); border-color: var(--acc-glow); box-shadow: 0 0 12px var(--acc-soft); }

.scene-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.scene-name { font-size: 13px; font-weight: 600; letter-spacing: 0.05em; }
.scene-sub { font-size: 10px; color: var(--ink-faint); letter-spacing: 0.03em; }
.scene-card.active .scene-sub { color: var(--ink-dim); }

.scene-meta {
  font-size: 9.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* equalizer bars while playing */
.scene-eq { display: none; align-items: flex-end; gap: 2px; height: 14px; flex: none; }
.scene-card.playing .scene-eq { display: flex; }
.scene-card.playing .scene-meta { display: none; }
.scene-eq i {
  width: 3px;
  background: var(--acc);
  border-radius: 2px;
  animation: eq 0.7s ease-in-out infinite;
}
.scene-eq i:nth-child(1) { animation-delay: 0s; }
.scene-eq i:nth-child(2) { animation-delay: 0.22s; }
.scene-eq i:nth-child(3) { animation-delay: 0.44s; }
@keyframes eq {
  0%, 100% { height: 4px; }
  50% { height: 14px; }
}

/* ---------- length panel ---------- */

.length-list { display: flex; flex-direction: column; gap: 5px; }

.len-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.025);
  text-align: left;
  transition: all 0.2s ease;
}
.len-row:hover { background: rgba(255, 255, 255, 0.055); border-color: var(--line-strong); }
.len-row.active {
  border-color: var(--acc);
  background: var(--acc-soft);
  box-shadow: inset 3px 0 0 var(--acc);
}

.len-bars {
  font-family: var(--font-display);
  font-size: 19px;
  width: 52px;
  flex: none;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.len-row.active .len-bars { color: var(--acc-bright); }
.len-bars small { font-size: 9.5px; margin-left: 2px; letter-spacing: 0.04em; }

.len-info { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.len-info b { font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em; }
.len-blocks { display: flex; gap: 2px; height: 5px; }
.len-blocks i { border-radius: 3px; opacity: 0.75; }

/* ---------- structure panel ---------- */

.structure-panel { padding: 12px 16px 8px; flex: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.structure-meta { display: flex; gap: 6px; }

.meta-chip {
  font-size: 10.5px;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

#structureView { width: 100%; }
.struct-svg { display: block; color: var(--ink); cursor: pointer; }
.struct-svg .chord-lb { fill: var(--ink-faint); font-size: 10px; font-family: var(--font-display); }
.struct-svg .bar-num { fill: var(--ink-faint); font-size: 9px; }
.struct-sec { cursor: pointer; }
.struct-sec:hover rect { fill-opacity: 0.32; }

/* ---------- transport ---------- */

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

.play-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--acc);
  color: #14120b;
  display: grid; place-items: center;
  box-shadow: 0 0 22px var(--acc-glow);
  transition: all 0.2s ease;
  flex: none;
}
.play-btn:hover { transform: scale(1.06); box-shadow: 0 0 30px var(--acc-glow); }
.play-btn svg { width: 20px; height: 20px; margin-left: 1px; }
.play-btn.playing svg { margin-left: 0; }

.ctl-btn {
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  display: grid; place-items: center;
  transition: all 0.18s;
  flex: none;
}
.ctl-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.ctl-btn.active { color: var(--acc-bright); border-color: var(--acc); background: var(--acc-soft); }
.ctl-btn svg { width: 15px; height: 15px; }

.pos-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 4px 14px;
  min-width: 86px;
}
#posDisplay {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-family: var(--font-display);
  color: var(--acc-bright);
  letter-spacing: 0.1em;
}
.pos-key { font-size: 8.5px; color: var(--ink-faint); letter-spacing: 0.04em; white-space: nowrap; }

.t-group { display: flex; align-items: center; gap: 6px; }
.t-group label { font-size: 10.5px; color: var(--ink-faint); letter-spacing: 0.06em; white-space: nowrap; }
.t-group.grow { flex: 1; min-width: 150px; }
.t-group.grow select { width: 100%; }
#tempoInput { width: 58px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  background: var(--line-strong);
  border: none;
  border-radius: 3px;
  padding: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 0 8px var(--acc-glow);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--acc);
  cursor: pointer;
}

.t-sep { width: 1px; height: 26px; background: var(--line); flex: none; }

/* ---------- piano roll ---------- */

.proll-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 260px;
  overflow: hidden;
}

.proll-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.proll-title {
  font-family: var(--font-display);
  font-size: 12.5px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  margin-right: 4px;
}

.track-chips { display: flex; gap: 5px; flex-wrap: wrap; }

.track-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 9px;
  border-radius: 20px;
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-dim);
  transition: all 0.18s;
}
.track-chip i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.track-chip:hover { border-color: var(--line-strong); color: var(--ink); }
.track-chip.active {
  border-color: var(--acc);
  color: var(--ink);
  background: var(--acc-soft);
  font-weight: 600;
}
.track-chip.hidden-track { opacity: 0.45; }
.chip-eye { display: grid; place-items: center; opacity: 0.7; }
.chip-eye:hover { opacity: 1; }
.chip-eye svg { width: 12px; height: 12px; }

.tool-box {
  display: flex;
  gap: 3px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
}

.tool-btn {
  width: 28px; height: 26px;
  border-radius: 6px;
  color: var(--ink-dim);
  display: grid; place-items: center;
  font-size: 13px;
  transition: all 0.15s;
}
.tool-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.05); }
.tool-btn.active { color: var(--acc-bright); background: var(--acc-soft); }
.tool-btn svg { width: 14px; height: 14px; }

.edited-badge {
  margin-left: auto;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--acc-bright);
  border: 1px solid var(--acc-glow);
  background: var(--acc-soft);
  padding: 3px 10px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.edited-badge.show { opacity: 1; }

.proll-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--bg0);
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 0;
}

.pr-spacer { position: absolute; top: 0; left: 0; pointer-events: none; }

.pr-grid, .pr-keys, .pr-ruler, .pr-corner {
  position: absolute;
  display: block;
  will-change: transform;
}
.pr-grid { z-index: 1; touch-action: none; }
.pr-keys { z-index: 2; cursor: pointer; }
.pr-ruler { z-index: 2; cursor: pointer; }
.pr-corner {
  z-index: 3;
  top: 0; left: 0;
  width: 64px; height: 30px;
  background: #101320;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: grid; place-items: center;
  color: var(--acc);
  font-size: 13px;
}

/* ---------- footer / toasts ---------- */

.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 20px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
  flex-wrap: wrap;
}
.statusbar .dot { opacity: 0.4; }
.statusbar .grow { margin-left: auto; color: var(--ink-faint); opacity: 0.8; }

.toasts {
  position: fixed;
  right: 20px;
  bottom: 44px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}

.toast {
  background: var(--panel-solid);
  border: 1px solid var(--acc-glow);
  border-left: 3px solid var(--acc);
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0.03em;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  body { overflow: auto; }
  #app { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { overflow: visible; flex-direction: row; flex-wrap: wrap; }
  .sidebar > .panel { flex: 1 1 280px; }
  .proll-panel { min-height: 380px; }
  .proll-scroll { height: 320px; }
  .topbar { flex-wrap: wrap; gap: 12px; }
  .genre-tabs { margin-left: 0; }
}
