*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px 16px 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #f4f6f9;
  color: #1b1f24;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1260px;
  margin: 0 auto;
}

header h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

header p {
  margin: 0 0 18px;
  color: #6b7280;
  font-size: 13px;
}

.search-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid #e3e7ee;
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.search-input-wrapper {
  position: relative;
  flex: 1 1 320px;
  min-width: 0;
  display: flex;
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: #9ca3af;
  pointer-events: none;
}

.search-input-wrapper input[type=text] {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 38px;
  border: 1px solid #d7dce5;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.search-input-wrapper input[type=text]:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  height: 42px;
  padding: 0 18px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-primary:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-ghost {
  background: #fff;
  border-color: #d7dce5;
  color: #374151;
}

.btn-ghost:hover {
  background: #f3f5f9;
}

.btn-ghost:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn-sm {
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 8px;
}

#homeBtn {
  padding: 0 14px;
  font-size: 16px;
  line-height: 1;
}

.source-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  color: #6b7280;
}

.source-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: #f1f3f8;
  border: 1px solid #e3e7ee;
}

.source-btn {
  height: 30px;
  padding: 0 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #6b7280;
  transition: all .15s;
  white-space: nowrap;
}

.source-btn:hover {
  color: #374151;
}

.source-btn.active {
  background: #fff;
  color: #2563eb;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .15);
}

.toolbar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
  font-size: 13px;
  color: #4b5563;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f4f6f9;
  padding: 8px 0;
}

.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toolbar select {
  height: 34px;
  padding: 0 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  background: #fff;
  outline: none;
}

.toolbar input[type=range] {
  width: 110px;
  vertical-align: middle;
}

.toolbar .spacer {
  flex: 1;
}

.toolbar .btn-ghost {
  height: 34px;
  padding: 0 12px;
}

.toggle-group {
  display: inline-flex;
  gap: 4px;
  padding: 2px;
  border-radius: 10px;
  background: #f1f3f8;
  border: 1px solid #e3e7ee;
}

.btn-toggle {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #9ca3af;
  transition: all .15s;
  white-space: nowrap;
}

.btn-toggle:hover {
  background: #e8ecf3;
  color: #374151;
}

.btn-toggle.active {
  background: #fff;
  border-color: #2563eb;
  color: #2563eb;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .12);
}

.btn-toggle:not(.active) .dot {
  background: #d1d5db;
}

.btn-toggle .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  background: #2563eb;
}

#mainArea.hide-chord .chord-line,
#mainArea.hide-number .number-line,
#mainArea.hide-transposed .transposed-line {
  display: none;
}

.status {
  margin-top: 10px;
  font-size: 13px;
  min-height: 18px;
}

.status.error {
  color: #dc2626;
}

.status.info {
  color: #2563eb;
}

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

@media (max-width: 920px) {
  .main {
    grid-template-columns: minmax(0, 1fr);
  }
}

.card {
  background: #fff;
  border: 1px solid #e3e7ee;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

#mainArea {
  min-height: 260px;
  max-height: 82vh;
  overflow-y: auto;
  overflow-x: hidden;
  --lh: 1;
}

#mainArea.full-view {
  max-height: none;
  overflow: visible;
}

#mainArea,
.sheet-head,
.line-group {
  font-family: 'Arimo', 'Noto Sans TC', monospace, sans-serif;
}

.sheet-head {
  padding: 18px 20px 6px;
}

.sheet-head h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.sheet-sub {
  color: #6b7280;
  font-size: 13px;
}

.transpose-info {
  margin-top: 10px;
  font-weight: 700;
  color: #d9534f;
  font-size: 13px;
}

.section-title {
  font-weight: 700;
  font-size: 15px;
  color: #111827;
  margin: 18px 20px 6px;
}

.line-group {
  margin: 0 20px 12px;
  font-size: 16px;
}

