/* ── Fonts ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=IBM+Plex+Mono:wght@400;500&family=Lato:wght@300;400&family=Noto+Sans+KR:wght@400;700&display=swap');

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:         #0f0e0c;
  --surface:    #1a1915;
  --surface2:   #242320;
  --border:     #2e2c28;
  --amber:      #d4952a;
  --amber-dim:  #a06e18;
  --cream:      #e8e0ce;
  --muted:      #7a7568;
  --danger:     #c0392b;

  --radius:     6px;
  --font-head:  'Playfair Display', Georgia, serif;
  --font-mono:  'IBM Plex Mono', monospace;
  --font-body:  'Lato', sans-serif;
  --transition: 0.18s ease;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar             { width: 8px; height: 8px; }
::-webkit-scrollbar-track       { background: transparent; }
::-webkit-scrollbar-thumb       { background: rgba(255,255,255,0.12); border-radius: 4px; min-height: 40px; transition: background 0.2s ease; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }
::-webkit-scrollbar-thumb:active{ background: rgba(255,255,255,0.32); }

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-body);
  font-weight: 300;
  line-height: 1.6;
  min-height: 100dvh;
}

a { color: var(--amber); text-decoration: none; }
a:hover { color: var(--cream); }

img, embed, iframe { display: block; max-width: 100%; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1rem;
}

@media (min-width: 700px) and (max-width: 1200px) {
  body:not(.index-page):not(.setlists-page):not(.admin-page) .app-shell {
    max-width: 92vw;
  }
}

/* ── Index fixed-top layout (only list scrolls) ───────────────────────────── */
body.index-page {
  --index-header-height: clamp(120px, 16vh, 158px);
  --index-search-height: 58px;
  --index-footer-height: 64px;
  --index-main-gap: 2.5rem;
}

body.index-page .app-shell {
  height: 100dvh;
  overflow: hidden; /* prevent window-level bounce on iOS Safari */
}

body.index-page .app-shell > header {
  position: sticky;
  top: 0;
  z-index: 15;
  background: var(--bg);
  padding-bottom: 0.35rem; /* tighten gap before divider so row-2 sits close to it */
}

/* ── Index page header: 3-column × 2-row grid ─────────────────────────────
   Row 1: [empty / 1fr]  [Logo+Title / auto]  [관리모드 / 1fr]
   Row 2: [선택  / 1fr]  [empty      / auto]  [셋리스트+업로드 / 1fr]
   The 1fr|auto|1fr columns guarantee the center column is always
   mathematically centred regardless of side content widths.           ── */
body.index-page .app-shell > header .header-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0.55rem 0.5rem; /* increased row-gap pushes row 2 down toward divider */
}

/* Center column, spans both rows */
body.index-page .app-shell > header .site-title-link {
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: center;
  align-self: center;
}

/* Row 1, Col 3 — admin toggle (injected by app.js) */
body.index-page .app-shell > header .header-actions {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  align-self: center;
  display: flex;
  align-items: center;
}

/* Row 1, Col 1 — 로그아웃 button */
body.index-page #logout-btn {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  align-self: center;
}

/* Row 2, Col 1 — 선택 button */
body.index-page #select-toggle {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  align-self: center;
  font-size: 0.82rem;
  padding: 0.42rem 1.3rem;
}

/* Row 2, Col 3 — 셋리스트 | 업로드+ */
body.index-page .app-shell > header .header-nav-row {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  align-self: center;
}

body.index-page .index-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.index-page .index-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.index-page .index-content .search-row {
  flex-shrink: 0;
  margin-bottom: 0.9rem;
}

body.index-page .index-content .state-msg {
  flex-shrink: 0;
  padding-top: 0.4rem;
  padding-bottom: 0.9rem;
}

body.index-page .index-song-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Prevent scroll from chaining to the parent window at list boundaries
     (page-level bounce), while still allowing the list itself to follow
     the finger naturally at the top/bottom edges. */
  overscroll-behavior: contain;
  /* New stacking context keeps positioned li children below the
     webkit overlay-scrollbar indicator layer. */
  isolation: isolate;
}

body.index-page #song-list .song-item {
  padding-right: 5.25rem;
}

@media (max-width: 720px) {
  body.index-page {
    --index-header-height: clamp(100px, 14vh, 132px);
    --index-search-height: 52px;
    --index-footer-height: 58px;
    --index-main-gap: 2.1rem;
  }

  /* Compact header when scrolling on mobile.
     Only the search row and cat-tabs collapse — logo+title stays visible. */
  body.index-page .app-shell > header.header-compact {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    margin-bottom: 0.75rem;
  }

  /* Search row — same, simultaneous */
  body.index-page .index-content .search-row {
    max-height: 6rem;
    overflow: hidden;
    opacity: 1;
    transition: max-height 0.38s ease, opacity 0.38s ease, margin-bottom 0.38s ease;
  }
  body.index-page .index-content .search-row.search-hidden {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
  }

  /* Cat tabs — same collapse behaviour as search-row */
  body.index-page .index-content .cat-tabs {
    max-height: 4rem;
    overflow: hidden;
    opacity: 1;
    transition: max-height 0.38s ease, opacity 0.38s ease, margin-bottom 0.38s ease;
  }
  body.index-page .index-content .cat-tabs.search-hidden {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
  }

  /* Always show scrollbar (native style) */
  body.index-page .index-song-list {
    overflow-y: scroll;
  }
}

