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

:root {
  --bg: #1a1a2e;
  --surface: #252538;
  --surface2: #2e2e48;
  --border: #3a3a5e;
  --accent: #7c6af7;
  --accent-hi: #a89cf8;
  --text: #e0e0f0;
  --muted: #777999;
  --note-active: #7c6af7;
  --note-done: #3a3a5e;
  --success: #4caf7d;
  --danger: #e05c5c;
  --warning: #e0a050;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ── Header ── */
header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}
header h1 { font-size: 1.3rem; font-weight: 700; color: var(--accent-hi); letter-spacing: -0.3px; }
.app-version { font-size: 0.62rem; font-weight: 600; color: var(--muted); letter-spacing: 0; vertical-align: baseline; }
header p  { font-size: 0.8rem; color: var(--muted); }

/* ── Layout ── */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 0;
  overflow: hidden;
  height: calc(100vh - 48px);
}

/* ── Left sidebar: settings + input ── */
.sidebar {
  grid-row: 1 / -1;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section {
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1rem;
}
.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

/* ── Settings grid ── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
}
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 0.72rem; color: var(--muted); }
.field select, .field input[type=number], .field input[type=range] {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
  width: 100%;
}
.field select:focus, .field input:focus { outline: 1px solid var(--accent); }
.derived-value {
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-hi);
  padding: 0.3rem 0;
}
.derived-note {
  font-size: 0.68rem;
  color: var(--muted);
  font-style: italic;
}
.field .value-label { font-size: 0.72rem; color: var(--accent-hi); text-align: right; }

/* ── ABC Input ── */
.abc-input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.9rem 1rem 0;
}
.abc-input-wrap textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  padding: 0.6rem;
  border-radius: 5px;
  resize: none;
  outline: none;
  min-height: 120px;
}
.abc-input-wrap textarea:focus { border-color: var(--accent); }
.input-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0 0.75rem;
}

/* ── Main area ── */
.main-area {
  grid-column: 2;
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Transport / click track ── */
.transport {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--surface);
}
.transport-btns { display: flex; gap: 0.5rem; }
.beat-display {
  display: flex;
  gap: 5px;
  align-items: center;
}
.beat-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.05s;
}
.beat-dot.downbeat { width: 14px; height: 14px; }
.beat-dot.active { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.beat-dot.downbeat.active { background: var(--accent-hi); }

.transport-status { font-size: 0.82rem; color: var(--muted); flex: 1; }
.transport-status.recording { color: var(--danger); font-weight: 600; }
.transport-status.ready { color: var(--success); font-weight: 600; }

/* ── Note sequence strip ── */
.note-strip-wrap {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.25rem;
  background: var(--bg);
  overflow-x: auto;
}
.note-strip {
  display: flex;
  gap: 5px;
  align-items: center;
  min-height: 44px;
}
.note-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 44px;
  border-radius: 5px;
  background: var(--surface2);
  border: 2px solid transparent;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  transition: all 0.08s ease;
  cursor: pointer;
  user-select: none;
  padding: 0 4px;
  position: relative;
}
.note-chip .dur-label {
  font-size: 0.55rem;
  font-weight: 400;
  color: var(--muted);
  font-family: 'Segoe UI', sans-serif;
  line-height: 1;
  margin-top: 2px;
}
.note-chip.active {
  background: var(--note-active);
  border-color: var(--accent-hi);
  color: #fff;
  transform: scale(1.12);
  box-shadow: 0 0 10px rgba(124,106,247,0.7);
}
.note-chip.active .dur-label { color: rgba(255,255,255,0.8); }
.note-chip.done { background: var(--note-done); color: #666; }
.note-chip.done .dur-label { color: #555; }
.note-chip.rest { color: var(--muted); font-style: italic; }
/* Hover affordance for the clickable note/rest chips (bar lines excluded). */
.note-chip:not(.bar):not(.cursor):not(.active):hover {
  border-color: var(--accent-hi);
}
.note-chip.bar {
  background: transparent;
  color: var(--border);
  min-width: 12px;
  font-size: 1.1rem;
  font-weight: 300;
  border: none;
  cursor: default;
}
/* Manual edit mode: note under the cursor */
.note-chip.cursor {
  background: var(--warning);
  border-color: #f0c040;
  color: #1a1a2e;
  transform: scale(1.12);
  box-shadow: 0 0 10px rgba(224,160,80,0.7);
}
.note-chip.cursor .dur-label { color: rgba(26,26,46,0.75); }

/* ── Big TAP button ── */
.tap-area {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.tap-btn {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.12s, transform 0.08s;
  user-select: none;
}
.tap-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.tap-btn:not(:disabled):active { transform: scale(0.98); }
.tap-btn.recording { background: #8b2020; }
.tap-btn.recording:not(:disabled):active { background: var(--danger); }

/* ── Score panel ── */
.score-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  background: var(--bg);
}
.score-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.score-tab {
  padding: 0.42rem 0.9rem;
  margin-bottom: -1px;
  border-radius: 5px 5px 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-bottom-color: var(--border);
  color: var(--muted);
}
.score-tab:not(.active):hover { color: var(--text); background: rgba(255,255,255,0.03); }
.score-tab.active {
  background: var(--bg);
  border-color: var(--border);
  border-bottom-color: var(--bg);
  color: var(--accent-hi);
}
#score-container { min-height: 120px; }

/* ── Output ABC ── */
.output-abc-wrap { padding: 0 1.25rem 1rem; }
#output-abc {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 0.6rem;
  border-radius: 5px;
  resize: vertical;
  outline: none;
  min-height: 80px;
}

/* ── Buttons ── */
button {
  padding: 0.35rem 0.75rem;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.12s, transform 0.08s;
}
button:disabled { opacity: 0.38; cursor: not-allowed; }
button:not(:disabled):active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent-hi); }
.btn-secondary { background: var(--surface2); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:not(:disabled):hover { border-color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }

@media (max-width: 750px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .main-area { grid-column: 1; }
}
