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

body {
  background: #1a1a2e;
  color: #eee;
  font-family: system-ui, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

header {
  background: #16213e;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
  border-bottom: 1px solid #0f3460;
  position: relative;
}

h1 { font-size: 1.2rem; color: #e94560; }

.icon-btn.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  background: #0f3460;
  border: 1px solid #e94560;
  border-radius: 5px;
  color: #eee;
}
/* Hamburger icon drawn with CSS bars — a Unicode glyph's box isn't centered
   within its own font metrics, so this guarantees a symmetric icon. The
   container's own height drives the button's size, so it lines up with the
   neighbouring (icon + label) buttons. */
.icon-btn.menu-btn .bars {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 18px;
}
.icon-btn.menu-btn .bars span {
  display: block;
  width: 100%;
  height: 3px;
  background: currentColor;
  border-radius: 1px;
}
.icon-btn.menu-btn:hover { background: #1a4a8a; }

.avatar-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #0f3460;
  border: 2px solid #e94560;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: #aaa;
  flex-shrink: 0;
}
.avatar-btn:hover { background: #1a4a8a; color: #eee; }
.avatar-btn.signed-in {
  border-color: #00dd77;
  color: #00dd77;
  font-weight: bold;
  font-size: 1rem;
  text-transform: uppercase;
}

.menu-panel {
  position: absolute;
  top: 100%;
  left: 16px;
  margin-top: 0;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  max-width: calc(100vw - 32px);
  box-shadow: 0 16px 50px rgba(0,0,0,0.55);
  z-index: 150;
}
.menu-panel.hidden { display: none; }

/* Tabs only appear once the menu starts hosting controls relocated from the
   (too-narrow-to-fit-everything) transport bar — see applyResponsiveLayout(). */
.menu-tabs {
  display: none;
  gap: 6px;
  flex-basis: 100%;
}
.menu-tab {
  padding: 6px 16px;
  font-size: 0.85rem;
  border-radius: 6px 6px 0 0;
  opacity: 0.55;
}
.menu-tab:hover { opacity: 0.8; }
.menu-tab.active { opacity: 1; background: #1a4a8a; }
/* `contents` keeps the panel's children acting as direct flex items of
   .menu-panel, so the existing wrapping layout is unaffected when shown. */
.menu-tab-panel { display: contents; }
.menu-tab-panel.hidden { display: none; }

@media (max-width: 760px) {
  .menu-tabs { display: flex; }
}

.current-file {
  color: #ffd250;
  font-size: 0.85rem;
  font-style: italic;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.current-file.hidden { display: none; }
.current-file::before { content: "🎵 "; font-style: normal; }

/* account / login */
.account-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.auth-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.auth-form input {
  background: #0f3460;
  color: #eee;
  border: 1px solid #e94560;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 0.85rem;
  width: 130px;
}
.auth-form input:focus { outline: none; border-color: #ff6b6b; }
.auth-form.hidden { display: none; }
.account-loggedin { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.account-loggedin.hidden { display: none; }
#accountEmail { color: #00dd77; }
.auth-error { color: #ff6b6b; font-size: 0.8rem; max-width: 220px; }
.auth-error:empty { display: none; }

.file-btn {
  background: #e94560;
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
}
.file-btn input { display: none; }
.file-btn:hover { background: #c73652; }

.row-break { flex-basis: 100%; height: 0; }

.upload-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(233, 69, 96, 0.08);
  border: 1px solid rgba(233, 69, 96, 0.45);
  border-radius: 8px;
}

#transport { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; row-gap: 8px; }
#transport.hidden { display: none; }
#playBtn.hidden, #stopBtn.hidden { display: none; }


button {
  background: #0f3460;
  border: 1px solid #e94560;
  color: #eee;
  padding: 5px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: #1a4a8a; }
#loopABtn { border-color: #00dd77; color: #00dd77; }
#loopBBtn { border-color: #ff7733; color: #ff7733; }
#loopABtn:hover, #loopBBtn:hover { background: #1a3a2a; }
.sep { width: 1px; height: 20px; background: #333; margin: 0 4px; }

#practiceStatus { font-size: 0.85rem; color: #ffd250; min-width: 60px; }

label { font-size: 0.85rem; display: flex; align-items: center; gap: 6px; }
input[type=range] { accent-color: #e94560; width: 100px; }
.toggle input { accent-color: #e94560; }

select {
  background: #0f3460;
  color: #eee;
  border: 1px solid #e94560;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
select:focus { outline: none; border-color: #ff6b6b; }

.midi-history-body { display: flex; flex-direction: column; gap: 10px; }
.midi-history-body input[type=search] {
  background: #0f3460;
  color: #eee;
  border: 1px solid #e94560;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 0.85rem;
}
.midi-history-body input[type=search]:focus { outline: none; border-color: #ff6b6b; }
.midi-history-list { list-style: none; max-height: 50vh; overflow-y: auto; }
.midi-history-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
}
.midi-history-list li:hover { background: rgba(233,69,96,0.10); }
.midi-history-list .midi-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.midi-history-list .midi-actions { display: flex; gap: 6px; flex-shrink: 0; }
.midi-history-list button { padding: 3px 10px; font-size: 0.78rem; }
.midi-history-empty { font-size: 0.8rem; color: #888; padding: 4px 8px; }

/* piano area: roll on top, keyboard at bottom */
#pianoWrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  position: relative;
}

#rollWrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#roll {
  position: absolute;
  top: 0;
  left: 0;
  cursor: ns-resize;
}

#keyboard {
  flex-shrink: 0;
  height: 130px;
  width: 100%;
  display: block;
  background: #111;
  border-top: 2px solid #e94560;
}

#dropzone {
  position: absolute;
  inset: 0;
  background: rgba(10,10,30,0.88);
  color: #e94560;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}
#dropzone.hidden { display: none; }
#dropzone.drag-over { background: rgba(233,69,96,0.22); pointer-events: auto; }

/* color/size configuration dialog */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5,5,15,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal.hidden { display: none; }
.modal-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  width: min(560px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 50px rgba(0,0,0,0.55);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid #0f3460;
}
.modal-header h2 { font-size: 1.05rem; color: #e94560; }
.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  align-items: center;
}
.field-section {
  grid-column: 1 / -1;
  margin-top: 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid #0f3460;
  color: #e94560;
  font-size: 0.78rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field-section:first-child { margin-top: 0; }
.field-label { font-size: 0.85rem; color: #ccc; }
.modal-body input[type=color] {
  width: 46px;
  height: 28px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 2px;
}
.modal-body input[type=number] {
  width: 56px;
  background: #0f3460;
  color: #eee;
  border: 1px solid #e94560;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 0.85rem;
  text-align: right;
}
.saved-themes { padding: 0 18px 14px; }
.saved-themes.hidden { display: none; }
.saved-themes-row { display: flex; gap: 8px; margin: 8px 0; }
.saved-themes-row input {
  flex: 1;
  background: #0f3460;
  color: #eee;
  border: 1px solid #e94560;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 0.85rem;
}
.saved-themes-row input:focus { outline: none; border-color: #ff6b6b; }
.saved-themes-list { list-style: none; max-height: 140px; overflow-y: auto; }
.saved-themes-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
}
.saved-themes-list li:hover { background: rgba(233,69,96,0.10); }
.saved-themes-list .theme-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-themes-list .theme-actions { display: flex; gap: 6px; flex-shrink: 0; }
.saved-themes-list button { padding: 3px 10px; font-size: 0.78rem; }
.saved-themes-empty { font-size: 0.8rem; color: #888; padding: 4px 8px; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid #0f3460;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-card { width: min(440px, 92vw); }
.confirm-body { display: block; }
.confirm-body p {
  white-space: pre-line;
  line-height: 1.5;
  color: #ddd;
  font-size: 0.92rem;
}
.danger-btn { background: #7a1530; border-color: #e94560; }
.danger-btn:hover { background: #a01c3f; }
.icon-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.icon-btn:hover { color: #e94560; background: rgba(233,69,96,0.12); }
