/* Trống điện tử online - Drum Machine | GarageBand Style */
:root {
  --bg-primary: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-elevated: #3a3a3c;
  --bg-tertiary: #48484a;
  --accent: #ff9f0a;
  --accent-hover: #ffb340;
  --accent-muted: rgba(255, 159, 10, 0.2);
  --text-primary: #ffffff;
  --text-secondary: #8e8e93;
  --border: #48484a;
  --cell-inactive: #3a3a3c;
  --cell-active: #ff9f0a;
  --cell-variant: #64d2ff;
  --red: #ff453a;
  --red-hover: #ff6961;
  --green: #30d158;
  --green-hover: #5ce27a;
  --blue: #0a84ff;
  --blue-hover: #409cff;
  --purple: #bf5af2;
  --purple-hover: #d48cf7;
  --teal: #64d2ff;
  --teal-hover: #8ee0ff;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.2);
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
}

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

/* Scrollbar dark theme */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  padding: calc(2rem + env(safe-area-inset-top, 0px)) calc(2rem + env(safe-area-inset-right, 0px)) calc(2rem + env(safe-area-inset-bottom, 0px)) calc(2rem + env(safe-area-inset-left, 0px));
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Chặn menu mặc định khi long-press trên iPhone/iPad (chỉ trang drum chính) */
body.app-drum {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.app-drum input,
body.app-drum textarea,
body.app-drum select {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  background: var(--bg-secondary);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow-subtle);
  border: 1px solid var(--border);
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.lang-switcher {
  display: flex;
  gap: 0.25rem;
}

.lang-switcher .lang-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.login-prompt {
  display: flex;
  align-items: center;
  position: relative;
}

.login-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 280px;
  white-space: normal;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10;
}

.login-prompt:hover .login-tooltip {
  opacity: 1;
  visibility: visible;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.user-name {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-ghost {
  border: none;
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}

.btn-ghost:hover {
  background: var(--accent-muted);
  color: var(--accent-hover);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
}

/* Controls - Transport bar style */
.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.preset-name {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
  min-width: 0;
}

.current-preset-section {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 2.5rem;
  margin-bottom: 1rem;
}

.sequencer-transport {
  display: flex;
  align-items: center;
  padding: 0.75rem 0;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.current-preset-name {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-muted);
  padding: 0.35rem 1rem;
  border-radius: 9999px;
  border: none;
  text-align: center;
  min-width: 120px;
  transition: opacity 0.2s;
}

.current-preset-name:empty {
  opacity: 0.7;
  color: var(--text-secondary);
  background: var(--cell-inactive);
  font-weight: 400;
}

.current-preset-name:empty::after {
  content: attr(data-empty);
  font-style: italic;
}

.current-preset-name:not(:empty)::before {
  content: attr(data-preset-label);
  font-weight: 500;
  color: var(--text-secondary);
  margin-right: 0.25rem;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
  touch-action: manipulation;
  box-shadow: var(--shadow-subtle);
}

.btn:hover {
  background: var(--bg-tertiary);
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-play {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border: none;
  color: #1a1a1a;
  border-radius: 50%;
  box-shadow: 0 2px 12px rgba(255, 159, 10, 0.4);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn-play:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(255, 159, 10, 0.5);
}

.btn-play.playing {
  background: var(--red);
  color: #fff;
  box-shadow: 0 2px 12px rgba(255, 69, 58, 0.4);
}

.btn-play.playing:hover {
  background: var(--red-hover);
  box-shadow: 0 4px 16px rgba(255, 69, 58, 0.5);
}

.play-icon {
  font-size: 1.2rem;
}

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

.tempo-control label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.tempo-control input {
  width: 60px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
  background: var(--bg-elevated);
  color: var(--text-primary);
}

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

.time-signature-control label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.time-signature-control select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
}

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

.sound-control label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sound-control select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  min-width: 100px;
}

.metronome-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.metronome-option input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--accent);
}

.controls-row-volume {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.controls-row-volume-end {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.master-volume-control,
.dynamics-control,
.swing-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.master-volume-control label,
.dynamics-control label,
.swing-control label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 4rem;
}

.master-volume-control input[type="range"],
.dynamics-control input[type="range"],
.swing-control input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
}

