:root, html[data-theme="light"] {
  --bg: #f6f7fb;
  --bg2: #eef1f7;
  --card: #ffffff;
  --card2: #f3f5fa;
  --line: rgba(20, 28, 45, 0.10);
  --text: #141c2d;
  --muted: #5b667a;
  --accent: #3b6ef5;
  --accent2: #2f5de0;
  --accent-soft: rgba(59, 110, 245, 0.10);
  --accent-glow: rgba(59, 110, 245, 0.18);
  --ok: #0f9f6e;
  --ok-bg: rgba(15, 159, 110, 0.10);
  --warn: #9a6b12;
  --warn-bg: #fff6e8;
  --danger: #d1435b;
  --danger-bg: rgba(209, 67, 91, 0.08);
  --danger-text: #b83248;
  --shadow: 0 18px 50px rgba(20, 28, 45, 0.08);
  --nav-bg: rgba(246, 247, 251, 0.88);
  --input-bg: #f8f9fc;
  --logo-grad: linear-gradient(145deg, #3b6ef5, #6a5cff);
  --logo-color: #fff;
  --radius: 20px;
  --max: 1120px;
  --theme-icon-sun: none;
  --theme-icon-moon: inline;
}
html[data-theme="dark"] {
  --bg: #0e1218;
  --bg2: #151a22;
  --card: #171d27;
  --card2: #1e2531;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8edf5;
  --muted: #9aa6b8;
  --accent: #6b8cff;
  --accent2: #8aa2ff;
  --accent-soft: rgba(107, 140, 255, 0.14);
  --accent-glow: rgba(107, 140, 255, 0.22);
  --ok: #3dd68c;
  --ok-bg: rgba(61, 214, 140, 0.12);
  --warn: #f0c27a;
  --warn-bg: rgba(240, 194, 122, 0.12);
  --danger: #ff7b8a;
  --danger-bg: rgba(255, 123, 138, 0.12);
  --danger-text: #ffb0b9;
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.35);
  --nav-bg: rgba(14, 18, 24, 0.86);
  --input-bg: #12171f;
  --logo-grad: linear-gradient(145deg, #6b8cff, #5ec8c0);
  --logo-color: #0e1218;
  --theme-icon-sun: inline;
  --theme-icon-moon: none;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; overflow-x: clip; }
body {
  margin: 0;
  overflow-x: clip;
  font-family: Manrope, ui-sans-serif, system-ui, sans-serif;
  background:
    radial-gradient(900px 420px at 100% -10%, var(--accent-glow), transparent 55%),
    radial-gradient(700px 380px at -10% 0%, rgba(42, 168, 160, 0.12), transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent2); text-decoration: none; }
button, input { font-family: inherit; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 18px; min-width: 0; }
.nav {
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(16px);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--line);
}
.nav-inner { display: flex; align-items: center; gap: 12px; padding: 12px 0; flex-wrap: nowrap; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; letter-spacing: -0.03em; min-width: 0; }
.brand-name { white-space: nowrap; }
img.logo {
  width: 36px; height: 36px; border-radius: 22%;
  background: transparent; box-shadow: none;
  object-fit: cover; display: block;
}
.logo-fallback {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800;
  background: #2f5bff; color: #fff;
}
.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; flex: 0 0 auto; min-width: 0; position: relative; }
.mobile-only, .signed-tools { display: none !important; }
body.signed-in .signed-tools:not(.hidden) { display: inline-flex !important; align-items: center; }
body.signed-in .brand-name,
body.signed-in #balanceLabel,
body.signed-in .desktop-when-signed { display: none !important; }
body.signed-in .nav-actions { gap: 8px; }
body.signed-in .balance {
  gap: 6px; padding: 3px 3px 3px 10px; border-radius: 999px;
  background: var(--card2); border: 1px solid var(--line); box-shadow: none;
}
body.signed-in .balance b {
  min-width: 0; height: auto; padding: 0; background: transparent; color: var(--text); font-size: .92rem;
}
body.signed-in #buyBtn {
  min-height: 30px; height: 30px; padding: 0 12px; border-radius: 999px;
  font-size: .78rem; line-height: 1; box-shadow: none;
}
body.signed-in .profile-btn {
  width: auto; height: 36px; min-height: 36px; padding: 3px 8px 3px 3px;
  border-radius: 999px; gap: 2px; background: var(--card2);
}
.install-mark { color: var(--accent2); flex: 0 0 auto; }
.balance b { font-variant-numeric: tabular-nums; }
.profile-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  min-width: 220px; max-width: min(280px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 4px;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); padding: 8px;
}
.profile-menu[hidden] { display: none !important; }
.profile-email { margin: 4px 8px 6px; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.profile-menu button {
  appearance: none; text-align: left; border: 0; background: transparent; color: var(--text);
  border-radius: 10px; min-height: 44px; padding: 8px 10px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
}
.menu-ico { width: 18px; height: 18px; flex: 0 0 auto; }
.app-intro h1 { margin: 4px 0 8px; font-size: clamp(1.7rem, 4vw, 2.3rem); letter-spacing: -0.04em; }
.steps { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
}
.step h2 { margin: 0 0 4px; font-size: 1rem; }
.step p { margin: 0; color: var(--muted); }
.step .btn { margin-top: 10px; }
.step-note { margin-top: 8px !important; }
.step-index {
  width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--card2); color: var(--muted); font-weight: 800;
}
.step.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.step.is-active .step-index { background: var(--accent); color: #fff; }
.step.is-done .step-index { background: var(--ok-bg); color: var(--ok); }
.profile-menu button:hover, .profile-menu button:focus-visible,
.profile-menu a:hover, .profile-menu a:focus-visible { background: var(--accent-soft); outline: none; }
.profile-menu a {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border-radius: 10px;
  color: var(--text); font-weight: 700; text-decoration: none;
}
.profile-menu a[hidden] { display: none !important; }
.profile-menu [aria-disabled="true"] { color: var(--muted); opacity: .72; cursor: default; }
.profile-face {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent2);
}
.profile-chevron { color: var(--muted); }
.balance {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 8px 6px 12px; font-weight: 700; font-size: .92rem;
}
#balanceLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.balance b {
  min-width: 26px; height: 26px; border-radius: 999px;
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent2);
}
.icon-btn, .theme-toggle {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
}
.theme-toggle .icon-sun { display: var(--theme-icon-sun); }
.theme-toggle .icon-moon { display: var(--theme-icon-moon); }
.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: 14px; font-weight: 700; font-size: .95rem;
  text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 10px 24px var(--accent-glow); }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--danger-bg); color: var(--danger-text); border: 1px solid transparent; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: .85rem; border-radius: 12px; }
