:root {
  color-scheme: dark;
  --bar: rgba(11, 12, 16, .88);
  --ph-a: #22242e;
  --ph-b: #15161c;
  --track: #3a3c48;
  --warn-text: #ffb020;
  --ok-text: #34c77b;
  --banner-bg: #3a2a0c;
  --login-glow: #2a0f15;
  --s1-text: #ff6b80;
  --s2-text: #6cc0ff;
  --s2e-text: #e6e7ff;
  --glow: .35;
  --bg: #0b0c10;
  --surface: #15161c;
  --surface-2: #1e2028;
  --line: #2a2c36;
  --text: #f3f3f6;
  --dim: #9799a8;
  --faint: #5d5f6d;
  --accent: #ff4655;
  --ok: #34c77b;
  --warn: #ffb020;
  --s1: #e60023;
  --s2: #1f9bff;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  --tabbar: calc(58px + var(--safe-b));
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* Light theme (set on <html data-theme> by the app) */
:root[data-theme=light] {
  color-scheme: light;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #e8e8ef;
  --line: #d9d9e1;
  --text: #121318;
  --dim: #686a78;
  --faint: #a2a4b0;
  --bar: rgba(242, 242, 247, .88);
  --ph-a: #e2e3ea;
  --ph-b: #f3f3f7;
  --track: #dcdce4;
  --warn-text: #a86200;
  --ok-text: #16884b;
  --banner-bg: #fff0d1;
  --login-glow: #ffd9dd;
  --s1-text: #d1001f;
  --s2-text: #0a72c9;
  --s2e-text: #3b3d8f;
  --glow: .16;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.dim { color: var(--dim); }
.spacer { flex: 1; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 16px; border-radius: 12px; background: var(--surface-2); font-weight: 600; font-size: 15px; transition: transform .12s, opacity .12s; }
.btn:active { transform: scale(.97); opacity: .85; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--accent); }
.btn.big { width: 100%; padding: 15px; font-size: 16px; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .45; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); }
.icon-btn:active { transform: scale(.92); }

input:not([type=checkbox]), select, textarea {
  width: 100%; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; outline: none; font-size: 16px; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; min-height: 90px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.stack { display: grid; gap: 10px; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b)); background: radial-gradient(120% 60% at 50% 0%, var(--login-glow) 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 12px 40px rgba(255, 70, 85, .25); }
.login h1 { margin: 18px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.login p { margin: 0 0 26px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--faint); margin: 18px 0; font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.err { color: var(--accent); font-size: 14px; margin-top: 14px; }

/* ---------- layout ---------- */
.main { position: fixed; inset: 0; display: flex; flex-direction: column; }
.top { flex: none; padding: calc(10px + var(--safe-t)) 16px 0; background: var(--bar); backdrop-filter: saturate(160%) blur(20px); -webkit-backdrop-filter: saturate(160%) blur(20px); border-bottom: 1px solid var(--line); z-index: 5; }
.top-row { display: flex; align-items: center; gap: 10px; height: 44px; }
.top h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.count { color: var(--dim); font-weight: 600; font-size: 15px; margin-top: 6px; }
.tools { padding: 8px 0 10px; }
.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 11px; background: var(--surface-2); color: var(--dim); }
.search input { border: 0; background: none; padding: 0; height: 100%; border-radius: 0; color: var(--text); }
.search input::-webkit-search-cancel-button { filter: invert(.6); }
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--surface-2); color: var(--dim); font-size: 14px; font-weight: 600; white-space: nowrap; transition: background .15s, color .15s; }
.chip.on { background: var(--text); color: var(--bg); }
.chip.sort { display: inline-flex; align-items: center; gap: 4px; background: none; border: 1px solid var(--line); }
.chip-sep { flex: none; width: 1px; background: var(--line); margin: 4px 2px; }

.banner { margin: 0 -16px; padding: 9px 16px; font-size: 14px; font-weight: 600; background: var(--banner-bg); color: var(--warn-text); }
.banner button { text-decoration: underline; font-weight: 700; }

.view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px 16px calc(var(--tabbar) + 24px); overscroll-behavior: contain; }

.sync-dot { width: 30px; height: 30px; display: grid; place-items: center; }
.sync-dot::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 199, 123, .18); }
.sync-dot.pending::after { background: var(--warn); box-shadow: 0 0 0 3px rgba(255, 176, 32, .18); }
.sync-dot.offline::after { background: var(--faint); box-shadow: none; }
.sync-dot.running::after { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar); padding-bottom: var(--safe-b); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bar); backdrop-filter: saturate(160%) blur(20px); -webkit-backdrop-filter: saturate(160%) blur(20px); border-top: 1px solid var(--line); z-index: 6; }
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 10.5px; font-weight: 600; }
.tabbar button.on { color: var(--accent); }