/* ── Setlists page: 3-column independent scroll ────────────────────────────── */
body.setlists-page .app-shell          { height: 100dvh; }
body.setlists-page .app-shell > header { flex-shrink: 0; }
body.setlists-page main {
  flex: 1;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  flex-direction: row;
  gap: 1rem;
}
body.setlists-page .setlist-section {
  flex: 1;
  min-width: 280px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 0;
}

@media (max-width: 480px) {
  /* Keep 3-column row layout on mobile — narrow screens scroll horizontally */
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  padding: 1.5rem 0 0.7rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.site-title-link {
  text-decoration: none;
  color: inherit;
}

.site-title {
  font-family: var(--font-head);
  font-size: clamp(1.9rem, 5.5vw, 2.7rem);
  color: #ffffff;
  letter-spacing: 0.02em;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.site-title-text {
  line-height: 1.1;
}

.site-logo {
  height: 2.2em;
  width: auto;
  display: block;
  flex-shrink: 0;
}

#admin-toggle-btn {
  white-space: nowrap;
  order: -1;
  -webkit-tap-highlight-color: transparent; /* iOS: no grey tap flash */
  outline: none;
}
#admin-toggle-btn:focus,
#admin-toggle-btn:focus-visible {
  outline: none;
}
/* Without .active-admin, focus must NOT bleed into the green active look */
#admin-toggle-btn:not(.active-admin):focus {
  border-color: var(--border);
  color: var(--muted);
}
/* Touch devices: iOS keeps :hover after tap — clamp it to the muted default */
@media (hover: none) {
  #admin-toggle-btn:not(.active-admin):hover {
    border-color: var(--border);
    color: var(--muted);
    background: transparent;
  }
}

body.setlists-page .app-shell > header .header-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
}

body.setlists-page .app-shell > header .header-row > .nav-link {
  justify-self: start;
}

body.setlists-page .app-shell > header .header-actions {
  justify-self: end;
  flex-direction: row;
  align-items: center;
}

/* ── Non-index pages: centered-title grid (song, admin, setlists) ─────────── */
/* Same 1fr/auto/1fr pattern as setlists desktop — applies on ALL screen sizes. */
body:not(.index-page) .app-shell > header .header-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
}

body:not(.index-page) .app-shell > header .site-title {
  grid-column: 2;
}

body:not(.index-page) .app-shell > header .header-row > .nav-link {
  justify-self: start;
}

body:not(.index-page) .app-shell > header .header-actions {
  grid-column: 3;
  justify-self: end;
}

/* Song page: lower side toggles to match index header toggle line */
body.song-page .app-shell > header .header-row > .nav-link,
body.song-page .app-shell > header .header-actions {
  align-self: end;
  margin-top: 0.28rem;
}

body.song-page .app-shell > header .header-actions {
  gap: 0.6rem;
}

body.song-page .app-shell > header .header-actions #admin-toggle-btn {
  margin-top: -0.22rem;
}

/* ── Header nav-links sized to match .btn ───────────────────────────────────── */
.header-actions .nav-link,
.header-nav-row .nav-link {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 0.6rem 1.1rem;
  line-height: 1;
  white-space: nowrap;
}

.nav-link {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: color var(--transition), border-color var(--transition);
  -webkit-tap-highlight-color: transparent; /* iOS: prevent link highlight on layout-shift taps */
}

@media (hover: hover) {
  .nav-link:hover {
    color: var(--amber);
    border-color: var(--amber-dim);
  }
}
/* Touch devices: prevent any pseudo-state (hover/active/focus) from brightening the link
   when it appears at the touch-lift position after a layout shift */
@media (hover: none) {
  .nav-link:hover,
  .nav-link:active,
  .nav-link:focus {
    color: var(--muted);
    border-color: var(--border);
  }
}

/* ── Search ────────────────────────────────────────────────────────────────── */
.search-row {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
  overflow: hidden;
}

.search-wrap:focus-within {
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 3px rgba(212, 149, 42, 0.18);
}

.search-wrap::after {
  content: '';
  position: absolute;
  right: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0.9rem;
  height: 0.9rem;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a7568' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='10' cy='10' r='7'/%3E%3Cpath d='M16.5 16.5 21 21'/%3E%3C/svg%3E") no-repeat center / contain;
  pointer-events: none;
  opacity: 0.55;
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  width: auto;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding-right: 2.2rem;
}

.search-wrap input:focus {
  border-color: transparent;
  box-shadow: none;
}

#search::placeholder {
  color: #545048;
}

/* ── Category tabs ──────────────────────────────────────────────────────────── */
.cat-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
  flex-shrink: 0;
}
.cat-tab {
  flex: 1;
  padding: 0.38rem 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.cat-tab.active {
  color: var(--amber);
  border-color: var(--amber-dim);
}
@media (hover: hover) {
  .cat-tab:hover {
    color: var(--amber);
    border-color: var(--amber-dim);
  }
}

.fav-filter-btn {
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition), border-color var(--transition);
  line-height: 1;
}

@media (hover: hover) {
  .fav-filter-btn:hover {
    color: var(--amber);
    border-color: var(--amber-dim);
  }
}

.fav-filter-btn.active {
  color: var(--amber);
  border-color: var(--amber-dim);
}

