:root {
  --bg: #0B0E14;
  --surface: #141923;
  --surface-elev: #1B2230;
  --border: #263042;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --accent: #38BDF8;
  --accent-strong: #2563EB;
  --danger: #F87171;
  --radius-xl: 18px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 16px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
  padding: 4px 2px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.version-pill {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

/* Auth Gate */
.auth-gate {
  min-height: 68vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  text-align: center;
}

.auth-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 18px;
}

.auth-form {
  display: flex;
  gap: 8px;
}

.auth-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.98rem;
  outline: none;
}

.auth-input:focus {
  border-color: var(--accent);
}

.btn-primary {
  height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary:active, .btn-accent:active, .btn-ghost:active, .seg-btn:active {
  transform: scale(0.97);
}

.auth-error {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--danger);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.filter-pill {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.filter-pill.is-active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
}

/* Video Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  text-align: left;
  color: inherit;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.video-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.card-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #05070A;
  overflow: hidden;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-dur {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(11, 14, 20, 0.88);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}

.card-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

/* Player View */
.player-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.player-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-accent {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(37, 99, 235, 0.2);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.segmented-control {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn.is-active {
  background: var(--accent-strong);
  color: #fff;
}

.stage-wrap {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.video-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #000;
}

.cinema-video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

.thumb-preview {
  position: absolute;
  bottom: 58px;
  transform: translateX(-50%);
  background: #0B0E14;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  padding: 4px;
  pointer-events: none;
  z-index: 20;
  text-align: center;
}

.thumb-sprite {
  width: 160px;
  height: 90px;
  background-repeat: no-repeat;
  border-radius: 6px;
}

.thumb-time {
  display: inline-block;
  margin-top: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.video-meta-bar {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.player-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.meta-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-pill {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

.chapters-section {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 12px;
}

.chapters-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.chapter-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
}

.chapter-btn:hover {
  border-color: var(--accent);
}

.chapter-time {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 10, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-elev);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.download-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dl-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.dl-item:hover {
  border-color: var(--accent);
}

.dl-item.is-original {
  border-color: rgba(56, 189, 248, 0.45);
}

.dl-label {
  font-size: 0.92rem;
  font-weight: 700;
}

.dl-note {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
}

.dl-size {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  .app-shell { padding: 10px 12px 28px; }
  .player-nav { gap: 8px; }
  .seg-btn { padding: 5px 8px; font-size: 0.74rem; }
}
