/* ==========================================================================
   Loomy Music Composer - styles
   ========================================================================== */

:root {
  --ink: #101418;
  --muted: #5b6572;
  --line: #d8dee6;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #c0392b;
  --ok: #12805c;
  --radius: 12px;
  --keyboard-scale: 1;
  --shadow: 0 1px 2px rgba(16, 20, 24, .08), 0 8px 24px rgba(16, 20, 24, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #eef1f5;
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
button:hover { background: var(--panel-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button.danger { background: #fff; border-color: #e6b8b2; color: var(--danger); }
button.danger:hover { background: #fdf1ef; }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
button[disabled] { opacity: .45; cursor: not-allowed; }

input[type="text"], input[type="number"], input[type="search"], select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  width: 100%;
}

.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   Header - logo to the left of the app name
   -------------------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(180deg, #ffffff, #f4f7fb);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-nav {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

main { padding: 16px 20px 40px; }

.view { max-width: 1600px; margin: 0 auto; }

/* --------------------------------------------------------------------------
   Library
   -------------------------------------------------------------------------- */
.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.library-toolbar input[type="search"] { max-width: 260px; }

.file-button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 7px 12px;
  cursor: pointer;
}
.file-button:hover { background: var(--panel-2); }

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.score-preview {
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--line);
}

/* background themes (original artwork-free gradients) */
.bg-bg1, .score-card.bg-bg1 .score-preview { background: linear-gradient(135deg, #fdf6e7, #f6e3c3); }
.bg-bg2, .score-card.bg-bg2 .score-preview { background: linear-gradient(135deg, #eaf3ff, #cfe2ff); }
.bg-bg3, .score-card.bg-bg3 .score-preview { background: linear-gradient(135deg, #ecfaef, #cbeed6); }
.bg-bg4, .score-card.bg-bg4 .score-preview { background: linear-gradient(135deg, #f6eaff, #e2d3ff); }
.bg-white, .score-card.bg-white .score-preview { background: #fff; }

.staff-mini {
  display: block;
  width: 150px;
  height: 40px;
  background-image: repeating-linear-gradient(to bottom, #a9b4c2 0 1px, transparent 1px 10px);
}

.score-card-body { padding: 12px 14px 6px; flex: 1; }
.score-card-body h3 { margin: 0 0 4px; font-size: 16px; }
.score-card-body .author { margin: 0; color: var(--muted); font-style: italic; }
.score-card-body .stats, .score-card-body .edited { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.score-card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 12px 12px;
  flex-wrap: wrap;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fff;
}

/* --------------------------------------------------------------------------
   Editor layout
   -------------------------------------------------------------------------- */
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}
.editor-head h2 { margin: 0; font-size: 20px; }
.editor-head .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.rush-host { max-width: 420px; }
.rush-card {
  background: var(--accent-soft);
  border: 1px solid #bcd2ff;
  border-radius: var(--radius);
  padding: 12px 14px;
}
.rush-card h3 { margin: 0 0 6px; font-size: 15px; }
.rush-card p { margin: 3px 0; font-size: 13px; }
.rush-target strong { font-size: 18px; color: var(--accent); }

.editor-body {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr) 288px;
  gap: 14px;
  align-items: start;
}

.palette, .inspector {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.palette-group { margin-bottom: 14px; }
.palette-group h4, .inspector-panel h4 {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.palette-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 8px;
  background: #fff;
  min-height: 46px;
}
.palette-glyph {
  font-family: Bravura, "Noto Music", "Segoe UI Symbol", "Apple Symbols", Symbola, serif;
  font-size: 19px;
  line-height: 1;
}
.palette-glyph.wide { font-size: 10px; font-style: italic; }
.palette-label { font-size: 8.5px; color: var(--muted); text-align: center; line-height: 1.1; }

.score-column { min-width: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.tool-group { display: flex; gap: 6px; align-items: center; padding-right: 8px; border-right: 1px solid var(--line); }
.tool-group:last-child { border-right: 0; }
.tool-group .inline { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.tool-group .inline select, .tool-group .inline input { width: auto; }
.tool-badge { font-size: 12px; color: var(--muted); }
.zoom-value {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: center;
  color: var(--muted);
}
.zoom-group { gap: 4px; }
.zoom-group .inline { white-space: nowrap; }
.zoom-group input[type="range"] { width: 130px; }

.score-scroll {
  background: #dde3ea;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  overflow: auto;
  max-height: calc(100vh - 300px);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .06);
}

.score-host {
  margin: 0 auto;
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 8px;
  width: max-content;
}
.score-host svg { display: block; }
.score-host svg g.ev { cursor: pointer; }
.score-host svg g.ev:hover { filter: drop-shadow(0 0 3px rgba(37, 99, 235, .55)); }

.keyboard-bar {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}

.add-note {
  margin-bottom: 8px;
  background: var(--accent-soft);
  border-color: #bcd2ff;
  color: var(--accent);
  font-weight: 600;
}

.piano {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  height: calc(150px * var(--keyboard-scale));
  overflow-x: auto;
}

.piano-key {
  position: relative;
  flex: 1 1 0;
  min-width: calc(22px * var(--keyboard-scale));
  height: 100%;
  border: 1px solid #b9c1cc;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(180deg, #fff, #eef1f5);
  padding: 0;
}
.piano-key span {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  font-size: 9px;
  color: #94a0ae;
}
.piano-key:active { background: #dbe7ff; }

.piano-key.black {
  position: absolute;
  top: 0;
  right: calc(-10px * var(--keyboard-scale));
  z-index: 2;
  width: calc(20px * var(--keyboard-scale));
  height: 60%;
  background: linear-gradient(180deg, #40474f, #14181c);
  border-color: #000;
}
.piano-key.black span { color: #cfd6de; font-size: 7px; }
.piano-key.black:active { background: #2c3a52; }

.keyboard-hint { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }

/* --------------------------------------------------------------------------
   Inspector
   -------------------------------------------------------------------------- */
.inspector-panel { margin-bottom: 16px; }
.inspector-body label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}
.inspector-body label input, .inspector-body label select { margin-top: 3px; }
.inspector-body label.checkbox { display: flex; align-items: center; gap: 6px; }
.inspector-body label.checkbox input { width: auto; margin: 0; }
.inspector-body input[type="range"] { width: 100%; }
.inspector-body h5 { margin: 12px 0 6px; font-size: 12px; }
.button-row { display: flex; gap: 6px; margin-bottom: 6px; }
.button-row button { flex: 1; }
.hint { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }

/* --------------------------------------------------------------------------
   Toasts and dialogs
   -------------------------------------------------------------------------- */
.toast-host {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  background: #1f2937;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: var(--ok); }
.toast-error { background: var(--danger); }

.dialog-host:empty { display: none; }
.dialog-host {
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 24, .38);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.dialog {
  background: #fff;
  border-radius: 14px;
  padding: 18px 20px;
  width: min(520px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog h3 { margin: 0 0 8px; font-size: 17px; }
.dialog-body { white-space: pre-wrap; color: #333; font-size: 13.5px; max-height: 48vh; overflow: auto; }
.dialog-field { display: block; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.dialog-field input { margin-top: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1180px) {
  .editor-body { grid-template-columns: 1fr; }
  .palette, .inspector { max-height: none; }
  .palette-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
}

@media (max-width: 720px) {
  .app-header { flex-wrap: wrap; }
  .brand h1 { font-size: 18px; }
  .brand-logo { width: 44px; height: 44px; }
  main { padding: 12px; }
}

/* --------------------------------------------------------------------------
   Print - only the engraving, no watermark
   -------------------------------------------------------------------------- */
@media print {
  .app-header, .palette, .inspector, .toolbar, .keyboard-bar, .toast-host, .dialog-host { display: none !important; }
  .score-scroll { border: 0; padding: 0; background: #fff; max-height: none; overflow: visible; }
  .score-host { box-shadow: none; }
}
