:root {
  --bg: #0f1115;
  --panel: #181b22;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #9aa3b2;
  --accent: #ff6a3d;
  --edge-w: 72px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Stop sideways overscroll turning into browser back/forward. */
  overscroll-behavior: none;
}
body { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* Horizontal feed: one slide per screen, native snap scrolling. */
.track {
  position: fixed; inset: 0;
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scroll-behavior: smooth;
  overscroll-behavior-x: contain; scrollbar-width: none;
}
.track::-webkit-scrollbar { display: none; }
.slide {
  position: relative; flex: 0 0 100%; height: 100%;
  scroll-snap-align: center; scroll-snap-stop: always;
  background: #fff;
}
.slide iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; }
/* Shown behind the iframe: visible while loading or if the site refuses to render. */
.fallback {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 12px;
  text-align: center; padding: 24px; background: #fff; color: #6b7280;
}
.fallback b { color: #111827; font-size: 18px; }
.fallback a { color: var(--accent); }

/* Loading screen: thin progress line, site name, shimmering page skeleton. */
.loader { place-content: center stretch; justify-items: center; }
.ld-card { width: min(520px, 100%); display: grid; gap: 14px; text-align: left; }
.ld-site { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; color: #6b7280; }
.ld-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: #111827; color: #fff; font-size: 14px; font-weight: 700;
}
.ld-title { font-size: 22px; line-height: 1.25; letter-spacing: -0.01em; }
.sk { display: grid; gap: 10px; margin-top: 6px; }
.sk i { display: block; height: 12px; border-radius: 6px; background: #f1f2f4; }
.sk .sk-img { height: 160px; border-radius: 14px; margin-bottom: 6px; }
.sk .sk-short { width: 60%; }
.ld-slow { font-size: 13px; opacity: 0; }
.progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; overflow: hidden; }

.loading .sk i {
  background: linear-gradient(90deg, #f1f2f4 0%, #e4e6ea 40%, #f1f2f4 80%) 0 0 / 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.loading .progress::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: indeterminate 1.2s cubic-bezier(.65,0,.35,1) infinite;
}
.loading .ld-slow { animation: fade-in .4s ease 5s forwards; }
.loading .ld-card { animation: rise .35s ease-out both; }
/* Loaded but still visible = the site didn't render; drop the skeleton, keep the escape hatch. */
.loader:not(.loading) .sk { display: none; }
.loader:not(.loading) .ld-slow { opacity: 1; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes indeterminate { from { left: -40%; } to { left: 100%; } }
@keyframes fade-in { to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  .loading .sk i, .loading .progress::before, .loading .ld-card { animation: none; }
  .loading .ld-slow { animation: none; opacity: 1; }
}

/* Full-height prev/next strips on the screen edges. */
.edge {
  position: fixed; top: 0; bottom: 0; z-index: 10; width: var(--edge-w);
  display: grid; align-items: center; padding: 0 6px;
  user-select: none; -webkit-user-select: none; overflow: hidden;
}
/* Dark at the screen edge, fading into the page. ::before carries a darker copy for hover. */
.edge-prev { left: 0; background: linear-gradient(to right, rgba(0,0,0,0.26), rgba(0,0,0,0.12) 35%, rgba(0,0,0,0.035) 70%, transparent); }
.edge-next { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.26), rgba(0,0,0,0.12) 35%, rgba(0,0,0,0.035) 70%, transparent); }
.edge::before { content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity .2s; }
.edge-prev::before { background: linear-gradient(to right, rgba(0,0,0,0.42), rgba(0,0,0,0.2) 35%, rgba(0,0,0,0.06) 70%, transparent); }
.edge-next::before { background: linear-gradient(to left, rgba(0,0,0,0.42), rgba(0,0,0,0.2) 35%, rgba(0,0,0,0.06) 70%, transparent); }
.edge:focus-visible::before { opacity: 1; }
@media (hover: hover) { .edge:hover::before { opacity: 1; } .edge:hover svg { background: rgba(17,17,17,.8); transform: scale(1.08); } }
.edge:focus-visible { outline: none; }
.edge:disabled { display: none; }
.edge-prev { justify-items: start; }
.edge-next { justify-items: end; }
/* Arrow sits in a frosted dark circle so it reads on any page, light or dark. */
.edge svg {
  position: relative; box-sizing: content-box; width: 22px; height: 22px; padding: 11px;
  border-radius: 50%; fill: none; stroke: #fff; stroke-width: 2.6;
  stroke-linecap: round; stroke-linejoin: round;
  background: rgba(17,17,17,.62); border: 1px solid rgba(255,255,255,.16);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
  transition: transform .15s ease, background .15s ease;
}
.edge:focus-visible svg { background: rgba(17,17,17,.8); transform: scale(1.08); }
.edge:active svg { transform: scale(.94); }
/* Mouse devices: keep the right strip off the site's scrollbar so it can still be dragged. */
@media (hover: hover) and (pointer: fine) { .edge-next { right: 16px; } }
@media (max-width: 600px) {
  :root { --edge-w: 44px; }
  .edge svg { width: 18px; height: 18px; padding: 8px; stroke-width: 2.8; }
}

/* Floating menu button, bottom-right over the next strip. */
.fab {
  position: fixed; right: max(6px, calc((var(--edge-w) - 40px) / 2)); bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 15; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 16px; letter-spacing: 1px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.fab:hover, .fab:focus-visible { background: rgba(0,0,0,.8); }
.menu-head { padding: 8px 12px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); min-width: 0; }
.domain { font-weight: 600; font-size: 14px; display: flex; gap: 6px; }
.saved-dot { color: var(--accent); }
.title, .why { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title { color: var(--muted); font-size: 13px; }
.why { color: var(--accent); font-size: 11px; opacity: 0.85; }

/* Menu */
.menu {
  position: fixed; right: 8px; bottom: calc(60px + env(safe-area-inset-bottom));
  width: 280px; max-width: calc(100% - 16px); max-height: calc(100% - 80px); overflow-y: auto; padding: 6px; border-radius: 14px; z-index: 20;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
}
.menu[hidden] { display: none; }
.menu > button { text-align: left; padding: 10px 12px; border-radius: 8px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.menu > button:hover { background: var(--line); }
.menu .muted { color: var(--muted); font-size: 13px; }

/* Sheets (saves, topics) */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: grid; place-items: end center; }
.sheet[hidden] { display: none; }
.sheet-card {
  width: min(560px, 100%); max-height: 80vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-card header { display: flex; justify-content: space-between; align-items: center; }
.sheet-card h2 { margin: 0; font-size: 18px; }
.sheet-card ul { list-style: none; padding: 0; margin: 12px 0 0; }
.sheet-card li { display: flex; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.sheet-card li a { flex: 1; min-width: 0; color: var(--text); text-decoration: none; }
.sheet-card li small { display: block; color: var(--muted); }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); }
.empty { color: var(--muted); margin-top: 12px; }

/* Intro */
.intro { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(15,17,21,.92); }
.intro[hidden] { display: none; }
.intro-card { max-width: 380px; text-align: center; }
.intro h1 { margin: 0 0 8px; font-size: 40px; color: var(--accent); }
.intro .hint { color: var(--muted); }
.primary { margin-top: 12px; padding: 12px 22px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(64px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  padding: 8px 14px; border-radius: 999px; background: var(--text); color: var(--bg);
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.noscript { padding: 24px; text-align: center; }
.intro .keys { display: inline-block; margin-top: 8px; font-size: 12px; opacity: .8; }
@media (hover: none) { .intro .keys { display: none; } }

/* Menu: add a blog */
.add-blog { display: grid; gap: 6px; padding: 10px 12px 8px; margin: 4px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.add-blog label { font-size: 12px; color: var(--muted); }
.add-row { display: flex; gap: 6px; }
.add-row input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 14px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); outline: none;
}
.add-row input:focus { border-color: var(--accent); }
.add-row button { padding: 8px 12px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; }
.add-row button:disabled { opacity: .6; cursor: progress; }
.add-status { font-size: 12px; color: var(--muted); min-height: 0; }
.add-status:empty { display: none; }
.add-status.err { color: #ff8a8a; }

/* All links sheet */
.all-search {
  width: 100%; margin-top: 12px; padding: 10px 12px; border-radius: 10px; font: inherit;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); outline: none;
}
.all-search:focus { border-color: var(--accent); }
.all-count { color: var(--muted); font-size: 12px; margin-top: 8px; }
.sheet-card h3 { margin: 16px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: none; }
.sheet-card li button.jump { flex: 1; min-width: 0; text-align: left; color: var(--text); }
.sheet-card li button.jump small { display: block; color: var(--muted); }
.sheet-card li button.jump:hover b { color: var(--accent); }
.sheet-card li button.jump b { font-weight: 500; }
