/* ==================================================================
   Music Studio —— DAW 風格深色介面
   深色是音樂製作軟體的通用語言（Logic / Ableton / FL 皆然），
   長時間盯網格也比較不吃力；品牌紫粉只用在強調處。
   ================================================================== */

:root {
  --bg: #0d0d13;
  --panel: #15151f;
  --panel-2: #1c1c28;
  --line: #2a2a3a;
  --line-soft: #23232f;
  --txt: #e9e9f2;
  --txt-2: #b9b9cc;
  --muted: #8585a0;
  --brand: #7b6cf6;
  --brand-2: #5b4bd6;
  --pink: #e0398a;
  --grad: linear-gradient(135deg, #7b6cf6 0%, #e0398a 100%);
  --pad-off: #22222f;
  --pad-hover: #2d2d3e;
  --radius: 12px;
  --head-w: 118px;
  --pad-size: clamp(15px, 1.35vw, 22px);
  --font: "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.55;
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: rgba(21, 21, 31, .86);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(14px);
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--txt-2);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  transition: color .18s, border-color .18s, background .18s;
  flex: 0 0 auto;
}
.back:hover { color: var(--txt); border-color: var(--brand); background: var(--panel-2); }

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}
.topbar-title h1 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--grad);
  color: #fff;
  flex: 0 0 auto;
}

.topbar-right { flex: 0 0 auto; }

.lang-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.lang-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .16s, background .16s;
}
.lang-btn:hover { color: var(--txt); }
.lang-btn.active { background: var(--brand); color: #fff; }

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

.layout {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 268px;
  gap: 16px;
  padding: 16px 22px 32px;
  align-items: start;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: 250px minmax(0, 1fr); }
  .layout > aside:last-of-type { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > aside:first-of-type { order: 2; }
  .layout > aside:last-of-type { order: 3; }
}

.col { min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}
.panel-title:not(:first-child) { margin-top: 22px; }

/* ---------------- form ---------------- */

.field { margin-bottom: 14px; }
.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--txt-2);
  margin-bottom: 6px;
}
.field label .val { color: var(--brand); font-variant-numeric: tabular-nums; font-weight: 600; }

textarea, select, input[type="range"] {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  background: var(--panel-2);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
textarea { resize: vertical; min-height: 62px; line-height: 1.5; }
textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(123, 108, 246, .16);
}
select { cursor: pointer; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

input[type="range"] { padding: 0; height: 26px; background: transparent; border: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--line); border-radius: 999px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -6px; border-radius: 50%; background: var(--brand); border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--brand); }
input[type="range"]::-moz-range-track { height: 4px; background: var(--line); border-radius: 999px; }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--brand); border: 2px solid var(--panel); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.tip { font-size: 12px; color: var(--muted); margin-top: 12px; }

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .18s, border-color .18s, color .18s, transform .12s, box-shadow .18s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; margin-bottom: 8px; }

.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 4px 16px rgba(123, 108, 246, .26); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-outline { background: transparent; color: var(--txt); border-color: var(--line); }
.btn-outline:hover:not(:disabled) { border-color: var(--brand); color: #fff; background: rgba(123, 108, 246, .12); }

.btn-ghost { background: var(--panel-2); color: var(--txt-2); border-color: var(--line-soft); }
.btn-ghost:hover:not(:disabled) { color: var(--txt); border-color: var(--line); }

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

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.btn-play { background: var(--brand); color: #fff; }
.btn-play:hover { background: var(--brand-2); }
.btn-play.is-playing { background: var(--pink); }
.btn-stop { background: var(--panel-2); color: var(--txt-2); border-color: var(--line); }
.btn-stop:hover { color: var(--txt); }

.readout {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.readout .k { font-size: 10px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.readout .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); }

.loop-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--txt-2);
  cursor: pointer;
  margin-left: auto;
}
.loop-toggle input { accent-color: var(--brand); width: 15px; height: 15px; }

/* ---------------- grid ---------------- */

