:root {
  --primary: #c9a227;
  --primary-dark: #a88620;
  --primary-soft: #1e222d;
  --positive: #34d399;
  --negative: #f87171;
  --neutral: #787b86;
  --bg: #131722;
  --surface: #131722;
  --surface-variant: #1e222d;
  --border: rgba(201, 162, 39, 0.22);
  --divider: #2a2e39;
  --best-bg: #1e222d;
  --text: #d1d4dc;
  --text-2: #c5c8d0;
  --text-3: #b2b5be;
  --tab-idle: #b2b5be;
  --on-primary: #131722;
  --nav-inactive: #b2b5be;
  --skeleton: #1e222d;
  --input-outline: #787b86;
  --font: Roboto, Inter, system-ui, sans-serif;
  --font-num: "Trebuchet MS", Ubuntu, Roboto, sans-serif;
  --radius: 14px;
  --radius-chart: 16px;
  --pad-h: 16px;
  --pad-top: 16px;
  --pad-bottom: 16px;
  --section-gap: 22px;
  --fs-header: 19px;
  --fs-title: 18px;
  --fs-section: 18px;
  --fs-body: 16px;
  --fs-table: 16px;
  --fs-caption: 15px;
  --fs-meta: 15px;
  --fs-change: 13px;
  --fs-big: 28px;
  --fs-tab: 16px;
}

/* iPhone: Safari vẽ nhỏ hơn Android — chỉ tăng nội dung, không phá cấp bậc. */
@supports (-webkit-touch-callout: none) {
  @media (hover: none) and (pointer: coarse) {
    :root {
      --fs-header: 19px;
      --fs-title: 18px;
      --fs-section: 19px;
      --fs-body: 16px;
      --fs-table: 17px;
      --fs-caption: 16px;
      --fs-meta: 15px;
      --fs-change: 14px;
      --fs-big: 30px;
      --fs-tab: 16px;
    }
  }
}

html[data-theme="dark"] {
  --primary: #c9a227;
  --primary-dark: #a88620;
  --primary-soft: #1e222d;
  --positive: #34d399;
  --negative: #f87171;
  --neutral: #787b86;
  --bg: #131722;
  --surface: #131722;
  --surface-variant: #1e222d;
  --border: rgba(201, 162, 39, 0.22);
  --divider: #2a2e39;
  --best-bg: #1e222d;
  --text: #d1d4dc;
  --text-2: #c5c8d0;
  --text-3: #b2b5be;
  --tab-idle: #b2b5be;
  --on-primary: #131722;
  --nav-inactive: #b2b5be;
  --skeleton: #1e222d;
  --input-outline: #787b86;
}