.chain-description {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.chain-add-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.chain-measures-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.chain-measures-input-wrap label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.chain-measures-input-wrap input {
  width: 48px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.9rem;
  text-align: center;
}

.chain-select {
  flex: 1;
  min-width: 0;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.chain-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.chain-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-elevated);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.chain-item .chain-order {
  font-weight: 600;
  color: var(--accent);
  min-width: 1.5rem;
}

.chain-item .chain-name {
  flex: 1;
}

.chain-item .chain-measures-edit {
  width: 44px;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.85rem;
  text-align: center;
}
.chain-item .chain-remove {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

.chain-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* === Semantic button colors by function ===
   btn-primary: Accent - main action (Play)
   btn-success: Green - save, add, confirm, export (Sao chép link, Thêm)
   btn-download: Teal - tải xuống file
   btn-info: Blue - share, user data (Điệu của tôi, Share)
   btn-browse: Purple - browse (Điệu mẫu)
   btn-danger: Red - delete, clear (Xoá, Xóa)
   btn-close: Outline - close, cancel (Đóng, Hủy)
   btn-edit: Accent - edit (Sửa)
   btn-ghost: Transparent - auth (Login, Logout)
*/
.btn-primary {
  background: var(--accent);
  color: #1a1a1a;
  box-shadow: 0 2px 8px rgba(255, 159, 10, 0.25);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(255, 159, 10, 0.35);
}

/* Success: save, add, confirm, export - xanh lá */
.btn-success {
  background: var(--green);
  color: #fff;
  box-shadow: 0 2px 8px rgba(48, 209, 88, 0.25);
}
.btn-success:hover {
  background: var(--green-hover);
  box-shadow: 0 4px 12px rgba(48, 209, 88, 0.35);
}

/* Info: share, user presets - xanh dương */
.btn-info {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(10, 132, 255, 0.25);
}
.btn-info:hover {
  background: var(--blue-hover);
  box-shadow: 0 4px 12px rgba(10, 132, 255, 0.35);
}

/* Browse: browse presets - tím */
.btn-browse {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 2px 8px rgba(191, 90, 242, 0.25);
}
.btn-browse:hover {
  background: var(--purple-hover);
  box-shadow: 0 4px 12px rgba(191, 90, 242, 0.35);
}

/* Danger: delete, clear - đỏ */
.btn-danger {
  background: var(--red);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 69, 58, 0.25);
}
.btn-danger:hover {
  background: var(--red-hover);
  box-shadow: 0 4px 12px rgba(255, 69, 58, 0.35);
}

/* Close: close, cancel - outline đỏ */
.btn-close {
  background: transparent;
  color: var(--red);
  border: 1.5px solid var(--red);
  box-shadow: none;
}
.btn-close:hover {
  background: rgba(255, 69, 58, 0.15);
  color: var(--red-hover);
  border-color: var(--red-hover);
}

/* Edit: edit action */
.btn-edit {
  background: var(--accent);
  color: #1a1a1a;
  box-shadow: 0 2px 8px rgba(255, 159, 10, 0.25);
}
.btn-edit:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(255, 159, 10, 0.35);
}

/* Download: tải xuống file - xanh ngọc */
.btn-download {
  background: var(--teal);
  color: #0d1f26;
  box-shadow: 0 2px 8px rgba(100, 210, 255, 0.25);
}
.btn-download:hover {
  background: var(--teal-hover);
  box-shadow: 0 4px 12px rgba(100, 210, 255, 0.35);
}

/* Upload: tải file lên */
.btn-upload {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(10, 132, 255, 0.25);
}
.btn-upload:hover {
  background: var(--blue-hover);
  box-shadow: 0 4px 12px rgba(10, 132, 255, 0.35);
}