.grid-scroll {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 0 12px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.grid-ruler, .tracks { min-width: max-content; }

.row-head {
  position: sticky;
  left: 0;
  z-index: 3;
  flex: 0 0 var(--head-w);
  width: var(--head-w);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  font-size: 12px;
  color: var(--txt-2);
  min-height: 26px;
}
.row-head .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-head .sub { font-size: 10px; color: var(--muted); }
.row-head .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.row-head.small { justify-content: flex-end; padding-right: 8px; }
.row-head.small .note { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

.grid-ruler { display: flex; margin-bottom: 6px; padding-bottom: 2px; }
.grid-ruler .row-head { min-height: 20px; }
.ruler-cell {
  flex: 0 0 var(--pad-size);
  width: var(--pad-size);
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--muted);
  position: relative;
  border-left: 1px solid var(--line-soft);
}
.ruler-cell.beat { color: var(--txt-2); }
.ruler-cell.bar-start { border-left: 1px solid var(--line); }
.ruler-num { font-variant-numeric: tabular-nums; font-weight: 600; }
.ruler-cell.playing { color: var(--brand); background: rgba(123, 108, 246, .12); border-radius: 4px; }

.tracks { display: flex; flex-direction: column; gap: 1px; }

.track { display: flex; align-items: stretch; }
.track .row-head { border-bottom: 1px solid var(--line-soft); }

.pads {
  display: grid;
  grid-template-columns: repeat(var(--steps, 64), var(--pad-size));
  flex: 1 1 auto;
}

.pad {
  height: 26px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: var(--pad-off);
  cursor: pointer;
  position: relative;
  transition: background .1s;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pad:hover { background: var(--pad-hover); }
.pad.beat { border-left-color: #33333f; }
.pad.bar-start { border-left: 1px solid var(--line); }

.pad[data-on="1"] {
  background: var(--pad-color, var(--brand));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.pad[data-on="1"]:hover { filter: brightness(1.14); }

.pad.playing {
  outline: 2px solid rgba(255, 255, 255, .55);
  outline-offset: -2px;
  z-index: 2;
}
.pad[data-on="1"].playing { filter: brightness(1.35); }

.pad-label .pad-txt {
  font-size: 8.5px;
  font-weight: 600;
  color: rgba(255, 255, 255, .9);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  letter-spacing: -.02em;
}

/* 旋律卷簾 */
.track-melody { flex-direction: column; }
.melody-head { width: 100%; flex: 0 0 auto; position: static; border-right: 0; padding: 8px 12px; background: var(--panel-2); margin-top: 4px; }
.melody-body { display: flex; flex-direction: column; }
.melody-row { display: flex; align-items: stretch; }
/* 卷簾的音名列跟 pad 同高，整行才不會被 min-height 撐開 */
.melody-row .row-head.small { min-height: 0; }
.pad-melody { height: 17px; }

/* ---------------- chord info ---------------- */

.chord-info { margin-top: 14px; }
.ci-head { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.ci-list { display: grid; gap: 5px; }
.ci-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  font-size: 12px;
}
.ci-bar { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 12px; }
.ci-name { font-weight: 700; color: var(--txt); }
.ci-type { font-size: 10px; color: var(--pink); font-weight: 700; }

/* ---------------- mixer ---------------- */

.mixer { display: grid; gap: 8px; }
.mx-row {
  display: grid;
  grid-template-columns: 8px 52px 1fr;
  align-items: center;
  gap: 8px;
}
.mx-row .dot { width: 8px; height: 8px; border-radius: 50%; }
.mx-name { font-size: 12px; color: var(--txt-2); }

/* ---------------- 云端同步 ---------------- */

.cloud-bar {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-top: 10px; padding: 7px 10px;
  background: var(--panel-2); border: 1px solid var(--line-soft);
  border-radius: 9px; font-size: 11.5px; min-height: 36px;
}
.cloud-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: #2ec4b6; box-shadow: 0 0 0 3px rgba(46, 196, 182, .16);
}
.cloud-text {
  color: var(--muted); min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 150px;
}
.cloud-quota { color: var(--muted); opacity: .65; font-variant-numeric: tabular-nums; }
.cloud-btn {
  margin-left: auto; flex: 0 0 auto;
  background: transparent; border: 1px solid var(--line);
  color: var(--brand); font-family: inherit; font-size: 11.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; cursor: pointer; text-decoration: none;
  transition: background .16s, border-color .16s, color .16s;
}
.cloud-btn:hover:not(:disabled) { background: var(--brand); color: #fff; border-color: var(--brand); }
.cloud-btn:disabled { opacity: .55; cursor: default; color: var(--muted); }
.cloud-err { flex-basis: 100%; color: #ff8fab; }

/* ---------------- projects ---------------- */

.projects { display: grid; gap: 7px; margin-top: 12px; }
.proj {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
}
.proj-info { flex: 1 1 auto; min-width: 0; display: grid; }
.proj-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proj-meta { font-size: 10.5px; color: var(--muted); }
.proj-cloud { font-size: 10px; color: #2ec4b6; }
.proj-acts { display: flex; gap: 5px; flex: 0 0 auto; }
.mini {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--txt-2);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 7px;
  cursor: pointer;
  transition: color .16s, border-color .16s, background .16s;
}
.mini:hover { color: #fff; border-color: var(--brand); background: rgba(123, 108, 246, .16); }
.mini.danger:hover { border-color: var(--pink); background: rgba(224, 57, 138, .16); }

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: var(--panel-2);
  color: var(--txt);
  border: 1px solid var(--line);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
  z-index: 100;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--pink); color: #ffd9e8; }

/* ---------------- 行動端微調 ---------------- */

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .back span { display: none; }
  .topbar-title h1 { font-size: 14px; }
  .layout { padding: 12px 12px 24px; }
  :root { --head-w: 92px; --pad-size: 17px; }
  .transport { gap: 8px; }
  .readout { padding: 4px 9px; }
}