html[data-theme="light"] {
  --primary: #9A8010;
  --primary-dark: #6F5C0A;
  --primary-soft: #F5F2E8;
  --positive: #047857;
  --negative: #DC2626;
  --neutral: #52525B;
  --bg: #F2F2F3;
  --surface: #FFFFFF;
  --surface-variant: #EBEBED;
  --border: #D4D4D8;
  --divider: #E4E4E7;
  --best-bg: #F0F0F2;
  --text: #09090B;
  --text-2: #3F3F46;
  --text-3: #52525B;
  --tab-idle: #3F3F46;
  --on-primary: #FFFFFF;
  --nav-inactive: #52525B;
  --skeleton: #E4E4E7;
  --input-outline: #A1A1AA;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, Inter, system-ui, sans-serif;
  font-size: 16px;
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
html[data-theme="light"] { color-scheme: light; }
body { overscroll-behavior-y: contain; }
button, input { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

.app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
.screen.is-on { display: flex; }

.hub-head, .page-head {
  display: flex;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 0 16px;
  gap: 8px;
  flex-shrink: 0;
}
.hub-head {
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 2px max(14px, env(safe-area-inset-left, 0px));
  gap: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(165deg, #2c2618 0%, #1e222d 100%);
  border: 1px solid rgba(201, 162, 39, 0.38);
}
html[data-theme="light"] .brand-mark {
  background: linear-gradient(165deg, #FBF6E4 0%, #F5F2E8 100%);
  border-color: rgba(154, 128, 16, 0.32);
}
.brand-mark svg { width: 20px; height: 20px; display: block; }
.brand-text { min-width: 0; }
.hub-head h1,
.page-head h1,
.head-back span {
  margin: 0;
  min-width: 0;
  font-size: var(--fs-header);
  font-weight: 500;
  letter-spacing: -0.35px;
  line-height: 1.2;
  color: var(--text);
}
.hub-head h1 { flex: none; }
.page-head h1,
.head-back span { flex: 1; }
.brand-meta {
  margin: 3px 0 0;
  font-size: var(--fs-body);
  line-height: 1.25;
  color: var(--text-2);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.theme-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 1px solid var(--border);
  background: var(--surface-variant);
  color: var(--text);
  border-radius: 12px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.theme-btn svg { width: 20px; height: 20px; fill: currentColor; }
.theme-btn:active { opacity: 0.82; }
.page-head {
  padding: calc(6px + env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) 6px max(4px, env(safe-area-inset-left, 0px));
}
.head-back {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 8px 12px 8px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.head-back svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}
.head-back:active {
  background: var(--surface-variant);
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  border-radius: 12px;
  display: grid;
  place-items: center;
  padding: 8px;
  cursor: pointer;
}
.page-head .btn-back {
  color: var(--text);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-sun, .icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: block; }
html[data-theme="light"] .icon-moon { display: block; }
.icon-btn:active { background: var(--surface-variant); color: var(--text); }

.tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  padding: 0 max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
  position: relative;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scroll-padding-inline: 12px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  appearance: none;
  position: relative;
  border: 0;
  background: transparent;
  color: var(--tab-idle);
  font-size: var(--fs-tab);
  font-weight: 400;
  line-height: 1.15;
  padding: 12px 10px 11px;
  min-height: 44px;
  border-radius: 0;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: -0.15px;
  -webkit-tap-highlight-color: transparent;
}
.tab.is-on {
  background: transparent;
  color: var(--primary);
  font-weight: 500;
}
.tab.is-on::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 2.5px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}
.tab:active { opacity: 0.88; }

.pager {
  flex: 1;
  min-height: 0;
  height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.page {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px max(var(--pad-h), env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(var(--pad-h), env(safe-area-inset-left, 0px));
}
.page.is-on {
  display: block;
  height: 100%;
}
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 16px max(var(--pad-h), env(safe-area-inset-right, 0px)) calc(var(--pad-bottom) + env(safe-area-inset-bottom, 0px)) max(var(--pad-h), env(safe-area-inset-left, 0px));
}

.title { font-size: var(--fs-title); font-weight: 500; letter-spacing: -0.2px; line-height: 1.25; margin: 0; color: var(--text); }
.section {
  font-size: var(--fs-section);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
  letter-spacing: -0.2px;
}
.caption,
.hint {
  margin: 0;
  font-size: var(--fs-caption);
  line-height: 1.4;
  color: var(--text-2);
  font-weight: 400;
}
.stamp {
  margin: 0;
  font-size: var(--fs-body);
  line-height: 1.35;
  color: var(--text-2);
  font-weight: 400;
}
.tip-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-variant);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-body);
  line-height: 1.4;
}
.tip-line svg {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  fill: var(--primary);
}
.tip-line + section { margin-top: 20px; }
.brand-cell {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.brand-cell:active { background: var(--surface-variant); }
.brand-cell .table-brand { flex: 1; min-width: 0; }
.row-chevron {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  fill: var(--text-3);
}
.body { font-size: var(--fs-body); color: var(--text-2); line-height: 1.35; }
.label { font-size: var(--fs-body); color: var(--text); }
.label-em { font-size: var(--fs-body); font-weight: 400; color: var(--text); }
.table-brand {
  font-size: var(--fs-table);
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.table {
  font-family: var(--font-num);
  font-size: var(--fs-table);
  font-weight: 400;
  color: var(--text);
  letter-spacing: 0;
  line-height: 22px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.table-h { font-size: 15px; font-weight: 500; color: var(--text-2); }
.change {
  font-family: var(--font-num);
  font-size: var(--fs-change);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 16px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.big {
  font-family: var(--font-num);
  font-size: var(--fs-big);
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.settings-sec {
  font-size: var(--fs-caption);
  font-weight: 400;
  color: var(--text-2);
  letter-spacing: 0.04em;
  margin: 18px 0 8px;
}
.up { color: var(--positive); }
.down { color: var(--negative); }
.flat { color: var(--text-3); }
.neutral { color: var(--neutral); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-pad { padding: 12px; }
.card-pad-sm { padding: 10px; }
.mt-10 { margin-top: 10px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }
.mt-18 { margin-top: 18px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.gap-sec { margin-top: var(--section-gap); }

.row {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px;
  gap: 0;
}
.row-tap { cursor: pointer; }
.row-tap:active { background: var(--surface-variant); }
.col { min-width: 0; }
.col-grow { flex: 1; min-width: 0; }
.end { text-align: right; }
.price-line {
  min-height: 22px;
  line-height: 22px;
  white-space: nowrap;
}
.divider { height: 1px; background: var(--divider); margin: 0 10px; }
.divider-full { height: 1px; background: var(--divider); }
.card > .divider,
.card > .divider-full {
  display: none;
}

.thead, .trow, .fav-row {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(5.75rem, 1fr) minmax(5.75rem, 1fr);
  align-items: center;
  column-gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
}
.thead {
  min-height: 40px;
  padding-top: 8px;
  padding-bottom: 8px;
}
.trow, .fav-row {
  min-height: 64px;
  padding: 10px 12px;
  border-top: 1px solid var(--divider);
  cursor: default;
}
.trow .cell { cursor: default; pointer-events: none; }
.thead .sort {
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  text-align: right;
  padding: 0;
  cursor: pointer;
  width: 100%;
  min-height: 32px;
}
.cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  text-align: right;
  padding: 0;
  min-width: 0;
  overflow: visible;
}
.cell.is-best { background: var(--best-bg); border-radius: 6px; padding: 4px 6px; }
.best-row { background: var(--best-bg); }

.fav-row {
  cursor: pointer;
}
.fav-row .change {
  display: block;
  min-height: 16px;
}
.fav-row .change:empty { display: none; }
.fav-spot {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 10px;
  cursor: pointer;
  gap: 10px;
}
.fav-spot .meta { flex: 1; min-width: 0; padding-right: 8px; }
.fav-spot .cell { flex: 0 1 auto; min-width: 0; max-width: 48%; }
.kind { font-size: var(--fs-caption); color: var(--text-2); }
.change:empty { display: none; }

.news-item {
  padding: 12px 12px;
  cursor: pointer;
  min-height: 56px;
  border-top: 1px solid var(--divider);
}
.card > .news-item:first-child { border-top: 0; }
.news-item:active { background: var(--surface-variant); }
.pill {
  display: inline-block;
  font-size: var(--fs-caption);
  font-weight: 400;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 12px;
  padding: 2px 8px;
}
.news-item .ttl {
  margin-top: 6px;
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-item .meta { margin-top: 4px; }

.more {
  width: 100%;
  appearance: none;
  background: none;
  border: 0;
  border-top: 1px solid var(--divider);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 400;
  padding: 12px 12px;
  text-align: right;
  cursor: pointer;
}
.charts-toggle {
  display: block;
  width: 100%;
  appearance: none;
  background: none;
  border: 0;
  margin-top: 8px;
  padding: 14px 4px 6px;
  color: var(--primary);
  font-size: var(--fs-body);
  font-weight: 400;
  text-align: center;
  cursor: pointer;
}
.charts-toggle:active { opacity: 0.75; }
.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  font-size: var(--fs-body);
  font-weight: 400;
  cursor: pointer;
}
.btn-out {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-fill {
  background: var(--primary);
  border: 0;
  color: var(--on-primary);
}
.btn + .btn { margin-top: 8px; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 36px;
  font-size: var(--fs-caption);
  font-weight: 400;
  cursor: pointer;
}
.chip.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #131722;
}

.tv-frame {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-chart);
  overflow: hidden;
  border: 1px solid var(--divider);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.tv-frame iframe {
  display: block;
  width: 100%;
  border: 0;
  background: var(--surface);
  pointer-events: none;
}
.tv-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.quick-row {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 10px 4px;
  gap: 8px;
}
.quick-row .name { flex: 1; min-width: 0; }
.quick-row .val { flex: 0.85; text-align: right; }
.quick-row .chg { flex: 0.55; text-align: right; }

.deposit-head, .deposit-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.9fr) minmax(0, 0.8fr);
  align-items: center;
  column-gap: 8px;
  padding: 8px 12px;
  min-height: 40px;
}
.deposit-row {
  min-height: 56px;
  padding: 10px 12px;
  border-top: 1px solid var(--divider);
}
.deposit-head button {
  border: 0; background: none; color: var(--text-2);
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; text-align: inherit;
  width: 100%; min-height: 32px; padding: 0;
}

.idx-card { padding: 12px; margin-bottom: 10px; }
.idx-top { display: flex; justify-content: space-between; align-items: center; }
.idx-top .name { font-size: var(--fs-caption); font-weight: 400; color: var(--text-2); }
.idx-mid { display: flex; align-items: center; margin-top: 4px; gap: 8px; }
.idx-mid .left { flex: 1; min-width: 0; }
.spark { width: 64px; height: 32px; flex-shrink: 0; }
.mover {
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 12px;
  gap: 8px;
  border-top: 1px solid var(--divider);
}
.card > .mover:first-child { border-top: 0; }
.mover .rank { width: 28px; text-align: center; color: var(--text-3); font-size: var(--fs-caption); }
.mover .sym { flex: 1; font-weight: 400; font-size: var(--fs-body); }
.mover .px { flex: 0.7; min-width: 0; text-align: right; font-weight: 400; }
.mover .pct { flex: 0.65; min-width: 0; text-align: right; }

.cover {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--surface-variant);
}
.news-headline {
  font-size: var(--fs-title);
  font-weight: 500;
  line-height: 1.25;
  margin: 10px 0 0;
}
.summary { font-size: var(--fs-body); color: var(--text-2); line-height: 1.2; white-space: pre-wrap; user-select: text; }
.source-box { margin-top: 16px; }
.link-btn {
  display: inline-block;
  margin-top: 6px;
  color: var(--primary-dark);
  font-weight: 400;
  font-size: var(--fs-body);
}

.input {
  width: 100%;
  box-sizing: border-box;
  margin-top: 12px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  font-family: inherit;
  outline: none;
}
.input:focus { border-color: var(--primary); }
.detail-table { margin-bottom: 16px; }
.detail-table .src { margin-top: 6px; }
.alt { background: transparent; }

.set-card { overflow: hidden; }
.set-row {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  gap: 12px;
  cursor: pointer;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-body);
  text-align: left;
}
.set-row:active { background: var(--surface-variant); }
.set-row .grow { flex: 1; }
.switch {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--border);
  position: relative;
  flex-shrink: 0;
  border: 0;
  cursor: pointer;
}
.switch.is-on { background: var(--primary); }
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform .15s;
}
.switch.is-on::after { transform: translateX(20px); }

.skel {
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--surface-variant) 50%, var(--skeleton) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 10px;
}
.skel-a { height: 72px; }
.skel-b { height: 120px; margin-top: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty, .error-card {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.offline-banner {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: var(--fs-caption);
  color: var(--text-2);
  margin-bottom: 10px;
}

.detail-table .thead,
.detail-table .trow {
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 1fr);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: #27272a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: var(--fs-caption);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  max-width: min(480px, calc(100% - 32px));
}
.toast.show { opacity: 1; }

.dialog-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.dialog {
  width: min(420px, 100%);
  background: var(--surface);
  color: var(--text);
  border-radius: 16px;
  padding: 8px 0;
  margin-bottom: 24px;
}
.dialog h3 { margin: 12px 16px; font-size: var(--fs-section); }
.dialog button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: var(--text);
  font-size: var(--fs-body);
  padding: 14px 16px;
  cursor: pointer;
}
.dialog button:active { background: var(--surface-variant); }