/* Legacy aliases for compatibility */
.btn-save { background: var(--green); color: #fff; box-shadow: 0 2px 8px rgba(48, 209, 88, 0.25); }
.btn-save:hover { background: var(--green-hover); box-shadow: 0 4px 12px rgba(48, 209, 88, 0.35); }
.btn-secondary { background: var(--blue); color: #fff; box-shadow: 0 2px 8px rgba(10, 132, 255, 0.25); }
.btn-secondary:hover { background: var(--blue-hover); box-shadow: 0 4px 12px rgba(10, 132, 255, 0.35); }

/* Disabled state for all buttons */
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.save-section {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.copy-status {
  font-size: 0.85rem;
  color: var(--accent);
}

/* Sequencer Grid */
.sequencer {
  margin-bottom: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.grid-header {
  display: flex;
  margin-bottom: 0.25rem;
}

.instrument-label {
  width: 140px;
  flex-shrink: 0;
  font-size: 0.8rem;
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.instrument-label.empty {
  visibility: hidden;
}

.volume-label {
  width: 48px;
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.instrument-volume-wrap {
  width: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.instrument-volume {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--cell-inactive);
  border-radius: 3px;
  cursor: pointer;
}

.instrument-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5ac8fa;
  cursor: pointer;
  transition: transform 0.1s;
}

.instrument-volume::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  background: #7dd4fc;
}

.instrument-volume::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #5ac8fa;
  cursor: pointer;
  border: none;
}

.instrument-volume::-moz-range-thumb:hover {
  background: #7dd4fc;
}

.steps-header {
  flex: 1;
  display: grid;
  gap: 2px;
}

.steps-header-12 { grid-template-columns: repeat(12, 1fr); min-width: 240px; }
.steps-header-16 { grid-template-columns: repeat(16, 1fr); min-width: 320px; }
.steps-header-24 { grid-template-columns: repeat(24, 1fr); min-width: 480px; }
.steps-header-32 { grid-template-columns: repeat(32, 1fr); min-width: 640px; }

.measure {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

.sequencer-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sequencer-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.instrument-name {
  width: 140px;
  flex-shrink: 0;
  font-size: 0.85rem;
  padding: 0.25rem 0;
  cursor: pointer;
  user-select: none;
  color: var(--text-primary);
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-secondary);
  transition: color 0.2s;
}

.instrument-name:hover {
  color: var(--text-primary);
}

.instrument-name.muted {
  color: var(--text-secondary);
  text-decoration: line-through;
}

.steps {
  display: grid;
  gap: 2px;
  flex: 1;
}

.steps-12 { grid-template-columns: repeat(12, 1fr); min-width: 240px; }
.steps-16 { grid-template-columns: repeat(16, 1fr); min-width: 320px; }
.steps-24 { grid-template-columns: repeat(24, 1fr); min-width: 480px; }
.steps-32 { grid-template-columns: repeat(32, 1fr); min-width: 640px; }

.step {
  aspect-ratio: 1;
  min-width: 20px;
  max-width: 26px;
  width: 100%;
  background: var(--cell-inactive);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none; /* Tắt menu mặc định, dùng long-press mở Tuplet */
}

/* Highlight nhịp đập đầu tiên của từng phách (ô 1, 5, 9, 13) */
.step.downbeat {
  background: #48484a;
}

.step:hover {
  background: var(--bg-tertiary);
}

.step.active {
  background: var(--cell-active);
}

.step.active:hover {
  background: var(--accent-hover);
}

/* Open Hi-hat / Snare rimshot - màu khác để phân biệt */
.step.active.variant {
  background: var(--cell-variant);
}

.step.active.variant:hover {
  background: #5ac8fa;
}

.step.active.ghost {
  background: rgba(255, 159, 10, 0.5);
}

.step.active.ghost:hover {
  background: rgba(255, 159, 10, 0.65);
}

.step.current {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.step.step-tuplet {
  position: relative;
}
.step-tuplet-badge {
  font-size: 0.6em;
  opacity: 0.9;
  font-weight: 600;
}

/* Tuplet popover */
.tuplet-popover {
  display: none;
  position: fixed;
  z-index: 1100;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  min-width: 180px;
}
.tuplet-popover.active {
  display: block;
}
.tuplet-popover-title {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}
.tuplet-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.tuplet-type-row label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-size: 0.85rem;
}
@media (max-width: 768px) {
  .tuplet-type-row label.tuplet-mobile-hidden {
    display: none;
  }
}
.tuplet-hits-row {
  margin-bottom: 0.5rem;
}
.tuplet-hits-row.hidden {
  display: none;
}
.tuplet-hits {
  display: flex;
  gap: 4px;
  margin-top: 0.25rem;
}
.tuplet-hit {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--cell-inactive);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.75rem;
  transition: background 0.15s;
}
.tuplet-hit:hover {
  background: var(--bg-tertiary);
}
.tuplet-hit.active {
  background: var(--cell-active);
  color: var(--text-primary);
}
.tuplet-hit.active.variant {
  background: var(--cell-variant);
}
.tuplet-hit.active.ghost {
  background: rgba(255, 159, 10, 0.5);
}
.tuplet-popover-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 400px;
  width: 90%;
  border: 1px solid var(--border);
}

.modal-content h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.setting-item {
  margin-bottom: 1rem;
}

.setting-item label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.setting-item select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.modal-rhythm {
  min-width: 380px;
  max-width: 480px;
}

/* Dialog modal (alert, confirm, prompt) */
#dialogModal {
  z-index: 1100;
}

