/* CardPerks — phone first. Everything sized for a thumb; wider screens just get a centred column. */
:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #14201d; --mute: #5b6b67; --line: #dfe6e3;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #d9f2ee;
  --hot: #c2410c; --warn: #a16207; --warn-soft: #fef3c7; --new: #7c3aed; --new-soft: #ede9fe;
  --chip: #e9efed; --shadow: 0 1px 2px rgba(20, 32, 29, .06), 0 2px 8px rgba(20, 32, 29, .05);
  --r: 14px; --tabh: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1416; --card: #13201f; --ink: #e6efec; --mute: #93a6a1; --line: #22332f;
    --brand: #2dd4bf; --brand-ink: #062a26; --brand-soft: #123532;
    --hot: #fb923c; --warn: #facc15; --warn-soft: #3a3214; --new: #c4b5fd; --new-soft: #2a2347;
    --chip: #1b2b29; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1416; --card: #13201f; --ink: #e6efec; --mute: #93a6a1; --line: #22332f;
  --brand: #2dd4bf; --brand-ink: #062a26; --brand-soft: #123532;
  --hot: #fb923c; --warn: #facc15; --warn-soft: #3a3214; --new: #c4b5fd; --new-soft: #2a2347;
  --chip: #1b2b29; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Sinhala", sans-serif;
  overscroll-behavior-y: contain;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding-bottom: calc(var(--tabh) + var(--safe-b) + 8px); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--brand); }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.logo { width: 28px; height: 28px; stroke-width: 2; }
.logo .tick { stroke-width: 2.4; }
.mycards {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid currentColor;
  background: transparent; color: inherit; font-size: 14px; font-weight: 600; max-width: 55%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- search + chips ---- */
.searchbar { position: sticky; top: calc(60px + var(--safe-t)); z-index: 15; background: var(--bg); padding: 10px 0 6px; }
.search {
  display: flex; align-items: center; gap: 8px; margin: 0 16px; padding: 0 14px; min-height: 48px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; color: var(--mute);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; padding: 12px 0; }
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search.small { margin: 0 0 12px; }
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 2px; scrollbar-width: none;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: 999px; border: 0; background: var(--chip); color: var(--ink); font-size: 14px; font-weight: 500;
  scroll-snap-align: start; white-space: nowrap;
}
.chip svg { width: 17px; height: 17px; }
.chip i { font-style: normal; font-size: 12px; color: var(--mute); }
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.chip[aria-pressed="true"] i { color: inherit; opacity: .8; }

