:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel-elev: #171e2c;
  --border: rgba(148, 163, 184, 0.14);
  --border-hi: rgba(56, 189, 248, 0.45);
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #22d3ee;
  --accent-2: #3b82f6;
  --green: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  background: radial-gradient(circle at 15% 0%, rgba(34, 211, 238, 0.07), transparent 40%), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

button,
a,
label,
select,
summary {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #041019;
  font-weight: 800;
  font-size: 19px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 6px 20px rgba(34, 211, 238, 0.24);
}

.brand-title {
  font-size: 18.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.topbar-utils {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid rgba(148, 163, 184, 0.14);
  flex-shrink: 0;
}

.btn-ghost {
  background: rgba(18, 23, 34, 0.85);
  color: #cbd5e1;
  border: 1px solid var(--border);
  border-radius: 9px;
  height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s, transform 0.15s ease-out;
}

@media (hover: hover) {
  .btn-ghost:hover {
    border-color: rgba(148, 163, 184, 0.32);
    background: var(--panel-elev);
    color: #fff;
  }
}

.btn-scan {
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  height: 36px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 4px 16px rgba(6, 182, 212, 0.24);
  transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s ease-out;
}

@media (hover: hover) {
  .btn-scan:hover:not(:disabled) {
    opacity: 0.95;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 6px 20px rgba(6, 182, 212, 0.34);
  }
}

.btn-scan:disabled {
  opacity: 0.58;
  cursor: wait;
}

/* Live Scan Status Banner (hidden automatically when idle/empty) */
.scan-log {
  margin-top: 12px;
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(34, 211, 238, 0.07);
  border: 1px solid rgba(34, 211, 238, 0.22);
  font-size: 12.5px;
  color: #bae6fd;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.scan-log:empty {
  display: none;
}

/* Unified Command Dock: Sources + Tracks + Search & Sort */
.command-dock {
  margin-top: 14px;
  background: linear-gradient(180deg, rgba(20, 26, 39, 0.92), rgba(15, 20, 31, 0.96));
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 16px;
  box-shadow: 0 14px 36px -14px rgba(2, 6, 23, 0.72), inset 0 1px 0 rgba(255, 255, 255, 0.045);
  overflow: hidden;
}

.dock-row {
  padding: 10px 14px;
}

.dock-row + .dock-row {
  border-top: 1px solid rgba(148, 163, 184, 0.09);
}

.dock-sources-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sources-scroll-rail {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.dock-label {
  font-size: 11.5px;
  font-weight: 600;
  color: #64748b;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-right: 2px;
  flex-shrink: 0;
}

.source-all-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(56, 189, 248, 0.14);
  color: #bae6fd;
  border: 1px solid rgba(56, 189, 248, 0.35);
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.15s ease-out;
}

.source-all-btn.is-all-on {
  background: rgba(255, 255, 255, 0.03);
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.14);
}

@media (hover: hover) {
  .source-all-btn:hover {
    border-color: rgba(56, 189, 248, 0.45);
    color: #e0f2fe;
    background: rgba(56, 189, 248, 0.16);
  }
}

.source-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 7px 0 9px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.11);
  color: #94a3b8;
  font-size: 12.5px;
  font-weight: 500;
  opacity: 0.6;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, transform 0.15s ease-out;
}

.source-toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.source-toggle:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.source-toggle.checked {
  opacity: 1;
  background: rgba(255, 255, 255, 0.055);
  border-color: rgba(148, 163, 184, 0.23);
  color: #eef2ff;
}

@media (hover: hover) {
  .source-toggle:hover {
    opacity: 1;
    border-color: rgba(148, 163, 184, 0.36);
    background: rgba(255, 255, 255, 0.08);
  }
}

.src-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.36);
  flex-shrink: 0;
  transition: background-color 0.15s, box-shadow 0.15s;
}

.source-toggle[data-src="x"].checked .src-dot {
  background: #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.7);
}

.source-toggle[data-src="huggingface"].checked .src-dot {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.65);
}

.source-toggle[data-src="github"].checked .src-dot {
  background: #a78bfa;
  box-shadow: 0 0 8px rgba(167, 139, 250, 0.65);
}

