/* ============================================================
   RESET & BASE  —  matches Sprite Tool design language
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  color: #1a1a1a;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================
   TOP BAR
   ============================================================ */
#topbar {
  background: #cccccc;
  border-bottom: 1.5px solid #999999;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  user-select: none;
}

#topbar h1 {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-right: 2px;
}

#topbar .subtitle {
  font-size: 11px;
  color: #789;
  font-style: italic;
  margin-right: 4px;
}

.sep {
  width: 1px;
  height: 22px;
  background: #999999;
  margin: 0 2px;
}

/* Standard button — mirrors .top-action-btn / .tool-btn from Sprite Tool */
.btn {
  padding: 5px 12px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  font-family: 'Segoe UI', system-ui, sans-serif;
}
.btn:hover                { background: #d5d5d5; border-color: #4a4a4a; }
.btn.active               { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.btn.green.active         { background: #3a7a3a; border-color: #2a5a2a; color: #fff; }
.btn#btn-clear            { border-color: #c07070; color: #a03030; background: #fef0f0; }
.btn#btn-clear:hover      { background: #fcd0d0; border-color: #a03030; }

label.top { font-size: 11px; color: #556; font-weight: 600; }

#bpm-input {
  background: #f8f8f8;
  border: 1.5px solid #5a5a5a;
  color: #1a1a1a;
  padding: 4px 6px;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  width: 58px;
  border-radius: 5px;
  text-align: center;
}
#bpm-input:focus {
  outline: none;
  border-color: #4a4a4a;
  box-shadow: 0 0 0 2px rgba(80,80,80,0.2);
}

#demo-select {
  background: #f8f8f8;
  border: 1.5px solid #5a5a5a;
  color: #1a1a1a;
  padding: 4px 6px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
}
#demo-select:focus {
  outline: none;
  border-color: #4a4a4a;
  box-shadow: 0 0 0 2px rgba(80,80,80,0.2);
}

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ============================================================
   LEFT SIDEBAR
   ============================================================ */
#sidebar {
  width: 178px;
  background: #bbbbbb;
  border-right: 1.5px solid #999999;
  padding: 8px 6px;
  overflow-y: auto;
  flex-shrink: 0;
}

