:root {
  --ink: #0f0f0f;
  --ink-soft: #262626;
  --gold: #b8935a;
  --gold-soft: #d8bd8a;
  --cream: #fefefc;
  --paper: #f6f3ec;
  --line: #e3ddd0;
  --muted: #7a7368;
  --shadow: 0 10px 30px rgba(15, 15, 15, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Iowan Old Style", "Palatino Linotype", "Georgia", serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Topbar ---------- */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(254, 254, 252, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.logo { width: 40px; height: 40px; color: var(--gold); }
.logo line { stroke: var(--line); stroke-width: 1.4; }
.brand-name {
  display: block;
  font-size: 19px;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.brand-tag { display: block; font-size: 11px; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.topnav { display: flex; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: transparent;
  color: var(--ink);
}
.btn.primary { background: var(--ink); color: var(--cream); }
.btn.primary:hover { background: var(--gold); }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn.lg { padding: 12px 22px; font-size: 15px; }
.btn.danger:hover { border-color: #b34a3a; color: #b34a3a; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--cream);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--ink);
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- Hero ---------- */
.hero {
  max-width: 1140px;
  margin: 0 auto;
  padding: 70px 28px 40px;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 48px;
  align-items: center;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 11px;
  color: var(--gold);
}
.hero h1 {
  font-size: 52px;
  line-height: 1.08;
  margin: 16px 0 18px;
  font-weight: 600;
}
.lead { font-size: 18px; line-height: 1.6; color: var(--ink-soft); max-width: 540px; }
.hero-actions { display: flex; gap: 12px; margin: 26px 0; }
.feature-list { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 10px; }
.feature-list li { padding-left: 24px; position: relative; color: var(--ink-soft); }
.feature-list li::before {
  content: "";
  position: absolute;
  left: 0; top: 9px;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid var(--gold);
}

.hero-art { display: flex; justify-content: center; }
.staff-card {
  position: relative;
  width: 100%;
  max-width: 430px;
  aspect-ratio: 4 / 3;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 28px;
}
.staff-line { height: 1px; background: #d8d1c2; margin: 26px 0; }
.note-dot { position: absolute; width: 14px; height: 11px; background: var(--ink); border-radius: 50%; }
.gloss {
  position: absolute;
  transform: translateX(-20%);
  background: var(--gold);
  color: var(--cream);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  font-family: system-ui, sans-serif;
}

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: 1fr 400px;
  height: calc(100vh - 64px);
}
.score-pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.score-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.piece-meta h2 { margin: 0; font-size: 18px; }
.toolbar-actions { display: flex; align-items: center; gap: 10px; }

.layer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  min-height: 46px;
}
.layer-chip {
  font-family: system-ui, sans-serif;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  background: var(--cream);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}
.layer-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.layer-chip.off { opacity: 0.42; text-decoration: line-through; }

.score-scroll { flex: 1; overflow: auto; background: #efece5; padding: 24px; }
.score-container { position: relative; display: inline-block; min-width: 100%; }
.score-loading { padding: 60px; text-align: center; color: var(--muted); }
#osmdContainer { background: var(--cream); box-shadow: var(--shadow); border-radius: 6px; }

/* ---------- Annotation pane ---------- */
.annotation-pane {
  display: flex;
  flex-direction: column;
  background: var(--cream);
  min-height: 0;
}
.annotation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.annotation-header h3 { margin: 2px 0 0; font-size: 20px; }
.measure-nav { display: flex; gap: 6px; }
.measure-nav .icon-btn { font-size: 18px; }
.piece-meta #measureStat { display: block; margin-top: 2px; }
.annotation-list { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.empty-hint { color: var(--muted); font-size: 14px; line-height: 1.55; }

.anchor-context {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--line);
}
.artic-chip {
  font-family: system-ui, sans-serif;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--cream);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}
.artic-chip:hover { border-color: var(--gold); color: var(--gold); }
.artic-chip.active { background: var(--gold); color: var(--cream); border-color: var(--gold); }

.ann-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  border-left-width: 4px;
}
.ann-card .ann-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.tag {
  font-family: system-ui, sans-serif;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.tag.type { background: var(--paper); color: var(--ink-soft); }
.ann-body { margin: 0 0 8px; line-height: 1.5; white-space: pre-wrap; }
.ann-source { font-size: 12px; word-break: break-all; }
.ann-source a { color: var(--gold); }
.ann-footer { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.vote-btn {
  font-family: system-ui, sans-serif;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--cream);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
}
.vote-btn.active { border-color: var(--gold); color: var(--gold); }
.ann-actions { margin-left: auto; display: flex; gap: 6px; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; font-family: system-ui, sans-serif; }
.link-btn:hover { color: var(--gold); }
.link-btn.danger:hover { color: #b34a3a; }

/* ---------- Form ---------- */
.annotation-form {
  border-top: 1px solid var(--line);
  padding: 16px 18px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.annotation-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-family: system-ui, sans-serif; }
.annotation-form select,
.annotation-form textarea,
.annotation-form input {
  font-family: system-ui, sans-serif;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
}
.annotation-form select:focus,
.annotation-form textarea:focus,
.annotation-form input:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.modal {
  background: var(--cream);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 84vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; }
.dropzone {
  margin: 20px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.dropzone.dragover { border-color: var(--gold); background: rgba(184, 147, 90, 0.08); }
.dropzone .btn { display: inline-block; }

.library-list { padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 10px; }
.library-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}
.library-item .li-title { font-weight: 600; }
.library-item .li-sub { font-size: 12px; color: var(--muted); font-family: system-ui, sans-serif; }
.library-item .li-actions { display: flex; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 11px 20px;
  border-radius: 999px;
  font-family: system-ui, sans-serif;
  font-size: 13px;
  z-index: 80;
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 40px; }
  .hero h1 { font-size: 38px; }
  .hero-art { display: none; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: auto; }
  .annotation-pane { border-top: 1px solid var(--line); max-height: 60vh; }
  .score-pane { border-right: none; }
}