.modal-dialog {
  min-width: 280px;
  max-width: 400px;
}

.dialog-title {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.dialog-message {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.dialog-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.dialog-input:focus {
  outline: none;
  border-color: var(--accent);
}

.dialog-input.hidden {
  display: none;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0;
}

.rhythm-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.rhythm-search::placeholder {
  color: var(--text-secondary);
}

.rhythm-search:focus {
  outline: none;
  border-color: var(--accent);
}

.rhythm-presets {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-height: 360px;
  overflow-y: auto;
  min-width: 0;
}

.rhythm-preset-group-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
}

.rhythm-preset-group-title:first-child {
  margin-top: 0;
}

.rhythm-loading,
.rhythm-empty {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 1rem;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.rhythm-preset {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
  transition: background 0.2s, border-color 0.2s;
}

.rhythm-preset:hover {
  background: var(--cell-inactive);
}

.my-presets-tabs {
  display: inline-flex;
  padding: 3px;
  gap: 0;
  margin-bottom: 1rem;
  background: var(--bg-elevated);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.my-preset-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.my-preset-tab:hover {
  background: var(--cell-inactive);
  color: var(--text-primary);
}

.my-preset-tab.active {
  background: var(--accent);
  color: #000;
  box-shadow: var(--shadow-subtle);
}

.my-preset-tab .tab-icon {
  font-size: 0.95em;
  line-height: 1;
  opacity: 0.9;
}

.my-preset-tab.active .tab-icon {
  opacity: 1;
}

.my-presets-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.my-presets-sort-icons {
  display: flex;
  gap: 0.25rem;
}

.my-presets-sort-icons .sort-icon {
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  min-width: auto;
}

.my-presets-sort-icons .sort-icon.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.share-mode-options {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.share-mode-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.share-mode-option input {
  accent-color: var(--accent);
}

.share-user-section {
  margin-bottom: 1rem;
}

.share-user-section.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.my-preset-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.my-preset-actions .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 0.35rem !important;
  min-width: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  box-shadow: none;
  transition: background 0.2s, color 0.2s;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-icon.btn-play:hover {
  background: rgba(48, 209, 88, 0.2);
  color: var(--green);
}

.btn-icon.btn-edit:hover {
  background: rgba(10, 132, 255, 0.2);
  color: var(--blue);
}

.btn-icon.btn-danger {
  background: transparent !important;
  color: var(--text-secondary);
}
.btn-icon.btn-danger:hover {
  background: rgba(255, 69, 58, 0.2) !important;
  color: var(--red);
}

.btn-icon.btn-favourite {
  background: transparent !important;
  color: var(--text-secondary);
  opacity: 0.6;
}
.btn-icon.btn-favourite:hover,
.btn-icon.btn-favourite.active {
  opacity: 1;
  color: #f5c518;
}
.btn-icon.btn-favourite:hover {
  background: rgba(245, 197, 24, 0.15) !important;
}

.my-preset-col-like {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.btn-like {
  padding: 0.2rem 0.35rem;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: color 0.2s, transform 0.1s;
}

.btn-like:hover {
  color: #0a84ff;
  transform: scale(1.05);
}

.btn-like.active {
  color: #0a84ff;
}

.btn-like-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 1.25rem;
  text-align: center;
}

.modal-actions-end {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.my-presets-list-header {
  display: grid;
  grid-template-columns: 1.75rem 1fr 4.5rem auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}

.my-preset-item {
  display: grid;
  grid-template-columns: 1.75rem 1fr 4.5rem auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  margin-bottom: 0.35rem;
  transition: border-color 0.2s;
}

.my-preset-item:hover {
  background: var(--cell-inactive);
}

.my-preset-col-check {
  display: flex;
  align-items: center;
  justify-content: center;
}

.my-preset-checkbox-placeholder {
  width: 1rem;
  height: 1rem;
  display: inline-block;
}

.my-preset-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.my-preset-name {
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.2;
}

.my-preset-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
  line-height: 1.2;
}

.share-user-results {
  max-height: 200px;
  overflow-y: auto;
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
}

.share-user-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.share-user-item:last-child {
  border-bottom: none;
}

.share-user-item:hover {
  background: var(--cell-inactive);
}

.share-user-item.selected {
  background: var(--cell-active);
  color: var(--text-primary);
}

/* btn-danger full: see semantic block above; icon variant above */

#closeSettings,
#closeRhythm {
  margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 1280px) {
  .container {
    max-width: 100%;
  }
}

/* Tablet */
@media (max-width: 768px) {
  body {
    padding: calc(1.5rem + env(safe-area-inset-top, 0px)) calc(1.5rem + env(safe-area-inset-right, 0px)) calc(1.5rem + env(safe-area-inset-bottom, 0px)) calc(1.5rem + env(safe-area-inset-left, 0px));
  }

  .container {
    padding: 1.5rem;
  }

  .title {
    font-size: 1.5rem;
  }

  .modal-content {
    max-height: 85vh;
    overflow-y: auto;
  }
}

/* Mobile landscape */
@media (max-width: 600px) {
  body {
    padding: calc(1rem + env(safe-area-inset-top, 0px)) calc(1rem + env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) calc(1rem + env(safe-area-inset-left, 0px));
  }

  .container {
    padding: 1rem;
  }

  /* Controls: stack rows, copy full-width */
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .controls-row-primary,
  .controls-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .sequencer-transport {
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
  }

  .controls-row-copy {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  .btn-copy {
    flex: 1;
    min-width: 0;
  }

  .instrument-name,
  .instrument-label {
    width: 100px;
    font-size: 0.75rem;
  }

  .volume-label,
  .instrument-volume-wrap {
    width: 36px;
  }

  .step {
    min-width: 28px;
    max-width: 32px;
  }

  .steps-header-12,
  .steps-12 {
    min-width: 280px;
  }

  .steps-header-16,
  .steps-16 {
    min-width: 360px;
  }

  .steps-header-24,
  .steps-24 {
    min-width: 520px;
  }

  .steps-header-32,
  .steps-32 {
    min-width: 720px;
  }

  .modal-content {
    width: 100%;
    max-width: none;
    margin: 1rem;
    max-height: 90vh;
    overflow-y: auto;
    padding: calc(1rem + env(safe-area-inset-top, 0px)) calc(1rem + env(safe-area-inset-right, 0px)) calc(1rem + env(safe-area-inset-bottom, 0px)) calc(1rem + env(safe-area-inset-left, 0px));
  }

  .modal-rhythm {
    min-width: 0;
  }
}

/* Mobile portrait */
@media (max-width: 480px) {
  .title {
    font-size: 1.25rem;
  }

  .user-name {
    max-width: 80px;
  }

  .instrument-name,
  .instrument-label {
    width: 80px;
    font-size: 0.7rem;
  }

  .volume-label,
  .instrument-volume-wrap {
    width: 32px;
  }

  .step {
    min-width: 28px;
    max-width: 30px;
  }

  .steps-header-12,
  .steps-12 {
    min-width: 240px;
  }

  .steps-header-16,
  .steps-16 {
    min-width: 320px;
  }

  .steps-header-24,
  .steps-24 {
    min-width: 480px;
  }

  .steps-header-32,
  .steps-32 {
    min-width: 640px;
  }

  .current-preset-name {
    font-size: 0.95rem;
    min-width: 100px;
  }

  .current-preset-name:not(:empty)::before {
    content: "";
    margin-right: 0;
  }
}

/* Very small screens */
@media (max-width: 360px) {
  body {
    padding: calc(0.75rem + env(safe-area-inset-top, 0px)) calc(0.75rem + env(safe-area-inset-right, 0px)) calc(0.75rem + env(safe-area-inset-bottom, 0px)) calc(0.75rem + env(safe-area-inset-left, 0px));
  }

  .container {
    padding: 0.75rem;
  }

  .title {
    font-size: 1.1rem;
  }

  .user-name {
    max-width: 60px;
  }

  .instrument-name,
  .instrument-label {
    width: 70px;
    font-size: 0.65rem;
  }

  .step {
    min-width: 26px;
    max-width: 28px;
  }

  .steps-header-12,
  .steps-12 {
    min-width: 220px;
  }

  .steps-header-16,
  .steps-16 {
    min-width: 280px;
  }

  .steps-header-24,
  .steps-24 {
    min-width: 420px;
  }

  .steps-header-32,
  .steps-32 {
    min-width: 560px;
  }
}
