* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1c1c1f;
  color: #eee;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---- Toolbar ---- */

#toolbar {
  width: 104px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: #2a2a2e;
  overflow-y: auto;
}

#toolbar hr {
  width: 80%;
  border: none;
  border-top: 1px solid #444;
  margin: 6px auto;
}

#toolbar button {
  --accent: #f2d22e;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 12px 4px;
  border: none;
  background: transparent;
  color: #ddd;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

#toolbar button .icon { font-size: 26px; line-height: 1; }
#toolbar button:hover { background: #333338; }
#toolbar button:disabled { opacity: 0.35; cursor: default; }
#toolbar #play:disabled { opacity: 0.5; cursor: wait; }

#toolbar button.active {
  background: #111;
  color: #fff;
}

#toolbar button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--accent);
}

/* Per-layer clear, only on the selected instrument */
#toolbar .clear-layer {
  display: none;
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 4px;
  font-size: 18px;
  color: #bbb;
}

#toolbar button.active .clear-layer { display: block; }
#toolbar .clear-layer:hover { color: #fff; }

/* ---- Stage ---- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#score-menu {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  background: #2a2a2e;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#score-menu[hidden] { display: none; }

#score-menu button {
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid #3a3a3f;
  background: transparent;
  color: #eee;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#score-menu button:hover { background: #3a3a3f; }
#score-menu small { display: block; color: #999; margin-top: 2px; }

#select-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  background: #2a2a2e;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#select-bar[hidden] { display: none; }

#select-bar button {
  padding: 12px 20px;
  border: none;
  border-right: 1px solid #3a3a3f;
  background: transparent;
  color: #eee;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

#select-bar button:last-child { border-right: none; }
#select-bar button:hover:not(:disabled) { background: #3a3a3f; }
#select-bar button:disabled { opacity: 0.35; cursor: default; }

/* ---- Modes ---- */

body[data-mode="free"] .chromatic-only,
body[data-mode="free"] .clear-layer {
  display: none !important;
}

#mode-dialog {
  width: calc(100% - 32px);
  max-width: 720px;
  padding: 32px;
  border: none;
  border-radius: 16px;
  background: #2a2a2e;
  color: #eee;
  text-align: center;
}

#mode-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }

#mode-dialog h1 {
  margin: 0 0 4px;
  font-size: 32px;
  letter-spacing: 0.04em;
}

#mode-dialog .subtitle {
  margin: 0 0 24px;
  color: #aaa;
}

#mode-continue {
  display: block;
  width: 100%;
  margin-bottom: 16px;
  padding: 16px;
  border: 2px solid #f2d22e;
  border-radius: 12px;
  background: #f2d22e;
  color: #1c1c1f;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

#mode-continue[hidden] { display: none; }
#mode-continue small { display: block; margin-top: 2px; font-size: 13px; font-weight: 500; }

.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.modes button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 20px;
  border: 2px solid #3a3a3f;
  border-radius: 12px;
  background: #1f1f22;
  color: #bbb;
  font: inherit;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
}

.modes button:hover,
.modes button.current { border-color: #f2d22e; }

.modes .icon { font-size: 40px; }
.modes strong { font-size: 20px; color: #fff; }

#mode-warning {
  margin: 20px 0 0;
  color: #f2a35e;
}

#mode-cancel {
  margin-top: 16px;
  border: none;
  background: none;
  color: #aaa;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---- Import ---- */

#import-dialog {
  width: calc(100% - 32px);
  max-width: 520px;
  padding: 24px;
  border: none;
  border-radius: 16px;
  background: #2a2a2e;
  color: #eee;
}

#import-dialog::backdrop { background: rgba(0, 0, 0, 0.65); }
#import-dialog h2 { margin: 0 0 8px; font-size: 20px; }
#import-error { margin: 0; color: #f2a35e; }
#import-error:empty { display: none; }

#import-parts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  margin: 12px 0;
  overflow-y: auto;
}

.import-part {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #1f1f22;
}

.import-part select {
  padding: 6px 8px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #2a2a2e;
  color: #eee;
  font: inherit;
}

.import-note { margin: 0 0 16px; color: #999; font-size: 13px; }

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-buttons button {
  padding: 10px 18px;
  border: 1px solid #444;
  border-radius: 8px;
  background: transparent;
  color: #eee;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.dialog-buttons button.primary { border-color: #f2d22e; background: #f2d22e; color: #1c1c1f; }
.dialog-buttons button[hidden] { display: none; }

/* ---- Controls ---- */

#controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 10px 16px;
  background: #2a2a2e;
  font-size: 13px;
}

#controls label {
  display: flex;
  align-items: center;
  gap: 8px;
}

#controls output {
  min-width: 3.5em;
  font-variant-numeric: tabular-nums;
  color: #aaa;
}

#controls input[type="checkbox"] { width: 18px; height: 18px; }
