:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface2: #23232f;
  --border: #2e2e3e;
  --text: #e8e8f0;
  --text-dim: #7a7a9a;
  --cut: #ff4d4d;
  --cut-bg: rgba(255,77,77,0.12);
  --highlight: #f5c518;
  --highlight-bg: rgba(245,197,24,0.12);
  --accent: #6c63ff;
  --green: #06C755;
  --radius: 12px;
  --progress-h: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Chrome Banner ── */
#chrome-banner {
  display: none;
  background: #1a73e8;
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  align-items: center;
  gap: 10px;
}
#chrome-banner span { flex: 1; }
#chrome-banner button {
  background: #fff;
  color: #1a73e8;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Header ── */
header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
header h1 { font-size: 17px; font-weight: 700; flex: 1; }
header .subtitle { font-size: 12px; color: var(--text-dim); }
.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-filename {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

/* ── Mode Selector ── */
.mode-bar {
  margin: 16px 20px 4px;
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}
.mode-opt {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .18s, color .18s;
}
.mode-opt.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.mode-opt.active.driving-opt {
  background: #2a1f00;
  color: var(--highlight);
}
.mode-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  margin-left: 6px;
}
.mode-tag.driving { background: rgba(245,197,24,.2); color: var(--highlight); }

/* ── HOME VIEW ── */
#home-view { display: flex; flex-direction: column; flex: 1; padding-bottom: 24px; }

.btn-start {
  margin: 24px 20px 8px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-start:active { opacity: .8; }

/* ── Projects List ── */
.section-title {
  margin: 20px 20px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
}
#projects-list { display: flex; flex-direction: column; gap: 10px; margin: 0 20px; }
.project-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
}
.project-name {
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}
.project-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.project-meta .badges { display: inline-flex; gap: 8px; margin-top: 3px; }
.badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge.cut { background: var(--cut-bg); color: var(--cut); }
.badge.highlight { background: var(--highlight-bg); color: var(--highlight); }

