:root {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-card: #1c202b;
  --border: #2a2f3d;
  --text: #eef0f5;
  --text-dim: #9aa1b2;
  --accent: #7c5cff;
  --accent-2: #ff6f9c;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --success: #3ddc97;
  --warn: #ffc857;
  --danger: #ff5c72;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(124, 92, 255, 0.18), transparent),
    radial-gradient(900px 500px at 90% 0%, rgba(255, 111, 156, 0.12), transparent),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---- Page shell ---- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 32px 48px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: white;
  color: #1f1f1f;
  border: 1px solid #dcdcdc;
  width: 100%;
  padding: 12px 18px;
  font-size: 14px;
}

.btn-google:hover { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }

.btn-google-compact {
  width: auto;
  padding: 9px 16px;
  font-size: 13.5px;
}

/* ---- Discover (熱播新番) ---- */
.discover-section {
  margin-bottom: 32px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 17px;
  margin: 0;
}

.section-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.discover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.discover-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

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

.discover-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: linear-gradient(135deg, #22263353, #171a2333);
}

.discover-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.discover-title {
  padding: 8px 10px 2px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 34px;
}

.discover-meta {
  padding: 0 10px 10px;
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.discover-skeleton {
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  background: linear-gradient(100deg, var(--bg-card) 30%, var(--bg-elevated) 50%, var(--bg-card) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.discover-empty {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px 0;
}

/* ---- Login prompt (未登入) ---- */
.login-prompt {
  margin-bottom: 32px;
}

.login-prompt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  max-width: 420px;
  margin: 0 auto;
}

.login-prompt-card h2 {
  font-size: 17px;
  margin: 0 0 8px;
}

.login-prompt-card p {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 18px;
}

/* ---- My list section ---- */
.my-list .section-head {
  margin-bottom: 16px;
}

/* ---- Footer ---- */
.site-footer {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

.site-footer a {
  color: var(--text-dim);
  text-decoration: none;
}

.site-footer a:hover { color: var(--text); text-decoration: underline; }

.footer-sep { margin: 0 8px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 700;
  font-size: 20px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.3px;
}

.tagline {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6a4bff);
  color: white;
  box-shadow: 0 8px 20px rgba(124, 92, 255, 0.35);
}

.btn-primary:hover { box-shadow: 0 10px 26px rgba(124, 92, 255, 0.5); }

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.user-chip img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}

.menu { position: relative; }

.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 140px;
  z-index: 20;
}

.menu-list a {
  display: block;
  padding: 10px 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 13.5px;
}

.menu-list a:hover { background: var(--accent-soft); }

.menu-list a.menu-danger { color: var(--danger); }
.menu-list a.menu-danger:hover { background: rgba(255, 92, 114, 0.12); }

/* ---- Stats ---- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
}

.stat-tile .stat-value {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---- Toolbar / filters ---- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  width: 100%;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#filter-search { max-width: 320px; }

.sort-select {
  width: auto;
  max-width: 160px;
  margin-left: auto;
  cursor: pointer;
}

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

.chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.chip:hover { border-color: var(--accent); color: var(--text); }

.chip-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* ---- Grid / cards ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
  position: relative;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.card-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: linear-gradient(135deg, #22263353, #171a2333);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--text-dim);
  font-size: 13px;
}

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

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
}

.status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.2px;
}

.status-想看 { background: rgba(255, 200, 87, 0.16); color: var(--warn); }
.status-在看 { background: rgba(124, 92, 255, 0.18); color: #b6a5ff; }
.status-看完 { background: rgba(61, 220, 151, 0.16); color: var(--success); }
.status-棄追 { background: rgba(255, 92, 114, 0.16); color: var(--danger); }

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: #2a2f3d;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width 0.2s ease;
}

.card-rating {
  font-size: 12px;
  color: var(--warn);
}

.watch-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-2);
  text-decoration: none;
  margin-top: 2px;
}

.watch-link:hover { text-decoration: underline; }

.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.card:hover .card-actions { opacity: 1; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(15, 17, 23, 0.85);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  backdrop-filter: blur(4px);
}

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

.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

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

.empty-state p { margin-bottom: 16px; font-size: 15px; }

/* ---- Ad slot ---- */
.ad-slot {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

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

.modal-header h2 { margin: 0; font-size: 17px; }

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

.search-box {
  position: relative;
  margin-bottom: 18px;
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
}

.suggestion-item {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  align-items: center;
}

.suggestion-item:hover { background: var(--accent-soft); }

.suggestion-item img {
  width: 38px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  background: #2a2f3d;
  flex-shrink: 0;
}

.suggestion-title { font-size: 13.5px; font-weight: 600; }
.suggestion-sub { font-size: 11.5px; color: var(--text-dim); }

.suggestion-empty {
  padding: 14px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.form-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 18px;
}

.preview {
  width: 120px;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: #2a2f3d;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 12px;
  border: 1px solid var(--border);
}

.preview img { width: 100%; height: 100%; object-fit: cover; }

.fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.field-error {
  display: none;
  color: var(--danger);
  font-size: 11.5px;
}

.field-error.visible { display: block; }

.input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 92, 114, 0.16);
}

.form-banner {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 92, 114, 0.12);
  border: 1px solid rgba(255, 92, 114, 0.4);
  color: var(--danger);
  font-size: 13px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

textarea.input { resize: vertical; font-family: inherit; }

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

.review-header-actions select { width: auto; }

.review-modal .modal-body { padding: 20px; }

.review-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.review-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  padding: 40px 0;
}

.review-top-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
}

.review-top-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
}

.review-top-card {
  text-align: center;
}

.review-top-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elevated);
  margin-bottom: 6px;
}

.review-top-cover img { width: 100%; height: 100%; object-fit: cover; }

.review-top-name {
  font-size: 11.5px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.review-top-score { font-size: 11px; color: var(--warn); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  .page { padding: 16px 14px 40px; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .btn-google-compact {
    width: 100%;
    padding: 10px 16px;
  }

  #topbar-user.topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }

  #topbar-user .btn { width: 100%; padding: 9px 8px; font-size: 12.5px; }
  #topbar-user .menu { width: 100%; }
  #topbar-user .user-chip span { display: none; }

  .brand h1 { font-size: 19px; }

  .discover-grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }

  .stats-bar { grid-template-columns: repeat(2, 1fr); }

  .toolbar { flex-direction: column; align-items: stretch; }
  #filter-search { max-width: none; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }

  .form-grid { grid-template-columns: 90px 1fr; }
  .preview { width: 90px; }

  .modal { max-height: 95vh; }
  .modal-body { padding: 14px 16px; }

  .login-prompt-card { padding: 22px 18px; }
}

@media (max-width: 380px) {
  .discover-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  #topbar-user.topbar-actions { grid-template-columns: 1fr 1fr; }
}