.count { margin: 8px 16px 4px; font-size: 13px; color: var(--mute); }
#notice:empty { display: none; }
.note {
  margin: 8px 16px; padding: 12px 14px; border-radius: var(--r); background: var(--brand-soft); font-size: 14px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.note button { flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 600; font-size: 14px; }
.note.warn { background: var(--warn-soft); }

/* ---- day groups + offer cards ---- */
.grp {
  position: sticky; top: var(--grptop, 170px); z-index: 5; display: flex; justify-content: space-between; align-items: baseline;
  margin: 14px 0 6px; padding: 6px 16px; background: var(--bg); font-size: 15px; font-weight: 700;
}
.grp i { font-style: normal; font-weight: 500; font-size: 13px; color: var(--mute); }
.grp.fav span { display: inline-flex; gap: 6px; align-items: center; }
.grp.fav svg { width: 17px; height: 17px; fill: #f59e0b; stroke: #f59e0b; }

.of {
  position: relative; margin: 0 12px 10px; padding: 14px 14px 12px 18px; background: var(--card); border-radius: var(--r);
  box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; content-visibility: auto; contain-intrinsic-size: auto 150px;
}
.of::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--bc, #888); }
.of .hd { display: flex; gap: 12px; align-items: flex-start; }
.of .who { flex: 1; min-width: 0; }
.of .mer { font-weight: 700; font-size: 17px; line-height: 1.25; overflow-wrap: anywhere; }
.of .sub { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 4px; font-size: 13px; color: var(--mute); }
.bank { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; color: #fff; background: var(--bc, #888); }
.disc { flex: none; text-align: right; max-width: 42%; }
.disc .big { display: block; font-size: 28px; font-weight: 800; line-height: 1; color: var(--brand); letter-spacing: -.02em; }
.disc .big.hot { color: var(--hot); }
.disc .up, .disc .rest { display: block; font-size: 12px; color: var(--mute); }
.disc .txt { display: block; font-size: 14px; font-weight: 700; color: var(--brand); }
.of .t { margin-top: 8px; font-size: 14px; color: var(--ink); opacity: .9; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.of .deal { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 8px; font-size: 13px; }
.of .deal .lim { color: var(--mute); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: var(--chip); font-size: 12px; color: var(--mute); }
.tag svg { width: 14px; height: 14px; }
.tag.new { background: var(--new-soft); color: var(--new); font-weight: 700; }
.tag.chk { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.tag.end { color: var(--hot); font-weight: 600; }
.life { margin-top: 10px; }
.life .lt { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--mute); }
.life .lt b { font-weight: 600; color: var(--ink); }
.life .lt b.end { color: var(--hot); }
.life .lt b.soon { color: var(--brand); }
.track { height: 4px; margin-top: 5px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.track i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.of .foot { display: flex; align-items: flex-end; gap: 6px; margin-top: 6px; }
.of .foot .tags { flex: 1; min-width: 0; margin-top: 4px; }
.of .star {
  position: relative; flex: none; width: 44px; height: 44px; margin: 0 -8px -8px 0; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--mute); border-radius: 50%;
}
.of .star[aria-pressed="true"] svg, .sheet .star[aria-pressed="true"] svg { fill: #f59e0b; stroke: #f59e0b; }
.of .open { position: absolute; inset: 0; border: 0; background: transparent; z-index: 1; border-radius: var(--r); }
.of .open:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.of .star { z-index: 2; }

.empty { margin: 24px 16px; padding: 24px 16px; text-align: center; color: var(--mute); background: var(--card); border-radius: var(--r); }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }
.empty button { margin-top: 14px; min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.skel { margin: 0 12px 10px; height: 130px; border-radius: var(--r); background: linear-gradient(90deg, var(--chip), var(--card), var(--chip)); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }
#sentinel { height: 1px; }

/* in-feed ad: same width as a card, reserved height so the list doesn't jump */
.adwrap { margin: 0 12px 10px; min-height: 120px; border-radius: var(--r); overflow: hidden; background: var(--card); border: 1px dashed var(--line); }
.adwrap .lbl { display: block; padding: 4px 10px 0; font-size: 11px; color: var(--mute); }

/* ---- other views ---- */
.view { display: block; }
.vh { margin: 18px 16px 4px; font-size: 22px; }
.hint { margin: 0 16px 12px; color: var(--mute); font-size: 14px; }
#view-cards { padding: 0 16px; }
#view-cards .vh, #view-cards .hint { margin-left: 0; margin-right: 0; }
.bankgrp { margin-bottom: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.bankgrp > summary {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 14px; list-style: none; cursor: pointer; font-weight: 600;
}
.bankgrp > summary::-webkit-details-marker { display: none; }
.bankgrp > summary .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bc); flex: none; }
.bankgrp > summary .n { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--brand); }
.bankgrp > summary .chev { color: var(--mute); transition: transform .2s; }
.bankgrp[open] > summary .chev { transform: rotate(180deg); }
.kindh { margin: 8px 14px 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); }
.cardrow { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.cardrow input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.cardrow .cn { flex: 1; min-width: 0; font-size: 15px; }
.cardrow .cn small { display: block; color: var(--mute); font-size: 12px; }
.donebar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + var(--safe-b)); z-index: 25; padding: 10px 16px;
  background: linear-gradient(transparent, var(--bg) 30%);
}
.primary { display: block; width: 100%; max-width: 608px; margin: 0 auto; min-height: 52px; border: 0; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font-weight: 700; font-size: 17px; box-shadow: 0 4px 14px rgba(15,118,110,.3); }

.panel { margin: 12px 16px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.panel h2 { margin: 0 0 8px; font-size: 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.row small { display: block; font-size: 12px; color: var(--mute); }
.row select { min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.small { font-size: 13px; color: var(--mute); margin: 4px 0; }
.switch { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--chip); position: relative; flex: none; transition: background .2s; border: 1px solid var(--line); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(20px); }
.kinds { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.bstat { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.bstat:first-child { border-top: 0; }
.bstat .ok { color: var(--brand); } .bstat .bad { color: var(--hot); }
.about p { font-size: 14px; color: var(--mute); }
.link { border: 0; background: none; color: var(--brand); text-decoration: underline; padding: 0; }
#favList .of { margin-left: 12px; margin-right: 12px; }

/* ---- bottom tabs ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  height: calc(var(--tabh) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--mute); font-size: 12px; font-weight: 600;
}
.tabs svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--brand); }
.tabs button[aria-current="page"] svg { stroke-width: 2.2; }

/* ---- offer sheet ---- */
dialog#sheet { padding: 0; border: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 88dvh; border-radius: 20px 20px 0 0; background: var(--card); color: var(--ink); }
dialog#sheet::backdrop { background: rgba(0, 0, 0, .45); }
dialog#sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }
.sheet { padding: 8px 18px calc(18px + var(--safe-b)); }
.sheet .grab { width: 40px; height: 5px; margin: 4px auto 10px; border-radius: 3px; background: var(--line); }
.sheet h2 { margin: 6px 0 4px; font-size: 21px; }
.sheet .sd { font-size: 15px; color: var(--mute); margin-bottom: 10px; }
.sheet .bigd { font-size: 34px; font-weight: 800; color: var(--brand); line-height: 1.1; }
.sheet dl { margin: 14px 0 0; }
.sheet dt { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); margin-top: 12px; }
.sheet dd { margin: 2px 0 0; font-size: 15px; overflow-wrap: anywhere; }
.sheet .mycard { color: var(--brand); font-weight: 600; }
.sheet .acts { display: flex; gap: 10px; margin-top: 18px; position: sticky; bottom: 0; padding-top: 10px; background: var(--card); }
.sheet .acts a, .sheet .acts button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; border-radius: 999px;
  font-weight: 700; text-decoration: none; border: 0; font-size: 15px;
}
.sheet .acts .go { background: var(--brand); color: var(--brand-ink); }
.sheet .acts .star, .sheet .acts .share { flex: none; width: 50px; background: var(--chip); color: var(--ink); }
.sheet .close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--chip); display: grid; place-items: center; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 14px); transform: translateX(-50%) translateY(20px);
  padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: 14px; opacity: 0;
  pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; transition: none !important; } }