/* ── Song list (index) ─────────────────────────────────────────────────────── */
.song-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-bottom: 2rem;
}

.song-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  /* No 'transform' here — prevents speculative compositor-layer promotion on touch devices */
  transition: background var(--transition), border-color var(--transition);
  text-decoration: none;
  color: inherit;
  width: 100%;
}

.song-item:hover {
  background: var(--surface2);
  border-color: var(--amber-dim);
}

/* Slide effect only on real-pointer devices — transform on touch triggers stacking
   context that paints above the overlay scrollbar. */
@media (hover: hover) {
  .song-item {
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
  }
  .song-item:hover {
    transform: translateX(3px);
  }
}

.song-number {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--amber);
  min-width: 2.2rem;
  text-align: right;
  flex-shrink: 0;
}

.song-title-group {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.song-title {
  font-family: var(--font-head);
  font-size: 1.05rem;
}

.song-matched-tags {
  display: none;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--amber-dim);
  letter-spacing: 0.06em;
}

.song-matched-tags.visible {
  display: block;
}

.song-pages {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.fav-btn {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.28);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: color var(--transition);
  padding: 0.25rem 0.3rem;
  user-select: none;
}

@media (hover: hover) {
  .fav-btn:hover {
    color: rgba(255, 255, 255, 0.6);
  }
}

.fav-btn.active {
  color: var(--amber);
}

/* ── Delete / Rename buttons (per song card) ─────────────────────────────────── */
#song-list li {
  position: relative;
}

#song-list .song-item {
  padding-right: 5.25rem;
}

