:root {
  --bg-primary: #0b0f17;
  --bg-secondary: #131b2e;
  --bg-tertiary: #1e293b;
  --bg-panel: #162032;
  --bg-hover: #27354f;
  
  --border-color: #2a3754;
  --border-focus: #38bdf8;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --accent-cyan: #00d2ff;
  --accent-pink: #ff4081;
  --accent-green: #00e676;
  --accent-blue: #3b82f6;
  --accent-gold: #f59e0b;
  --accent-red: #ef4444;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: #2a3d5e #0b111b;
}

/* ===================================================
   Custom Sleek Dark Scrollbars (整體深色調整合)
   =================================================== */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: #090e17;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #202e45;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s ease, border-color 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
  background: #2e4363;
  border-color: rgba(0, 210, 255, 0.35);
}

::-webkit-scrollbar-thumb:active {
  background: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.6);
}

::-webkit-scrollbar-corner {
  background: #090e17;
}

/* Specific styling for Timeline horizontal scrollbar */
.timeline-canvas-container::-webkit-scrollbar {
  height: 8px;
}
.timeline-canvas-container::-webkit-scrollbar-track {
  background: #070b12;
  border-top: 1px solid var(--border-color);
}
.timeline-canvas-container::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, #1d2c44, #283d5f);
  border-radius: 6px;
  border: 1px solid rgba(0, 210, 255, 0.25);
}
.timeline-canvas-container::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(90deg, #2a4168, #375685);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(0, 210, 255, 0.4);
}

/* Specific styling for Right tab content vertical scrollbar */
.tab-content::-webkit-scrollbar {
  width: 6px;
}
.tab-content::-webkit-scrollbar-track {
  background: rgba(11, 17, 27, 0.6);
  border-radius: 4px;
}
.tab-content::-webkit-scrollbar-thumb {
  background: #1f2c42;
  border-radius: 4px;
}
.tab-content::-webkit-scrollbar-thumb:hover {
  background: #314668;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  height: 56px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 20;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
}

.logo-icon {
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
  background: var(--bg-tertiary);
  color: var(--text-main);
}

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

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

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: 1px solid #3b82f6;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.btn-success {
  background: linear-gradient(135deg, #059669, #047857);
  color: white;
  border: 1px solid #10b981;
}
.btn-success:hover {
  background: linear-gradient(135deg, #10b981, #059669);
}

.btn-accent {
  background: linear-gradient(135deg, #ec4899, #db2777);
  color: white;
  border: 1px solid #f472b6;
}
.btn-accent:hover {
  background: linear-gradient(135deg, #f472b6, #ec4899);
}

.btn-coffee {
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #ffffff !important;
  font-weight: 600;
  border: 1px solid #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.25);
  text-decoration: none;
}
.btn-coffee:hover {
  background: linear-gradient(135deg, #f59e0b, #d97706) !important;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.5) !important;
  transform: translateY(-1px);
}

.btn-tap {
  background: linear-gradient(135deg, #00d2ff, #0284c7);
  color: #000;
  font-weight: 700;
  font-size: 1rem;
  padding: 10px 24px;
  box-shadow: 0 0 15px rgba(0, 210, 255, 0.35);
}
.btn-tap:hover {
  background: linear-gradient(135deg, #38bdf8, #00d2ff);
  box-shadow: 0 0 20px rgba(0, 210, 255, 0.55);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.8rem;
}

/* Main Split View */
.main-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: calc(100vh - 56px - 280px); /* Leaves 280px for bottom timeline */
}

/* Video & Canvas Preview Section */
.preview-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #05070a;
  position: relative;
  border-right: 1px solid var(--border-color);
  overflow: hidden;
}

.preview-container {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: #000;
}

#video-element {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

#ktv-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Drag overlay for position adjustment */
#position-drag-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  display: none;
}

.drag-handle {
  position: absolute;
  border: 2px dashed #00d2ff;
  background: rgba(0, 210, 255, 0.15);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: move;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
  transform: translate(-10px, -10px);
}

.drag-handle.line2-handle {
  border-color: #ff4081;
  background: rgba(255, 64, 129, 0.15);
  transform: translate(calc(-100% + 10px), -10px);
}

.autosave-indicator {
  font-size: 0.76rem;
  color: #10b981;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.3s ease;
  font-weight: 500;
}
.autosave-indicator.show {
  opacity: 1;
}

/* Clickable & Draggable Video Progress / Seek Bar */
.video-progress-wrap {
  width: 100%;
  height: 12px;
  background-color: var(--bg-secondary);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0;
  transition: height 0.15s ease;
  user-select: none;
  border-top: 1px solid var(--border-color);
}
.video-progress-wrap:hover {
  height: 16px;
}
.video-progress-bg {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  position: relative;
  transition: height 0.15s ease;
}
.video-progress-wrap:hover .video-progress-bg {
  height: 6px;
}
.video-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00d2ff, #00e676);
  pointer-events: none;
}
.video-progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px rgba(0,0,0,0.6);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.video-progress-wrap:hover .video-progress-thumb {
  opacity: 1;
}

/* Video Control Bar */
.preview-controls {
  height: 48px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-display {
  font-family: monospace;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.time-display .current {
  color: var(--accent-cyan);
  font-weight: bold;
}

/* Draggable Resizer Splitter between Preview and Right Panel */
.panel-resizer-h {
  width: 6px;
  background: var(--border-color);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  z-index: 10;
  user-select: none;
}
.panel-resizer-h:hover,
.panel-resizer-h.dragging {
  background: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.6);
}

/* Right Inspector Tabs */
.inspector-panel {
  width: 530px;
  min-width: 460px;
  max-width: 75vw;
  background-color: var(--bg-panel);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-left: 1px solid var(--border-color);
}

.tabs-header {
  height: 42px;
  display: flex;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.tab-btn.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: var(--bg-panel);
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: none;
}

.tab-content.active {
  display: block;
}

/* Form Styles */
.form-section {
  margin-bottom: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.section-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-group {
  margin-bottom: 12px;
}
.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-control:focus {
  border-color: var(--border-focus);
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-input {
  width: 42px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

.range-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.range-wrap input[type="range"] {
  flex: 1;
  accent-color: var(--accent-cyan);
}
.range-val {
  font-family: monospace;
  font-size: 0.85rem;
  width: 44px;
  text-align: right;
  color: var(--text-muted);
}

/* Singer Color Card */
.singer-color-card {
  border-left: 4px solid var(--accent-cyan);
  padding-left: 10px;
  margin-bottom: 10px;
}
.singer-color-card.male { border-left-color: var(--accent-cyan); }
.singer-color-card.female { border-left-color: var(--accent-pink); }
.singer-color-card.duet { border-left-color: var(--accent-green); }

/* Sentence List Items */
.sentence-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.15s;
}

.sentence-item:hover {
  border-color: var(--border-focus);
}

.sentence-item.active {
  border-color: var(--accent-gold);
  background: rgba(245, 158, 11, 0.08);
}

.sentence-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  gap: 8px;
  flex-wrap: nowrap;
}

.sentence-item-header > div:first-child {
  white-space: nowrap;
  flex-shrink: 0;
}

.sentence-item-header .ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.singer-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.singer-badge.male { background: rgba(0, 210, 255, 0.2); color: var(--accent-cyan); border: 1px solid var(--accent-cyan); }
.singer-badge.female { background: rgba(255, 64, 129, 0.2); color: var(--accent-pink); border: 1px solid var(--accent-pink); }
.singer-badge.duet { background: rgba(0, 230, 118, 0.2); color: var(--accent-green); border: 1px solid var(--accent-green); }

.sentence-item-header .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.countdown-check-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.76rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.countdown-check-label:hover {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--text-main);
}

.countdown-check-label.checked {
  background: rgba(245, 158, 11, 0.18);
  border-color: var(--accent-gold);
  color: #fbbf24;
  font-weight: 600;
}

.sentence-countdown-checkbox {
  cursor: pointer;
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--accent-gold);
}

.sentence-text {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  cursor: text;
}

.sentence-edit-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
  margin: 3px 0;
}

.sentence-edit-input {
  flex: 1;
  padding: 5px 10px;
  font-size: 0.95rem;
  font-weight: 600;
  background: #090e17;
  border: 1.5px solid var(--accent-cyan);
  border-radius: 6px;
  color: #ffffff;
  outline: none;
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.2);
  transition: all 0.15s ease;
}

