/*
 * A research instrument, not a product: everything on screen is either a
 * measurement, a coordinate, or a control that changes what is measured. The
 * dark ground is so the timeline's own lines are the brightest thing here.
 */

:root {
  --bg: #101319;
  --panel: #181c24;
  --panel-2: #1f2430;
  --line: #2c3340;
  --text: #e9edf5;
  --muted: #98a2b3;
  --accent: #6ea8fe;
  --playhead: #ff5a5f;
  --grid-1: #6ea8fe;
  --grid-2: #f9a03f;
  --grid-3: #7bd88f;
  --grid-4: #e07be0;
  --grid-5: #6fd7e0;
  --grid-6: #ffd166;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

body { display: flex; flex-direction: column; overflow: hidden; }

.muted { color: var(--muted); }
.fineprint { color: var(--muted); font-size: 11px; margin: 6px 0 0; }

/* --------------------------------------------------------------------- top */

.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.title strong { font-size: 14px; }
.title .muted { margin-left: 8px; font-size: 12px; }
.file {
  margin-left: auto; cursor: pointer; font-size: 12px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); color: var(--text);
}
.file + .file { margin-left: 0; }
.file input { display: none; }
.file:hover { border-color: var(--accent); }

.warnings {
  padding: 8px 14px; background: #3a2a12; border-bottom: 1px solid #6b4a17;
  color: #ffd9a0; font-size: 12px; max-height: 130px; overflow: auto;
}
.warnings ul { margin: 4px 0 0; padding-left: 18px; }
.warnings.bad { background: #40191c; border-color: #7c2b31; color: #ffc2c6; }

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

.transport {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.spacer { flex: 1; }

button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: #23364f; border-color: #33507a; }
button.ghost { background: transparent; color: var(--muted); }
button.tiny { padding: 2px 6px; font-size: 11px; }
#play { min-width: 46px; font-size: 14px; }

.clock { font-variant-numeric: tabular-nums; font-size: 13px; letter-spacing: .3px; }
.warn { color: #ffd166; }
.zoom { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.zoom input { width: 170px; }
.follow { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* ------------------------------------------------------------------- main */

main { flex: 1; display: flex; min-height: 0; }

.timeline-wrap { position: relative; flex: 1; min-width: 0; }
.timeline { height: 100%; overflow: auto; background: var(--bg); }
.content { position: relative; min-width: 100%; }

.empty { position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; text-align: center;
  color: var(--muted); pointer-events: none; }
.empty code { color: var(--text); background: var(--panel-2); padding: 1px 4px; border-radius: 3px; }

/* ------------------------------------------------------------------ lanes */

.lane { position: relative; border-bottom: 1px solid var(--line); }
.lane-label {
  position: sticky; left: 0; z-index: 6;
  display: inline-block; padding: 2px 8px 2px 6px; margin: 2px 0 0 2px;
  background: rgba(24, 28, 36, .92); border-radius: 0 4px 4px 0;
  font-size: 11px; color: var(--muted); white-space: nowrap;
  border-left: 3px solid var(--grid-color, var(--line));
  /* 说明文字默认不显示（研究者：挡视线）。信息没有丢：光标移到这一轨上就淡入，
     也可以看每轨的悬停提示。 */
  opacity: 0; transition: opacity .12s ease;
  pointer-events: none;
}
.lane:hover .lane-label, .lane:focus-within .lane-label { opacity: 1; }
.lane.ruler { height: 24px; background: var(--panel); }
.lane.ruler .lane-label { color: var(--text); }
.lane.events { min-height: 22px; }
.lane.grid { height: 46px; }

/* 和弦层：每条读法一条轨道，画在同一张时间轴上（数据来自 music_explorer 的 harmony.json）。
   一格一个标签，三条读法不一致的格子加边框——那才是值得上耳朵的地方。 */
.lane.chords { height: 18px; }
.lane.chords .chord {
  position: absolute; top: 1px; height: 15px; line-height: 15px;
  font-size: 10px; padding: 0 2px; overflow: hidden; white-space: nowrap;
  border-radius: 2px; background: rgba(110, 168, 254, .16);
  box-shadow: inset 0 0 0 1px rgba(110, 168, 254, .35);
  cursor: pointer;
}
.lane.chords[data-source="chart"] .chord { background: rgba(255, 217, 160, .14);
  box-shadow: inset 0 0 0 1px rgba(255, 217, 160, .3); }
.lane.chords[data-source="madmom"] .chord { background: rgba(160, 255, 200, .12);
  box-shadow: inset 0 0 0 1px rgba(160, 255, 200, .28); }
.lane.chords .chord.disagree { box-shadow: inset 0 0 0 2px #ff8fab; }
.lane.chords .chord .deg {
  margin-left: 3px; font-size: 9px; opacity: .75; vertical-align: super;
}
.lane.chords .chord .deg.rootonly { opacity: .45; }     /* 只有根音落在音阶上：浅色 */

/* 歌单在上、时间轴在下：这一条是"上层"，选一首就换下面整条时间轴。 */
.songbar {
  display: flex; align-items: center; gap: 14px;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.songbar select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 6px; min-width: 260px; font-size: 13px;
}

.tick {
  position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line);
}
.tick span {
  position: sticky; left: 4px; display: inline-block; padding-left: 3px;
  font-size: 10px; color: var(--muted); white-space: nowrap;
}

/* A bar is a block, because clicking one has to mean "go to this bar". */
.bar {
  position: absolute; top: 0; bottom: 0;
  border-left: 3px solid var(--grid-color);
  background: rgba(255, 255, 255, .02);
  cursor: pointer;
}
.bar.alt { background: rgba(255, 255, 255, .05); }
.bar:hover { background: rgba(110, 168, 254, .18); }
.bar.selected { box-shadow: inset 0 0 0 2px #fff; }

/* 边界邻域：围绕小节线 ±0.5 拍的关联窗口（Boundary Association）。
   小节线本身仍是那条 3px 细线（.bar 的 border-left），这里只是给它加一层淡色，
   不遮挡事件层；宽度直接取布局算好的 --beat（一拍多少像素），所以缩放时自动跟着变。
   默认关着：一个曲库里常有 3–5 条网格，全亮会糊成一片。 */
.bar .boundary-near {
  position: absolute; top: 0; bottom: 0;
  left: calc(-0.5 * var(--beat)); width: var(--beat);
  background: var(--grid-color); opacity: .13;
  pointer-events: none;
}
body:not(.show-near) .bar .boundary-near { display: none; }

/* Grid Pair Diff 的三色高亮：同一个事件能不能被两边都解释成"发生在小节切换附近"。 */
.evt.diff-shared { box-shadow: 0 0 0 2px #79d18a; }
.evt.diff-a-only { box-shadow: 0 0 0 2px #6ea8fe; }
.evt.diff-b-only { box-shadow: 0 0 0 2px #ffd479; }
.evt.diff-machine { opacity: .55; }

/* 整首热力带：一格一小节，颜色越红分歧越大；格子可点，点了就跳过去。 */
.heat-strip { display: flex; margin-top: 6px; height: 14px; border-radius: 3px; overflow: hidden; }
.heat-strip span { flex: 1 1 0; cursor: pointer; }
.heat-strip span:hover { outline: 1px solid #fff; }
/* A bar that is not a whole bar. It has to be visible at a glance, because it is
   the thing the whole multi-grid question is about - the half-bar. */
.bar.short {
  background: repeating-linear-gradient(135deg,
    rgba(255, 143, 171, .30) 0 4px, rgba(255, 143, 171, .06) 4px 9px);
}
.bar.short .bar-no { color: #ff8fab; font-weight: 600; }
.bar::after {
  content: ''; position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    to right, rgba(233, 237, 245, .34) 0 1px, transparent 1px var(--beat, 40px));
  pointer-events: none;
}
.bar-no {
  position: absolute; top: 1px; left: 5px; font-size: 10px;
  color: var(--muted); pointer-events: none;
}
.bar-head { position: absolute; top: 0; left: -3px; width: 3px; background: var(--grid-color); }

/* ----------------------------------------------------------------- events */

.evt {
  position: absolute; height: 16px; line-height: 16px; font-size: 11px;
  text-align: center; border-radius: 3px; cursor: pointer;
  color: #0d1015; font-weight: 600; overflow: hidden; white-space: nowrap;
}
.evt.point { width: 18px; padding: 0; }
.evt.span { padding: 0 4px; text-align: left; }
.evt:hover { filter: brightness(1.2); }
.evt.selected { box-shadow: 0 0 0 2px #fff; }
.evt.shape-span, .evt.part-bass { background: #f9a03f; }
.evt.part-guitar { background: #6ea8fe; }
.evt.part-drums { background: #7bd88f; }
.evt.part-piano { background: #e07be0; }
.evt.part-vocal { background: #ff8fab; }
.evt.part-other { background: #b9c2d0; }
.evt.shape-meter { background: #ffd166; }
.evt.shape-tempo { background: #6fd7e0; }
.evt.shape-halfbar { background: #ff8fab; }
.evt.shape-dot { background: #b9c2d0; }

/* IN points up, OUT points down, so a pair reads as one thing opening and closing. */
.evt.shape-in { border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.evt.shape-out { border-top-left-radius: 0; border-top-right-radius: 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%); }
.evt.shape-dot { border-radius: 50%; }
.evt.shape-meter { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.evt.shape-tempo { clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.evt.shape-halfbar { border-radius: 0; }

.playhead {
  position: absolute; top: 0; bottom: 0; width: 2px; background: var(--playhead);
  z-index: 8; pointer-events: none;
}
.playhead i {
  position: absolute; top: 0; left: -5px; width: 0; height: 0;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 9px solid var(--playhead);
}

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

.panel {
  width: 340px; flex: none; overflow-y: auto;
  border-left: 1px solid var(--line); background: var(--panel);
}
.panel section { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.panel h2 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-weight: 600;
  text-transform: none; letter-spacing: .3px; }

.coords dl, #phase dl { margin: 0; }
.coord-row { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.coord-row .key { min-width: 74px; color: var(--muted); font-size: 11px; }
.coord-row .val { font-variant-numeric: tabular-nums; }
.big-time { font-size: 18px; font-variant-numeric: tabular-nums; margin: 0 0 6px; }

.grid-row { border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; margin-bottom: 6px; }
.grid-row .head { display: flex; align-items: center; gap: 6px; }
.grid-row .swatch { width: 9px; height: 9px; border-radius: 2px; background: var(--grid-color); flex: none; }
.grid-row .name { font-weight: 600; }
.grid-row .spec { color: var(--muted); font-size: 11px; }
.grid-row .actions { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.grid-row .count { color: var(--muted); font-size: 11px; margin-top: 4px; }
.grid-row.hidden { opacity: .45; }

.filter-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 12px; }
.filter-row .dot { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.dot.shape-in { background: #6ea8fe; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.dot.shape-out { background: #6ea8fe; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.dot.shape-meter { background: #ffd166; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.dot.shape-tempo { background: #6fd7e0; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.dot.shape-halfbar { background: #ff8fab; }
.dot.shape-dot { background: #b9c2d0; border-radius: 50%; }
.filter-row .lane-tag { color: var(--muted); font-size: 11px; margin-left: auto; }

.warnings hr { border: none; border-top: 1px solid currentColor; opacity: .35; margin: 6px 0; }
.tiny { font-size: 11px; margin: 4px 0 0; padding-left: 16px; }

.marker-form { display: flex; flex-direction: column; gap: 6px; }
.marker-form select, .marker-form input, .panel input[type=text] {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; width: 100%;
}
.two { display: flex; gap: 6px; }

.record { border-left: 2px solid var(--line); padding: 4px 0 4px 8px; margin: 6px 0; font-size: 12px; }
.record .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.record .del { float: right; }
.save-row { display: flex; gap: 6px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: #0b0e13; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font-size: 11px; line-height: 1.45; max-width: 260px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.tooltip b { color: var(--text); }

/* Dropping files anywhere on the page pairs them by name. */
body.dropping::after {
  content: '松手：按名字自动配对音频和 JSON'; position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(16, 19, 25, .82); border: 2px dashed var(--accent);
  color: var(--text); font-size: 18px; pointer-events: none;
}

@media (max-width: 900px) {
  main { flex-direction: column; }
  .panel { width: auto; max-height: 46%; border-left: none; border-top: 1px solid var(--line); }
}
