@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,600;1,400&display=swap');

:root, [data-theme="light"] {
  --bg:          #fffff8;
  --surface:     #f8f6f0;
  --border:      #d5cfc4;
  --text:        #1a1a1a;
  --dim:         #555;
  --accent:      #8b2500;
  --accent-light:#c44b20;
  --score-bg:    #fffff8;
  --staff:       #ccc5b8;
  --bar:         #ddd8cc;
  --clef:        #222;
  --track-label: #b0a898;
  --measure-num: #c4b9a8;
}

[data-theme="dark"] {
  --bg:          #1a1a1e;
  --surface:     #242428;
  --border:      #3a3a40;
  --text:        #e0ddd8;
  --dim:         #999;
  --accent:      #e08050;
  --accent-light:#f0a070;
  --score-bg:    #1e1e22;
  --staff:       #3a3a40;
  --bar:         #333338;
  --clef:        #bbb8b0;
  --track-label: #666;
  --measure-num: #555;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ── */

.hdr {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 12px 24px 10px;
  background: var(--bg);
  flex-shrink: 0;
}

.hdr-logo {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 1px;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.hdr-status {
  font-size: 15px;
  font-style: italic;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* ── Controls ── */

.ctrl {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 6px 24px;
  background: var(--bg);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ctrl-link {
  background: none;
  border: none;
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, sans-serif;
  cursor: pointer;
  padding: 3px 6px;
  transition: color .15s;
  white-space: nowrap;
  touch-action: manipulation;
}

.ctrl-link:hover:not(:disabled) { color: var(--accent); }
.ctrl-link:disabled { opacity: .3; cursor: default; }
.ctrl-link.active { font-weight: 600; }

.sep  { color: var(--border); font-size: 16px; padding: 0 2px; user-select: none; }
.ctrl-label { font-size: 15px; color: var(--dim); white-space: nowrap; }
.tdsp { font-size: 16px; color: var(--text); min-width: 38px; font-variant-numeric: tabular-nums; }

/* ── Legend ── */

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 20px;
  padding: 8px 24px;
  background: var(--bg);
  flex-shrink: 0;
  min-height: 28px;
}

.leg-item { display: flex; align-items: center; gap: 3px; font-size: 16px; font-weight: 600; color: var(--text); }
.leg-dot  { width: 18px; height: 12px; border-radius: 50%; }
.legend-placeholder { font-size: 15px; font-style: italic; color: var(--dim); }

/* ── Score toolbar (inside score-wrap, below meta) ── */

.score-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 0 10px;
  flex-wrap: wrap;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  color: var(--dim);
  font: 13px/1 system-ui, -apple-system, sans-serif;
  cursor: pointer;
  padding: 5px 10px;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
  touch-action: manipulation;
}
.tb-btn:hover { color: var(--text); border-color: var(--dim); }

.tb-btn-sm { padding: 5px 7px; }

.tb-icon { width: 16px; height: 16px; flex-shrink: 0; }
.tb-label { font-size: 13px; }

.tb-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 0 2px;
}
.tb-group .tb-btn { border: none; border-radius: 4px; padding: 5px 6px; }
.tb-group .tb-btn:hover { background: var(--border); }

.tb-val {
  font: 600 14px/1 system-ui, -apple-system, sans-serif;
  color: var(--text);
  min-width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.play-icon { vertical-align: middle; }

/* ── Score ── */

.score-wrap {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px 40px;
  background: var(--bg);
  position: relative;
  transition: background .2s;
}

.score-wrap.drag-over {
  background: rgba(139, 37, 0, 0.02);
}

/* Empty state */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 280px;
  border: none;
  cursor: pointer;
  gap: 14px;
  transition: border-color .2s, background .2s;
  user-select: none;
}

.empty:hover { background: rgba(139,37,0,.02); }
.empty-icon  { font-size: 52px; color: #c4b9a8; }
.empty-hint  { font-size: 17px; color: var(--dim); text-align: center; padding: 0 10px; font-style: italic; }

.empty-examples {
  display: flex;
  gap: 28px;
  font-size: 16px;
  color: var(--text);
  padding: 12px 16px;
  justify-content: center;
}

.examples-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-start;
}

.examples-heading {
  font-weight: 600;
  font-size: 14px;
  color: var(--dim);
  margin-bottom: 2px;
}

.empty-examples button, button.saved-item {
  color: var(--text);
  background: none;
  border: none;
  font: 16px/1.4 system-ui, -apple-system, sans-serif;
  cursor: pointer;
  padding: 2px 4px;
  transition: color .15s;
  text-decoration: none;
}

.empty-examples button:hover, .saved-item:hover {
  color: var(--accent);
}

.saved-entry {
  display: flex;
  align-items: center;
  gap: 6px;
}

.saved-delete {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.4;
  transition: opacity .15s, color .15s;
}
.saved-delete:hover { opacity: 1; color: var(--accent); }

/* ── Score metadata ── */

.score-meta {
  text-align: center;
  padding: 12px 24px 4px;
}

.meta-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.meta-title-text {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

.meta-author-text {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 16px;
  font-style: italic;
  color: var(--dim);
}

.meta-comment-text {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 14px;
  color: var(--dim);
}

.meta-edit-btn, .meta-done-btn {
  background: none;
  border: none;
  font: 14px/1 system-ui, -apple-system, sans-serif;
  color: var(--dim);
  cursor: pointer;
  opacity: 0.5;
  margin-top: 4px;
  transition: opacity .15s, color .15s;
}
.meta-edit-btn:hover, .meta-done-btn:hover { opacity: 1; color: var(--accent); }

.meta-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.meta-input {
  display: block;
  width: 100%;
  max-width: 400px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  font-family: 'EB Garamond', Georgia, serif;
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color .2s;
}
.meta-input:focus { border-bottom-color: var(--accent); }
.meta-input::placeholder { color: var(--dim); opacity: 0.4; }
.meta-input-title  { font-size: 22px; font-weight: 600; padding: 3px 0; }
.meta-input-author { font-size: 16px; font-style: italic; padding: 2px 0; }
.meta-input-comment { font-size: 14px; padding: 2px 0; }

#fileInput { display: none; }
#scoreSvg  { display: none; width: 100%; }
#scoreSvg svg { display: block; width: 100%; break-inside: avoid; }

.note-g {
  cursor: pointer;
  transition: filter 0.1s ease-out;
}
.note-g:hover .note-head { filter: brightness(1.2) !important; }

.note-tooltip {
  display: none;
  position: fixed;
  background: var(--text);
  color: var(--bg);
  font: 600 13px/1 system-ui, -apple-system, sans-serif;
  padding: 3px 7px;
  border-radius: 3px;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
}

/* Active note glow during playback */
.note-g.active {
  filter: drop-shadow(0 0 4px var(--note-color, #8b2500))
          drop-shadow(0 0 8px var(--note-color, #8b2500));
}

/* Tempo input */
.tempo-input {
  width: 48px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, sans-serif;
  text-align: center;
  padding: 2px 0;
  outline: none;
}
.tempo-input:focus { border-bottom-color: var(--accent); }
.bar-input { width: 38px; }
.vscale-range {
  width: 64px;
  vertical-align: middle;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  outline: none;
}
.vscale-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); cursor: pointer;
}
.vscale-range::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); border: none; cursor: pointer;
}

/* hide number spinners */
.tempo-input::-webkit-outer-spin-button,
.tempo-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tempo-input[type=number] { -moz-appearance: textfield; }

/* ── Responsive ── */

@media (max-width: 640px) {
  .hdr {
    gap: 10px;
    padding: 8px 14px;
  }

  .hdr-logo { font-size: 18px; }
  .hdr-status { font-size: 13px; }

  .ctrl {
    padding: 5px 14px;
    gap: 2px;
  }

  .ctrl-link { font-size: 14px; padding: 3px 4px; }
  .sep { display: none; }
  .ctrl-label { font-size: 13px; }
  .zrng { width: 56px; }

  .legend { padding: 4px 14px; gap: 3px 10px; }
  .score-wrap { padding: 12px 8px 30px; }

  .empty { height: 220px; }
  .empty-icon { font-size: 40px; }
  .empty-hint { font-size: 14px; }
  .empty-examples { font-size: 14px; gap: 16px; }
}

@media (max-width: 380px) {
  .hdr-logo { font-size: 16px; }
  .hdr-status { display: none; }
  .ctrl { justify-content: center; }
  .ctrl-link { font-size: 13px; }
}

/* ── Print ── */

@media print {
  *, *::before, *::after { overflow: visible !important; }
  body {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
    color: #000 !important;
    display: block !important;
    min-height: 0 !important;
  }
  .hdr, .ctrl, .legend, .score-toolbar, .meta-edit-btn, .meta-done-btn, .meta-form, .note-tooltip, #empty { display: none !important; }
  .score-wrap {
    all: unset !important;
    display: block !important;
  }
  .score-meta {
    padding: 10px 0 2px !important;
    margin: 0 !important;
    display: block !important;
  }
  .meta-display { display: flex !important; gap: 0 !important; }
  .meta-title-text { color: #000 !important; font-size: 20px !important; }
  .meta-author-text { color: #444 !important; font-size: 14px !important; }
  .meta-comment-text { color: #666 !important; font-size: 12px !important; }
  #scoreSvg {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  #scoreSvg svg {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}
