/* Colours come from Telegram's theme params so the app matches whatever
   theme the user is running. The fallbacks after each var() are what you get
   in a plain browser during development. */

:root {
  --bg:        var(--tg-theme-bg-color, #ffffff);
  --text:      var(--tg-theme-text-color, #000000);
  --hint:      var(--tg-theme-hint-color, #707579);
  --link:      var(--tg-theme-link-color, #2481cc);
  --button:    var(--tg-theme-button-color, #2481cc);
  --button-tx: var(--tg-theme-button-text-color, #ffffff);
  --card:      var(--tg-theme-section-bg-color, #ffffff);
  --group:     var(--tg-theme-secondary-bg-color, #efeff4);
  --header:    var(--tg-theme-section-header-text-color, #6d6d72);
  --danger:    var(--tg-theme-destructive-text-color, #df3f40);
  --sep:       color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 12px;
  --tab-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The `hidden` attribute is only a UA-stylesheet `display: none`, so ANY author
 * rule that sets `display` silently defeats it -- .sheet and .tabs below both
 * do. Without this, the sheet stays on screen with its full-screen backdrop
 * swallowing every tap. Keep this rule above anything that sets display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--group);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }

.view { padding: 12px 12px 20px; max-width: 640px; margin: 0 auto; }

/* ---------- typography ---------- */
h1 { font-size: 20px; margin: 4px 0 14px; font-weight: 600; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
     color: var(--header); margin: 20px 4px 8px; font-weight: 600; }
.hint { color: var(--hint); font-size: 14px; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- grouped list, the iOS/Telegram idiom ---------- */
.group { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.group + .group { margin-top: 14px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; min-height: 48px;
  background: none; border: 0; width: 100%;
  color: inherit; font: inherit; text-align: left;
  cursor: pointer;
}
.row + .row { box-shadow: inset 0 .5px 0 var(--sep); }
.row:active { background: var(--group); }
.row[disabled], .row.static { cursor: default; }
.row.static:active { background: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { display: block; }
.row .sub { display: block; color: var(--hint); font-size: 13px; margin-top: 2px; }
.row .value { color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .chev { color: var(--hint); opacity: .5; }
.row.danger .title { color: var(--danger); }
.row .lead { width: 26px; text-align: center; flex: none; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- hero ---------- */
.hero { background: var(--card); border-radius: var(--radius); padding: 18px 16px; text-align: center; }
.hero .label { color: var(--hint); font-size: 13px; }
.hero .delta { color: var(--hint); font-size: 14px; margin-top: 6px; }

/* ---------- buttons ---------- */
.btn {
  display: block; width: 100%; padding: 14px;
  border: 0; border-radius: var(--radius);
  background: var(--button); color: var(--button-tx);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { opacity: .85; }
.btn[disabled] { opacity: .4; cursor: default; }
.btn.secondary { background: var(--card); color: var(--link); }
.btn.danger { background: var(--card); color: var(--danger); }
.btn + .btn { margin-top: 10px; }

/* ---------- chip grid (cards, categories, multipliers) ---------- */
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.chip {
  padding: 12px 8px; border: 0; border-radius: var(--radius);
  background: var(--card); color: inherit; font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.chip:active { opacity: .7; }
.chip .name { font-weight: 500; font-size: 15px; max-width: 100%; }
.chip .mult { font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--button); color: var(--button-tx); }
.chip.on .mult { color: var(--button-tx); opacity: .8; }

/* ---------- amount entry + keypad ---------- */
.amount { text-align: center; padding: 22px 0 10px; }
.amount .figure { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amount .ctx { color: var(--hint); font-size: 14px; margin-top: 6px; }
.amount .earn { margin-top: 8px; font-weight: 600; color: var(--link); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.key {
  padding: 16px 0; border: 0; border-radius: var(--radius);
  background: var(--card); color: inherit;
  font: inherit; font-size: 24px; font-weight: 500; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.key:active { background: var(--group); }

/* ---------- inputs ---------- */
.field { padding: 10px 14px; background: var(--card); }
.field label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.field input {
  width: 100%; border: 0; background: none; color: inherit;
  font: inherit; padding: 4px 0; outline: none;
}
.field + .field { box-shadow: inset 0 .5px 0 var(--sep); }

/* ---------- bottom tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg); box-shadow: inset 0 .5px 0 var(--sep);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; height: var(--tab-h);
  font: inherit; font-size: 10px; color: var(--hint);
}
.tab span { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .55; }
.tab.on { color: var(--link); }
.tab.on span { filter: none; opacity: 1; }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-body {
  position: relative; width: 100%; max-height: 82vh; overflow-y: auto;
  background: var(--group); border-radius: 16px 16px 0 0;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6 } to { transform: none; opacity: 1 } }
.sheet h3 { margin: 2px 4px 12px; font-size: 17px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 18px);
  transform: translateX(-50%); z-index: 40;
  background: rgba(0,0,0,.84); color: #fff;
  padding: 10px 16px; border-radius: 20px; font-size: 14px;
  max-width: 86vw; text-align: center;
}
.toast.bad { background: var(--danger); }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--hint); padding: 40px 20px; }
.empty .icon { font-size: 40px; display: block; margin-bottom: 10px; }
.pager { display: flex; gap: 8px; margin-top: 12px; align-items: center; justify-content: center; }
.pager button { flex: 1; }
.pager .of { color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.bar { height: 4px; border-radius: 2px; background: var(--button); opacity: .85; margin-top: 6px; }
.spin { text-align: center; padding: 50px; color: var(--hint); }

/* ---------- export / import textarea ---------- */
.dump {
  width: 100%; height: 34vh; resize: vertical;
  background: var(--card); color: var(--text);
  border: 0; border-radius: var(--radius); padding: 12px;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  outline: none;
}
