/* ============================================================
   真奧堂崇拜系統 - Design System & Global Styles
   Mobile-first | Dark/Light Mode | iOS + Google Drive aesthetic
   ============================================================ */

:root {
  /* Brand */
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --google-docs: #2563eb;
  --google-slides: #d97706;

  /* Light Mode (default) */
  --bg-page: #f8f9fa;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --nav-bg: rgba(255,255,255,0.92);
  --overlay-bg: rgba(0,0,0,0.4);
  --pill-bg: #f3f4f6;
  --danger: #dc2626;
  --danger-light: #fef2f2;

  /* Spacing & Rhythm */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  /* Content heights (exclude safe areas — those are added dynamically) */
  --header-content: 52px;
  --nav-content: 56px;
  /* Dynamic safe areas: env() with constant() fallback for older iOS */
  --safe-top: 0px;
  --safe-bottom: 0px;
  --safe-left: 0px;
  --safe-right: 0px;
  --safe-top: constant(safe-area-inset-top, 0px);
  --safe-bottom: constant(safe-area-inset-bottom, 0px);
  --safe-left: constant(safe-area-inset-left, 0px);
  --safe-right: constant(safe-area-inset-right, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  /* Total chrome heights including safe areas */
  --header-height: calc(var(--header-content) + var(--safe-top));
  --nav-height: calc(var(--nav-content) + var(--safe-bottom));

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Google Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size-base: 16px;
  --line-height: 1.5;
}

[data-theme="dark"] {
  --bg-page: #030712;
  --bg-card: #111827;
  --bg-elevated: #1f2937;
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border: #1f2937;
  --border-strong: #374151;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
  --nav-bg: rgba(17,24,39,0.92);
  --overlay-bg: rgba(0,0,0,0.6);
  --pill-bg: #1f2937;
  --danger-light: #450a0a;
  --primary-light: #064e3b;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  height: 100%;
  height: -webkit-fill-available;
}
body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: var(--line-height);
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* PWA full-bleed under status bar / home indicator */
  padding: 0;
  margin: 0;
}
button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
ul, ol { list-style: none; }

/* App Shell */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  max-width: 100vw;
  /* Horizontal safe areas for landscape notch */
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  /* Total height = content + notch/status bar */
  height: var(--header-height);
  min-height: var(--header-height);
  display: flex;
  align-items: flex-end; /* content sits below safe area */
  justify-content: space-between;
  padding: 0 var(--space-lg);
  padding-top: var(--safe-top);
  box-sizing: border-box;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.app-header .header-left,
.app-header .header-right {
  height: var(--header-content);
  display: flex;
  align-items: center;
}
.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}
.logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
}
.site-title {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--text-primary);
  transition: background 0.15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--pill-bg); }
.icon-btn.hidden { display: none; }
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Main Content */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  /* nav-height already includes safe-bottom */
  padding-bottom: calc(var(--nav-height) + var(--space-md));
  -webkit-overflow-scrolling: touch;
}
/* When header is hidden (non-home tabs), still reserve notch / status-bar space */
body.chrome-no-header .main-content {
  padding-top: var(--safe-top);
}
body.chrome-no-header .view.subpage {
  padding-top: var(--safe-top);
}

.view {
  display: none;
  padding: var(--space-lg);
  min-height: 100%;
  animation: fadeIn 0.2s ease;
}
.view.active { display: block; }
/* Home / roster: edge-to-edge on phone to reduce wasted margin */
#view-home.view {
  padding: var(--space-sm);
  padding-bottom: 0;
}
@media (max-width: 767px) {
  #view-home.view {
    padding: 0;
  }
  #view-home .roster-container {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }
}
.view.subpage {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 200;
  background: var(--bg-page);
  padding: var(--space-lg);
  padding-top: calc(var(--header-height) + var(--space-md));
  padding-bottom: calc(var(--nav-height) + var(--space-lg));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Off-screen when closed; do not use display:none alone so transition works */
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
  box-sizing: border-box;
}
.view.subpage.active {
  display: block !important;
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}
/* While subpage is open, keep underlying tab content out of the way */
body.subpage-open .view:not(.subpage) {
  visibility: hidden !important;
  pointer-events: none !important;
}
body.subpage-open .fab {
  display: none !important;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Bottom Navigation — mobile fixed bar (default) */
.bottom-nav {
  position: fixed;
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 150;
  height: var(--nav-height);
  min-height: var(--nav-height);
  max-height: var(--nav-height);
  padding: 0;
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-around;
  gap: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  border-right: none;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.nav-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--nav-content);
  min-height: var(--nav-content);
  max-height: var(--nav-content);
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.1;
  box-shadow: none;
  transition: color 0.15s;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg {
  stroke: currentColor;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}
.nav-item span {
  display: block;
  font-size: 0.7rem;
}
.nav-item.active {
  color: var(--primary);
  background: transparent;
}
.nav-item:active { opacity: 0.7; }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
  transition: box-shadow 0.15s;
}
.card:active { box-shadow: var(--shadow-lg); }