/* ---------- grid ---------- */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px 12px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.card { min-width: 0; display: flex; flex-direction: column; justify-content: flex-start; align-self: start; text-align: left; content-visibility: auto; contain-intrinsic-size: 110px 170px; }
.card:active .cover { transform: scale(.96); }
.cover { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface-2); transition: transform .15s; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; font-size: 12px; font-weight: 700; color: var(--dim); background: linear-gradient(135deg, var(--ph-a), var(--ph-b)); }
.badge { position: absolute; top: 6px; left: 6px; padding: 2px 6px; border-radius: 6px; font-size: 10px; font-weight: 800; letter-spacing: .02em; color: #fff; background: var(--s1); box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.badge.switch2 { background: var(--s2); }
.badge.switch2_edition { background: linear-gradient(90deg, var(--s1), var(--s2)); }
.flag { position: absolute; bottom: 6px; right: 6px; padding: 2px 6px; border-radius: 6px; font-size: 10px; font-weight: 800; background: rgba(0, 0, 0, .7); color: #fff; }
.flag.unpaid { background: var(--warn); color: #241800; }
.flag.paid { background: var(--ok); color: #04210f; }
.card-title { margin-top: 7px; font-size: 12.5px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty { text-align: center; color: var(--dim); padding: 70px 20px; }
.empty .ico { width: 44px; height: 44px; color: var(--faint); margin-bottom: 10px; }

/* ---------- sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; animation: up .28s cubic-bezier(.2, .8, .2, 1); }
.sheet.closing { animation: down .22s ease-in forwards; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }
.sheet-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(8px + var(--safe-t)) 14px 8px; background: var(--bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.sheet-bar .title { font-weight: 700; }
.link-btn { color: var(--accent); font-weight: 600; padding: 8px 4px; }
.link-btn.strong { font-weight: 800; }
.sheet-body { padding: 4px 18px calc(30px + var(--safe-b)); max-width: 640px; margin: 0 auto; }

.hero { position: relative; margin: 6px auto 18px; width: min(78vw, 360px); }
.hero .cover { border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .55); }
.hero-bg { position: absolute; inset: -40px -80px; background-size: cover; background-position: center; filter: blur(50px) saturate(1.4); opacity: .35; z-index: -1; }
.d-title { font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; margin: 0 0 4px; text-align: center; }
.d-edition { text-align: center; color: var(--dim); margin-bottom: 12px; }
.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 20px; }
.pill { padding: 5px 10px; border-radius: 999px; background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--dim); }
.pill.switch { background: rgba(230, 0, 35, .18); color: var(--s1-text); }
.pill.switch2 { background: rgba(31, 155, 255, .18); color: var(--s2-text); }
.pill.switch2_edition { background: linear-gradient(90deg, rgba(230, 0, 35, .2), rgba(31, 155, 255, .2)); color: var(--s2e-text); }

.section-label { font-size: 13px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; margin: 22px 4px 8px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 13px; background: var(--surface); }
.seg button { padding: 10px 6px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--dim); transition: background .15s, color .15s; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }

.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--dim); }
.row .v { margin-left: auto; text-align: right; font-weight: 500; overflow-wrap: anywhere; }
.row.notes { display: block; white-space: pre-wrap; }
button.row { width: 100%; text-align: left; }
.row.danger { color: var(--accent); font-weight: 600; justify-content: center; }
.row .chev { margin-left: auto; color: var(--faint); }
.countdown { font-weight: 700; color: var(--warn-text); }
.countdown.out { color: var(--ok-text); }

/* toggle switch */
.switch-ctl { position: relative; width: 51px; height: 31px; flex: none; margin-left: auto; }
.switch-ctl input { position: absolute; opacity: 0; inset: 0; margin: 0; z-index: 1; }
.switch-ctl span { position: absolute; inset: 0; border-radius: 99px; background: var(--track); transition: background .2s; }
.switch-ctl span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch-ctl input:checked + span { background: var(--ok); }
.switch-ctl input:checked + span::after { transform: translateX(20px); }

/* editor */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--dim); margin: 0 4px 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cover-pick { position: relative; display: block; width: 180px; margin: 4px auto 22px; }
.cover-pick .cover { border-radius: 16px; }
.cover-pick .cover-edit { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); padding: 6px 12px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 700; white-space: nowrap; }
.cover-pick input { display: none; }
.prefix { position: relative; }
.prefix span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--dim); }
.prefix input { padding-left: 28px; }

/* settings */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 12px; }
.stat b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat span { font-size: 12.5px; color: var(--dim); font-weight: 600; }
.stat small { display: block; margin-top: 6px; font-size: 11.5px; color: var(--faint); line-height: 1.5; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.footnote { color: var(--faint); font-size: 12.5px; margin: 8px 6px 0; }
.version { text-align: center; color: var(--faint); font-size: 12px; margin-top: 28px; }

/* dialog & toast */
.dialog { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 30px; background: rgba(0, 0, 0, .55); animation: fade .15s; }
.dialog-box { width: 100%; max-width: 320px; background: var(--surface-2); border-radius: 18px; padding: 22px 18px 16px; text-align: center; }
.dialog-box p { margin: 0 0 18px; font-weight: 600; }
.dialog-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-btns .btn { background: var(--surface); }
.dialog-btns .btn.primary { background: var(--accent); }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 14px); transform: translateX(-50%); z-index: 50; padding: 11px 18px; border-radius: 99px; background: var(--text); color: var(--bg); font-weight: 700; font-size: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4); animation: fade .2s; white-space: nowrap; }

/* portrait only on phones */
.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .rotate { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--bg); color: var(--dim); font-weight: 600; }
  .rotate .ico { width: 46px; height: 46px; transform: rotate(-90deg); }
}

:root[data-theme=light] .seg { background: var(--surface-2); }
:root[data-theme=light] .seg button.on { background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