.sentence-edit-input:focus {
  border-color: #00e5ff;
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.35);
  background: #0d1522;
}

.btn-save-edit {
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-cyan);
  color: #06090e;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-save-edit:hover {
  background: #22d3ee;
  transform: scale(1.04);
}

.btn-cancel-edit {
  padding: 4px 8px;
  font-size: 0.8rem;
  background: #253347;
  color: #94a3b8;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-cancel-edit:hover {
  background: #334155;
  color: #ffffff;
}

.lyric-char-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.lyric-char-tag:hover {
  background: rgba(0, 210, 255, 0.25);
  color: #00d2ff;
  transform: translateY(-1px);
}
.lyric-char-tag.has-time {
  border-bottom: 2px solid rgba(0, 230, 118, 0.6);
}

.sentence-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
}

/* Bottom Timeline & Tap Section */
.bottom-panel {
  height: 280px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}

.bottom-toolbar {
  height: 44px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.mode-toggle {
  display: flex;
  background: var(--bg-tertiary);
  padding: 2px;
  border-radius: var(--radius-sm);
}

.mode-btn {
  padding: 4px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}

.mode-btn.active {
  background: var(--accent-blue);
  color: white;
}

/* Tap Recording HUD */
.tap-mode-view {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1b2845 0%, #0c121e 100%);
  padding: 20px;
  position: relative;
}

.tap-mode-view.active {
  display: flex;
}

.tap-prompt-title {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.tap-lyric-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 2.2rem;
  font-weight: 700;
  margin: 12px 0;
  min-height: 50px;
}

.tap-char {
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.15s ease;
  color: #64748b;
  border: 1.5px solid transparent;
  cursor: pointer;
}

/* 已錄製完成的字：標示為青藍色已打點 */
.tap-char.recorded {
  color: var(--accent-cyan);
  background: rgba(0, 210, 255, 0.1);
  border-color: rgba(0, 210, 255, 0.3);
}

/* 當前準備打點的字：不框字、不設邊框底色，避免誤認為已唱到！ */
.tap-char.current {
  color: #94a3b8;
  background: transparent;
  border: 1.5px solid transparent;
  box-shadow: none;
  transform: none;
}

/* 句末按住長音中：翠綠動態光暈 */
.tap-char.active-holding {
  color: #000 !important;
  background: #00e676 !important;
  border-color: #00e676 !important;
  box-shadow: 0 0 25px rgba(0, 230, 118, 0.9) !important;
  transform: scale(1.15) !important;
}

.tap-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 10px;
}

/* Timeline View */
.timeline-view {
  flex: 1;
  display: none;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.timeline-view.active {
  display: flex;
}

.timeline-canvas-container {
  flex: 1;
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  background-color: #0d131f;
  user-select: none;
}

#timeline-canvas {
  display: block;
  cursor: crosshair;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Progress bar */
.progress-bar-container {
  width: 100%;
  height: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  overflow: hidden;
  margin: 16px 0;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-pink));
  width: 0%;
  transition: width 0.2s ease;
}
