:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --panel-2: #1f232a;
  --line: #2b3038;
  --text: #e8eaee;
  --muted: #98a0ad;
  --accent: #00a1e0;
  --accent-ink: #ffffff;
  --good: #2fbf71;
  --warn: #e5a50a;
  --bad: #ff6b6b;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8;
    --panel: #ffffff;
    --panel-2: #f2f4f7;
    --line: #dde2e9;
    --text: #15181d;
    --muted: #5d6675;
    --accent: #0079b0;
    --good: #198754;
    --warn: #a46b00;
    --bad: #c53030;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 64px; }
.top-actions { display: flex; gap: 8px; }

/* unlock screen */
.lock { display: flex; justify-content: center; padding: 12vh 16px 32px; }
.lock-card { width: min(100%, 360px); padding: 22px; display: grid; gap: 12px; margin: 0; }
.lock-card h2 { margin: 0; font-size: 20px; }
.lock-card .note, .lock-card .err { margin: 0; }
.lock-card input {
  padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel-2);
}
.lock-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 9px; padding: 8px 14px; cursor: pointer; font-weight: 600;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }

/* panels */
.panel, .acct {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 12px;
}
.panel > summary, .acct > summary {
  list-style: none; cursor: pointer; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.panel > summary::-webkit-details-marker, .acct > summary::-webkit-details-marker { display: none; }
.panel > summary::after, .acct > summary::after {
  content: ""; margin-left: auto; flex: none; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s;
}
.panel[open] > summary::after, .acct[open] > summary::after { transform: rotate(-135deg); }
.add > summary { font-weight: 600; }

#addForm { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; padding: 0 14px 14px; }
#addForm input {
  min-width: 0; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2);
}
#addForm input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#addForm .note, #addForm .err { grid-column: 1 / -1; margin: 0; }

.note { color: var(--muted); font-size: 12.5px; }
.note.center { text-align: center; margin-top: 32px; }
.err { color: var(--bad); font-size: 13px; }

/* account card */
.who { display: flex; flex-direction: column; min-width: 0; }
.who strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 6px; margin-left: auto; flex: none; }
.chip {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.chip.full { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, transparent); }

.acct-body { padding: 0 14px 14px; display: grid; gap: 12px; }

.codes { display: flex; gap: 10px; }
.code {
  background: #fff; border: 0; border-radius: 10px; padding: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  height: 104px; transition: box-shadow .12s;
}
.code:hover, .code:focus-visible { box-shadow: 0 0 0 2px var(--accent); outline: none; }
.code.qr { width: 104px; flex: none; }
.code.qr img { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.code.bc { flex: 1; min-width: 0; }
.code.bc canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }

.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12.5px; }
.meta b { color: var(--text); font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .spacer { flex: 1; }
.acct .err { margin: 0; }
.stale { color: var(--warn); font-size: 12.5px; margin: 0; }

/* offers */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.offer {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 10px; display: flex; flex-direction: column; gap: 4px; min-height: 112px;
}
.o-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.o-type { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.o-head { font-weight: 700; font-size: 16px; }
.o-sub { color: var(--muted); font-size: 13px; flex: 1; }
.o-code { font-size: 11.5px; color: var(--muted); font-family: ui-monospace, monospace; }
.offer .btn { margin-top: 6px; width: 100%; }
.offer .btn:disabled { background: transparent; border-color: var(--line); color: var(--muted); opacity: 1; }

.offer.selected { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
.offer.selected .badge { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.offer.redeemed { opacity: .7; }
.offer.redeemed .badge { background: var(--line); color: var(--text); }
.offer.expired { opacity: .5; }
.offer.expired .badge { background: var(--line); color: var(--muted); }
.acct.busy .acct-body { opacity: .6; pointer-events: none; }

/* fullscreen code */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: #fff; color: #111;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px;
}
.ov-tabs {
  position: absolute; top: max(16px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; background: #eef0f3; border-radius: 999px; padding: 3px;
}
.ov-tabs button {
  border: 0; background: transparent; padding: 7px 18px; border-radius: 999px;
  font-weight: 600; color: #444; cursor: pointer;
}
.ov-tabs button[aria-selected="true"] { background: #fff; color: #111; box-shadow: 0 1px 3px rgb(0 0 0 / .15); }
.ov-code { display: flex; align-items: center; justify-content: center; }
.ov-code img { width: min(78vw, 60vh); height: min(78vw, 60vh); image-rendering: pixelated; display: block; }
.ov-code canvas { width: min(92vw, 720px); height: auto; image-rendering: pixelated; display: block; }
.ov-num { font: 600 22px/1 ui-monospace, monospace; letter-spacing: 1px; }
.ov-name { color: #666; font-size: 14px; }
.ov-hint { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); margin: 0; color: #888; font-size: 12.5px; }
.ov-close {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 14px;
  border: 0; background: none; font-size: 34px; line-height: 1; color: #111; cursor: pointer;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; max-width: min(92vw, 520px); padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: 0 6px 24px rgb(0 0 0 / .3);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  .top { padding-left: 12px; padding-right: 12px; }
  main { padding: 10px 10px 56px; }
  #addForm { grid-template-columns: 1fr; }
  .acct > summary { padding: 11px 12px; }
  .acct-body { padding: 0 12px 12px; gap: 10px; }
  .code { height: 88px; }
  .code.qr { width: 88px; }
  .chips .chip.promo { display: none; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .offer { min-height: 104px; padding: 9px; }
  .o-head { font-size: 15px; }
  .o-sub { font-size: 12.5px; }
}