.chord-line,
.number-line,
.transposed-line,
.lyric-line {
  font-family: 'Arimo', 'Noto Sans TC', monospace, sans-serif;
  font-size: inherit;
  line-height: var(--lh, 1);
  white-space: nowrap;
}

.chord-line {
  color: #2b5c8f;
  font-weight: 700;
}

.number-line {
  color: #d9534f;
  font-weight: 700;
}

.transposed-line {
  color: #166534;
  font-weight: 700;
}

.lyric-line {
  color: #111827;
  font-weight: 400;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #9ca3af;
  font-size: 13px;
  text-align: center;
  padding: 60px 20px;
}

.empty-state .big {
  font-size: 34px;
  opacity: .35;
}

.results-head {
  padding: 14px 18px;
  font-size: 13px;
  color: #6b7280;
  border-bottom: 1px solid #e3e7ee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.results-head .query-tag {
  background: #eef2ff;
  color: #3730a3;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
}

.results-head .src-tag {
  background: #fef3c7;
  color: #92400e;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  margin-left: 6px;
}

.head-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-dice {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  border: none;
  height: 30px;
  min-width: 36px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(239, 68, 68, .2);
  transition: transform .12s, box-shadow .12s, opacity .12s;
}

.btn-dice:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.06);
  box-shadow: 0 4px 12px rgba(245, 158, 11, .45);
}

.btn-dice:active:not(:disabled) {
  transform: scale(.98);
}

.btn-dice:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-dice.spinning {
  animation: diceSpin .35s linear infinite;
}

@keyframes diceSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.result-item.slot-highlight {
  background: #fef3c7 !important;
  box-shadow: inset 0 0 0 2px #f59e0b;
  transition: none !important;
}

.result-item.slot-final {
  background: #d1fae5 !important;
  box-shadow: inset 0 0 0 2px #10b981;
  transition: none !important;
  animation: slotWin .4s ease-out;
}

@keyframes slotWin {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.03);
  }

  100% {
    transform: scale(1);
  }
}

.results {
  padding: 6px;
}

.result-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
}

.result-item:hover {
  background: #f5f7fa;
}

.result-item+.result-item {
  border-top: 1px solid #f1f4f8;
}

.result-main {
  flex: 1;
  min-width: 0;
}

.result-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 12px;
}

.stat-like {
  color: #16a34a;
  font-weight: 600;
}

.stat-dislike {
  color: #dc2626;
  font-weight: 600;
}

.stat-ratio {
  background: #f3f4f6;
  color: #374151;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.stat-no-rating {
  color: #9ca3af;
  font-size: 12px;
}

.badge {
  display: inline-block;
  background: #eef2ff;
  color: #3730a3;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

.badge-ug {
  background: #fef3c7;
  color: #92400e;
}

.move-actions {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex-shrink: 0;
  opacity: .55;
  transition: opacity .15s;
}

.result-item:hover .move-actions {
  opacity: 1;
}

.move-btn {
  width: 24px;
  height: 18px;
  padding: 0;
  font-size: 9px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f3f8;
  border: 1px solid #e3e7ee;
  border-radius: 6px;
  color: #6b7280;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.move-btn:hover:not(:disabled) {
  background: #eef2ff;
  border-color: #2563eb;
  color: #2563eb;
}

.move-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}

.song-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .15s;
}

.result-item:hover .song-actions {
  opacity: 1;
}

@media (hover: none) {

  .move-actions,
  .song-actions {
    opacity: 1;
  }
}

.side-head {
  display: flex;
  border-bottom: 1px solid #e3e7ee;
}

.tab-btn {
  flex: 1;
  height: 46px;
  background: none;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  color: #6b7280;
  cursor: pointer;
}

.tab-btn.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}

.tab-btn:hover:not(.active) {
  color: #374151;
}

.list {
  max-height: 64vh;
  overflow-y: auto;
  padding: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
}

.list-item:hover {
  background: #f5f7fa;
}

.list-item.active {
  background: #eef2ff;
}