.ch-panel {
  margin-bottom: 8px;
  padding: 7px 8px;
  background: #cccccc;
  border: 1.5px solid #aaaaaa;
  border-radius: 6px;
  border-left-width: 4px;
}
.ch-panel.p-ch1   { border-left-color: #c0392b; }
.ch-panel.p-ch2   { border-left-color: #27ae60; }
.ch-panel.p-ch3   { border-left-color: #2980b9; }
.ch-panel.p-noise { border-left-color: #777777; }

.ch-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.ch-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.p-ch1   .ch-label { color: #c0392b; }
.p-ch2   .ch-label { color: #27ae60; }
.p-ch3   .ch-label { color: #2980b9; }
.p-noise .ch-label { color: #555555; }

.mute-btn {
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  color: #3a3a3a;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  cursor: pointer;
  border-radius: 4px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  transition: background 0.15s;
}
.mute-btn:hover          { background: #d5d5d5; }
.mute-btn.muted          { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }

.vol-row { display: flex; align-items: center; gap: 5px; }
.vol-lbl { font-size: 10px; color: #666; font-weight: 600; width: 24px; }

input[type=range] {
  flex: 1;
  height: 4px;
  cursor: pointer;
  accent-color: #5a5a5a;
}
.vol-num { font-size: 10px; color: #555; font-weight: 700; width: 16px; text-align: right; }

.noise-row {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.noise-type-btn {
  flex: 1;
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  color: #3a3a3a;
  font-size: 9px;
  font-weight: 700;
  padding: 3px 2px;
  cursor: pointer;
  border-radius: 4px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  text-align: center;
  transition: background 0.15s;
}
.noise-type-btn.active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.noise-type-btn:hover:not(.active) { background: #d5d5d5; }
.noise-hint {
  font-size: 9px;
  color: #7a5a00;
  background: #fff8cc;
  border-radius: 3px;
  padding: 2px 5px;
  margin-top: 4px;
  min-height: 14px;
  line-height: 1.4;
}

/* ============================================================
   TRACKER AREA
   ============================================================ */
#tracker-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Column headers */
#grid-header {
  display: grid;
  grid-template-columns: 30px 72px 72px 72px 58px;
  background: #cccccc;
  border-bottom: 1.5px solid #999999;
  flex-shrink: 0;
  user-select: none;
}
.gh-cell {
  padding: 5px 4px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-right: 1px solid #aaaaaa;
  color: #1a1a1a;
}
.gh-cell:last-child { border-right: none; }
.gh-cell.ch1   { color: #c0392b; }
.gh-cell.ch2   { color: #27ae60; }
.gh-cell.ch3   { color: #2980b9; }
.gh-cell.noise { color: #666666; }

/* Scrollable grid body */
#grid-body {
  flex: 1;
  overflow-y: scroll;
  overflow-x: hidden;
  background: #e8e8e8;
}

/* Each row — subtle alternating bands every 4 rows */
.g-row {
  display: grid;
  grid-template-columns: 30px 72px 72px 72px 58px;
  border-bottom: 1px solid #d8d8d8;
  min-height: 22px;
}
.g-row:nth-child(8n+1),
.g-row:nth-child(8n+2),
.g-row:nth-child(8n+3),
.g-row:nth-child(8n+4) { background: #ebebeb; }
.g-row:nth-child(8n+5),
.g-row:nth-child(8n+6),
.g-row:nth-child(8n+7),
.g-row:nth-child(8n)   { background: #e0e0e0; }

/* Playing row highlight */
.g-row.playing { background: #c8e6c8 !important; }
.g-row.playing .row-num { color: #27ae60; font-weight: 700; }

.row-num {
  color: #aaaaaa;
  font-size: 10px;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-weight: 600;
  padding: 4px 5px 4px 2px;
  text-align: right;
  border-right: 1px solid #cccccc;
  user-select: none;
  line-height: 14px;
}

/* Individual cell */
.g-cell {
  padding: 3px 6px;
  font-size: 11px;
  font-family: 'Cascadia Code', Consolas, monospace;
  border-right: 1px solid #d0d0d0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 22px;
  position: relative;
  transition: background 0.05s;
}
.g-cell:last-child { border-right: none; }
.g-cell:hover { background: rgba(0,0,0,0.04); }

/* Selected cell */
.g-cell.sel {
  outline: 2px solid #5a5a5a;
  outline-offset: -2px;
  background: rgba(90,90,90,0.10) !important;
  z-index: 2;
}

.cn { flex: 1; font-size: 11px; letter-spacing: 0.5px; font-weight: 700; }
.cv { font-size: 9px; color: #999; min-width: 14px; text-align: right; font-weight: 600; }

/* Color-coded note text per channel */
.g-cell.has-note.ch1   .cn { color: #c0392b; }
.g-cell.has-note.ch2   .cn { color: #27ae60; }
.g-cell.has-note.ch3   .cn { color: #2980b9; }
.g-cell.has-note.noise .cn { color: #666666; }
.g-cell.has-note .cv        { color: #888; }
.g-cell:not(.has-note) .cn  { color: #cccccc; }

/* ============================================================
   INSPECTOR (bottom panel)
   ============================================================ */
#inspector {
  background: #cccccc;
  border-top: 1.5px solid #999999;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#insp-pos {
  font-size: 11px;
  color: #789;
  font-weight: 600;
  font-style: italic;
  min-width: 120px;
}

.insp-lbl { font-size: 11px; color: #556; font-weight: 600; }

#insp-note, #insp-ntype {
  background: #f8f8f8;
  border: 1.5px solid #5a5a5a;
  color: #1a1a1a;
  padding: 3px 6px;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  border-radius: 5px;
}
#insp-note:focus, #insp-ntype:focus {
  outline: none;
  border-color: #4a4a4a;
  box-shadow: 0 0 0 2px rgba(80,80,80,0.2);
}
#insp-note  { width: 88px; }
#insp-ntype { width: 106px; }

#insp-vol {
  background: #f8f8f8;
  border: 1.5px solid #5a5a5a;
  color: #1a1a1a;
  padding: 3px 6px;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  border-radius: 5px;
  width: 52px;
}
#insp-vol:focus {
  outline: none;
  border-color: #4a4a4a;
  box-shadow: 0 0 0 2px rgba(80,80,80,0.2);
}

/* ============================================================
   PIANO BAR
   ============================================================ */
#piano-bar {
  background: #bbbbbb;
  border-top: 1.5px solid #999999;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 6px 8px 5px;
  user-select: none;
}
#piano-canvas {
  display: block;
  cursor: pointer;
}
#piano-controls {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
}
.piano-ctrl-label {
  font-size: 9px;
  font-weight: 700;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#piano-root, #piano-scale {
  background: #f8f8f8;
  border: 1.5px solid #5a5a5a;
  color: #1a1a1a;
  padding: 2px 4px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  width: 108px;
}

/* ============================================================
   STATUS BAR
   ============================================================ */
#statusbar {
  background: #aaaaaa;
  border-top: 1px solid #999999;
  padding: 3px 12px;
  font-size: 10px;
  color: #444;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}
#status-save { color: #336633; font-weight: 600; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #d0d0d0; }
::-webkit-scrollbar-thumb { background: #999999; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #777777; }

/* ============================================================
   IMPORT MODAL
   ============================================================ */
#import-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#import-overlay.show { display: flex; }

#import-modal {
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  border-radius: 8px;
  width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

#import-modal .modal-title {
  background: #5a5a5a;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  border-radius: 6px 6px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#import-modal .modal-close {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.1s;
}
#import-modal .modal-close:hover { color: #fff; }

#import-hint {
  padding: 8px 14px 4px;
  font-size: 11px;
  color: #556;
  line-height: 1.5;
  border-bottom: 1px solid #cccccc;
  background: #f4f4f4;
}

#import-textarea {
  flex: 1;
  resize: none;
  border: none;
  padding: 10px 12px;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #1a1a1a;
  background: #fafafa;
  outline: none;
  min-height: 280px;
}

#import-error {
  padding: 5px 14px;
  font-size: 11px;
  color: #a03030;
  font-weight: 600;
  min-height: 22px;
  background: #fef0f0;
  display: none;
}
#import-error.show { display: block; }

#import-footer {
  padding: 8px 14px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 1.5px solid #cccccc;
  background: #e4e4e4;
  border-radius: 0 0 6px 6px;
}
#import-footer .fmt-note {
  font-size: 11px;
  color: #789;
  font-style: italic;
  margin-left: auto;
}

/* ============================================================
   EXPORT MODAL
   ============================================================ */
#modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
#modal-overlay.show { display: flex; }

#modal {
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  border-radius: 8px;
  width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

#modal-title {
  background: #5a5a5a;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  border-radius: 6px 6px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#modal-close {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.1s;
}
#modal-close:hover { color: #fff; }

#modal-code {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-size: 11px;
  line-height: 1.6;
  white-space: pre;
  color: #2a4a2a;
  background: #f4f4ee;
  font-family: 'Cascadia Code', Consolas, monospace;
  border-top: 1px solid #cccccc;
}

#modal-footer {
  padding: 8px 14px;
  display: flex;
  gap: 8px;
  border-top: 1.5px solid #cccccc;
  background: #e4e4e4;
  border-radius: 0 0 6px 6px;
}