/* Pills / Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--pill-bg);
  color: var(--text-secondary);
  white-space: nowrap;
}
.pill.primary {
  background: var(--primary-light);
  color: var(--primary);
}
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-sm);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--pill-bg);
  color: var(--text-primary);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-docs {
  background: var(--google-docs);
  color: #fff;
}
.btn-slides {
  background: var(--google-slides);
  color: #fff;
}
.btn-block { width: 100%; }
.btn-lg { padding: 14px 24px; font-size: 1rem; }

/* FAB */
.fab {
  position: fixed;
  right: var(--space-xl);
  bottom: calc(var(--nav-height) + var(--space-xl));
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
  z-index: 120;
  transition: transform 0.15s, background 0.15s;
}
.fab:hover { background: var(--primary-hover); }
.fab:active { transform: scale(0.92); }
.fab svg { width: 28px; height: 28px; }

/* Forms */
.form-group {
  margin-bottom: var(--space-lg);
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}
.form-textarea { min-height: 120px; resize: vertical; }
.segmented {
  display: flex;
  background: var(--pill-bg);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.segmented button.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow);
}

/* Search */
/* Songs page: filter | sort | search bar */
.songs-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
  transition: background 0.15s, border-color 0.15s;
}
.toolbar-btn:active {
  background: var(--pill-bg);
}
.toolbar-btn svg {
  color: var(--text-secondary);
  flex-shrink: 0;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  margin-bottom: var(--space-md);
  min-width: 0;
}
.search-bar.search-bar-grow {
  flex: 1;
  margin-bottom: 0;
  height: 40px;
  box-sizing: border-box;
}
.search-bar input {
  flex: 1;
  background: transparent;
  font-size: 0.95rem;
  border: none;
  outline: none;
  min-width: 0;
}
.search-bar svg,
.search-bar .search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}
.search-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.search-input-wrap .search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}
@media (max-width: 380px) {
  .toolbar-btn span { display: none; }
  .toolbar-btn { padding: 0 10px; width: 40px; }
}
.fab-with-text {
  width: auto !important;
  padding: 0 18px;
  gap: 8px;
  border-radius: 28px;
}
.fab-with-text span {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 80px);
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #f9fafb;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  text-align: center;
}
.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px);
}
[data-theme="dark"] .toast {
  background: #f9fafb;
  color: #111827;
}

/* Overlay / Popover */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 250;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s;
}
.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
/* Anchored mode: dim only; popover is position:fixed by JS near the button */
.overlay.overlay-anchored {
  align-items: stretch;
  justify-content: stretch;
  background: rgba(0, 0, 0, 0.25);
}
.popover {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: var(--space-xl);
  animation: slideUp 0.25s ease;
  box-shadow: var(--shadow-lg);
}
/* Floating card next to button — not a bottom sheet */
.popover.popover-anchored {
  border-radius: 16px;
  width: min(320px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: min(70vh, calc(100dvh - 24px));
  animation: popIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid var(--border);
}
.popover.popover-anchored .popover-handle {
  display: none; /* no drag handle on floating cards */
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
.popover-handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto var(--space-lg);
}
.popover-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: var(--space-lg);
}

