/* ============================================================
   style.css — Band Metronome Dark Theme
   Mobile-first, touch-friendly (min 44px targets)
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0d;
  --surface:   #1a1a1a;
  --surface2:  #242424;
  --border:    #333;
  --text:      #f0f0f0;
  --text2:     #999;
  --gold:      #f5c518;
  --gold-dim:  #a07c0a;
  --green:     #22c55e;
  --red:       #ef4444;
  --blue:      #60a5fa;
  --accent-dot: #f5c518;
  --beat-dot:   #60a5fa;
  --radius:    12px;
  --radius-sm: 8px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-family: inherit;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ================================================================
   PENDING BAR (fixed top, slides in)
================================================================ */
#pending-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: linear-gradient(135deg, #1a2a1a, #0d1a0d);
  border-bottom: 2px solid var(--green);
  padding: 12px 16px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.pending-content {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.pending-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pending-label {
  font-size: 0.7rem;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.pending-song {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pending-bpm-badge {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--green);
  letter-spacing: -0.03em;
}

.commit-btn {
  flex-shrink: 0;
  background: var(--green);
  color: #000;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: var(--radius);
  min-height: 48px;
  transition: opacity 0.15s;
}
.commit-btn:active { opacity: 0.7; }

/* ================================================================
   SYNC STATUS BAR (top of page content)
================================================================ */
.sync-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text2);
}

.sync-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}
.sync-dot.disconnected { background: var(--text2); }
.sync-dot.connecting   { background: var(--gold); animation: pulse 1s infinite; }
.sync-dot.active,
.sync-dot.pending      { background: var(--green); }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

.sync-actions { display: flex; gap: 8px; }

.sync-btn {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  min-height: 36px;
}
.sync-btn.danger {
  border-color: var(--red);
  color: var(--red);
}
.sync-btn:active { opacity: 0.7; }

/* ================================================================
   NOW PLAYING BAR
================================================================ */
#now-playing-bar {
  background: #1a1520;
  border-bottom: 1px solid #3a2060;
  padding: 8px 16px;
  text-align: center;
}

#now-playing-text {
  font-size: 0.9rem;
  color: #c084fc;
  font-weight: 500;
}

/* ================================================================
   MAIN CONTENT
================================================================ */
.main-content {
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 0 32px;
}

/* ================================================================
   SECTION WRAPPER
================================================================ */
.section {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text2);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ================================================================
   BPM SECTION
================================================================ */
.bpm-section {
  text-align: center;
  padding-top: 28px;
  padding-bottom: 24px;
}

.bpm-display-wrap {
  margin-bottom: 8px;
  position: relative;
}

#bpm-display {
  font-size: 6rem;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: 12px;
  transition: background 0.15s;
}
#bpm-display:active {
  background: rgba(255,200,0,0.12);
}

/* BPM inline input — แสดงแทน #bpm-display เมื่อจิ้ม */
#bpm-input {
  font-size: 6rem;
  font-weight: 900;
  color: var(--gold);
  background: transparent;
  border: none;
  border-bottom: 3px solid var(--gold);
  outline: none;
  width: 220px;
  text-align: center;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  caret-color: var(--gold);
  -moz-appearance: textfield;
}
#bpm-input::-webkit-outer-spin-button,
#bpm-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.bpm-unit {
  font-size: 0.85rem;
  color: var(--text2);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* BPM control row */
.bpm-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.bpm-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  min-width: 48px;
  min-height: 48px;
  padding: 0 10px;
  transition: background 0.1s;
}
.bpm-btn:active { background: var(--border); }

/* BPM Slider */
#bpm-slider {
  flex: 1;
  min-width: 120px;
  max-width: 200px;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  outline: none;
}
#bpm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
}
#bpm-slider::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--gold);
  border: none;
  cursor: pointer;
}

/* Beat dots */
#beat-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 18px 0 14px;
}

.beat-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
  transition: background 0.05s, border-color 0.05s, transform 0.05s;
}
.beat-dot.active {
  background: var(--beat-dot);
  border-color: var(--beat-dot);
  transform: scale(1.2);
}
.beat-dot.accent {
  background: var(--accent-dot);
  border-color: var(--accent-dot);
  transform: scale(1.4);
  box-shadow: 0 0 10px var(--gold);
}