/* ---- tablets: a little more room, still one column ---- */
@media (min-width: 700px) and (max-width: 979px) {
  #app { max-width: 760px; }
  #list, #favList { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2px; }
  #list > .grp, #list > .empty, #list > .skel, #list > .adwrap, #favList > .empty { grid-column: 1 / -1; }
}

/* ---- desktop: filters column on the left, offers grid on the right (like the Home Dashboard) ---- */
@media (min-width: 980px) {
  #app { max-width: 1440px; padding-bottom: 32px; }
  .top { padding: 0 24px; height: 64px; }
  .mycards { display: none; }                 /* "My cards" is in the top tabs on desktop */
  /* bottom tabs become top-right navigation inside the header bar */
  .tabs {
    position: fixed; top: 0; bottom: auto; left: auto; right: max(24px, calc((100vw - 1440px) / 2 + 24px));
    height: 64px; padding: 0; background: transparent; border: 0; gap: 4px; z-index: 30;
  }
  .tabs button { flex-direction: row; gap: 8px; max-width: none; padding: 0 14px; white-space: nowrap; color: var(--brand-ink); opacity: .78; font-size: 14px; border-radius: 999px; height: 42px; align-self: center; }
  .tabs button:hover { opacity: 1; background: rgba(255,255,255,.12); }
  .tabs button[aria-current="page"] { color: var(--brand-ink); opacity: 1; background: rgba(255,255,255,.18); }
  .tabs svg { width: 20px; height: 20px; }

  #view-offers:not([hidden]) {
    display: grid; grid-template-columns: 320px minmax(0, 1fr); column-gap: 24px; align-items: start; padding: 0 24px;
  }
  #view-offers .searchbar {
    grid-column: 1; grid-row: 1 / span 5; position: sticky; top: 80px; padding: 16px; margin-top: 16px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
    max-height: calc(100dvh - 96px); overflow-y: auto;
  }
  #view-offers .searchbar .search { margin: 0; }
  #view-offers .chips { flex-wrap: wrap; overflow: visible; padding: 12px 0 0; }
  #view-offers .chips.cats { flex-direction: column; flex-wrap: nowrap; gap: 4px; padding-top: 14px; margin-top: 12px; border-top: 1px solid var(--line); }
  #view-offers .chips.cats .chip { justify-content: flex-start; width: 100%; border-radius: 10px; background: transparent; min-height: 40px; }
  #view-offers .chips.cats .chip:hover { background: var(--chip); }
  #view-offers .chips.cats .chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
  #view-offers .chips.cats .chip i { margin-left: auto; }
  #view-offers #notice, #view-offers .count, #view-offers #list, #view-offers #sentinel { grid-column: 2; }
  #view-offers .count { margin: 20px 4px 0; }
  #notice .note { margin: 16px 0 0; }

  #list, #favList { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; align-items: stretch; }
  #list > .grp, #list > .empty, #list > .skel, #list > .adwrap, #favList > .empty { grid-column: 1 / -1; }
  #list .of, #favList .of { margin: 0; display: flex; flex-direction: column; }
  #list .of .foot, #favList .of .foot { margin-top: auto; padding-top: 6px; }
  .grp { top: 64px; margin: 10px 0 0; padding: 10px 4px; }
  .adwrap { margin: 0; }
  .skel { margin: 0; }
  .of { transition: box-shadow .15s, transform .15s; }
  .of:hover { box-shadow: 0 4px 18px rgba(20, 32, 29, .12); transform: translateY(-1px); }

  #view-favs, #view-more { padding: 0 24px; }
  #view-favs .vh, #view-favs .hint, #view-more .vh { margin-left: 0; margin-right: 0; }
  #view-cards { padding: 0 24px; }
  #cardPicker { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; align-items: start; }
  .bankgrp { margin: 0; }
  #view-cards .search.small { max-width: 480px; }
  .donebar { bottom: 0; }
  .primary { max-width: 420px; }
  #view-more:not([hidden]) { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; align-items: start; }
  #view-more .vh { grid-column: 1 / -1; }
  #view-more .panel { margin: 0; }

  dialog#sheet { margin: auto; max-width: 600px; max-height: 86dvh; border-radius: 20px; }
  .sheet .grab { display: none; }
  #toast { bottom: 24px; }
}
