:root {
  --bg: #f5f6fb;
  --panel-bg: #ffffff;
  --border: #dcdfe8;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #4338ca;
  --primary-hover: #372cb0;
  --danger: #b91c1c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151b;
    --panel-bg: #1d1f27;
    --border: #333644;
    --text: #e7e8ee;
    --muted: #9aa0ac;
    --primary: #7c6ff0;
    --primary-hover: #9089f5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--primary);
  color: white;
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.badge {
  background: rgba(255,255,255,0.2);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}
.toolbar-row:last-of-type { margin-bottom: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.field input, .field select {
  font-size: 0.95rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
}
#title-input { min-width: 220px; }

.btn {
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-large { font-size: 1.1rem; padding: 0.6rem 1.4rem; }
.file-btn { position: relative; display: inline-flex; align-items: center; }

.btn-group { display: flex; gap: 0.35rem; align-items: center; }
.btn-group .toggle.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.octave-display {
  min-width: 1.6rem;
  text-align: center;
  font-weight: 600;
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}
.hint kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.3rem;
}

.staff-scroll {
  overflow-x: auto;
  padding: 0.5rem 0;
}
#staff-container svg { display: block; cursor: crosshair; }

.piano-scroll { overflow-x: auto; }
.piano {
  position: relative;
  height: 110px;
  margin: 0 auto;
}
.piano-key {
  position: absolute;
  top: 0;
  cursor: pointer;
  border: 1px solid #33364455;
  border-radius: 0 0 4px 4px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.piano-key-white {
  width: 32px;
  height: 110px;
  background: #fff;
  z-index: 1;
}
.piano-key-white:hover { background: #eef0ff; }
.piano-key-white:active { background: var(--primary); }
.piano-key-black {
  width: 20px;
  height: 68px;
  background: #23252d;
  z-index: 2;
}
.piano-key-black:hover { background: #40434f; }
.piano-key-black:active { background: var(--primary); }
.piano-key-label {
  font-size: 0.65rem;
  color: #888;
  margin-bottom: 2px;
}

.playback-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-content {
  background: var(--panel-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: min(520px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }

.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.library-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.library-title { font-weight: 600; flex: 1; }
.library-date { font-size: 0.8rem; color: var(--muted); }

@media print {
  .topbar, .toolbar-panel, .piano-panel, .playback-panel, .hint, .modal { display: none !important; }
  body, main { background: white; }
  .panel { border: none; padding: 0; }
  .staff-scroll { overflow: visible; }
}