/* Groups rename + delete together at the right edge of each card */
.song-btn-group {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.delete-btn,
.rename-btn {
  position: static;
  transform: none;
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.3rem 0.45rem;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
  line-height: 1;
}

.delete-btn:hover {
  color: var(--danger);
  background: rgba(192, 57, 43, 0.12);
}

.rename-btn:hover {
  color: var(--amber);
  background: rgba(212, 149, 42, 0.12);
}

/* Inline error line inside modals */
.modal-error {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: #e05a4e;
  min-height: 1.1em;
  margin-bottom: 0.75rem;
}

/* ── Global modal overlay ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.65);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  width: 90%;
  max-width: 420px;
  background: #111;
  padding: 24px;
  border-radius: 12px;
}

#set-title-modal .modal-msg {
  margin-bottom: 0.75rem;
}

#set-title-modal .form-group {
  margin-bottom: 0.85rem;
}

.modal-msg {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}

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

.btn-danger:hover {
  background: #e04535;
  border-color: #e04535;
}

/* ── Empty / loading states ────────────────────────────────────────────────── */
.state-msg {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  padding: 2.5rem 0;
  text-align: center;
  letter-spacing: 0.06em;
}

/* ── Song viewer (song.html) ───────────────────────────────────────────────── */
.song-meta {
  margin-bottom: 1.5rem;
}

.song-meta h1 {
  font-family: var(--font-head);
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  line-height: 1.25;
  margin-bottom: 0.3rem;
}

.song-meta .meta-row {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.badge-amber {
  color: var(--amber);
}

.song-tags {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #aaa;
  letter-spacing: 0.07em;
}

.tag-edit {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tag-input {
  width: 14rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.tag-save-btn {
  font-size: 0.65rem;
  padding: 0.38rem 0.75rem;
  white-space: nowrap;
}

/* Page viewer */
.page-viewer {
  background: transparent;
  border: none;
  border-radius: 0;
  overflow: visible;
  margin-bottom: 1rem;
  min-height: calc(100vh - 120px);
  min-height: calc(100svh - var(--song-header-height, 120px));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.song-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: calc(100vh - 120px);
  min-height: calc(100svh - var(--song-header-height, 120px));
}

.song-container img {
  max-width: 95vw;
  max-height: calc(100vh - 120px);
  max-height: calc(100svh - var(--song-header-height, 120px));
  width: auto;
  height: auto;
  display: block;
}

.song-track {
  display: flex;
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.song-slide {
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: start;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.pdf-canvas {
  max-width: 100%;
  height: auto;
}

.song-slide img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  max-height: calc(100svh - var(--song-header-height, 120px));
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.song-slide.is-pdf {
  display: block;
}

.song-pdf-frame {
  width: 100%;
  height: calc(100vh - var(--song-header-height, 120px));
  border: none;
}

.song-track .no-page {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  margin: auto;
}

/* ── Mobile fullscreen mode (double-tap image to enter, swipe to exit) ─────── */
@media (hover: none) and (pointer: coarse) {
  body.song-fullscreen {
    overflow: hidden;
  }
  body.song-fullscreen .app-shell > header,
  body.song-fullscreen .page-nav,
  body.song-fullscreen footer,
  body.song-fullscreen .sync-bar {
    display: none !important;
  }
  body.song-fullscreen .page-viewer {
    position: fixed;
    inset: 0;
    z-index: 999;
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
  }
  body.song-fullscreen .song-track {
    height: 100dvh;
  }
  body.song-fullscreen .song-slide {
    height: 100dvh;
  }
  body.song-fullscreen .song-container img,
  body.song-fullscreen .song-slide img,
  body.song-fullscreen .pdf-canvas {
    max-height: 100dvh;
    max-width: 100vw;
    object-fit: contain;
  }
}

/* Navigation bar */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.page-indicator {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-align: center;
  flex: 1;
}

/* Dot strip */
.dot-strip {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--transition);
  cursor: pointer;
}

.dot.active {
  background: var(--amber);
}

/* Jump Sync toast */
.sync-toast {
  position: fixed;
  bottom: 9rem;   /* high enough to clear the sync/share button row */
  left: 50%;
  transform: translateX(-50%) translateY(0.6rem);
  background: rgba(20, 20, 20, 0.88);
  color: #00e5a0;
  font-weight: 300;
  text-shadow: 0 0 10px rgba(0, 229, 160, 0.45);
  padding: 0.55rem 1.4rem;
  border-radius: 2rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  line-height: 1.5;
  text-align: center;
  white-space: pre-line;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.sync-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Sync button */
.sync-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.sync-bar-left,
.sync-bar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  line-height: 1;
  background: transparent;
}

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--bg);
}
.btn-primary:hover {
  background: var(--cream);
  border-color: var(--cream);
  color: var(--bg);
}

.btn-ghost {
  border-color: var(--border);
  color: var(--muted);
}
.btn-ghost:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
}

.btn-ghost:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.btn-ghost:disabled:hover {
  border-color: var(--border);
  color: var(--muted);
}

.btn-sync {
  border-color: var(--border);
  color: var(--muted);
  font-size: 0.65rem;
}
@media (hover: hover) {
  .btn-sync:hover {
    border-color: var(--amber-dim);
    color: var(--amber);
  }
}
.btn-sync.sharing {
  border-color: var(--amber-dim);
  color: var(--amber);
}
.btn-sync.synced {
  border-color: #3a7c4a;
  color: #5aad6e;
}

.btn-sync.locked {
  position: relative;
  overflow: hidden;
  border-color: rgba(215, 100, 100, 0.38);
  color: rgba(215, 100, 100, 0.5);
}
.btn-sync.locked::before,
.btn-sync.locked::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.btn-sync.locked::before {
  background: linear-gradient(
    to bottom right,
    transparent calc(50% - 0.5px),
    rgba(215, 100, 100, 0.38) calc(50% - 0.5px),
    rgba(215, 100, 100, 0.38) calc(50% + 0.5px),
    transparent calc(50% + 0.5px)
  );
}
.btn-sync.locked::after {
  background: linear-gradient(
    to bottom left,
    transparent calc(50% - 0.5px),
    rgba(215, 100, 100, 0.38) calc(50% - 0.5px),
    rgba(215, 100, 100, 0.38) calc(50% + 0.5px),
    transparent calc(50% + 0.5px)
  );
}

/* ── Admin form ─────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  margin-bottom: 2rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.65rem 0.85rem;
  width: 100%;
  transition: border-color var(--transition);
  outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
  border-color: var(--amber-dim);
}

/* File input */
.file-drop {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
}

.file-drop:hover,
.file-drop.dragover {
  border-color: var(--amber-dim);
  background: rgba(212, 149, 42, 0.04);
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.file-drop-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  pointer-events: none;
}

.file-drop-label strong {
  color: var(--amber);
  font-weight: 500;
}

.file-list {
  list-style: none;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.file-list li {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--cream);
  background: var(--surface2);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-list li.batch-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem 0.65rem;
  white-space: normal;
  overflow: visible;
}

.batch-filename {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  flex-shrink: 0;
  max-width: 38%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-title-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  outline: none;
  transition: border-color var(--transition);
}

.batch-title-input:focus {
  border-color: var(--amber-dim);
}

/* Status message */
.status {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  display: none;
}

.status.visible { display: block; }
.status.success { background: rgba(58, 124, 74, 0.15); color: #5aad6e; border: 1px solid #3a7c4a; }
.status.error   { background: rgba(192, 57, 43, 0.15); color: #e05a4e; border: 1px solid var(--danger); }

/* ── Footer ────────────────────────────────────────────────────────────────── */
footer {
  margin-top: auto;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.theme-toggle-btn {
  font-size: 0.6rem;
  padding: 0.35rem 0.75rem;
  position: absolute;
  right: 0;
}

/* ── Light mode ─────────────────────────────────────────────────────────────── */
body.light-mode {
  --bg:        #f5f2ec;
  --surface:   #eceae2;
  --surface2:  #d8d4cb;
  --border:    #a8a39a;
  --cream:     #1a1915;
  --muted:     #524d45;
  --amber:     #a06b12;
  --amber-dim: #7d520d;
}

body.light-mode ::-webkit-scrollbar-thumb       { background: rgba(0,0,0,0.30); }
body.light-mode ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.48); }

body.light-mode .modal-box { background: #f0ede6; }

body.light-mode input[type="text"],
body.light-mode input[type="number"],
body.light-mode input[type="password"] { background: var(--surface); }

body.light-mode .search-wrap { background: var(--surface); }

/* Hardcoded white overrides */
body.light-mode .site-title           { color: #1a1915; }
body.light-mode .fav-btn              { color: rgba(0, 0, 0, 0.28); }
@media (hover: hover) { body.light-mode .fav-btn:hover { color: rgba(0, 0, 0, 0.55); } }
body.light-mode .fav-btn.active       { color: #e8960a; }

/* Button / nav-link text darker in light mode */
body.light-mode .btn-ghost      { color: #2e2924; }
body.light-mode .nav-link       { color: #2e2924; }
body.light-mode .fav-filter-btn { color: #2e2924; }

/* Brighter hover states in light mode */
body.light-mode .btn-ghost:hover        { color: #c47d08; border-color: #a06b12; }
body.light-mode .nav-link:hover         { color: #c47d08; border-color: #8a5b10; background: rgba(160, 107, 18, 0.10); }
@media (hover: hover) { body.light-mode .fav-filter-btn:hover { color: #c47d08; border-color: #a06b12; } }
body.light-mode .back-link:hover        { color: #c47d08; }
body.light-mode .song-item:hover        { border-color: #a06b12; }
body.light-mode .date-item:hover        { border-color: #a06b12; }
body.light-mode .rename-btn:hover       { color: #c47d08; background: rgba(196, 125, 8, 0.14); }

/* Stronger focus glow on light bg */
body.light-mode .search-wrap:focus-within {
  box-shadow: 0 0 0 3px rgba(200, 130, 18, 0.28);
}

/* Selected song card */
body.light-mode .song-list.select-mode li.selected .song-item {
  background: rgba(160, 107, 18, 0.16);
  border-color: #8a5b10;
}

/* Favorites filter button */
body.light-mode .fav-filter-btn.active {
  background: rgba(160, 107, 18, 0.10);
  border-color: #8a5b10;
  color: #7d520d;
}

/* ── Light mode: additional active / selected state overrides ──────────────── */

/* Category tab active */
body.light-mode .cat-tab.active {
  background: rgba(160, 107, 18, 0.10);
  border-color: #8a5b10;
  color: #7d520d;
}

/* Select-mode button while active */
body.light-mode .btn-ghost.selecting {
  background: rgba(160, 107, 18, 0.10);
  border-color: #8a5b10;
  color: #7d520d;
}

/* Admin mode button active */
body.light-mode #admin-toggle-btn.active-admin {
  background: rgba(45, 106, 60, 0.14);
  border-color: #2d6a3c;
  color: #1f5229;
}

/* ── Back link ──────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.25rem;
  transition: color var(--transition);
}

.back-link:hover { color: var(--amber); }

/* ── Page-load animation ────────────────────────────────────────────────────── */
.fade-in {
  animation: fadeInSlide 0.35s ease both;
}

/* Slide+fade: used for page wrappers and date items (few elements, no scrollbar conflict) */
@keyframes fadeInSlide {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Opacity-only: used for song items.
   No transform = no stacking context = scrollbar stays on top. */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.song-item {
  animation: fadeIn 0.3s ease both;
}

/* ── Header actions ─────────────────────────────────────────────────────────── */
.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
}

.header-nav-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Select mode ─────────────────────────────────────────────────────────────── */
.btn-ghost.selecting {
  border-color: var(--amber-dim);
  color: var(--amber);
}

/* ── Setlist horizontal slider (setlist.html) ─────────────────────────────── */
html:has(body.sl-page),
body.sl-page {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  /* Prevent long-press text selection / iOS callout on the slide viewer */
  user-select: none;
  -webkit-user-select: none;
}

body.sl-page {
  margin: 0;
  min-height: 100vh;
  background: #000;
  -webkit-touch-callout: none;
}

body.sl-page .sl-track {
  background: #000;
}

.sl-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.25rem 0.45rem;
  pointer-events: auto;
}

.sl-header .back-link {
  margin-bottom: 0;
  padding: 0.48rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 14, 12, 0.72);
  backdrop-filter: blur(6px);
  font-size: 0.82rem;
  line-height: 1.15;
}

.sl-header-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.12rem;
  padding: 0.38rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 14, 12, 0.72);
  backdrop-filter: blur(6px);
  line-height: 1.1;
}

.sl-set-name,
.sl-date {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sl-set-name { color: var(--amber); }
.sl-date { color: var(--muted); }

.sl-track {
  display: flex;
  width: 100vw;
  margin-top: var(--sl-header-space, 0px);
  height: calc(100vh  - var(--sl-header-space, 0px));
  height: calc(100svh - var(--sl-header-space, 0px));
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.sl-slide {
  position: relative;
  flex: 0 0 100vw;
  width: 100vw;
  height: calc(100vh  - var(--sl-header-space, 0px));
  height: calc(100svh - var(--sl-header-space, 0px));
  scroll-snap-align: start;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.sl-media {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.sl-slide img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
  border: none;
}

.sl-slide iframe {
  max-width: 95vw;
  max-height: 95vh;
  width: auto;
  height: auto;
  border: none;
}

.overlay-ui {
  position: fixed;
  left: 50%;
  bottom: 0.9rem;
  transform: translateX(-50%);
  z-index: 20;
  width: min(94vw, 960px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay-ui.active {
  opacity: 1;
  pointer-events: auto;
}

.sl-title {
  max-width: 100%;
  padding: 0.38rem 0.6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 14, 12, 0.7);
  color: var(--cream);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

.sl-footer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(15, 14, 12, 0.78);
  backdrop-filter: blur(6px);
}

.sl-counter {
  min-width: 6.2rem;
  text-align: center;
  color: var(--cream);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

@media (max-width: 700px) {
  .sl-header {
    padding: 0.2rem 0.32rem;
    gap: 0.35rem;
  }

  .sl-header-info {
    max-width: 62vw;
    padding: 0.35rem 0.6rem;
  }

  .sl-header .back-link {
    padding: 0.58rem 1.05rem;
    font-size: 0.88rem;
  }

  .sl-set-name,
  .sl-date {
    font-size: 0.65rem;
  }

  .sl-title {
    max-width: 94vw;
    font-size: 0.58rem;
  }

  .overlay-ui {
    bottom: 0.6rem;
    width: 96vw;
  }

  .sl-footer {
    padding: 0.35rem 0.45rem;
  }
}

.song-list.select-mode .song-item {
  cursor: default;
}

.song-list.select-mode .song-item:hover {
  transform: none;
}

.song-list.select-mode li.selected .song-item {
  border-color: var(--amber);
  background: rgba(212, 149, 42, 0.1);
}

.song-list.select-mode li[data-select-order]::after {
  content: attr(data-select-order);
  position: absolute;
  top: 50%;
  right: 0.6rem;
  transform: translateY(-50%);
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 999px;
  border: none;
  background: var(--amber);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  line-height: 1.2rem;
  text-align: center;
}

/* ── Select panel ────────────────────────────────────────────────────────────── */
.select-panel {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.85rem 1rem;
  z-index: 10;
}

.select-panel.visible {
  display: block;
}

.select-panel-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
}

.select-panel select,
.select-panel input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--cream);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 0.55rem 0.75rem;
  outline: none;
  transition: border-color var(--transition);
}

.select-panel select:focus,
.select-panel input[type="date"]:focus {
  border-color: var(--amber-dim);
}

.panel-msg {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: #e05a4e;
}

/* ── Setlists page ───────────────────────────────────────────────────────────── */
.setlist-section {
  margin-bottom: 2rem;
}

.setlist-heading {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.6rem;
}

.setlist-empty {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.75rem 0;
  letter-spacing: 0.06em;
}

.date-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.date-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  animation: fadeInSlide 0.3s ease both;
}

.date-item:hover {
  background: var(--surface2);
  border-color: var(--amber-dim);
  transform: translateX(3px);
}

.date-label {
  font-family: var(--font-head);
  font-size: 1rem;
}

.date-arrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}


/* ── PDF canvas (PDF.js rendered pages) ────────────────────────────────────── */
.pdf-canvas {
  max-width: 95vw;
  max-height: 95vh;
  width: auto;
  height: auto;
  display: block;
}

/* ── Responsive: small screens (≤ 480px) ──────────────────────────────────── */
/* ── Admin mode ─────────────────────────────────────────────────────────────── */
.admin-only {
  display: none;
}

/* Higher specificity needed: .header-actions/.header-nav-row .nav-link (0,2,0)
   beats .admin-only (0,1,0), so we match that specificity to force display:none. */
.header-actions .admin-only,
.header-nav-row .admin-only {
  display: none;
}

body.admin-mode .admin-only {
  display: inline-flex;
}

body.admin-mode .header-actions .admin-only,
body.admin-mode .header-nav-row .admin-only {
  display: inline-flex;
}

body.admin-mode .song-btn-group.admin-only {
  display: flex;
}

#admin-toggle-btn.active-admin {
  background: rgba(58, 124, 74, 0.2);
  border-color: #3a7c4a;
  color: #5aad6e;
}

@media (max-width: 480px) {
  /* Slightly reduce header elements on narrow screens to prevent overlap */
  body.index-page .site-logo {
    width: auto;
  }
  body.index-page .site-title {
    font-size: clamp(1.5rem, 5vw, 2rem);
    gap: 0.35rem;
  }
  /* Admin + nav links: slightly smaller on narrow screens */
  body.index-page .header-actions #admin-toggle-btn,
  body.index-page .header-nav-row .nav-link {
    font-size: 0.68rem;
    padding: 0.32rem 0.6rem;
  }
  /* 선택 button: one step larger than other buttons on mobile */
  body.index-page #select-toggle {
    font-size: 0.76rem;
    padding: 0.38rem 1.1rem;
  }
}

/* ── Band-only visibility ─────────────────────────────────────────────────── */
.band-only {
  display: none !important;
}
body.band-mode .band-only,
body.admin-mode .band-only {
  display: inline-flex !important;
}
/* band-only nav links inside header-nav-row */
body.band-mode .header-nav-row .band-only,
body.admin-mode .header-nav-row .band-only {
  display: inline-flex !important;
}
/* fav-btn inside song list items */
body.band-mode .fav-btn,
body.admin-mode .fav-btn {
  display: inline !important;
}
.fav-btn {
  display: none !important;
}
/* sync bar: hidden unless band/admin mode */
.sync-bar {
  display: none !important;
}
body.band-mode .sync-bar,
body.admin-mode .sync-bar {
  display: flex !important;
}

/* ── Footer: 3-column grid (admin-btn | Asaph Scores | theme-toggle) ──────── */
footer {
  display: grid !important;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding-left: 1rem;
  padding-right: 1rem;
}
.theme-toggle-btn {
  position: static !important;
  justify-self: end;
}
.admin-mode-btn {
  justify-self: start;
  font-size: 0.6rem;
  padding: 0.35rem 0.75rem;
}
.admin-mode-btn.active-admin {
  background: rgba(58, 124, 74, 0.2);
  border-color: #3a7c4a;
  color: #5aad6e;
}

/* ── Login overlay (full-screen block) ───────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 9, 8, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.35s ease;
  opacity: 1;
}
.login-overlay.login-hidden {
  opacity: 0;
  pointer-events: none;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 2.4rem 2rem 2rem;
  width: min(380px, 88vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  transform: scale(1);
  animation: login-in 0.3s ease;
}
@keyframes login-in {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}

.login-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--cream);
  letter-spacing: 0.04em;
  margin: 0;
}
.login-subtitle {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin: 0 0 0.25rem;
}

#login-input {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--cream);
  outline: none;
  text-align: center;
  letter-spacing: 0.05em;
  transition: border-color 0.18s, box-shadow 0.18s;
  box-sizing: border-box;
  /* Mask input visually like a password field while allowing Korean IME */
  -webkit-text-security: disc;
}
#login-input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(212, 149, 42, 0.18);
}

.login-error {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--danger);
  min-height: 1em;
  margin: 0;
  text-align: center;
}

.login-submit-btn {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
}

/* light-mode login box */
body.light-mode .login-box {
  background: #f0ede6;
  border-color: #a8a39a;
}
body.light-mode #login-input {
  background: #e4e0d8;
  border-color: #a8a39a;
  color: #1a1915;
}
body.light-mode #login-input:focus {
  border-color: var(--amber);
}

/* ── Setlist annotation system ──────────────────────────────────────────────── */

/* Header right group: memo toggle + set-info badge */
.sl-header-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

/* Memo toggle button */
#memo-toggle-btn {
  font-size: 0.7rem;
  padding: 0.38rem 0.8rem;
  background: rgba(15, 14, 12, 0.72);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent; /* iOS: no grey tap flash */
  outline: none;
}
/* Focus ring suppressed — the .active class alone controls the "lit" appearance */
#memo-toggle-btn:focus,
#memo-toggle-btn:focus-visible {
  outline: none;
}
/* Without .active, hover/focus must NOT show the green active look */
#memo-toggle-btn:not(.active):hover,
#memo-toggle-btn:not(.active):focus,
#memo-toggle-btn:not(.active):active {
  background: rgba(15, 14, 12, 0.72);
  border-color: var(--border);
  color: var(--muted);
}
#memo-toggle-btn.active {
  background: rgba(58, 124, 74, 0.2);
  border-color: #3a7c4a;
  color: #5aad6e;
}

#setlist-edit-toggle-btn {
  font-size: 0.7rem;
  padding: 0.38rem 0.8rem;
  background: rgba(15, 14, 12, 0.72);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

#setlist-edit-toggle-btn:focus,
#setlist-edit-toggle-btn:focus-visible {
  outline: none;
}

