:root {
  --bg: #ffffff;
  --surface: #f5f5f7;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --border: #e5e5ea;
  --green: #1f9d4c;
  --green-hover: #188540;
  --green-soft: #e9f7ef;
  --green-text: #157a3a;
  --danger: #d70015;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, textarea, input { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 24px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.save-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.save-status.ok::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.save-status.err { color: var(--danger); cursor: pointer; }

.container { max-width: 1240px; margin: 0 auto; padding: 40px 24px 80px; }

/* ---------- Home ---------- */
.page-head { margin-bottom: 32px; }
.page-head h1 { font-size: 40px; line-height: 1.1; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 8px; }
.page-head p { color: var(--muted); margin: 0; font-size: 17px; }

.search {
  width: 100%; max-width: 360px; margin-top: 20px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); outline: none;
  transition: border-color .15s, background .15s;
}
.search:focus { background: #fff; border-color: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.projects { display: flex; flex-direction: column; gap: 20px; }
.project {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.project-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; padding: 0 4px; }
.project-head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.015em; }
.project-head span { color: var(--muted); font-size: 13px; }

.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.video-card {
  display: block; background: #fff; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border); transition: transform .2s ease, box-shadow .2s ease;
}
.video-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.thumb { aspect-ratio: 16 / 9; background: #111; position: relative; }
.thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play {
  position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.9); display: grid; place-items: center; opacity: 0; transition: opacity .2s;
}
.video-card:hover .play { opacity: 1; }
.play svg { width: 16px; height: 16px; margin-left: 2px; fill: var(--text); }
.video-meta { padding: 12px 14px 14px; }
.video-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.video-sub { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; align-items: center; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
  background: var(--surface); color: var(--muted);
}
.pill.green { background: var(--green-soft); color: var(--green-text); }

.empty {
  text-align: center; padding: 72px 24px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty h3 { color: var(--text); margin: 0 0 6px; font-weight: 600; }
.empty code { font-family: var(--mono); font-size: 13px; background: var(--surface); padding: 2px 6px; border-radius: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; cursor: pointer; border-radius: 999px; padding: 8px 16px;
  font-size: 14px; font-weight: 500; background: var(--surface); color: var(--text);
  transition: background .15s, transform .05s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: #ebebef; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-hover); }
.btn.ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
.btn.ghost:hover { background: var(--surface); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.danger.confirm { background: var(--danger); color: #fff; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn svg { width: 16px; height: 16px; }
kbd {
  font-family: var(--font); font-size: 11px; padding: 1px 6px; border-radius: 5px;
  background: rgba(255,255,255,.22); border: 1px solid rgba(255,255,255,.3);
}

/* ---------- Player ---------- */
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.crumbs a:hover { color: var(--green-text); }
.player-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 24px; word-break: break-word; }

.player-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 28px; align-items: start; }

.stage { position: sticky; top: 80px; }
.video-wrap { background: #000; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.video-wrap video { width: 100%; display: block; max-height: 70vh; background: #000; }

.track { position: relative; height: 28px; margin: 14px 2px 0; cursor: pointer; }
.track-line { position: absolute; left: 0; right: 0; top: 12px; height: 4px; border-radius: 2px; background: var(--border); }
.track-progress { position: absolute; left: 0; top: 12px; height: 4px; border-radius: 2px; background: var(--text); opacity: .2; }
.track-head { position: absolute; top: 6px; width: 2px; height: 16px; background: var(--text); border-radius: 1px; transform: translateX(-1px); }
.marker {
  position: absolute; top: 8px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--green); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--green);
  transform: translateX(-6px); transition: transform .15s;
}
.marker:hover, .marker.active { transform: translateX(-6px) scale(1.35); }

.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.timecode { font-family: var(--mono); font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.timecode b { color: var(--text); font-weight: 500; }
.hint { font-size: 12px; color: var(--faint); margin-top: 12px; }
.hint kbd { background: var(--surface); border-color: var(--border); color: var(--muted); }

.panel { display: flex; flex-direction: column; gap: 20px; }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head .count { color: var(--muted); font-size: 13px; }

textarea.field {
  width: 100%; resize: vertical; min-height: 96px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff;
  outline: none; line-height: 1.5; transition: border-color .15s, box-shadow .15s;
}
textarea.field:focus { border-color: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.notes { display: flex; flex-direction: column; gap: 8px; }
.note {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; transition: border-color .2s, box-shadow .2s;
}
.note.active { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.note-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.tc {
  font-family: var(--mono); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
  background: var(--green-soft); color: var(--green-text); border: 0; border-radius: 6px;
  padding: 3px 8px; cursor: pointer;
}
.tc:hover { background: #d9f0e2; }
.note-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.note:hover .note-actions, .note:focus-within .note-actions { opacity: 1; }
@media (hover: none) { .note-actions { opacity: 1; } }
.note-text { white-space: pre-wrap; word-break: break-word; }
.note-edit { display: flex; flex-direction: column; gap: 10px; }
.note-edit-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.note-edit-bar .right { display: flex; gap: 6px; }
.notes-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 20px 8px; }

.export { display: flex; gap: 8px; flex-wrap: wrap; }

.loading { color: var(--muted); padding: 40px 0; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 960px) {
  .player-layout { grid-template-columns: minmax(0, 1fr); }
  .stage { position: static; }
}
@media (max-width: 600px) {
  .container { padding: 24px 16px 64px; }
  .topbar { padding: 0 16px; }
  .page-head h1 { font-size: 32px; }
  .player-title { font-size: 22px; }
  .project { padding: 14px; }
  .search { max-width: none; }
  .hint { display: none; }
  .save-status { max-width: 55vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  .save-status.ok::before { display: none; }
}
