/* ============================================
   8ビット音楽作成 - アプリ固有スタイル
   ============================================ */

.eightbit-music-body {
  min-height: 100vh;
  background: var(--bg-secondary);
}

/* ============================================
   メインレイアウト
   ============================================ */
.music-main {
  padding: var(--spacing-lg) var(--spacing-md);
  min-height: calc(100vh - 60px);
}

.music-container {
  max-width: 1000px;
  margin: 0 auto;
}

.music-header {
  text-align: center;
  margin-bottom: var(--spacing-xl);
}

.music-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--spacing-xs);
}

.music-subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* ============================================
   トランスポートバー
   ============================================ */
.transport-bar {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-sm) var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  flex-wrap: wrap;
}

.transport-btn {
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
}

.transport-btn--play {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
}

.transport-btn--play:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.transport-btn--play.is-playing {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.transport-btn--stop {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.transport-btn--stop:hover {
  background: var(--border-color);
}

.transport-btn--eraser {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.transport-btn--eraser:hover {
  background: var(--border-color);
}

.transport-btn--eraser.is-active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.sequencer.eraser-mode .step-cell {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Crect x='3' y='8' width='14' height='9' rx='2' fill='%23f59e0b'/%3E%3Crect x='6' y='3' width='8' height='6' rx='1' fill='%23fbbf24'/%3E%3C/svg%3E") 3 18, crosshair;
}

.transport-btn--import {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  margin-left: auto;
}

.transport-btn--import:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.transport-btn--export-midi {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
}

.transport-btn--export-midi:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.transport-btn--export {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
}

.transport-btn--export:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.transport-loop {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
}

.transport-loop input[type="checkbox"] {
  accent-color: var(--primary-color);
  width: 16px;
  height: 16px;
}

.steps-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.steps-label {
  color: var(--text-light);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.steps-select {
  display: flex;
  gap: 3px;
}

.steps-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: monospace;
}

.steps-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.steps-btn.active {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #2563eb;
  color: white;
}

.bpm-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bpm-label {
  color: var(--text-light);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.bpm-slider {
  width: 120px;
  accent-color: var(--primary-color);
  cursor: pointer;
}

.bpm-value {
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 700;
  min-width: 2.5rem;
  text-align: right;
}

/* ============================================
   パターンバー
   ============================================ */
.pattern-bar-wrap {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.pattern-bar-label {
  color: var(--text-light);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.pattern-bar {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.pattern-tab {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 5px;
  position: relative;
}

.pattern-tab:hover {
  border-color: #60a5fa;
  color: #60a5fa;
}

.pattern-tab.is-active {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #2563eb;
  color: white;
}

.pattern-tab--add {
  color: var(--text-light);
  font-size: 1rem;
  padding: 0.2rem 0.6rem;
}

.pattern-tab--add:hover {
  color: #10b981;
  border-color: #10b981;
}

.pattern-tab--add:disabled {
  opacity: 0.4;
  cursor: default;
}

.pattern-tab-del {
  font-size: 0.65rem;
  opacity: 0.6;
  line-height: 1;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: none;
  align-items: center;
  justify-content: center;
}

.pattern-tab-del:hover {
  opacity: 1;
  background: rgba(255,255,255,0.25);
}

body.eraser-active .pattern-tab-del {
  display: flex;
}

/* ============================================
   シーケンサーグリッド
   ============================================ */
.sequencer {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.channel-label {
  width: 90px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.channel-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
}

.channel-sub {
  font-size: 0.7rem;
  color: var(--text-light);
}

.step-grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.sequencer.steps-32 .step-cell {
  font-size: 0.45rem;
}

.sequencer.steps-8 .step-cell {
  font-size: 0.75rem;
}

/* ステップセル（メロディ系・共通） */
.step-cell {
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  cursor: pointer;
  position: relative;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: transparent;
  overflow: hidden;
}

.step-cell:hover {
  border-color: var(--primary-light);
  background: rgba(59, 130, 246, 0.1);
}

/* アクティブなメロディステップ */
.step-cell.is-active {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-color: #6366f1;
  color: rgba(255, 255, 255, 0.9);
}

/* アルペジオ付きステップ */
.step-cell.has-arp {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  border-color: #ec4899;
  color: rgba(255, 255, 255, 0.9);
}

/* アルペジオマーク */
.step-cell.has-arp::after {
  content: 'A';
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.5rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1;
}

/* 音の長さ > 1 のセル */
.step-cell.has-length {
  justify-content: flex-start;
  padding-left: 6px;
}

.step-cell.has-length::before {
  content: '×' attr(data-length);
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.5rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1;
}

/* 現在再生中のステップ */
.step-cell.is-playing {
  box-shadow: 0 0 0 2px #fbbf24, 0 0 8px rgba(251, 191, 36, 0.6);
  z-index: 1;
}

/* ノイズチャンネルのセル */
.step-cell--hh {
  background: linear-gradient(135deg, #0891b2, #06b6d4);
  border-color: #06b6d4;
  color: white;
  font-size: 0.6rem;
}

.step-cell--sn {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  border-color: #f59e0b;
  color: white;
  font-size: 0.6rem;
}

.step-cell--kk {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  border-color: #ef4444;
  color: white;
  font-size: 0.6rem;
}

/* rim / tom はノイズの派生色 */
.step-cell--rim {
  background: linear-gradient(135deg, #7c3aed, #8b5cf6);
  border-color: #8b5cf6;
  color: white;
  font-size: 0.6rem;
}

.step-cell--tom {
  background: linear-gradient(135deg, #b45309, #d97706);
  border-color: #d97706;
  color: white;
  font-size: 0.6rem;
}




/* Wave プリセットセレクター */
.wave-select {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.wave-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #1f2937;
  color: #e5e7eb;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background 0.15s, border-color 0.15s;
  min-width: 50px;
}
.wave-btn-desc {
  font-size: 0.6rem;
  color: #9ca3af;
}
.wave-btn:hover {
  background: #374151;
  border-color: #22d3ee;
}
.wave-btn.active {
  background: linear-gradient(135deg, #0e4f5a, #06b6d4);
  border-color: #06b6d4;
  color: white;
}
.wave-btn.active .wave-btn-desc {
  color: #a5f3fc;
}

/* GB ノイズセル */
.step-cell--noise-gb {
  background: linear-gradient(135deg, #166534, #22c55e);
  border-color: #22c55e;
  color: white;
  font-size: 0.6rem;
}

/* ノイズポップアップ */
.noise-popup {
  max-width: 320px;
}

.noise-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.noise-mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.6rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.noise-mode-btn:hover {
  border-color: var(--accent-color);
}

.noise-mode-btn.is-selected {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
}

.noise-mode-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: monospace;
}

.noise-mode-desc {
  font-size: 0.7rem;
  color: var(--text-light);
}

/* ステップ番号行 */
.step-numbers {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-top: 4px;
}

.channel-label-spacer {
  width: 90px;
  flex-shrink: 0;
}

.step-number-row {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.step-num {
  text-align: center;
  font-size: 0.6rem;
  color: var(--text-light);
  font-weight: 600;
}

.step-num.is-beat {
  color: var(--primary-light);
}

/* ============================================
   音程ポップアップ
   ============================================ */
.note-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}

.note-popup-overlay[hidden] {
  display: none;
}

.note-popup {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--spacing-md);
  width: min(560px, 96vw);
  box-shadow: var(--shadow-xl);
}

.note-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-md);
}

.note-popup-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.note-popup-close {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.note-popup-close:hover {
  color: var(--text-primary);
}

.note-popup-section {
  margin-bottom: var(--spacing-md);
}

.note-popup-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* 音程選択グリッド（オクターブラベル列 + 12半音列） */
.note-select-grid {
  display: grid;
  grid-template-columns: 1.4rem repeat(12, 1fr);
  gap: 3px;
}

.note-oct-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-light);
}

.note-btn {
  padding: 0.35rem 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

/* 黒鍵（#）スタイル */
.note-btn--sharp {
  background: #1e2533;
  border-color: #3a4458;
  color: var(--text-light);
  font-size: 0.6rem;
}

.note-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary-light);
}

.note-btn.is-selected {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-color: #6366f1;
  color: white;
}

/* デューティ比選択 */
.duty-select {
  display: flex;
  gap: 6px;
}

.duty-btn {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: monospace;
}

.duty-btn:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

.duty-btn.active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-color: #d97706;
  color: white;
}

/* アルペジオ選択 */
.arp-select {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.arp-btn {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.arp-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.arp-btn.active {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  border-color: #ec4899;
  color: white;
}

/* 音の長さ選択 */
.length-select {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.length-btn {
  flex: 1;
  padding: 0.4rem 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.length-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary-light);
}

.length-btn.active {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-color: #6366f1;
  color: white;
}

.note-popup-actions {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
  margin-top: var(--spacing-sm);
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--border-color);
}

.note-popup-btn {
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
}

.note-popup-btn--clear {
  background: var(--bg-secondary);
  color: var(--text-light);
  border: 1px solid var(--border-color);
}

.note-popup-btn--clear:hover {
  color: #ef4444;
  border-color: #ef4444;
}

.note-popup-btn--ok {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: white;
}

.note-popup-btn--ok:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* ============================================
   エクスポートオーバーレイ
   ============================================ */
.export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

.export-overlay[hidden] {
  display: none;
}

.export-dialog {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--spacing-xl);
  width: min(360px, 90vw);
  text-align: center;
  box-shadow: var(--shadow-xl);
}

.export-message {
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: var(--spacing-md);
}

.export-bar-wrap {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.export-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  border-radius: var(--radius-full);
  transition: width 0.2s ease;
}

/* ============================================
   ポートレートモード（縦長 / スマホ）
   ============================================ */

/* ── ポートレートグリッドラッパー ── */
.portrait-wrapper {
  display: grid;
  gap: 3px;
  width: 100%;
}

.portrait-ch-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  min-width: 0;
}

.portrait-ch-name {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.portrait-ch-sub {
  font-size: 0.5rem;
  color: var(--text-light);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.portrait-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--text-light);
  min-width: 0;
}

.portrait-step-num.is-beat {
  color: var(--primary-light);
  font-weight: 800;
}

/* Continuation cell (covered by a length-span in portrait mode) */
.step-cell--cont {
  background: rgba(59, 130, 246, 0.12);
  border: 1px dashed rgba(99, 102, 241, 0.3);
  height: 28px;
  cursor: default;
  pointer-events: none;
}

/* ── レスポンシブ共通 (≤640px) ── */
@media (max-width: 640px) {
  .music-main {
    padding: var(--spacing-sm);
  }

  .music-container {
    max-width: 100%;
  }

  .music-header {
    margin-bottom: var(--spacing-md);
  }

  /* トランスポートバー: 2行に折り返し */
  .transport-bar {
    gap: 0.4rem;
    padding: var(--spacing-xs) var(--spacing-sm);
    row-gap: 0.5rem;
  }

  .bpm-slider {
    width: 70px;
  }

  .transport-btn {
    padding: 0.45rem 0.8rem;
    font-size: 0.8rem;
  }

  /* インポート・エクスポートボタンは行末ではなく通常フロー */
  .transport-btn--import,
  .transport-btn--export-midi,
  .transport-btn--export {
    margin-left: 0;
  }

  /* ステップ数・チップモードを小さく */
  .steps-label,
  .chip-mode-label {
    display: none;
  }

  /* シーケンサー本体 */
  .sequencer {
    padding: var(--spacing-xs) var(--spacing-xs);
    gap: 3px;
  }

  /* ポートレートモードのセルは小さく */
  .portrait-wrapper .step-cell {
    height: 28px;
    font-size: 0.5rem;
  }

  /* ポップアップをフルスクリーン寄りに */
  .note-popup {
    width: min(98vw, 560px);
    max-height: 90vh;
    overflow-y: auto;
    padding: var(--spacing-sm);
    border-radius: var(--radius-lg);
  }

  .note-select-grid {
    gap: 2px;
  }

  .note-btn {
    padding: 0.3rem 0;
    font-size: 0.6rem;
  }

  .length-select {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
  }

  .length-btn {
    padding: 0.35rem 0;
    font-size: 0.75rem;
  }

  .arp-select {
    gap: 4px;
  }

  .arp-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
  }

  /* ノイズポップアップ */
  .noise-popup {
    max-width: 98vw;
  }
}