#setlist-edit-toggle-btn:not(.active):hover,
#setlist-edit-toggle-btn:not(.active):focus,
#setlist-edit-toggle-btn:not(.active):active {
  background: rgba(15, 14, 12, 0.72);
  border-color: var(--border);
  color: var(--muted);
}

#setlist-edit-toggle-btn.active {
  background: rgba(58, 124, 74, 0.2);
  border-color: #3a7c4a;
  color: #5aad6e;
}

.setlist-editor {
  position: fixed;
  top: calc(var(--sl-header-space, 50px) + 0.4rem);
  left: 0.45rem;
  right: 0.45rem;
  z-index: 24;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 14, 12, 0.88);
  backdrop-filter: blur(8px);
}

.setlist-editor-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 60px;
  gap: 0.4rem;
}

#setlist-editor-search {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--cream);
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
}

#setlist-editor-song-select,
#setlist-editor-position {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--cream);
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
}

#setlist-editor-add-btn {
  width: 100%;
  min-width: 0;
}

.setlist-editor-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 38vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.34rem;
}

.setlist-editor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.38rem 0.45rem;
}

.setlist-editor-item.active {
  border-color: #5aad6e;
  box-shadow: 0 0 0 1px rgba(90, 173, 110, 0.22) inset;
}

.setlist-editor-item-title {
  color: var(--cream);
  font-size: 0.78rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setlist-editor-item-actions {
  display: flex;
  align-items: center;
  gap: 0.28rem;
}

.setlist-editor-item-actions .btn {
  min-width: 2rem;
  padding: 0.22rem 0.45rem;
  font-size: 0.72rem;
}

.setlist-editor-item-actions .btn.active-arrow {
  border-color: #3a7c4a;
  color: #5aad6e;
  background: rgba(58, 124, 74, 0.2);
}

@media (hover: none) {
  .setlist-editor-item-actions .btn:hover {
    border-color: var(--border);
    color: var(--muted);
    background: transparent;
  }
  .setlist-editor-item-actions .btn.active-arrow:hover {
    border-color: #3a7c4a;
    color: #5aad6e;
    background: rgba(58, 124, 74, 0.2);
  }
}

.setlist-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

@media (max-width: 420px) {
  .setlist-editor-top {
    grid-template-columns: minmax(0, 1fr) 68px 56px;
    gap: 0.3rem;
  }
  #setlist-editor-search,
  #setlist-editor-song-select,
  #setlist-editor-position {
    padding: 0.42rem 0.42rem;
    font-size: 0.75rem;
  }
  #setlist-editor-add-btn {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    font-size: 0.72rem;
  }
}

