:root {
  --bg: #0f1117;
  --panel: #171b24;
  --panel-border: #262c3a;
  --text: #e6ebf5;
  --muted: #8b95a7;
  --accent: #4f8cff;
  --accent-hover: #3b76e8;
  --danger: #ef4444;
  --success: #10b981;
  --cell-bg: #1c212c;
  --cell-beat: #222836;
  --cell-active: #4f8cff;
  --playhead: rgba(250, 204, 21, 0.22);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 28px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
}

.subtitle {
  font-size: 12px;
  color: var(--muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

select,
input[type="number"],
input[type="text"] {
  background: #0d1016;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

input[type="number"] {
  width: 72px;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.badge-d1 {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-local {
  background: rgba(79, 140, 255, 0.16);
  color: #7aaaff;
  border: 1px solid rgba(79, 140, 255, 0.35);
}

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
  padding: 16px 20px;
  flex: 1;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

.editor-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* Buttons */
.btn {
  background: #232938;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #2d3548;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-accent {
  background: var(--success);
  border-color: var(--success);
  color: #062117;
  font-weight: 600;
}

.btn-accent:hover {
  filter: brightness(1.08);
}

.btn-record.active {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse 1.2s infinite;
}

.btn.active-toggle {
  background: #334155;
  border-color: var(--accent);
  color: #93c5fd;
}

.btn-ghost {
  background: transparent;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.72; }
}

/* Toolbar & Save bar */
.toolbar,
.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 14px;
}

.transport-buttons,
.tempo-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tempo-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.save-bar {
  justify-content: flex-start;
}

.save-bar input[type="text"] {
  flex: 1;
  min-width: 200px;
}

.status-message {
  font-size: 12px;
  color: var(--muted);
}

/* Sequencer / Piano Roll */
.sequencer-section,
.piano-section,
.sidebar {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.section-header h2 {
  font-size: 14px;
  font-weight: 600;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.sequencer-scroll {
  overflow: auto;
  max-height: 340px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: #0d1016;
}

.sequencer-grid {
  display: grid;
  width: max-content;
}

.seq-row {
  display: flex;
  align-items: stretch;
}

.seq-label {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 56px;
  min-width: 56px;
  padding: 3px 6px;
  font-size: 11px;
  font-family: monospace;
  background: #151923;
  color: var(--muted);
  border-right: 1px solid var(--panel-border);
  border-bottom: 1px solid #1d222e;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.seq-label.is-black {
  background: #10131b;
  color: #6b7280;
}

.seq-label.is-c {
  color: #93c5fd;
  font-weight: 700;
}

.seq-cell {
  width: 26px;
  height: 20px;
  background: var(--cell-bg);
  border-right: 1px solid #161a23;
  border-bottom: 1px solid #161a23;
  cursor: pointer;
  transition: background 0.08s;
}

.seq-cell.beat-start {
  background: var(--cell-beat);
  border-left: 1px solid #2d3548;
}

.seq-cell:hover {
  background: #2b3346;
}

.seq-cell.active {
  background: var(--cell-active);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.seq-cell.playhead {
  box-shadow: inset 0 0 0 99px var(--playhead);
}

.seq-cell.active.playhead {
  background: #facc15;
}

/* Piano Keyboard */
.octave-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.octave-label {
  font-size: 12px;
  font-weight: 600;
  min-width: 58px;
  text-align: center;
}

.piano-keyboard {
  position: relative;
  display: flex;
  height: 165px;
  user-select: none;
  touch-action: none;
  overflow-x: auto;
  padding-bottom: 4px;
}

.white-key {
  position: relative;
  flex: 1;
  min-width: 38px;
  height: 100%;
  background: linear-gradient(180deg, #ffffff 0%, #e5e7eb 100%);
  border: 1px solid #9ca3af;
  border-radius: 0 0 6px 6px;
  color: #374151;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 8px;
  font-size: 11px;
  cursor: pointer;
  z-index: 1;
}

.white-key:hover {
  background: linear-gradient(180deg, #f9fafb 0%, #d1d5db 100%);
}

.white-key.pressed {
  background: linear-gradient(180deg, #dbeafe 0%, #93c5fd 100%);
  transform: translateY(2px);
}

.black-key {
  position: absolute;
  top: 0;
  width: 24px;
  height: 60%;
  background: linear-gradient(180deg, #374151 0%, #111827 100%);
  border: 1px solid #030712;
  border-radius: 0 0 4px 4px;
  color: #9ca3af;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 6px;
  font-size: 10px;
  cursor: pointer;
  z-index: 2;
  transform: translateX(-50%);
}

.black-key:hover {
  background: linear-gradient(180deg, #4b5563 0%, #1f2937 100%);
}

.black-key.pressed {
  background: linear-gradient(180deg, #3b82f6 0%, #1d4ed8 100%);
  color: #fff;
}

.key-shortcut {
  font-size: 9px;
  opacity: 0.7;
  margin-top: 2px;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.score-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.score-item {
  background: #10141d;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.score-info {
  min-width: 0;
  cursor: pointer;
  flex: 1;
}

.score-info:hover .score-name {
  color: var(--accent);
}

.score-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.score-actions {
  display: flex;
  gap: 4px;
}

.io-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.file-label {
  display: inline-flex;
  align-items: center;
}