.btn-block { width: 100%; }
.store-card .btn {
  width: 100%; align-self: stretch; min-height: 36px; min-width: 0;
  padding: 4px 8px; font-size: .75rem; line-height: 1.15; border-radius: 10px;
  box-shadow: none;
}
.page { padding: 22px 0 64px; }
.lede { margin: 0 0 14px; color: var(--muted); max-width: 40rem; }
.hero { max-width: 40rem; padding-top: 18px; }
.hero h1 {
  margin: 0 0 12px; font-size: clamp(1.75rem, 4.4vw, 2.7rem);
  letter-spacing: -0.045em; line-height: 1.12;
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 28px; }
.hero-actions .btn { min-height: 48px; padding: 12px 18px; }
.landing-block { margin: 8px 0 22px; }
.landing-block h2 { margin: 0 0 8px; font-size: clamp(1.25rem, 2vw, 1.5rem); letter-spacing: -0.03em; }
.benefits { margin-top: 4px; }
.lede strong { color: var(--text); }
.guide {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px;
}
.guide article {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 14px; box-shadow: var(--shadow); min-height: 100%;
}
.guide span {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent2); font-weight: 800; font-size: .8rem; margin-bottom: 6px;
}
.guide h2 { margin: 0 0 4px; font-size: .98rem; letter-spacing: -0.02em; }
.guide p { margin: 0; color: var(--muted); font-size: .86rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; min-width: 0; }
.panel, .aside-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.search {
  width: 100%; padding: 13px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--input-bg); color: var(--text); font-size: 1rem;
}
.search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%; }
.chip {
  appearance: none; border: 1px solid var(--line); background: var(--card2); color: var(--text);
  border-radius: 999px; min-height: 40px; padding: 8px 14px; font-weight: 700; cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }
.count-line { color: var(--muted); font-size: .86rem; margin: 0 0 10px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; min-width: 0; }
.store-card {
  content-visibility: auto;
  contain-intrinsic-size: 148px;
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
  min-height: 0;
}
.store-top { display: flex; gap: 8px; align-items: center; min-width: 0; }
.store-copy { min-width: 0; flex: 1; }
.store-icon, .store-fallback {
  width: 48px; height: 48px; border-radius: 12px; flex: 0 0 auto;
  background: var(--bg2); object-fit: cover;
}
.store-fallback {
  display: none; place-items: center; font-weight: 800; color: #fff; font-size: 1.4rem;
  background: var(--logo-grad);
}
.store-icon.missing { display: none; }
.store-icon.missing + .store-fallback { display: grid; }
.store-name {
  margin: 0; font-size: .95rem; letter-spacing: -0.02em; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.seller { margin: 2px 0 0; color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seller.wrap { white-space: normal; }
.status {
  display: inline-flex; align-items: center; width: fit-content; max-width: 100%;
  border-radius: 999px; padding: 1px 6px; font-size: .62rem; font-weight: 600; line-height: 1.3;
  background: transparent; color: var(--muted); border: 0; opacity: .8;
}
.status.owned { color: var(--ok); }
.status.not_owned { color: var(--danger-text); }
.status.unverified { color: var(--warn); }
.status.needs_apple { color: var(--muted); }
.empty, .note, .msg {
  border-radius: 14px; padding: 12px 14px; background: var(--card2); color: var(--muted); border: 1px solid var(--line);
}
.msg.error { background: var(--danger-bg); color: var(--danger-text); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.hidden { display: none !important; }
.section-title { margin: 22px 0 8px; font-size: 1.15rem; letter-spacing: -0.02em; }
.aside { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 78px; }
.qr { width: 180px; height: 180px; display: block; margin: 8px auto; background: #fff; border-radius: 12px; }
.aside h2, .modal h3 { margin: 0 0 6px; letter-spacing: -0.02em; }
.aside p, .modal p { margin: 0 0 10px; color: var(--muted); font-size: .9rem; }
.skeleton { height: 168px; border-radius: 18px; background: linear-gradient(90deg, var(--card2), var(--bg2), var(--card2)); background-size: 200% 100%; animation: shine 1.2s infinite; }
@keyframes shine { to { background-position: -200% 0; } }
dialog {
  width: min(460px, calc(100vw - 20px)); max-height: min(92dvh, 760px); overflow: auto;
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--card); color: var(--text); padding: 20px; box-shadow: var(--shadow);
  margin: auto;
}
dialog::backdrop { background: rgba(15, 20, 30, .45); }
label { display: block; margin: 10px 0 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
input[type="email"], input[type="password"], input[type="text"] {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--input-bg); color: var(--text); font-size: 1rem;
}
.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button { border: 1px solid var(--line); background: var(--card2); color: var(--muted); border-radius: 999px; padding: 8px 12px; font-weight: 700; cursor: pointer; }
.tabs button.active { background: var(--accent-soft); color: var(--accent2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.pkg { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--card2); }
.pkg .btn { min-height: 44px; }
.history-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }
footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; padding: 22px 0 40px; }
footer strong { color: var(--text); }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .aside { position: static; }
  .guide { grid-template-columns: 1fr; }
  .phone-desktop { display: none; }
  .nav-inner { gap: 8px; }
  .nav-actions { width: auto; margin-left: auto; }
  .brand { gap: 6px; }
  .brand-name { font-size: .92rem; }
  img.logo { width: 30px; height: 30px; }
  .nav-actions .btn { min-height: 36px; padding: 6px 10px; font-size: .78rem; }
  .nav-actions .theme-toggle { width: 36px; height: 36px; min-height: 36px; }
  .btn, .chip, .icon-btn, .theme-toggle { min-height: 44px; }
  .store-card .btn { min-height: 40px; }
  .wrap { padding-left: 12px; padding-right: 12px; }
  body.signed-in .nav-inner {
    padding-left: 12px;
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
  }
  .page { padding-top: 16px; }
  dialog { padding: 16px; }
  .actions .btn { flex: 1 1 140px; }
  #balanceLabel { max-width: 42vw; }
}
@media (max-width: 430px) {
  .nav-inner { gap: 6px; padding: 8px 0; }
  body.signed-in .nav-inner {
    padding-top: 8px; padding-bottom: 8px; padding-left: 12px;
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
  }
  body.signed-in .nav-actions { gap: 8px; }
  body.signed-in #buyBtn { padding: 0 10px; font-size: .74rem; }
  .brand-name { font-size: .82rem; }
  img.logo { width: 26px; height: 26px; }
  .nav-actions { gap: 4px; }
  .nav-actions .btn { padding: 5px 8px; font-size: .72rem; }
  .nav-actions .theme-toggle { width: 32px; height: 32px; min-height: 32px; }
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 721px) and (max-width: 860px) {
  .guide { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 861px) {
  .phone-mobile { display: none; }
}
@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