/* Annotation canvas — always layered above media, pointer-events off by default */
.annotation-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
  z-index: 5;
}

/* Prevent long-press callout on slide images and PDF canvases */
body.sl-page .sl-slide img,
body.sl-page .sl-slide .pdf-canvas {
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Annotation mode: enable canvas, disable track scroll so swipe doesn't fight drawing */
body.annotation-mode .annotation-canvas {
  pointer-events: auto;
  cursor: crosshair;
  /* manipulation = pan-x pan-y pinch-zoom, AND explicitly disables double-tap zoom.
     pinch-zoom alone does NOT block double-tap zoom on all iOS Safari versions. */
  touch-action: manipulation;
}
body.annotation-mode .sl-track {
  overflow-x: hidden;
  scroll-snap-type: none;
}

/* Memo toolbar — two-row column layout */
.memo-toolbar {
  display: none; /* shown via JS when memo mode is ON */
  position: fixed;
  top: calc(var(--sl-header-space, 50px) + 0.5rem);
  right: 0.6rem;
  z-index: 25;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0.38rem 0.6rem;
  background: rgba(15, 14, 12, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

/* Each row inside the toolbar */
.memo-row {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.22rem 0;
}

/* Thin divider between rows */
.memo-row + .memo-row {
  border-top: 1px solid var(--border);
}

.memo-tool-btn {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.28rem 0.68rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.memo-tool-btn:hover {
  color: var(--cream);
  border-color: var(--amber-dim);
}
.memo-tool-btn.active {
  background: rgba(212, 149, 42, 0.15);
  border-color: var(--amber-dim);
  color: var(--amber);
}

.memo-color-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.memo-color-btn:hover {
  transform: scale(1.15);
}
.memo-color-btn.active {
  border-color: var(--cream);
  box-shadow: 0 0 0 2px var(--amber);
  transform: scale(1.2);
}

.memo-width-sel {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.22rem 0.38rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--cream);
  cursor: pointer;
}

.memo-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.memo-action-btn {
  font-size: 0.68rem;
  padding: 0.28rem 0.72rem;
}
/* Save button: dim by default, green while saving, flash on success */
.memo-save-btn {
  color: var(--muted);
  border-color: var(--border);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.memo-save-btn:hover {
  color: var(--cream);
  border-color: var(--amber-dim);
}
.memo-save-btn.saving {
  background: rgba(58, 124, 74, 0.2);
  border-color: #3a7c4a;
  color: #5aad6e;
}
@keyframes save-flash {
  0%, 50% { background: rgba(58,124,74,0.25); border-color: #3a7c4a; color: #5aad6e; }
  100%    { background: transparent; border-color: var(--border); color: var(--muted); }
}
.memo-save-btn.save-flash {
  animation: save-flash 1.4s ease-out forwards;
}

/* Memo save confirmation toast — top of screen, below header */
.memo-save-toast {
  position: fixed;
  top: calc(var(--sl-header-space, 50px) + 0.75rem);
  left: 50%;
  transform: translateX(-50%) translateY(-0.5rem);
  background: rgba(20, 20, 20, 0.88);
  color: #00e5a0;
  font-weight: 300;
  text-shadow: 0 0 10px rgba(0, 229, 160, 0.45);
  padding: 0.55rem 1.4rem;
  border-radius: 2rem;
  font-size: 0.84rem;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 10000;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.memo-save-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Hide memo UI entirely on phones */
@media (max-width: 767px) {
  #memo-toggle-btn { display: none; }
  .memo-toolbar    { display: none !important; }
}

/* ── Memo toolbar — width buttons (SVG visual) ──────────────────────────────── */
.memo-widths-group {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}
.memo-width-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.memo-width-btn:hover {
  color: var(--cream);
  border-color: var(--amber-dim);
}
.memo-width-btn.active {
  background: rgba(212, 149, 42, 0.15);
  border-color: var(--amber-dim);
  color: var(--amber);
}

/* ── Undo one-time flash ─────────────────────────────────────────────────────── */
@keyframes undo-flash {
  0%   { background: rgba(212,149,42,0.4); border-color: var(--amber); color: var(--amber); }
  100% { background: transparent; border-color: var(--border); color: var(--muted); }
}
.memo-action-btn.undo-flash {
  animation: undo-flash 0.5s ease-out forwards;
}

/* Cursor variants are handled dynamically via JS (updateAnnotationCursor)
   which sets element.style.cursor to an SVG data-URL per tool/color/width. */

/* ── Draggable toolbar ───────────────────────────────────────────────────────── */
.memo-toolbar.dragging {
  cursor: grabbing !important;
  opacity: 0.92;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  user-select: none;
}

/* ── Text box overlay textarea ───────────────────────────────────────────────── */
.memo-text-overlay {
  position: fixed;
  z-index: 30;
  border: 1.5px dashed rgba(255, 255, 255, 0.45);
  background: transparent;
  font-family: "Noto Sans KR", "Lato", "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  font-weight: bold;
  font-size: 0.9rem;
  line-height: 1.4;
  padding: 2px 4px;
  resize: none;
  outline: none;
  box-shadow: none;
  border-radius: 2px;
  white-space: pre;
  overflow: hidden;          /* keeps scrollHeight = content height for auto-resize */
  word-break: normal;
  /* iOS: allow typing; prevent page scroll while textarea is active */
  touch-action: manipulation;
  user-select: text;
  -webkit-user-select: text;
}