.legal { font-size: var(--fs-caption); color: var(--text-2); line-height: 1.4; margin-top: 20px; }
.footer {
  color: var(--text-2);
  border-top: 0;
  margin-top: 20px;
  padding: 8px 0 12px;
  font-size: var(--fs-caption);
  line-height: 1.4;
}
.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.footer p {
  margin: 0;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
}
.footer a {
  color: var(--text-3);
  text-decoration: none;
  font-size: inherit;
}
.footer a:hover {
  color: var(--text);
  text-decoration: underline;
}
.hidden { display: none !important; }
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 320–359: iPhone SE gen 1, máy siêu nhỏ */
@media (max-width: 359.98px) {
  :root {
    --pad-h: 12px;
    --fs-header: 18px;
    --fs-section: 16px;
    --fs-body: 15px;
    --fs-table: 15px;
    --fs-caption: 14px;
    --fs-meta: 14px;
    --fs-change: 12px;
    --fs-tab: 15px;
    --fs-big: 26px;
  }
  .brand-mark { width: 32px; height: 32px; flex-basis: 32px; }
  .brand-mark svg { width: 18px; height: 18px; }
  .theme-btn { width: 36px; height: 36px; flex-basis: 36px; }
  .thead, .trow, .fav-row, .deposit-head, .deposit-row { padding-left: 10px; padding-right: 10px; }
  .tab { padding-left: 8px; padding-right: 8px; min-height: 40px; }
}