.source-toggle[data-src="reddit"].checked .src-dot {
  background: #fb923c;
  box-shadow: 0 0 8px rgba(251, 146, 60, 0.65);
}

.source-toggle[data-src="hackernews"].checked .src-dot {
  background: #f97316;
  box-shadow: 0 0 8px rgba(249, 115, 22, 0.7);
}

.source-toggle em {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(9, 13, 21, 0.65);
  padding: 1px 6px;
  border-radius: 999px;
  color: #64748b;
  transition: color 0.15s;
}

.source-toggle.checked em {
  color: #cbd5e1;
}

.result-counter {
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(9, 13, 21, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

/* Dock Row 2: Category Tracks + Live Counter */
.dock-tracks-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: rgba(9, 13, 21, 0.24);
}

.category-chips {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
  min-width: 0;
}

.chips-divider {
  width: 1px;
  height: 16px;
  background: rgba(148, 163, 184, 0.18);
  margin: 0 4px;
  flex-shrink: 0;
}

.chip {
  height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s ease-out;
}

@media (hover: hover) {
  .chip:hover:not(.active):not(.digest-chip) {
    background: rgba(255, 255, 255, 0.055);
    color: #e2e8f0;
  }
}

.chip.active {
  background: rgba(56, 189, 248, 0.14);
  color: #e0f2fe;
  border-color: rgba(56, 189, 248, 0.35);
  font-weight: 600;
}

.chip.digest-chip {
  border-radius: 8px;
  padding: 0 11px;
  border-color: rgba(245, 158, 11, 0.28);
  color: #fde68a;
  background: rgba(245, 158, 11, 0.08);
  font-weight: 600;
}

@media (hover: hover) {
  .chip.digest-chip:hover:not(.active) {
    border-color: rgba(251, 191, 36, 0.55);
    background: rgba(245, 158, 11, 0.15);
  }
}

.chip.digest-chip.active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.28), rgba(234, 88, 12, 0.18));
  color: #fef3c7;
  border-color: rgba(251, 191, 36, 0.62);
  box-shadow: 0 2px 14px rgba(245, 158, 11, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.digest-rank-pill {
  font-size: 11.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.24), rgba(234, 88, 12, 0.18));
  color: #fde68a;
  border: 1px solid rgba(251, 191, 36, 0.45);
}

/* Compact Topbar Search + Dock Dropdown Controls */
.search-field {
  position: relative;
  width: 215px;
  display: flex;
  align-items: center;
  transition: width 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.search-field:focus-within {
  width: 265px;
}

.search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: #64748b;
  pointer-events: none;
  transition: color 0.15s;
}

.search-field:focus-within .search-icon {
  color: var(--accent);
}

select,
input[type="search"],
input[type="password"],
input[type="text"] {
  background: rgba(11, 15, 25, 0.88);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 9px;
  padding: 7px 11px;
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}

#search-input {
  width: 100%;
  height: 34px;
  padding: 0 10px 0 32px;
}

#search-input::placeholder {
  color: #64748b;
}

select:focus,
input:focus {
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
  background: #090d16;
}

.select-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  margin-left: auto;
}

#time-select,
#sort-select {
  appearance: none;
  -webkit-appearance: none;
  height: 30px;
  padding: 0 28px 0 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: #cbd5e1;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5.5 7.5L10 12L14.5 7.5' stroke='%2394a3b8' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

@media (hover: hover) {
  #time-select:hover,
  #sort-select:hover,
  #search-input:hover {
    border-color: rgba(148, 163, 184, 0.32);
    background-color: rgba(15, 22, 36, 0.92);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .btn-scan:not(:disabled):active,
  .btn-translate-page:not(:disabled):active,
  .btn-ghost:not(:disabled):active,
  .source-all-btn:active,
  .source-toggle:active,
  .chip:active {
    transform: scale(0.96);
  }
}

/* Cards Grid */
.cards-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(410px, 1fr));
  gap: 16px;
}

.radar-card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  transition: border-color 0.15s, transform 0.15s;
}

.radar-card:hover {
  border-color: rgba(56, 189, 248, 0.35);
}

.radar-card.is-fresh {
  border-color: rgba(16, 185, 129, 0.36);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.08);
}

.radar-card.is-read {
  opacity: 0.62;
}

