/* Offline Digest — mobile-first dark reading UI */

:root {
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #1f2228;
  --border: #2a2e36;
  --text: #ecebe7;
  --text-2: #a9adb6;
  --text-3: #767b86;
  --accent: #f2b45a;
  --accent-ink: #1a1408;
  --danger: #ff6b6b;
  --ok: #6fd08c;
  --mark: rgba(242, 180, 90, 0.28);

  --cat-ai: #8fb8ff;
  --cat-history: #f0a37a;
  --cat-tech: #7fd6b4;
  --cat-world: #ff8f9e;

  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --gutter: 16px;

  --ui-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --read-font: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--ui-font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Library header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--sat) + 10px) calc(var(--gutter) + var(--sar)) 0 calc(var(--gutter) + var(--sal));
  background: rgba(14, 15, 18, 0.86);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.brand {
  margin: 0;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.net {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.icon-btn {
  margin-left: auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--accent);
}
.icon-btn:active { transform: scale(0.95); }

.search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 8px 0 10px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--text-3);
}
.search:focus-within { border-color: var(--border); }
.search svg { position: absolute; left: 12px; pointer-events: none; }

.search input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 40px 0 38px;
  border: 0;
  background: transparent;
  font-size: 16px; /* >= 16px prevents iOS zoom-on-focus */
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }

.clear-btn {
  position: absolute;
  right: 6px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin: 0 calc(-1 * var(--gutter));
  padding-left: var(--gutter);
  padding-right: var(--gutter);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.tab .count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.tab[aria-selected="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.tab[aria-selected="true"] .count { color: #55585f; }

/* ---------- Article list ---------- */

.list-main {
  padding: 4px calc(var(--gutter) + var(--sar)) calc(var(--sab) + 32px) calc(var(--gutter) + var(--sal));
  max-width: 720px;
  margin: 0 auto;
}

.result-info {
  margin: 10px 2px 8px;
  font-size: 13px;
  color: var(--text-3);
  min-height: 1em;
}

.article-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.card {
  display: block;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.12s ease;
}
.card:active { transform: scale(0.985); background: var(--surface-2); }

.card-meta,
.card-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 12.5px;
  color: var(--text-3);
}

.chip {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--cat, var(--text-2));
}
.chip[data-cat="ai"] { --cat: var(--cat-ai); }
.chip[data-cat="history"] { --cat: var(--cat-history); }
.chip[data-cat="tech"] { --cat: var(--cat-tech); }
.chip[data-cat="world"] { --cat: var(--cat-world); }

.card-title {
  margin: 8px 0 6px;
  font-family: var(--read-font);
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.005em;
}

.card-excerpt {
  margin: 0 0 12px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
}

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
}
.empty strong { display: block; color: var(--text-2); font-size: 17px; margin-bottom: 6px; }

/* ---------- Reader ---------- */

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--sat) + 6px) calc(10px + var(--sar)) 6px calc(6px + var(--sal));
  background: rgba(14, 15, 18, 0.86);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--border);
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 17px;
  font-weight: 500;
}

.font-ctl {
  display: flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.font-ctl button {
  min-width: 52px;
  height: 36px;
  border: 0;
  background: none;
  font-family: var(--read-font);
  font-weight: 700;
  font-size: 17px;
}
.font-ctl button + button { border-left: 1px solid var(--border); font-size: 21px; }
.font-ctl button:disabled { opacity: 0.35; }
.font-ctl .minus, .font-ctl .plus { font-family: var(--ui-font); font-size: 0.75em; margin-left: 1px; }

.progress {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.08s linear;
}

.reader {
  --reader-size: 18px;
  max-width: 680px;
  margin: 0 auto;
  padding: 28px calc(22px + var(--sar)) calc(var(--sab) + 72px) calc(22px + var(--sal));
  font-family: var(--read-font);
  font-size: var(--reader-size);
  line-height: 1.68;
  overflow-wrap: break-word;
}

.reader .chip { font-family: var(--ui-font); }

.reader h1 {
  margin: 10px 0 12px;
  font-size: 1.65em;
  line-height: 1.18;
  letter-spacing: -0.01em;
}

.reader-meta {
  font-family: var(--ui-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-3);
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.reader-meta .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.reader-body p { margin: 0 0 1.1em; }
.reader-body ul, .reader-body ol { margin: 0 0 1.1em; padding-left: 1.3em; }
.reader-body li { margin-bottom: 0.45em; }
.reader-body li::marker { color: var(--accent); }
.reader-body strong { color: #fff; }
.reader-body h2 {
  margin: 1.6em 0 0.5em;
  font-size: 1.2em;
  line-height: 1.3;
}

.reader-foot {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-family: var(--ui-font);
  font-size: 14px;
  color: var(--text-3);
}
.reader-foot a { color: var(--accent); }

/* ---------- Import sheet ---------- */

.sheet {
  width: min(100% - 24px, 520px);
  max-height: calc(100dvh - var(--sat) - 24px);
  margin: auto auto calc(12px + var(--sab));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet[open] { animation: sheet-in 0.22s ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }

@media (min-width: 640px) {
  .sheet { margin: auto; }
}

.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 18px; }

.sheet-sec { padding: 16px 20px 4px; }
.sheet-sec h3 { margin: 0 0 4px; font-size: 15px; }
.hint { margin: 0 0 12px; font-size: 13.5px; color: var(--text-3); }

.row { display: flex; gap: 8px; margin-bottom: 10px; }

.sheet input[type="url"],
.sheet textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
  outline: none;
}
.sheet textarea { resize: vertical; margin-bottom: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.sheet input:focus, .sheet textarea:focus { border-color: var(--accent); }

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  margin-bottom: 10px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }
.row .btn { margin-bottom: 0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); width: 100%; }
.btn-ghost { background: transparent; color: var(--accent); border-color: transparent; padding: 0 4px; }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255, 107, 107, 0.35); }
.btn-primary:focus-within { outline: 2px solid var(--text); outline-offset: 2px; }

.status {
  margin: 0;
  padding: 4px 20px calc(18px + var(--sab));
  font-size: 14px;
  color: var(--text-2);
  min-height: 1em;
}
.status.ok { color: var(--ok); }
.status.error { color: var(--danger); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--sab));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14.5px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
.toast-action {
  border: 0;
  background: none;
  color: #9a5d00;
  font-weight: 700;
  padding: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
