:root {
  --bg-deep: #08080d;
  --bg: #0a0a0f;
  --panel: #12121a;
  --tile: #16161f;
  --tile-hi: #1c1c28;
  --border: #2a2a3a;
  --accent: #818cf8;
  --accent-2: #a78bfa;
  --glow: rgba(139, 92, 246, 0.55);
  --txt: #f0f0f5;
  --muted: #8888a0;
  --danger: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg-deep); color: var(--txt); font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: contain; }
body { display: grid; grid-template-rows: auto 1fr auto auto; min-height: 100vh; background: radial-gradient(circle at 30% -10%, rgba(139, 92, 246, 0.12), transparent 55%), var(--bg); }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 14px 10px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.logo { border-radius: 6px; filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.6)); }
.brand { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.brand-name { font-weight: 800; letter-spacing: 0.18em; font-size: 13px; color: var(--txt); }
.brand-sub { color: var(--muted); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; }
.icon-btn { width: 36px; height: 36px; background: var(--tile); border: 1px solid var(--border); border-radius: 8px; color: var(--accent); font-size: 18px; cursor: pointer; }
.icon-btn:active { background: var(--tile-hi); }

/* Screen + pages */
.screen { padding: 12px 12px 8px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page.hidden { display: none; }

.title { margin: 4px 0 4px; letter-spacing: 0.16em; font-size: 13px; color: var(--accent-2); font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.muted.small { font-size: 11px; }
.center { text-align: center; }

/* Search */
.search-row { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; margin-bottom: 12px; }
.search-icon { color: var(--accent); font-size: 16px; }
input[type="search"], input[type="text"], input[type="password"] { width: 100%; background: transparent; border: 0; color: var(--txt); padding: 8px 0; font-size: 15px; outline: none; }
input::placeholder { color: var(--muted); }
#api-key { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 12px; font-size: 14px; }
#api-key:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25); }

/* Grid (2 cols on phones, more on tablets) */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card { background: var(--tile); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease; position: relative; }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: 0; transition: opacity 0.15s; }
.card:hover { border-color: rgba(167,139,250,0.6); box-shadow: 0 0 0 1px rgba(139,92,246,0.35), 0 0 18px -4px var(--glow); }
.card:active { transform: scale(0.98); border-color: var(--accent); }
.card:active::before { opacity: 1; }
.card-thumb { width: 100%; aspect-ratio: 1 / 1; display: block; object-fit: contain; padding: 3% 4% 2%; transform: scale(1.14); background: radial-gradient(115% 78% at 50% 14%, rgba(186,190,214,0.18) 0%, rgba(120,124,156,0.06) 30%, rgba(120,124,156,0) 58%), radial-gradient(95% 120% at 50% 122%, rgba(139,92,246,0.16) 0%, rgba(139,92,246,0) 55%), linear-gradient(180deg, #20212c 0%, #16161f 58%, #0c0c12 100%); filter: drop-shadow(0 10px 14px rgba(0,0,0,0.45)); }
.card-body { padding: 8px 10px 10px; }
.card-name { font-size: 12px; font-weight: 600; margin: 0 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { color: var(--muted); font-size: 10px; letter-spacing: 0.04em; }

/* Page row (pagination) */
.page-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 14px 0 4px; }
.page-label { color: var(--muted); font-size: 12px; letter-spacing: 0.06em; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; background: var(--tile); border: 1px solid var(--border); border-radius: 8px; color: var(--txt); padding: 10px 14px; font-size: 14px; cursor: pointer; text-decoration: none; transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease; min-height: 42px; }
.btn.primary { background: linear-gradient(135deg, #6f72f5, #5850ec); color: #fff; border-color: rgba(167, 139, 250, 0.55); font-weight: 700; box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 0 0 1px rgba(139,92,246,0.4), 0 0 16px -3px var(--glow); }
.btn.primary:active { transform: scale(0.98); box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 0 0 1px rgba(167,139,250,0.85), 0 0 24px 0 var(--glow); }
.btn.ghost { background: transparent; }
.btn.ghost:active { background: var(--tile-hi); }
.btn:disabled { opacity: 0.4; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.row .btn { flex: 1; }

/* Settings */
.field-label { display: block; color: var(--muted); font-size: 11px; letter-spacing: 0.12em; margin: 14px 0 6px; }
.verify { background: var(--tile); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 12px 14px; margin-top: 14px; }
.verify.hidden { display: none; }
.verify-tier { color: var(--accent-2); letter-spacing: 0.14em; font-size: 11px; font-weight: 700; margin-bottom: 6px; }
.verify-quota { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.quota-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.quota-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.3s; }

/* Install help */
.install-help { margin-top: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.install-help.hidden { display: none; }
.install-help h3 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.14em; color: var(--accent-2); }
.install-help ol { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.install-help li { margin-bottom: 6px; }
.install-help strong { color: var(--txt); }

/* Viewer */
#page-viewer { display: flex; flex-direction: column; gap: 10px; }
.viewer-wrap { width: 100%; aspect-ratio: 1 / 1; background: var(--bg-deep); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: inset 0 0 30px rgba(139, 92, 246, 0.10); }
.viewer-poster { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.viewer-meta { background: var(--tile); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 12px 14px; }
.viewer-meta h2 { margin: 0 0 4px; font-size: 16px; }

/* Footer status */
#status { padding: 6px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; letter-spacing: 0.12em; background: var(--panel); text-align: center; }
#status.error { color: var(--danger); }
#status.ok { color: var(--accent-2); }

/* Tab bar */
.tabbar { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); }
.tab { background: transparent; border: 0; color: var(--muted); padding: 10px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; min-height: 56px; position: relative; }
.tab-glyph { font-size: 22px; line-height: 1; }
.tab-lbl { letter-spacing: 0.06em; }
.tab.active { color: var(--accent); }
.tab.active::before { content: ""; position: absolute; top: 0; left: 18%; right: 18%; height: 2px; background: var(--accent); border-radius: 0 0 2px 2px; box-shadow: 0 0 10px rgba(139, 92, 246, 0.7); }
.tab:active { background: var(--tile); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