/* Desktop adaptations */
/* Explicit mobile lock — prevents desktop rules from leaking on phones */
@media (max-width: 767px) {
  .bottom-nav {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--nav-height) !important;
    min-height: var(--nav-height) !important;
    max-height: var(--nav-height) !important;
    flex-direction: row !important;
    justify-content: space-around !important;
    align-items: flex-start !important;
    border-right: none !important;
    border-top: 1px solid var(--border) !important;
    gap: 0 !important;
  }
  .nav-item {
    flex: 1 1 0 !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    height: var(--nav-content) !important;
    min-height: var(--nav-content) !important;
    max-height: var(--nav-content) !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    font-size: 0.7rem !important;
    gap: 2px !important;
  }
  .nav-item.active {
    background: transparent !important;
    color: var(--primary) !important;
  }
  .nav-item svg {
    width: 24px !important;
    height: 24px !important;
  }
  .app-header,
  .main-content,
  .view.subpage {
    margin-left: 0 !important;
    left: 0;
  }
}

/* Desktop: compact left side menu */
@media (min-width: 768px) {
  .bottom-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 200px;
    height: 100%;
    min-height: 100%;
    max-height: none;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: calc(var(--safe-top) + var(--space-lg)) var(--space-md) var(--space-lg);
    padding-bottom: var(--safe-bottom);
    border-top: none;
    border-right: 1px solid var(--border);
    gap: 4px;
  }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
  }
  .nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }
  .nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
  }
  .app-header {
    margin-left: 200px;
  }
  .main-content {
    margin-left: 200px;
    padding-bottom: var(--space-2xl);
  }
  .view.subpage {
    left: 200px;
  }
  .fab {
    bottom: var(--space-2xl);
  }
  .popover {
    border-radius: var(--radius);
    margin-bottom: 10vh;
  }
}

/* Utility */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-center { text-align: center; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.w-full { width: 100%; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Song Card specific */
.song-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  cursor: pointer;
}
.song-card .song-info { flex: 1; min-width: 0; }
.song-card .song-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 2px;
}
.song-card .song-author {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.song-card .btn-add {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.song-card .btn-add:hover { background: var(--primary); color: #fff; }

/* Stats bar */
.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

/* ChordPro rendering */
.chordpro-sheet {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
}
.chordpro-sheet .section-header {
  font-family: var(--font);
  font-weight: 700;
  color: var(--primary);
  margin: var(--space-lg) 0 var(--space-sm);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--primary-light);
}
.chordpro-sheet .chord {
  color: var(--primary);
  font-weight: 600;
}

/* Click Metronome specific */
.click-display {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
}
.click-bpm {
  font-size: 4rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}
.click-time-sig {
  font-size: 1.5rem;
  color: var(--text-secondary);
  margin-top: var(--space-sm);
}
.click-song-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: var(--space-lg);
}
.beat-indicator {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: var(--space-xl) 0;
}
.beat-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background 0.05s, transform 0.05s;
}
.beat-dot.active {
  background: var(--primary);
  transform: scale(1.3);
}
.beat-dot.accent {
  background: var(--primary-hover);
}

/* Settings groups */
.settings-group {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: var(--space-lg);
  overflow: hidden;
}
.settings-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-md) var(--space-lg) var(--space-xs);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  min-height: 52px;
}
.settings-row:first-of-type { border-top: none; }
.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.stepper button {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--pill-bg);
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stepper .value {
  min-width: 48px;
  text-align: center;
  font-weight: 600;
}
.toggle {
  width: 51px;
  height: 31px;
  background: var(--border-strong);
  border-radius: 16px;
  position: relative;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle.on { background: var(--primary); }
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.on::after { transform: translateX(20px); }

/* Roster */
.roster-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.roster-container img {
  width: 100%;
  height: auto;
  /* header-height & nav-height already include safe-top / safe-bottom */
  max-height: calc(100dvh - var(--header-height) - var(--nav-height) - 4px);
  max-height: calc(100svh - var(--header-height) - var(--nav-height) - 4px);
  object-fit: contain;
  object-position: top center;
  display: block;
  margin: 0 auto;
}
@media (max-width: 767px) {
  .roster-container img {
    max-height: calc(100dvh - var(--header-height) - var(--nav-height) - 2px);
    max-height: calc(100svh - var(--header-height) - var(--nav-height) - 2px);
    width: 100%;
  }
  .main-content {
    padding-bottom: var(--nav-height);
  }
  #view-home.view {
    /* Fill remaining space between header and nav */
    min-height: calc(100dvh - var(--header-height) - var(--nav-height));
    min-height: calc(100svh - var(--header-height) - var(--nav-height));
  }
}
.roster-menu-btn {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 40px;
  height: 40px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--text-muted);
}
.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-lg);
  opacity: 0.4;
}

