:root {
  color-scheme: dark;
  --bg: #1a1b26;
  --surface: #1f2335;
  --surface-2: #292e42;
  --border: #2f354b;
  --border-strong: #414868;
  --text: #c0caf5;
  --muted: #8890b5;
  --accent: #7aa2f7;
  --on-accent: #16161e;
  --mark: #e0af68;
  --on-mark: #16161e;
  --danger: #f7768e;
  --focus: #7dcfff;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #e1e2e7;
    --surface: #f2f3f7;
    --surface-2: #e4e6ee;
    --border: #cdd0dc;
    --border-strong: #a8aecb;
    --text: #343b58;
    --muted: #5d6593;
    --accent: #2e7de9;
    --on-accent: #ffffff;
    --mark: #8f5e15;
    --on-mark: #ffffff;
    --danger: #c4234f;
    --focus: #007197;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h2 { margin: 0 0 10px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.file-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-name {
  color: var(--muted);
  font-size: 14px;
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

/* Buttons */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.mark { background: transparent; border-color: var(--mark); color: var(--mark); }
.btn.mark:hover { background: color-mix(in srgb, var(--mark) 12%, transparent); }
.btn.small { min-height: 26px; padding: 0 8px; font-size: 12px; }
.btn.link {
  min-height: 0;
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
}
.btn.link:hover { color: var(--text); text-decoration: underline; }
.btn.link.danger:hover { color: var(--danger); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
label.btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

select {
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font: 12px var(--mono);
}

/* Empty state */
.drop-zone {
  display: block;
  padding: 48px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}
.drop-zone:hover { border-color: var(--accent); }
.drop-zone p { margin: 4px 0; }

/* Timeline */
.timeline {
  position: relative;
  height: 40px;
  margin: 2px 0 10px;
  cursor: pointer;
  touch-action: none;
}
.track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 6px;
  margin-top: -3px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress { width: 0; height: 100%; background: var(--accent); }
.knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--surface);
  pointer-events: none;
}
.markers { position: absolute; inset: 0; pointer-events: none; }
.marker {
  position: absolute;
  top: 5px;
  bottom: 5px;
  width: 12px;
  margin-left: -6px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: auto;
}
.marker::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 5px;
  width: 2px;
  border-radius: 1px;
  background: var(--mark);
  opacity: 0.8;
}
.marker:hover::before, .marker.active::before { left: 4px; width: 4px; opacity: 1; }
.hover-time {
  position: absolute;
  bottom: 100%;
  left: 0;
  max-width: 340px;
  margin-bottom: 2px;
  padding: 2px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-2);
  font: 12px var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transform: translateX(-50%);
}

/* Controls */
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.play { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.play svg { width: 18px; height: 18px; fill: currentColor; }
.play .i-pause, .play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.time { margin: 0 6px; color: var(--muted); font: 14px var(--mono); font-variant-numeric: tabular-nums; }
.time #cur { color: var(--text); }
.speed { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

/* Composer */
.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--mark);
  border-radius: 8px;
  background: var(--bg);
}
.composer-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.composer-head .hint { margin-left: 6px; }
.chip {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--mark);
  color: var(--on-mark);
  font: 13px var(--mono);
  font-variant-numeric: tabular-nums;
}
.composer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

/* Comment list */
.count {
  padding: 0 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font: 12px var(--mono);
}
.list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 4px 10px;
  padding: 6px 8px;
  border-left: 3px solid transparent;
  border-radius: 8px;
}
.list li:hover { background: var(--surface-2); }
.list li.active { border-left-color: var(--mark); background: color-mix(in srgb, var(--mark) 9%, transparent); }
.list li.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } }
.ts {
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--mark);
  font: 13px var(--mono);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.ts:hover { border-color: var(--mark); }
.text { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 2px; opacity: 0; }
.list li:hover .item-actions, .list li:focus-within .item-actions { opacity: 1; }
@media (hover: none) { .item-actions { opacity: 1; } }
.edit-wrap { display: flex; flex-direction: column; gap: 6px; grid-column: 2 / 4; }
.edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.empty { margin: 0; font-size: 14px; }

/* Export */
.export { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; font-size: 13px; }

footer { font-size: 13px; line-height: 2; }

.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 10;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}

@media (max-width: 560px) {
  .spacer { display: none; }
  #addBtn { width: 100%; }
  .file-name { max-width: 20ch; }
  .composer-head .hint { display: none; }
}