.radar-card.is-read:hover {
  opacity: 0.92;
}

.radar-card.is-read .card-title {
  color: #cbd5e1;
}

.radar-card.is-sinking {
  opacity: 0;
  transform: scale(0.96) translateY(8px);
  pointer-events: none;
  transition: opacity 0.17s ease, transform 0.17s ease;
}

@keyframes cardShelfIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.radar-card.just-shelved {
  animation: cardShelfIn 0.24s ease-out;
}

.fresh-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.42);
}

.read-btn {
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.28);
  color: #e2e8f0;
  border-radius: 7px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.read-btn:hover:not(:disabled) {
  border-color: rgba(16, 185, 129, 0.55);
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
}

.read-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.read-btn.is-read {
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.08);
  border-color: rgba(148, 163, 184, 0.22);
  font-weight: 500;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.score-badge {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(34, 211, 238, 0.14);
  color: var(--accent);
  border: 1px solid rgba(34, 211, 238, 0.32);
}

.score-badge.high {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

.rising-badge {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(249, 115, 22, 0.15);
  color: #fb923c;
  border: 1px solid rgba(249, 115, 22, 0.38);
}

.play-badge {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
}

.play-READY_NOW {
  background: rgba(16, 185, 129, 0.13);
  color: #6ee7b7;
}

.play-DEMO_PAPER {
  background: rgba(245, 158, 11, 0.14);
  color: #fcd34d;
}

.play-WAITLIST_HYPE,
.play-PENDING {
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

.cat-tag,
.src-tag {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
  color: #cbd5e1;
}

.src-tag {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.11);
}

.card-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.card-tr-btn {
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: #a5f3fc;
  border-radius: 7px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.card-tr-btn:hover:not(:disabled) {
  background: rgba(34, 211, 238, 0.2);
  color: #fff;
}

.card-tr-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.card-raw-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.card-raw-btn:hover {
  border-color: rgba(59, 130, 246, 0.5);
  color: #bfdbfe;
}

.card-raw-btn.active {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.45);
  color: #bfdbfe;
}

.status-pill b {
  font-weight: 500;
}

.star-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  padding: 3px 8px;
  font-size: 13px;
  cursor: pointer;
}

