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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: #f5f5f5;
  color: #222;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
#header {
  background: #3949AB;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#header h1 { font-size: 16px; font-weight: 700; flex: 1; color: #fff; }

button {
  padding: 5px 14px;
  border: none;
  border-radius: 4px;
  background: #3949AB;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
button:hover { background: #283593; }

#header button {
  background: #fff;
  color: #3949AB;
  border: 1px solid rgba(255, 255, 255, 0.6);
  font-weight: 600;
}
#header button:hover {
  background: #E8EAF6;
  border-color: rgba(255, 255, 255, 0.9);
}

/* ── Main layout ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* General Edit */
#general-edit {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 12px 16px;
  flex-shrink: 0;
}
#general-edit h2 {
  font-size: 13px;
  font-weight: 700;
  background: #E8EAF6;
  color: #283593;
  padding: 6px 16px;
  margin: -12px -16px 10px -16px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.field-row label {
  width: 110px;
  font-weight: 600;
  flex-shrink: 0;
  font-size: 13px;
}
.field-row input[type="text"] {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
}
.field-row input[type="text"]:focus { outline: none; border-color: #3949AB; }

/* Lower split */
#lower {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Articulation List */
#articulation-list {
  width: 220px;
  min-width: 160px;
  background: #fff;
  border-right: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#articulation-list .list-header {
  padding: 8px 10px;
  background: #E8EAF6;
  border-bottom: 1px solid #C5CAE9;
  display: flex;
  align-items: center;
  gap: 6px;
}
#articulation-list .list-header span {
  font-weight: 700;
  font-size: 13px;
  color: #283593;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex: 1;
}
#btn-add-articulation { padding: 2px 8px; font-size: 16px; line-height: 1; }
#artic-list-body { flex: 1; overflow-y: auto; }

.artic-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  gap: 6px;
}
.artic-item:hover { background: #E8EAF6; }
.artic-item.selected { background: #C5CAE9; }
.artic-item .artic-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.artic-item .btn-del-artic {
  padding: 1px 5px;
  font-size: 11px;
  background: transparent;
  color: #c62828;
  border: 1px solid #ef9a9a;
  font-weight: normal;
  flex-shrink: 0;
}
.artic-item .btn-del-artic:hover { background: #fff0f0; }

/* Articulation Edit */
#articulation-edit {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  background: #fafafa;
}
#articulation-edit h2 {
  font-size: 13px;
  font-weight: 700;
  background: #E8EAF6;
  color: #283593;
  padding: 6px 16px;
  margin: -12px -16px 10px -16px;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: -12px;
  z-index: 1;
}
#artic-edit-placeholder { color: #999; font-size: 13px; padding: 20px 0; }

.midi-section-title {
  font-weight: 700;
  font-size: 13px;
  margin: 12px 0 6px;
  color: #3949AB;
}

.midi-msg-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.midi-msg-row .midi-idx { font-size: 11px; color: #888; width: 24px; text-align: right; flex-shrink: 0; }
.midi-msg-row select {
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 12px;
  background: #fff;
}
.midi-msg-row select:focus { outline: none; border-color: #3949AB; }
.midi-msg-row .midi-label { font-size: 11px; color: #666; }
.midi-msg-row input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 12px;
}
.midi-msg-row input[type="number"]:focus { outline: none; border-color: #3949AB; }
.midi-msg-row .btn-del-midi {
  padding: 2px 6px;
  font-size: 11px;
  background: transparent;
  color: #c62828;
  border: 1px solid #ef9a9a;
  font-weight: normal;
}
.midi-msg-row .btn-del-midi:hover { background: #fff0f0; }

#btn-add-midi { margin-top: 4px; font-size: 12px; }
#btn-artic-extra { margin-top: 10px; font-size: 12px; }

/* ── Extra Modal ── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
#modal-overlay.open { display: flex; }

#extra-modal {
  background: #fff;
  border: 1px solid #C5CAE9;
  border-radius: 6px;
  padding: 0;
  width: 480px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#extra-modal .modal-header {
  display: flex;
  align-items: center;
  background: #E8EAF6;
  padding: 10px 16px;
  border-bottom: 1px solid #C5CAE9;
  flex-shrink: 0;
}
#extra-modal .modal-header h3 { flex: 1; font-size: 15px; color: #283593; font-weight: 700; }
#btn-modal-close {
  background: transparent;
  color: #3949AB;
  border: 1px solid rgba(57, 73, 171, 0.4);
  padding: 2px 8px;
  font-size: 14px;
  font-weight: normal;
}
#btn-modal-close:hover { background: #E8EAF6; }

.extra-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.extra-row input[type="text"] {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
}
.extra-row input[type="text"]:focus { outline: none; border-color: #3949AB; }
.extra-row .btn-del-extra {
  padding: 2px 6px;
  font-size: 11px;
  background: transparent;
  color: #c62828;
  border: 1px solid #ef9a9a;
  flex-shrink: 0;
  font-weight: normal;
}
.extra-row .btn-del-extra:hover { background: #fff0f0; }

#extra-col-header {
  display: flex;
  gap: 6px;
  font-size: 11px;
  color: #888;
  margin-bottom: 2px;
  padding: 10px 16px 0;
}
#extra-col-header span:first-child { flex: 1; }
#extra-col-header span:nth-child(2) { flex: 1; }
#extra-rows-container { overflow-y: auto; max-height: 300px; padding: 0 16px; }
#btn-add-extra { font-size: 12px; align-self: flex-start; margin: 6px 16px 12px; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 200;
}
.toast {
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 13px;
  color: #fff;
  opacity: 1;
  transition: opacity 0.4s;
  pointer-events: none;
}
.toast.success { background: #2a9d2a; }
.toast.error   { background: #c0392b; }
.toast.fadeout { opacity: 0; }

/* ── Responsive ── */
@media (max-width: 600px) {
  #lower { flex-direction: column; }
  #articulation-list {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #ddd;
    max-height: 180px;
  }
}