/* Play button */
#play-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--surface2);
  border: 3px solid var(--gold);
  color: var(--gold);
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  transition: background 0.15s, transform 0.1s;
}
#play-btn.playing {
  background: var(--gold);
  color: #000;
  box-shadow: 0 0 24px var(--gold-dim);
}
#play-btn:active { transform: scale(0.93); }

/* Tap button */
#tap-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 12px 28px;
  min-height: 48px;
  transition: background 0.1s, color 0.1s;
}
#tap-btn:active {
  background: var(--gold);
  color: #000;
}

/* Ritardando button */
#rit-btn, #rall-btn, #atempo-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 12px 14px;
  min-height: 48px;
  flex: 1 1 auto;
  min-width: 0;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
#rit-btn:active, #rall-btn:active {
  background: var(--gold);
  color: #000;
}
#atempo-btn:active {
  background: #1a7a3a;
  color: #fff;
}
/* Rit. active = กำลัง rit อยู่ */
#rit-btn.active {
  background: #b04000;
  border-color: #ff7733;
  color: #fff;
  box-shadow: 0 0 10px 2px rgba(255, 100, 0, 0.45);
  animation: rit-pulse 0.6s ease-in-out infinite alternate;
}
/* Rall. active = กำลัง rall อยู่ — สีแดงเข้มกว่า */
#rall-btn.active {
  background: #800020;
  border-color: #ff3355;
  color: #fff;
  box-shadow: 0 0 10px 2px rgba(255, 50, 50, 0.45);
  animation: rit-pulse 0.4s ease-in-out infinite alternate;
}
@keyframes rit-pulse {
  from { box-shadow: 0 0 6px 1px rgba(255,100,0,0.35); }
  to   { box-shadow: 0 0 16px 4px rgba(255,100,0,0.65); }
}

/* ================================================================
   BUTTON ROWS (time sig, subdivision, presets)
================================================================ */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.timesig-btn,
.subdiv-btn,
.preset-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 14px;
  min-height: 44px;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.timesig-btn.active,
.subdiv-btn.active,
.preset-btn:active {
  background: var(--surface);
  border-color: var(--gold);
  color: var(--gold);
}

/* Subdivision toggle pill */
#subdiv-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 12px;
  min-height: 28px;
  letter-spacing: 0.05em;
  transition: background 0.15s, color 0.15s;
}
#subdiv-toggle.on {
  background: var(--green);
  border-color: var(--green);
  color: #000;
}

/* ================================================================
   SOUND SLOTS
================================================================ */
.sound-slot {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.slot-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.slot-badge {
  font-size: 1rem;
  flex-shrink: 0;
}
.slot-badge.accent { color: var(--gold); }
.slot-badge.normal { color: var(--text2); }
.slot-badge.subdiv { color: var(--blue); }

.slot-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.snd-filename {
  font-size: 0.75rem;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: right;
}

.slot-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.upload-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 14px;
  min-height: 40px;
  flex: 1;
}
.upload-btn:active { background: var(--border); }

.clear-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 700;
  width: 40px;
  min-height: 40px;
}
.clear-btn:active { background: var(--border); }

/* Sliders */
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.slider-label {
  font-size: 0.72rem;
  color: var(--text2);
  min-width: 42px;
}

.mini-slider {
  flex: 1;
  height: 5px;
  background: var(--surface);
  border-radius: 3px;
  outline: none;
}
.mini-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
}
.mini-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gold);
  border: none;
}

