:root {
  --bg: #0f1117;
  --surface: #171b26;
  --surface-2: #1f2433;
  --border: #2a3142;
  --text: #e8ecf4;
  --text-muted: #9aa4b8;
  --primary: #5b8def;
  --primary-hover: #4a7de0;
  --success: #3ecf8e;
  --danger: #f07178;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #0c0e14 0%, #12151d 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  padding-bottom: var(--safe-bottom);
}

a {
  color: inherit;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 max(16px, var(--safe-right)) 0 max(16px, var(--safe-left));
}

.header {
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: var(--safe-top);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
}

.header-text {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.3;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.back-link {
  display: inline-block;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.back-link:hover {
  text-decoration: underline;
}

.header-actions {
  flex-shrink: 0;
}

.user-menu {
  position: relative;
  flex-shrink: 0;
}

.avatar-btn {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

.avatar-btn:focus-visible {
  outline: 2px solid rgba(91, 141, 239, 0.6);
  outline-offset: 3px;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  background: linear-gradient(135deg, #5b8def 0%, #3a6fd8 100%);
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 14px rgba(91, 141, 239, 0.28);
  user-select: none;
}

.avatar-circle.sm {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(240px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 30;
}

.user-dropdown-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 10px;
}

.user-dropdown-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.user-dropdown-sub {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

.user-dropdown-item {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.92rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.user-dropdown-item:hover,
.user-dropdown-item:focus-visible {
  background: rgba(91, 141, 239, 0.12);
  outline: none;
}

.user-dropdown-item:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.user-dropdown-item.danger {
  color: var(--danger);
}

.user-menu.open .avatar-circle {
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.28);
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.stat-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.stat-value {
  display: block;
  margin-top: 6px;
  font-size: 1rem;
  font-weight: 600;
  word-break: break-word;
}

.channel-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 4px;
}

.channel-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}

.channel-chip:hover {
  border-color: rgba(91, 141, 239, 0.5);
}

.channel-chip.active {
  background: rgba(91, 141, 239, 0.18);
  border-color: var(--primary);
  color: #fff;
}

.channel-count {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.channel-chip.active .channel-count {
  color: #c9d8ff;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: stretch;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.item-top {
  margin-bottom: 6px;
}

.item-channel {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--primary);
  background: rgba(91, 141, 239, 0.12);
  border: 1px solid rgba(91, 141, 239, 0.25);
  border-radius: 999px;
  padding: 2px 8px;
}

.sync-status {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
}

.sync-status.success {
  border-color: rgba(62, 207, 142, 0.4);
  color: var(--success);
}

.sync-status.error {
  border-color: rgba(240, 113, 120, 0.4);
  color: var(--danger);
}

input[type="search"] {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px; /* 避免 iOS 自动放大 */
}

input[type="search"]:focus {
  outline: 2px solid rgba(91, 141, 239, 0.35);
  border-color: var(--primary);
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:hover {
  background: #2a3142;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.hidden {
  display: none !important;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: 0.15s ease;
  text-decoration: none;
  color: inherit;
  display: block;
  -webkit-tap-highlight-color: transparent;
}

.item-card:hover {
  border-color: rgba(91, 141, 239, 0.5);
  box-shadow: var(--shadow);
}

.item-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  line-height: 1.4;
  word-break: break-word;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 28px 0 40px;
  flex-wrap: wrap;
}

.pagination button {
  min-width: 72px;
}

.pagination .page-info {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* 详情页 */
.detail-page {
  padding-top: 20px;
  padding-bottom: 40px;
}

.detail-article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.detail-badges {
  margin-bottom: 10px;
}

.detail-title {
  margin: 0 0 12px;
  font-size: 1.35rem;
  line-height: 1.4;
  word-break: break-word;
}

.detail-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-body {
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.detail-body img,
.detail-body video {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
  margin: 12px 0;
}

.detail-body a {
  color: var(--primary);
  word-break: break-all;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 720px) {
  .container {
    padding: 0 12px;
  }

  h1 {
    font-size: 1.2rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  .header-inner {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
  }

  .header-text {
    flex: 1;
    min-width: 0;
  }

  .header-actions .btn {
    width: auto;
  }

  .stats-bar {
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 14px 0;
  }

  .stat-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
  }

  .stat-value {
    margin-top: 0;
    text-align: right;
    font-size: 0.95rem;
  }

  .toolbar {
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .btn {
    flex: 1;
  }

  .item-card {
    padding: 14px;
  }

  .item-card:hover {
    transform: none;
  }

  .item-title {
    font-size: 1rem;
  }

  .detail-article {
    padding: 16px;
    border-radius: 10px;
  }

  .detail-title {
    font-size: 1.15rem;
  }

  .detail-actions .btn {
    flex: 1;
    min-width: 120px;
  }

  .pagination {
    margin: 20px 0 32px;
  }
}

@media (min-width: 721px) {
  .channel-bar {
    flex-wrap: wrap;
    overflow: visible;
  }
}

/* 登录页 */
.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px max(16px, var(--safe-right)) 24px max(16px, var(--safe-left));
}

.login-wrap {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-card h1 {
  font-size: 1.4rem;
  text-align: center;
}

.login-desc {
  margin: 0 0 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.login-card input[type="password"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
}

.login-card input[type="password"]:focus {
  outline: 2px solid rgba(91, 141, 239, 0.35);
  border-color: var(--primary);
}

.turnstile-wrap {
  display: flex;
  justify-content: center;
  margin: 4px 0 2px;
  min-height: 65px;
}

.login-btn {
  width: 100%;
  margin-top: 8px;
}

.login-error {
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
}

.login-error.login-success {
  color: var(--success);
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