/* 360+: Android phổ biến (Galaxy A, Redmi, Oppo) */
@media (min-width: 360px) {
  :root {
    --pad-h: 14px;
    --fs-header: 19px;
    --fs-section: 18px;
    --fs-table: 16px;
    --fs-tab: 16px;
    --fs-caption: 15px;
    --fs-change: 13px;
  }
}

/* 390+: iPhone 12–15, Pixel */
@media (min-width: 390px) {
  :root {
    --pad-h: 16px;
    --fs-header: 19px;
    --fs-section: 18px;
    --fs-body: 16px;
    --fs-table: 16px;
    --fs-caption: 15px;
    --fs-change: 13px;
    --fs-tab: 16px;
    --fs-big: 30px;
  }
}

/* 414+: iPhone Plus / Pro Max, Android lớn */
@media (min-width: 414px) {
  :root {
    --fs-header: 20px;
    --fs-table: 16px;
    --fs-tab: 16px;
    --fs-caption: 15px;
    --fs-section: 18px;
  }
  .spark { width: 72px; height: 36px; }
}

@supports (-webkit-touch-callout: none) {
  @media (hover: none) and (pointer: coarse) and (min-width: 390px) {
    :root {
      --fs-header: 19px;
      --fs-body: 17px;
      --fs-table: 17px;
      --fs-caption: 16px;
      --fs-change: 14px;
      --fs-tab: 16px;
      --fs-section: 19px;
    }
  }
}

/* Nằm ngang: dùng hết chiều ngang, gọn header */
@media (orientation: landscape) and (max-height: 500px) {
  .app { max-width: 100%; }
  .brand-mark { width: 28px; height: 28px; flex-basis: 28px; }
  .hub-head { padding-top: max(4px, env(safe-area-inset-top, 0px)); }
  .tab { min-height: 36px; padding-top: 8px; padding-bottom: 8px; }
  .page, .scroll { padding-top: 8px; }
  .tv-frame iframe { max-height: 42vh; }
}

@media (min-width: 481px) {
  .app {
    min-height: 100dvh;
    box-shadow: 0 0 0 1px var(--divider);
  }
}