/* Loading */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: var(--space-2xl) auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  flex-wrap: wrap;
}
.pagination button {
  min-width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-weight: 500;
}
.pagination button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.pagination select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}

/* Drag handle for setlist */
.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  padding: 8px;
}
.setlist-song-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  touch-action: none;
}
.setlist-song-item.dragging {
  opacity: 0.6;
  box-shadow: var(--shadow-lg);
}
.insert-indicator {
  height: 3px;
  background: var(--primary);
  border-radius: 2px;
  margin: 4px 0;
}


/* ========== Click Module (from click.html) ========== */
.click-wrap { max-width: 500px; margin: 0 auto; }
.visual-beats-container {
  width: 100%;
  height: 48px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.beat-indicator-grid {
  display: flex;
  gap: 12px;
  height: 100%;
  align-items: center;
  justify-content: center;
}
.beat-box {
  width: 44px;
  height: 44px;
  background: var(--bg-muted, #d1d1d6);
  border-radius: 12px;
  transition: background-color 0.08s, transform 0.08s, box-shadow 0.08s;
}
.beat-box.active {
  background: #007aff;
  transform: scale(1.08);
  box-shadow: 0 0 16px rgba(0, 122, 255, 0.5);
}
.beat-box.accent-active {
  background: #ff3b30;
  transform: scale(1.12);
  box-shadow: 0 0 18px rgba(255, 59, 48, 0.6);
}
.click-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  width: 100%;
}
.click-ctrl-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 16px;
  font-weight: 600;
  font-size: 17px;
  height: 60px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm, 0 2px 10px rgba(0,0,0,0.03));
  transition: transform 0.2s, opacity 0.2s;
}
.click-ctrl-btn:active { transform: scale(0.97); opacity: 0.88; }
.click-ctrl-btn.mode {
  background: var(--bg-muted, #e5e5ea);
  color: var(--text, #1c1c1e);
}
.click-ctrl-btn.play {
  background: #007aff;
  color: #fff;
}
.click-ctrl-btn.play.playing {
  background: #ff3b30;
}
.click-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  margin-bottom: 12px;
}
.click-card {
  background: var(--bg-card, #fff);
  border-radius: 18px;
  padding: 12px 8px;
  box-shadow: var(--shadow-sm);
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 140px;
  box-sizing: border-box;
}
.click-card:active { transform: scale(0.98); }
.click-card.active {
  border-color: #007aff;
  box-shadow: 0 4px 18px rgba(0, 122, 255, 0.18);
}
.click-card .view-fields {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.click-card .view-fields strong {
  font-size: 18px;
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
  letter-spacing: -0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  padding: 0 4px;
}
.click-card .view-fields span {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary, #8e8e93);
}
.click-card.active .view-fields span { color: #007aff; }
.click-card .ts-label {
  font-size: 12px;
  margin-top: 3px;
  color: var(--text-secondary);
  font-weight: 600;
  background: var(--bg-muted, #e5e5ea);
  padding: 2px 8px;
  border-radius: 100px;
}
.click-card .edit-fields {
  width: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
}
.ts-toggle-group {
  display: flex;
  width: 92%;
  gap: 4px;
}
.ts-btn {
  flex: 1;
  padding: 5px 0;
  border: 1px solid var(--border, rgba(60,60,67,0.12));
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-muted);
  cursor: pointer;
  color: var(--text);
}
.ts-btn.selected {
  background: #007aff;
  color: #fff;
  border-color: #007aff;
}
.edit-tools {
  flex-direction: column;
  gap: 12px;
  width: 100%;
}
.tap-pad {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 18px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  background: var(--bg-card);
  color: #007aff;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  user-select: none;
}
.tap-pad:active {
  transform: scale(0.98);
  background: rgba(0, 122, 255, 0.1);
}
.settings-panel .setting-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}
.slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slider-container input {
  flex: 1;
  accent-color: #007aff;
  height: 6px;
}
.slider-container span {
  font-weight: 600;
  font-size: 14px;
  width: 42px;
}

/* Setlist song rows — inline KEY / BPM (draft editor) */
.sl-song-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.sl-song-row-ro {
  opacity: 0.95;
}
.sl-song-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sl-song-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}
.sl-meta-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  border: none;
  cursor: pointer;
}
.sl-meta-chip.ro {
  cursor: default;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--primary);
}
.sl-meta-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-transform: uppercase;
}
.sl-key-select,
.sl-bpm-input {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0;
  margin: 0;
  outline: none;
  cursor: pointer;
  text-align: center;
}
.sl-key-select {
  padding-right: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23059669' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  min-width: 2.2em;
}
.sl-bpm-input {
  width: 3.2em;
  -moz-appearance: textfield;
}
.sl-bpm-input::-webkit-outer-spin-button,
.sl-bpm-input::-webkit-inner-spin-button {
  opacity: 1;
  height: 1.4em;
}
.sl-remove-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger-light);
  color: var(--danger);
  border: none;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}
