:root {
  --bg: #f4f6f8;
  --ink: #14202b;
  --brand: #1b4965;
  --accent: #f2a900; /* peso gold */
  --card: #ffffff;
  --ok: #1a7f4b;
  --warn: #b00020;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  /* big fonts: app is read at a glance at the register */
  font-size: clamp(18px, 2.5vw + 12px, 24px);
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

.screen {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px
           max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand h1 {
  font-size: clamp(36px, 9vw, 52px);
  margin: 0;
  color: var(--brand);
  letter-spacing: -0.02em;
}
.brand h1 span { margin-left: 8px; }
.tagline { margin: 4px 0 0; color: #4a5b69; }

/* --- top bar + status ---------------------------------------------------- */
.topbar { display: flex; flex-direction: column; gap: 6px; }
.logo { font-size: clamp(28px, 7vw, 40px); margin: 0; color: var(--brand); letter-spacing: -0.02em; }
.statusbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 15px; }
.status { color: #4a5b69; }
.source { color: var(--brand); text-decoration: underline; }
.refresh {
  margin-left: auto; min-width: 44px; min-height: 44px; font-size: 22px; line-height: 1;
  border: 0; border-radius: 12px; background: transparent; color: var(--brand); cursor: pointer;
}
.refresh:active { transform: rotate(90deg); }
.refresh:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- currency picker (chips) -------------------------------------------- */
.picker { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 64px; min-height: 56px; padding: 8px 12px; cursor: pointer;
  background: var(--card); color: var(--ink); border: 2px solid transparent;
  border-radius: 14px; font: inherit;
}
.chip-flag { font-size: 22px; }
.chip-code { font-size: 14px; font-weight: 700; }
.chip.active { border-color: var(--brand); background: #e7f0f6; }
.chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- converter card ----------------------------------------------------- */
.converter {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 2px 12px rgba(20, 32, 43, 0.08);
  display: flex; flex-direction: column; gap: 8px;
}
.row { display: flex; flex-direction: column; gap: 2px; }
.ccy { font-size: 16px; font-weight: 700; color: #4a5b69; }
.amount {
  font-size: clamp(40px, 13vw, 64px); font-weight: 800; line-height: 1.1;
  color: var(--ink); border: 0; background: transparent; width: 100%; padding: 0;
  font-variant-numeric: tabular-nums;
}
.amount:focus-visible { outline: none; }
#amount { caret-color: var(--brand); }
.result { color: var(--brand); }
.to { background: rgba(27, 73, 101, 0.06); border-radius: 12px; padding: 10px 12px; }
/* Fitts: large central swap target between the two amounts */
.swap {
  align-self: center; min-width: 52px; min-height: 52px; font-size: 26px;
  border: 0; border-radius: 50%; background: var(--brand); color: #fff; cursor: pointer;
}
.swap:active { transform: scale(0.96); }
.swap:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- manual rate setter (VND / custom) ---------------------------------- */
.manual { display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
  padding-top: 12px; border-top: 1px dashed #c7d2dc; }
.manual label { font-size: 16px; font-weight: 600; color: #4a5b69; }
.manual input {
  font-size: 22px; font-weight: 700; min-height: 48px; margin-left: 6px; padding: 4px 10px;
  border: 2px solid #c7d2dc; border-radius: 10px; max-width: 9ch; background: var(--card); color: var(--ink);
}
.manual input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--brand); }
.manual-note { margin: 0; font-size: 14px; color: #6b7b89; font-weight: 400; }

.status.stale { color: var(--warn); font-weight: 700; }

/* Banner ad slot — space reserved now (ad network is post-launch). The ad
   script replaces the placeholder; reserving height avoids layout shift later. */
.adslot { margin-top: 8px; min-height: 60px; display: flex; align-items: center;
  justify-content: center; overflow: hidden; border: 1px dashed #d3dce3; border-radius: 12px; }
.adslot-ph { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: #9aa7b2; }

.net { margin: 0; font-weight: 600; }
.net.offline { color: var(--warn); }
.net.online { color: var(--ok); }

.install { margin-top: auto; }
/* Fitts + thumb zone: large primary action near the bottom */
#installBtn {
  width: 100%;
  min-height: 56px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
#installBtn:active { transform: translateY(1px); }
#installBtn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- scan price tag ------------------------------------------------------ */
.scan {
  width: 100%; min-height: 52px; font-size: 18px; font-weight: 700; cursor: pointer;
  color: var(--brand); background: rgba(27, 73, 101, 0.08);
  border: 2px dashed var(--brand); border-radius: var(--radius);
}
.scan:active { transform: translateY(1px); }
.scan:disabled { opacity: 0.6; cursor: progress; }
.scan:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.scan-msg { margin: 0; font-size: 15px; font-weight: 600; color: var(--brand); }

/* --- card picker -------------------------------------------------------- */
.cards { background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 2px 12px rgba(20, 32, 43, 0.08); display: flex; flex-direction: column; gap: 12px; }
.cards-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.cards-head h2 { font-size: 20px; margin: 0; }
.link-btn { background: none; border: 0; color: var(--brand); font: inherit; font-weight: 700;
  text-decoration: underline; cursor: pointer; padding: 6px 0; min-height: 44px; }
.link-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* DCC guard — important, stands out, but not a trick (Von Restorff) */
.dcc { margin: 0; padding: 12px 14px; border-radius: 12px; font-size: 16px; line-height: 1.35;
  background: #fff4d6; color: #5a4500; border: 1px solid #f2cf6b; }

.savings { margin: 0; font-size: 16px; color: var(--ok); font-weight: 600; }
.add-cards { min-height: 56px; width: 100%; font-size: 18px; font-weight: 700; color: #fff;
  background: var(--brand); border: 0; border-radius: var(--radius); cursor: pointer; }
.add-cards:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { margin: 0; font-size: 14px; color: #6b7b89; }
.estimate { margin: 0; font-size: 13px; color: #6b7b89; }

.ranking { display: flex; flex-direction: column; gap: 8px; }
.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px;
  border: 2px solid transparent; background: rgba(20, 32, 43, 0.03); }
.rank-row.winner { border-color: var(--ok); background: rgba(26, 127, 75, 0.08); }
.rank-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.rank-name { font-size: 16px; font-weight: 700; }
.rank-sub { font-size: 13px; color: #6b7b89; }
.rank-cost { text-align: right; font-size: 18px; font-weight: 800; color: var(--brand);
  white-space: nowrap; display: flex; flex-direction: column; }
.rank-cost small { font-size: 12px; font-weight: 600; color: #6b7b89; }

/* card visual: official face image over a CSS-chip fallback */
.cardart { position: relative; flex: 0 0 auto; width: 56px; height: 38px; border-radius: 7px; padding: 5px 6px;
  display: flex; flex-direction: column; justify-content: space-between; color: #fff; overflow: hidden;
  background: linear-gradient(135deg, hsl(var(--h) 55% 42%), hsl(var(--h) 60% 28%)); }
.cardart b { font-size: 9px; font-weight: 800; line-height: 1; }
.cardart i { font-size: 7px; font-style: normal; opacity: 0.85; }
.cardimg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

.rank-prov { font-size: 12px; }
.rank-ok { color: var(--ok); }
.rank-warn { color: var(--warn); }
.rank-src { color: var(--brand); }

.badge { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; vertical-align: middle; }
.badge.win { background: var(--ok); color: #fff; }
.badge.promo { background: var(--accent); color: #3a2c00; }
.badge.unver { background: #e3e8ec; color: #5a6b78; }

/* card dialog */
.card-dialog { border: 0; border-radius: var(--radius); padding: 20px; max-width: 440px; width: 92vw;
  color: var(--ink); background: var(--card); }
.card-dialog::backdrop { background: rgba(10, 16, 22, 0.55); }
.card-dialog h2 { margin: 0 0 4px; }
.dialog-sub { margin: 0 0 12px; color: #6b7b89; font-size: 15px; }
.card-list fieldset { border: 0; padding: 0; margin: 0 0 14px; }
.card-list legend { font-weight: 700; color: var(--brand); padding: 0; margin-bottom: 4px; }
.card-check { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 4px 0; cursor: pointer; }
.card-check input { width: 24px; height: 24px; accent-color: var(--brand); }
.card-check span { display: flex; flex-direction: column; }
.card-check small { color: #6b7b89; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; }
.dialog-actions .primary { min-height: 48px; padding: 0 24px; font-size: 16px; font-weight: 700;
  color: #fff; background: var(--brand); border: 0; border-radius: 12px; cursor: pointer; }

/* --- trip total + ticker ------------------------------------------------- */
.ticker-actions { display: flex; gap: 14px; }
.trip-totals { display: flex; flex-direction: column; gap: 6px; }
.trip-cat, .trip-grand { display: flex; justify-content: space-between; align-items: baseline; font-size: 17px; }
.trip-cat b, .trip-grand b { font-variant-numeric: tabular-nums; }
.trip-grand { margin-top: 6px; padding-top: 10px; border-top: 2px solid #e3e8ec;
  font-size: 20px; font-weight: 800; color: var(--brand); }

.ticker-list { display: flex; flex-direction: column; gap: 8px; }
.tk-row { display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: 12px; background: rgba(20, 32, 43, 0.03); }
.tk-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.tk-amount { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tk-amount span { color: #6b7b89; margin: 0 4px; }
.tk-label { align-self: flex-start; background: none; border: 0; padding: 4px 0; min-height: 36px;
  color: var(--brand); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.tk-note { color: #6b7b89; font-weight: 400; }
.tk-edit { display: flex; flex-direction: column; gap: 6px; }
.tk-edit input { font-size: 16px; min-height: 44px; padding: 6px 10px;
  border: 2px solid #c7d2dc; border-radius: 10px; background: var(--card); color: var(--ink); }
.tk-right { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.tk-buy { min-height: 44px; padding: 0 14px; font-size: 14px; font-weight: 700; cursor: pointer;
  color: #fff; background: var(--brand); border: 0; border-radius: 10px; }
.tk-buy:focus-visible, .tk-undo:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tk-cats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 4px; }
.tk-cats button { min-height: 40px; font-size: 13px; cursor: pointer; white-space: nowrap;
  background: var(--card); border: 1px solid #c7d2dc; border-radius: 8px; color: var(--ink); }
.tk-bought { font-size: 14px; font-weight: 700; color: var(--ok); }
.tk-undo { background: none; border: 0; color: #6b7b89; font: inherit; font-size: 13px;
  text-decoration: underline; cursor: pointer; min-height: 32px; }
.privacy { margin: 0; font-size: 12px; color: #6b7b89; line-height: 1.4; }

@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1620; --ink: #e7eef4; --card: #16222e; --brand: #7db7d8; }
  .status, .ccy, .manual label { color: #9fb2c2; }
  .chip.active { background: #1f3240; }
  .to { background: rgba(125, 183, 216, 0.12); }
  .manual input, .chip { border-color: #2c3e4d; }
  .muted, .estimate, .rank-sub, .rank-cost small, .dialog-sub, .card-check small { color: #9fb2c2; }
  .dcc { background: #2c2510; color: #f0d99a; border-color: #5a4a1c; }
  .rank-row { background: rgba(125, 183, 216, 0.06); }
  .badge.unver { background: #2c3e4d; color: #9fb2c2; }
  .scan { background: rgba(125, 183, 216, 0.10); }
  .tk-row { background: rgba(125, 183, 216, 0.06); }
  .tk-edit input, .tk-cats button { border-color: #2c3e4d; }
  .trip-grand { border-color: #2c3e4d; }
  .tk-note, .tk-amount span, .privacy, .tk-undo { color: #9fb2c2; }
  .adslot { border-color: #2c3e4d; }
}

/* Accessibility: honour reduced-motion — drop the tactile transforms. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .swap:active, .refresh:active, .scan:active, #installBtn:active, .chip:active { transform: none !important; }
}