.star-btn.starred {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.1);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.42;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.highlights-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.highlights-list li {
  font-size: 13px;
  color: #cbd5e1;
  padding-left: 14px;
  position: relative;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.highlights-list li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.media-box {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #06080d;
  border: 1px solid var(--border);
}

.media-box video {
  width: 100%;
  max-height: 215px;
  object-fit: contain;
  background: #06080d;
  display: block;
}

.media-box img {
  width: 100%;
  max-height: 205px;
  object-fit: cover;
  display: block;
}

.video-pill {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  pointer-events: none;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(9, 13, 22, 0.78);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
}

.raw-details {
  font-size: 12px;
  color: var(--muted);
}

.raw-details summary {
  cursor: pointer;
  user-select: none;
  color: #94a3b8;
}

.raw-details pre {
  margin-top: 7px;
  white-space: pre-wrap;
  word-break: break-word;
  background: #0b0f17;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
  color: #cbd5e1;
  max-height: 190px;
  overflow-y: auto;
}

.metrics-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bm-highlight {
  color: #fde68a;
  font-weight: 600;
}

.views-viral {
  color: #fb923c;
  font-weight: 700;
  background: rgba(251, 146, 60, 0.14);
  border: 1px solid rgba(251, 146, 60, 0.35);
  padding: 1px 6px;
  border-radius: 5px;
}

.views-stat {
  color: #93c5fd;
  font-weight: 500;
}

.links-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.link-btn {
  text-decoration: none;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 7px;
  background: var(--panel-elev);
  color: #e2e8f0;
  border: 1px solid var(--border);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.link-btn:hover {
  border-color: var(--accent);
  color: #fff;
}

.link-btn.primary-deliverable {
  background: rgba(34, 211, 238, 0.1);
  border-color: rgba(34, 211, 238, 0.35);
  color: #a5f3fc;
  font-weight: 600;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 14px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 15, 0.76);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(500px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

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

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
}

.modal-tip {
  font-size: 12px;
  color: var(--muted);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 12.5px;
  color: #cbd5e1;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

/* Pagination Bar */
.pagination-bar {
  margin-top: 22px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-bar.hidden {
  display: none;
}

.page-info {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.page-info strong {
  color: var(--text);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 34px;
  height: 32px;
  padding: 0 10px;
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: all 0.15s;
}

.page-btn:hover:not(:disabled):not(.active) {
  border-color: rgba(59, 130, 246, 0.5);
  color: #bfdbfe;
}

.page-btn.active {
  background: rgba(59, 130, 246, 0.22);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.65);
  font-weight: 600;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-dots {
  color: var(--muted);
  font-size: 12.5px;
  padding: 0 4px;
}

/* Manual Translate Button & Language Switch */
.btn-translate-page {
  background: rgba(34, 211, 238, 0.12);
  color: #a5f3fc;
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 9px;
  height: 36px;
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.15s ease-out;
}

.btn-translate-page.hidden {
  display: none;
}

@media (hover: hover) {
  .btn-translate-page:hover:not(:disabled) {
    background: rgba(34, 211, 238, 0.22);
    border-color: rgba(34, 211, 238, 0.55);
    color: #fff;
  }
}

.btn-translate-page:disabled {
  opacity: 0.52;
  cursor: wait;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  background: rgba(18, 23, 34, 0.85);
  border: 1px solid var(--border);
  border-radius: 9px;
  height: 34px;
  padding: 2px;
  gap: 2px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.lang-btn.active {
  background: rgba(56, 189, 248, 0.16);
  color: #e0f2fe;
  font-weight: 600;
}

/* Floating Back-to-Top Pill */
.back-top-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  background: rgba(18, 23, 34, 0.88);
  color: #e2e8f0;
  border: 1px solid rgba(56, 189, 248, 0.42);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 38px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: opacity 0.18s, transform 0.15s;
}

.back-top-fab.hidden {
  display: none;
}

/* Touch feedback on iOS / touch devices */
@media (hover: none) {
  .btn-scan:active:not(:disabled),
  .btn-translate-page:active:not(:disabled),
  .btn-ghost:active,
  .tab:active,
  .chip:active,
  .source-toggle:active,
  .mini-check:active,
  .link-btn:active,
  .card-tr-btn:active,
  .card-raw-btn:active,
  .read-btn:active,
  .star-btn:active,
  .back-top-fab:active,
  .page-btn:active:not(:disabled) {
    transform: scale(0.97);
    opacity: 0.9;
  }
}

/* iPhone & Mobile Adaptation (iOS Safari + Home Screen Standalone PWA) */
@media (max-width: 768px) {
  .app-shell {
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 34px);
    padding-left: max(12px, env(safe-area-inset-left, 0px));
  }

  /* Compact 2-row mobile header: Line 1 = Brand + Lang/Auth, Line 2 = Full-width Scan CTA */
  .topbar {
    flex-wrap: wrap;
    gap: 10px 8px;
    padding-bottom: 12px;
  }

  .brand-wrap {
    gap: 10px;
    min-width: 0;
    flex: 1;
    margin-right: 0;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    font-size: 16px;
    flex-shrink: 0;
  }

  .brand-title {
    font-size: 15.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-sub {
    display: none;
  }

  .topbar-utils {
    gap: 6px;
    flex-shrink: 0;
  }

  .lang-switch {
    height: 34px;
  }

  .lang-btn {
    padding: 0 9px;
    height: 28px;
    font-size: 12px;
  }

  #btn-auth-account {
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
    height: 34px;
  }

  .topbar-primary {
    flex: 1 1 100%;
    padding-left: 0;
    border-left: none;
    gap: 8px;
    flex-wrap: wrap;
  }

  .search-field,
  .search-field:focus-within {
    flex: 1 1 160px;
    width: auto;
    min-width: 0;
  }

  #search-input {
    height: 40px;
    padding: 0 10px 0 34px;
  }

  #btn-scan {
    flex: 0 0 auto;
    height: 40px;
    min-height: 40px;
    font-size: 13.5px;
    padding: 0 14px;
  }

  #btn-translate-page {
    flex: 1 1 100%;
    min-height: 38px;
    padding: 0 12px;
    font-size: 12.5px;
  }

  /* Prevent iOS Safari forced page zoom on form input/select focus (<16px triggers zoom) */
  select,
  input[type="search"],
  input[type="password"],
  input[type="text"] {
    font-size: 16px;
  }

  .scan-log {
    margin-top: 10px;
    font-size: 12px;
    padding: 8px 12px;
    overflow-wrap: anywhere;
  }

  /* Unified 2-Row Command Dock on Mobile */
  .command-dock {
    margin-top: 12px;
    border-radius: 14px;
  }

  .dock-row {
    padding: 9px 12px;
  }

  .dock-sources-row {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 8px;
  }

  .sources-scroll-rail {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 7px;
    width: calc(100% + 24px);
    margin: 0 -12px;
    padding: 2px 26px 2px 12px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
  }

  .sources-scroll-rail::-webkit-scrollbar {
    display: none;
  }

  .sources-scroll-rail .dock-label {
    display: none;
  }

  .sources-scroll-rail > * {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .source-all-btn,
  .source-toggle {
    height: 34px;
    font-size: 12.5px;
  }

  .select-group {
    width: 100%;
    margin-left: 0;
    display: flex;
    gap: 8px;
  }

  #time-select {
    flex: 1 1 44%;
    min-width: 0;
    height: 38px;
    padding: 0 28px 0 10px;
  }

  #sort-select {
    flex: 1.35 1 56%;
    min-width: 0;
    height: 38px;
    padding: 0 28px 0 10px;
    text-overflow: ellipsis;
  }

  .dock-tracks-row {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 6px;
    padding: 8px 12px;
  }

  .category-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    width: calc(100% + 24px);
    margin: 0 -12px;
    padding: 2px 26px 2px 12px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
  }

  .category-chips::-webkit-scrollbar {
    display: none;
  }

  .category-chips .chip {
    flex: 0 0 auto;
    white-space: nowrap;
    height: 34px;
    padding: 0 11px;
  }

  .result-counter {
    display: block;
    width: 100%;
    margin-left: 0;
    text-align: right;
    font-size: 11.5px;
    padding: 0;
    background: transparent;
    border: none;
    color: #94a3b8;
  }

  /* Single-column cards optimized for iPhone thumb scrolling */
  .cards-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-top: 10px;
  }

  .radar-card {
    padding: 14px;
    border-radius: 13px;
    gap: 10px;
  }

  .card-top {
    gap: 6px;
  }

  .card-tr-btn,
  .card-raw-btn,
  .read-btn,
  .star-btn {
    min-height: 34px;
    min-width: 34px;
    padding: 5px 10px;
    font-size: 12.5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .card-title {
    font-size: 15.5px;
    line-height: 1.44;
  }

  .media-box video {
    max-height: 240px;
  }

  .media-box img {
    max-height: 220px;
  }

  .metrics-row {
    gap: 6px 10px;
    font-size: 11.5px;
  }

  .raw-details summary {
    padding: 5px 0;
    min-height: 32px;
    display: flex;
    align-items: center;
  }

  .links-footer {
    gap: 7px;
  }

  .link-btn {
    min-height: 36px;
    padding: 6px 11px;
    font-size: 12.5px;
    display: inline-flex;
    align-items: center;
  }

  /* Touch-friendly centered pagination */
  .pagination-bar {
    margin-top: 16px;
    padding: 12px;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
  }

  .page-controls {
    justify-content: center;
    width: 100%;
  }

  .page-btn {
    min-width: 38px;
    height: 38px;
    font-size: 13px;
  }

  /* Keyboard-safe login modal on iOS */
  .modal-backdrop {
    align-items: flex-start;
    padding: calc(env(safe-area-inset-top, 0px) + 8vh) 14px calc(24px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .modal-card {
    width: 100%;
    max-width: 420px;
    padding: 18px;
    border-radius: 15px;
  }

  .modal-close {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
  }

  .modal-card input {
    min-height: 44px;
  }

  .modal-actions button {
    flex: 1;
    min-height: 44px;
    font-size: 15px;
  }
}

/* Extra-narrow iPhone SE / mini guard */
@media (max-width: 380px) {
  .brand-title {
    font-size: 14.5px;
  }

  #time-select,
  #sort-select {
    font-size: 15px;
    padding: 0 24px 0 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