.sl-remove-btn:active {
  transform: scale(0.92);
  opacity: 0.85;
}
@media (max-width: 400px) {
  .sl-song-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .sl-song-title {
    flex-basis: calc(100% - 40px);
  }
  .sl-meta-chip {
    margin-left: 38px;
  }
  .sl-remove-btn {
    margin-left: auto;
  }
}

/* Drag handle & reorder animation */
.sl-drag-handle {
  flex-shrink: 0;
  width: 28px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: grab;
  touch-action: none;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  -webkit-user-select: none;
  user-select: none;
}
.sl-drag-handle:active {
  cursor: grabbing;
  color: var(--primary);
  background: var(--primary-light);
}
.sl-song-row {
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s, opacity 0.15s;
  touch-action: pan-y;
}
.sl-song-row.sl-dragging {
  position: relative;
  opacity: 0.95;
  box-shadow: 0 12px 28px rgba(0,0,0,0.18);
  border-color: var(--primary);
  background: var(--bg-card);
  cursor: grabbing;
  z-index: 50;
  transition: box-shadow 0.15s;
  /* transform driven by JS during drag */
}
.sl-song-placeholder {
  border-radius: 16px;
  border: 2px dashed var(--primary);
  background: var(--primary-light);
  margin-bottom: 10px;
  opacity: 0.7;
  box-sizing: border-box;
  transition: height 0.15s ease;
}
#songs-section {
  position: relative;
}

/* ========== Song detail ========== */
.song-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.song-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
}
.song-detail-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.song-detail-left,
.song-detail-right {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
}
/* Wide: left = video + info, right = lyrics */
@media (min-width: 900px) {
  .song-detail-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-lg);
    align-items: start;
  }
  .song-detail-right .song-sheet-card {
    position: sticky;
    top: calc(var(--header-height) + var(--space-md));
    max-height: calc(100dvh - var(--header-height) - var(--nav-height) - var(--space-2xl));
    overflow-y: auto;
  }
}
@media (min-width: 1200px) {
  .song-detail-body {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  }
}
.song-detail-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}
.song-detail-author {
  margin-top: 4px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* YouTube embed */
.yt-preview-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.yt-embed-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  background: #000;
}
.yt-embed-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.yt-switcher {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.yt-switch-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--pill-bg);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.yt-switch-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Info card grid */
.song-info-card,
.song-sheet-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.song-info-heading {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 12px;
  letter-spacing: 0.02em;
}
.song-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 10px;
}
.song-info-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.song-info-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.song-info-value.accent {
  color: var(--primary);
}
.song-info-themes {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.song-info-desc {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ChordPro sheet */
.cp-sheet {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.25;
}
.cp-section {
  margin: 14px 0 6px;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary);
}
.cp-section:first-child {
  margin-top: 0;
}
.cp-spacer {
  height: 10px;
}
.cp-line {
  margin: 0 0 2px;
}
.cp-line-chords {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  column-gap: 0;
  margin-bottom: 6px;
}
.cp-seg {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}
.cp-ch {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
  min-height: 1.2em;
  white-space: pre;
  padding-right: 4px;
}
.cp-ch-empty {
  color: transparent;
  user-select: none;
}
.cp-ly {
  display: block;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.cp-lyrics {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Legacy chordpro-sheet class */
.chordpro-sheet {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