.project-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-card {
  flex: 1;
  min-width: 0;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.btn-card:active { background: var(--border); }
.btn-card.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-card.share { background: var(--green); border-color: var(--green); color: #fff; }
.btn-card.danger { color: var(--cut); border-color: var(--cut-bg); }

.empty-hint {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.8;
}

/* ── PLAYER VIEW ── */
#player-view { display: none; flex-direction: column; flex: 1; }

.file-info {
  margin: 0 20px 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}
.file-info .change-btn {
  margin-left: auto;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px 8px;
}

/* ── Progress Bar ── */
.progress-wrapper {
  margin: 8px 20px 4px;
  position: relative;
  height: var(--progress-h);
  background: var(--surface2);
  border-radius: 99px;
  cursor: pointer;
  touch-action: none;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  pointer-events: none;
}
.progress-thumb {
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  pointer-events: none;
}
.mark-dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  border: 2px solid var(--bg);
}
.mark-dot.cut { background: var(--cut); }
.mark-dot.highlight { background: var(--highlight); }

.time-row {
  margin: 4px 20px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ── Transport ── */
.transport {
  margin: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-icon {
  background: var(--surface);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-icon:active { background: var(--surface2); }
.btn-play {
  width: 60px;
  height: 60px;
  font-size: 24px;
  background: var(--accent);
}
.btn-play:active { background: #5a52e0; }
.speed-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  cursor: pointer;
  height: 48px;
  min-width: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Mark Buttons ── */
.mark-buttons {
  margin: 12px 20px;
  display: flex;
  gap: 12px;
}
.btn-mark {
  flex: 1;
  height: 56px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity .15s, transform .1s;
}
.btn-mark:active { opacity: .8; transform: scale(.97); }
.btn-cut { background: var(--cut); color: #fff; }
.btn-highlight { background: var(--highlight); color: #1a1400; }

/* ── Mark List ── */
.list-section { margin: 16px 20px; flex: 1; }
.list-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.list-header h2 { font-size: 15px; font-weight: 700; flex: 1; }
.filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active-cut { background: var(--cut-bg); border-color: var(--cut); color: var(--cut); }
.filter-btn.active-highlight { background: var(--highlight-bg); border-color: var(--highlight); color: var(--highlight); }
.filter-btn.active-all { background: rgba(108,99,255,.15); border-color: var(--accent); color: var(--accent); }

#mark-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 140px; }
.mark-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-left: 3px solid transparent;
}
.mark-item.cut { border-left-color: var(--cut); }
.mark-item.highlight { border-left-color: var(--highlight); }
.mark-icon { font-size: 20px; line-height: 1; flex-shrink: 0; margin-top: 1px; }
.mark-body { flex: 1; min-width: 0; }
.mark-time {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  color: var(--accent);
  display: inline-block;
}
.mark-time:hover { text-decoration: underline; }
.mark-label { font-size: 13px; color: var(--text-dim); margin-top: 2px; word-break: break-all; }
.mark-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.mark-delete:active { color: var(--cut); }
.mark-edit {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.mark-edit:active { color: var(--accent); }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Completed Badge ── */
.badge-done {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(6,199,85,.15);
  color: #06C755;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
}

/* ── Export Bar (Player) ── */
.export-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}
.export-row { display: flex; gap: 8px; }
.btn-done {
  width: 100%;
  height: 62px;
  background: linear-gradient(135deg, #06C755 0%, #04a844 100%);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(6,199,85,.35);
  transition: opacity .15s, transform .1s;
}
.btn-done:active { opacity: .85; transform: scale(.98); }
.btn-export {
  flex: 1;
  height: 46px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-export:active { background: var(--border); }
.btn-line-sm {
  flex: 1;
  height: 46px;
  background: var(--green);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-send {
  flex: 2;
  height: 46px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-send:active { background: #5a52e0; }

/* ── Bottom Sheet ── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  align-items: flex-end;
}
.sheet-overlay.open { display: flex; }
.sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px 40px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  animation: slideUp .25s cubic-bezier(.32,0,.67,0);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 20px;
}
.sheet h3 { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.sheet .sheet-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  padding: 12px;
  resize: none;
  height: 90px;
  font-family: inherit;
  margin-top: 12px;
}
.sheet textarea:focus { outline: none; border-color: var(--accent); }
.sheet textarea::placeholder { color: var(--text-dim); }
.btn-sheet {
  flex: 1;
  height: 48px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-sheet-primary { background: var(--accent); color: #fff; }
.btn-sheet-secondary { background: var(--surface2); color: var(--text); }
.btn-sheet-danger { background: var(--cut-bg); color: var(--cut); border: 1px solid var(--cut); }

.preset-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.preset-chip:active,
.preset-chip.selected {
  background: var(--cut-bg);
  border-color: var(--cut);
  color: var(--cut);
}

/* ── Driving Mode Overrides ── */
body.driving .btn-play {
  width: 80px; height: 80px; font-size: 32px;
}
body.driving .btn-icon {
  width: 62px; height: 62px; font-size: 24px;
}
body.driving .speed-btn {
  height: 62px; min-width: 62px; font-size: 16px;
}
body.driving .mark-buttons {
  gap: 16px; margin: 16px 20px;
}
body.driving .btn-cut,
body.driving .btn-highlight {
  height: 86px; font-size: 22px; border-radius: 16px;
}
body.driving .progress-wrapper {
  height: 16px; margin: 14px 20px 6px;
}
body.driving .progress-thumb {
  width: 28px; height: 28px;
}
body.driving .mark-dot {
  width: 16px; height: 16px;
}

/* 行車模式：預設選項變成 2×2 大格子 */
body.driving #preset-chips {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
body.driving .preset-chip {
  height: 80px;
  padding: 0;
  font-size: 19px;
  font-weight: 800;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
}
body.driving .btn-done { height: 74px; }
body.driving .sheet textarea { font-size: 17px; height: 100px; }
body.driving .btn-sheet { height: 60px; font-size: 18px; }

.speed-option {
  padding: 14px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
  transition: background .15s;
  color: var(--text);
}
.speed-option:hover, .speed-option.selected { background: var(--surface2); color: var(--accent); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 18px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Cloud version additions ── */
#file-input { display: none; }
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
}
.btn-logout:active { color: var(--text); }

.upload-bar {
  height: 10px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
  margin: 16px 0 8px;
}
.upload-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 99px;
  transition: width .2s;
}
.upload-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.card-progress {
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
  margin: 6px 0 12px;
}
.card-progress > div { height: 100%; background: var(--highlight); }
.badge-uploading {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--highlight-bg);
  color: var(--highlight);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  white-space: nowrap;
}

.save-status {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.save-status.error { color: var(--cut); }

.loading-hint {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Login ── */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .subtitle { font-size: 13px; color: var(--text-dim); margin-bottom: 24px; }
.login-card label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 8px; }
.login-card input {
  width: 100%;
  height: 50px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 0 14px;
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .btn-start { margin: 18px 0 0; width: 100%; height: 54px; font-size: 16px; }
.login-card .btn-start:disabled { opacity: .6; }
.login-error { color: var(--cut); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ── Share page ── */
.share-actions { display: flex; gap: 8px; margin: 12px 20px; }
.share-actions .btn-export { height: 50px; font-size: 14px; }
.readonly-note {
  margin: 12px 20px 0;
  font-size: 12px;
  color: var(--text-dim);
}
