:root {
  --bg: #ffffff;
  --text: #1f1f1f;
  --sub: #4d5156;
  --muted: #70757a;
  --chip: #f1f3f4;
  --chip-border: #dadce0;
  --border: #ecedef;
  --search-bg: #ffffff;
  --search-shadow: 0 1px 6px rgba(32, 33, 36, .28);
  --thumb: #f1f3f4;
  --visit: #0b57d0;
  --visit-text: #ffffff;
  --viewer-img: #f8f9fa;
  --signin: #0b57d0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1f1f;
    --text: #e3e3e3;
    --sub: #bfbfbf;
    --muted: #9aa0a6;
    --chip: #303134;
    --chip-border: #3c4043;
    --border: #303134;
    --search-bg: #303134;
    --search-shadow: none;
    --thumb: #303134;
    --visit: #a8c7fa;
    --visit-text: #062e6f;
    --viewer-img: #131314;
    --signin: #a8c7fa;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1f1f;
  --text: #e3e3e3;
  --sub: #bfbfbf;
  --muted: #9aa0a6;
  --chip: #303134;
  --chip-border: #3c4043;
  --border: #303134;
  --search-bg: #303134;
  --search-shadow: none;
  --thumb: #303134;
  --visit: #a8c7fa;
  --visit-text: #062e6f;
  --viewer-img: #131314;
  --signin: #a8c7fa;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Google Sans", Roboto, Arial, -apple-system, system-ui, sans-serif;
  font-size: 14px;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.ico { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--sub); }
.ico svg { width: 24px; height: 24px; fill: currentColor; }

/* Header */
header { padding-top: env(safe-area-inset-top); }
.bar { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 8px; }
.logo { font-family: "Product Sans", "Google Sans", Arial, sans-serif; font-size: 26px; font-weight: 500; letter-spacing: -1px; direction: ltr; user-select: none; }
.logo .b { color: #4285f4; } .logo .r { color: #ea4335; } .logo .y { color: #fbbc05; } .logo .g { color: #34a853; }
.signin { background: var(--signin); color: var(--visit-text); border-radius: 20px; padding: 8px 16px; font-weight: 500; font-size: 14px; margin-inline-end: 4px; }

.search { display: flex; align-items: center; margin: 4px 16px 0; height: 48px; padding: 0 4px 0 14px; border-radius: 24px; background: var(--search-bg); box-shadow: var(--search-shadow); }
[dir="rtl"] .search { padding: 0 14px 0 4px; }
.search .sicon svg { width: 20px; height: 20px; fill: var(--muted); display: block; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; padding: 0 12px; }
.search .sep { width: 1px; height: 24px; background: var(--chip-border); margin: 0 2px; }
.search .ico { width: 36px; height: 36px; }
.search .ico svg { width: 22px; height: 22px; }

.tabs { display: flex; gap: 22px; overflow-x: auto; scrollbar-width: none; padding: 0 16px; margin-top: 10px; border-bottom: 1px solid var(--border); }
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tabs span { flex: none; padding: 12px 0 10px; color: var(--sub); font-size: 14px; border-bottom: 3px solid transparent; }
.tabs span.on { color: var(--text); font-weight: 500; border-bottom-color: var(--text); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 12px 16px; }
.chips span { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--chip-border); color: var(--text); font-size: 14px; }
.chips span img { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; margin-inline-start: -6px; background: var(--thumb); }

/* Grid */
#grid { display: flex; gap: 8px; padding: 0 12px; align-items: flex-start; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.item { display: block; text-align: start; width: 100%; }
.thumb { width: 100%; border-radius: 12px; overflow: hidden; background: var(--thumb); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cap { padding: 6px 2px 0; height: 46px; overflow: hidden; }
.src { display: flex; align-items: center; gap: 6px; color: var(--sub); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav { flex: none; width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 9px; font-weight: 700; }
.ttl { color: var(--text); font-size: 13px; line-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
#end { height: 48px; }

/* Viewer */
#viewer { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
#viewer[hidden] { display: none; }
.vbar { display: flex; align-items: center; height: 56px; padding: 0 4px; }
.grow { flex: 1; }
.vimg { background: var(--viewer-img); display: flex; align-items: center; justify-content: center; height: 58vh; }
.vimg img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.vinfo { padding: 16px; }
.vinfo .src { font-size: 14px; }
.vinfo .fav { width: 20px; height: 20px; font-size: 11px; }
.vtitle { font-size: 18px; line-height: 24px; margin: 8px 0 16px; color: var(--text); }
.visit { background: var(--visit); color: var(--visit-text); border-radius: 20px; padding: 10px 22px; font-weight: 500; }