.slider-val {
  font-size: 0.72rem;
  color: var(--text2);
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Pan slider — blue thumb */
.pan-slider::-webkit-slider-thumb { background: var(--blue); }
.pan-slider::-moz-range-thumb     { background: var(--blue); }

/* Pan L/Both/R buttons */
.pan-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.global-pan-row {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.pan-btns {
  display: flex;
  gap: 6px;
  flex: 1;
}

.pan-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 4px;
  min-height: 36px;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.pan-btn.active {
  background: #1a2840;
  border-color: var(--blue);
  color: var(--blue);
}
.pan-btn:active { opacity: 0.7; }

/* ================================================================
   PAD SIDEBARS — fixed left & right columns
================================================================ */
.pads-layout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  pointer-events: none;  /* pass-through clicks to content behind */
  z-index: 10;
}

.pads-col {
  pointer-events: all;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 80px 4px 20px;  /* top = below sync-bar */
  width: 88px;
  flex-shrink: 0;
  overflow-y: auto;
}

.pads-col-left  { align-items: flex-end; }
.pads-col-right { align-items: flex-start; }

.pads-center-gap { flex: 1; pointer-events: none; }

/* Override pad-btn size for sidebar */
.pads-col .pad-btn {
  width: 80px;
  min-height: 72px;
  border-radius: var(--radius);
  padding: 8px 4px;
}

/* Nudge main-content away from sidebars */
.main-content {
  margin-left: 88px;
  margin-right: 88px;
}

/* ================================================================
   QUICK PADS (old grid — keep for reference, hidden)
================================================================ */
.pads-section .section-title small {
  font-size: 0.65rem;
  color: var(--text2);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

#pads-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.pad-btn {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  min-height: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.1s, border-color 0.1s, transform 0.08s;
  padding: 8px 4px;
  -webkit-touch-callout: none;
  user-select: none;
}
.pad-btn.assigned {
  border-color: var(--blue);
  color: var(--text);
}
.pad-btn:active {
  background: var(--blue);
  color: #000;
  transform: scale(0.94);
}

.pad-num {
  font-size: 0.65rem;
  color: var(--text2);
  font-weight: 600;
}
.pad-name {
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  padding: 0 4px;
}
.pad-hint {
  font-size: 0.65rem;
  color: var(--text2);
}

/* ================================================================
   INSTALL BANNER
================================================================ */
#install-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 150;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border-top: 2px solid var(--gold);
  padding: 14px 16px;
  animation: slideUp 0.35s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.install-content {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 600px;
  margin: 0 auto;
}

.install-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.install-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.install-text strong {
  font-size: 0.95rem;
  color: var(--text);
}

.install-text span {
  font-size: 0.75rem;
  color: var(--text2);
}

.install-do-btn {
  flex-shrink: 0;
  background: var(--gold);
  color: #000;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  min-height: 44px;
  white-space: nowrap;
}
.install-do-btn:active { opacity: 0.75; }

.install-skip-btn {
  flex-shrink: 0;
  color: var(--text2);
  font-size: 1.1rem;
  padding: 8px;
  min-width: 36px;
  min-height: 44px;
}

/* iOS step guide */
#ios-steps {
  max-width: 600px;
  margin: 12px auto 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ios-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.ios-num {
  background: var(--gold);
  color: #000;
  font-weight: 800;
  font-size: 0.8rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ios-icon {
  font-size: 1.1rem;
  background: #007aff;
  border-radius: 4px;
  padding: 1px 4px;
  color: #fff;
}

/* ================================================================
   SETTINGS PANEL
================================================================ */
#settings-panel {
  border-top: 2px solid var(--gold-dim);
  background: #111;
}

#settings-panel .section {
  background: #111;
}

/* Swing/Shuffle buttons get a distinct accent */
.swing-btn { color: #c084fc; border-color: #4a2060; }
.swing-btn.active {
  background: #2a1040;
  border-color: #c084fc;
  color: #c084fc;
}

/* ================================================================
   SYNC MODAL
================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.modal-box h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

.modal-box label {
  display: block;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 14px;
}

.modal-box label span {
  display: block;
  margin-bottom: 6px;
}

.modal-box input[type="text"],
.modal-box input[type="date"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 10px 12px;
  outline: none;
}
.modal-box input:focus {
  border-color: var(--gold);
}

/* colour-scheme for native date picker on dark OS */
.modal-box input[type="date"] {
  color-scheme: dark;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-ghost {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text2);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px;
  min-height: 48px;
}

.btn-primary {
  flex: 2;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: #000;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px;
  min-height: 48px;
}
.btn-primary:active { opacity: 0.8; }

/* ================================================================
   RESPONSIVE — iPad & wider screens
================================================================ */
@media (min-width: 480px) {
  #bpm-display { font-size: 8rem; }

  #pads-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .pad-btn { min-height: 80px; }
}

@media (min-width: 600px) {
  .bpm-section { padding-top: 36px; }

  .sound-slot {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
  }
  .slot-header  { grid-column: 1 / -1; }
  .slot-actions { grid-column: 1 / -1; }
}