.li-main {
  flex: 1;
  min-width: 0;
}

.li-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.li-sub {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.li-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}

.list-item:hover .li-actions {
  opacity: 1;
}

.icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: #9ca3af;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: #e8ecf3;
  color: #374151;
}

.empty-list {
  padding: 30px 14px;
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
}

.video-panel {
  border-top: 1px solid #e3e7ee;
  padding: 10px 12px 14px;
  max-height: 46vh;
  overflow-y: auto;
}

.video-panel .video-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  margin: 0 0 10px;
  letter-spacing: .02em;
}

.video-panel .video-head .yt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
}

.video-item+.video-item {
  margin-top: 12px;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.video-caption {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
  color: #4b5563;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 16px);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 999;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}

.modal h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.setlist-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 14px;
}

.setlist-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: #f5f7fa;
  border: 1px solid #e3e7ee;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  color: #1b1f24;
  height: auto;
  transition: background .12s, border-color .12s;
}

.setlist-option:hover {
  background: #eef2ff;
  border-color: #2563eb;
}

.setlist-option .sl-name {
  font-weight: 600;
}

.setlist-option .sl-count {
  font-size: 12px;
  color: #6b7280;
}

.new-setlist-form {
  display: flex;
  gap: 6px;
}

.new-setlist-form input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}

.new-setlist-form input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.new-setlist-form button {
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
}

.modal-actions {
  margin-top: 12px;
  text-align: right;
}

.chord-player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  bottom: env(safe-area-inset-bottom, 0);
  z-index: 90;
  display: none;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.chord-player.visible {
  display: flex;
}

.chord-player-toggle {
  pointer-events: auto;
  width: 68px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 12px 12px 0 0;
  background: #2563eb;
  color: #fff;
  font-size: 11px;
  line-height: 1;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 -2px 10px rgba(37, 99, 235, .28);
  transition: background .15s, transform .1s;
}

.chord-player-toggle:hover {
  background: #1d4ed8;
}

.chord-player-toggle:active {
  transform: translateY(1px);
}

.chord-player-toggle .arrow {
  transition: transform .22s ease;
  display: inline-block;
  font-size: 10px;
}

.chord-player-body {
  pointer-events: auto;
  width: 100%;
  background: #fff;
  border-top: 1px solid #e3e7ee;
  box-shadow: 0 -2px 12px rgba(16, 24, 40, .10);
  overflow: hidden;
  max-height: 0;
  transition: max-height .24s ease;
  display: flex;
  justify-content: center;
}

.chord-player.expanded .chord-player-body {
  max-height: 96px;
}

.chord-player-inner {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 1260px;
  padding: 10px 16px;
  gap: 8px;
}

.chord-sort-btn {
  flex-shrink: 0;
  height: 44px;
  min-width: 52px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid #d7dce5;
  background: #f9fafb;
  color: #6b7280;
  font-family: 'Arimo', 'Noto Sans TC', inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, color .12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chord-sort-btn:hover {
  background: #eef2ff;
  border-color: #2563eb;
  color: #2563eb;
}

.chord-sort-btn.active {
  background: #eef2ff;
  border-color: #2563eb;
  color: #2563eb;
}

.chord-player-buttons {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 8px;
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.chord-player-buttons::-webkit-scrollbar {
  height: 4px;
}

.chord-player-buttons::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

.chord-btn {
  flex-shrink: 0;
  height: 44px;
  min-width: 54px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid #d7dce5;
  background: #f9fafb;
  color: #1b1f24;
  font-family: 'Arimo', 'Noto Sans TC', inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, transform .08s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chord-btn:hover {
  background: #eef2ff;
  border-color: #2563eb;
  color: #1e40af;
}

.chord-btn:active,
.chord-btn.playing {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  transform: scale(.94);
}

body.chord-player-visible #mainArea {
  padding-bottom: 40px;
}

body.chord-player-visible.player-expanded #mainArea {
  padding-bottom: 120px;
}