/*
 * Amber Mini App.
 *
 * Colours come from Telegram's theme variables so the app matches whatever the
 * user runs; the fallbacks only matter when the page is opened in a plain
 * browser. Amber's own accent is used sparingly — for the brand mark and for
 * state that has to read as "ours" rather than as "Telegram's".
 */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #10151a);
  --hint: var(--tg-theme-hint-color, #79838d);
  --card: var(--tg-theme-secondary-bg-color, #f2f4f7);
  --link: var(--tg-theme-link-color, #2a6cb8);
  --button: var(--tg-theme-button-color, #2a6cb8);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --section: var(--tg-theme-section-bg-color, var(--card));
  --separator: color-mix(in srgb, var(--hint) 22%, transparent);
  /*
   * Telegram's own hint colour lands around 3.4:1 on its card background,
   * which fails WCAG AA for the 12-13px labels that carry half this screen.
   * Deriving from it rather than hardcoding a grey keeps the app inside
   * whatever theme the user picked while making the small type readable.
   */
  --hint-strong: color-mix(in srgb, var(--hint) 72%, var(--text));
  /*
   * Accent and danger are used as text on a 14% tint of themselves, which in
   * a light theme lands near 2:1. These keep the hue and add the contrast;
   * because they mix toward --text they flip with the theme on their own.
   */
  --accent-ink: color-mix(in srgb, var(--accent) 55%, var(--text));
  --danger-ink: color-mix(in srgb, var(--danger) 62%, var(--text));
  /* Link text sits on --card, not on the page, which costs it contrast. */
  --link-ink: color-mix(in srgb, var(--link) 58%, var(--text));

  --accent: #e2941f;
  --accent-soft: color-mix(in srgb, #e2941f 14%, transparent);
  --danger: #d5544c;

  --radius: 14px;
  --radius-sm: 10px;
  --gap: 12px;
  --pad: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f1f5f9);
    --hint: var(--tg-theme-hint-color, #8b98a5);
    --card: var(--tg-theme-secondary-bg-color, #1f2b38);
    --accent: #f0a63a;
  }
}

* { box-sizing: border-box; }

/* Telegram renders this inside a native view: the browser's blue focus ring and
   tap highlight read as rendering glitches there, not as affordances. Keyboard
   focus keeps a visible ring through :focus-visible. */
button, input {
  -webkit-tap-highlight-color: transparent;
}

/* A long press on a control should feel like holding a button, not like
   selecting a word. Deliberately not applied to the archive itself: the whole
   point of a recovered message is being able to copy it. */
button, .tab, .chip {
  -webkit-user-select: none;
  user-select: none;
}

button:focus:not(:focus-visible) { outline: none; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ header */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 12px var(--pad);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--separator);
}

.brand { display: flex; align-items: center; gap: 9px; }

.mark { width: 21px; height: 21px; display: block; }

.name { font-weight: 650; letter-spacing: -0.01em; }

.plan-chip {
  border: 0;
  /* Reads as a badge but is a real button into the plan tab, so it needs a
     thumb-sized target rather than a badge-sized one. */
  min-height: 40px;
  padding: 5px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  /* Amber on a 14% amber tint is barely 2:1; mixing toward the text colour
     keeps it unmistakably ours and actually legible. */
  color: color-mix(in srgb, var(--accent) 58%, var(--text));
  background: var(--accent-soft);
  cursor: pointer;
}

/* -------------------------------------------------------------------- view */

.view { padding: var(--pad); display: grid; gap: var(--gap); }

.section-title {
  margin: 6px 2px 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--hint-strong);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 14px;
}

.card + .card { margin-top: -2px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.muted { color: var(--hint-strong); }
.small { font-size: 13px; }
.strong { font-weight: 600; }

.empty {
  padding: 44px 24px;
  text-align: center;
  color: var(--hint-strong);
  font-size: 14px;
}

/* ------------------------------------------------------- first run/connect */

/*
 * Shown instead of the archive while no connection exists. Centred in the
 * viewport rather than pinned to the top: on an empty first run there is
 * nothing else on screen, and a lone paragraph under the header reads as a
 * loading failure.
 */
.connect {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 24px;
  text-align: center;
}

.connect-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.connect-body {
  font-size: 14px;
  line-height: 1.45;
  color: var(--hint);
  max-width: 32ch;
}

.connect-cta {
  margin-top: 8px;
  border: 0;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  color: var(--button-text);
  background: var(--accent);
  cursor: pointer;
}

.connect-cta:active {
  opacity: 0.85;
}

/* ------------------------------------------------------------ fox / levels */

.fox-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.fox {
  width: 64px;
  height: 64px;
  flex: none;
  /* The resin glow is the only thing that says "this is amber" at small size. */
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 30%, transparent));
}

.fox-body {
  min-width: 0;
  flex: 1;
}

.fox-track {
  margin-top: 8px;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 22%, transparent);
  overflow: hidden;
}

.fox-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .4s ease;
}

.fox-pips {
  display: flex;
  gap: 5px;
  margin-top: 8px;
}

.fox-pip {
  width: 16px;
  height: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 30%, transparent);
}

.fox-pip.on { background: var(--accent); }

/* --------------------------------------------------------------- referral */

.ref-counts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.ref-count {
  text-align: center;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--hint) 10%, transparent);
}

.ref-count-n {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
}

.ref-count-l {
  font-size: 11px;
  color: var(--hint-strong);
  margin-top: 2px;
}

.ref-earned {
  margin: 12px 0 8px;
}

.ref-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--separator);
  font-size: 14px;
}

.ref-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-stage {
  font-size: 12px;
  color: var(--hint-strong);
  flex: none;
}

/* Clicked a link, actually connected, actually paid — the three states the
   bonus depends on, and the reason the screen is not a single number. */
.ref-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex: none;
  background: var(--hint);
}

.ref-dot.connected { background: var(--accent); }
.ref-dot.paid { background: #4db6ac; }

/* ------------------------------------------------------------------ search */

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--card);
  border-radius: var(--radius);
}

.search svg { width: 17px; height: 17px; flex: none; stroke: var(--hint); }

.search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 12px 0;
  min-width: 0;
}

.search input::placeholder { color: var(--hint); }

/* ------------------------------------------------------------------ chips */

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  border: 0;
  /* 44px is the smallest target a thumb hits reliably; these are the most
     tapped controls on the screen, so they get it even though the label is
     small enough to fit in less. */
  min-height: 44px;
  padding: 7px 15px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  color: var(--hint-strong);
  background: var(--card);
  cursor: pointer;
  transition: color .15s, background .15s;
}

.chip[aria-selected="true"] {
  color: var(--button-text);
  background: var(--button);
  font-weight: 600;
}

/* ------------------------------------------------------------------ events */

.event { display: grid; gap: 7px; }

.event .head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
}

.event .who { font-weight: 600; }
.event .when { margin-left: auto; color: var(--hint-strong); font-size: 12px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 2px 7px;
  border-radius: 6px;
  text-transform: lowercase;
}

.badge.deleted { color: var(--danger-ink); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.badge.edited  { color: var(--accent-ink); background: var(--accent-soft); }

.quote {
  margin: 0;
  padding-left: 10px;
  border-left: 2px solid var(--separator);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.quote.was { border-left-color: var(--danger); }
.quote.now { border-left-color: var(--accent); }

.event .media {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--hint);
}

.thumb {
  margin-top: 4px;
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
}

/* ---------------------------------------------------------------- commands */

.cmd { display: grid; gap: 4px; cursor: pointer; }

.cmd .line { display: flex; align-items: center; gap: 8px; }

.cmd code {
  font: 600 13.5px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 7px;
}

.cmd.locked code { color: var(--hint-strong); background: var(--separator); }

.lock { margin-left: auto; font-size: 11px; color: var(--hint-strong); }

/* ------------------------------------------------------------------ chats */

.chat-actions { display: flex; gap: 8px; margin-top: 11px; }

.counts { display: flex; gap: 8px; font-size: 12.5px; color: var(--hint-strong); }
.counts b { font-weight: 620; color: var(--text); }

.pill {
  border: 0;
  /* These carry the chat actions, including taking a chat off watch. A
     destructive action on a 33px target is a mis-tap waiting to happen. */
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background: color-mix(in srgb, var(--hint) 14%, transparent);
  color: var(--text);
  white-space: nowrap;
}

.pill.danger { color: var(--danger-ink); }
.pill.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* ------------------------------------------------------------------- plan */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 14px;
}

.stat b { display: block; font-size: 21px; font-weight: 680; letter-spacing: -0.02em; }
.stat span { font-size: 12.5px; color: var(--hint-strong); }

.tier {
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.tier.current { border-color: var(--accent); background: var(--accent-soft); }

.tier h3 { margin: 0; font-size: 16px; font-weight: 650; }
.tier ul { margin: 0; padding-left: 18px; color: var(--hint-strong); font-size: 13.5px; }
.tier li { margin: 3px 0; }

.buy {
  width: 100%;
  border: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 620;
  color: var(--button-text);
  background: var(--button);
  cursor: pointer;
}

.buy.ghost { background: transparent; color: var(--link); border: 1px solid var(--separator); }

/* The switch reads best at 26px but a 26px target does not. ::before widens
   the hit area to 44px without moving a pixel of the visible control — the
   knob already owns ::after. */
.toggle::before {
  content: "";
  position: absolute;
  inset: -9px -6px;
}

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 35%, transparent);
  cursor: pointer;
  transition: background .18s;
  flex: none;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}

.toggle[aria-pressed="true"] { background: var(--accent); }
.toggle[aria-pressed="true"]::after { transform: translateX(18px); }

/* -------------------------------------------------------------------- nav */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--separator);
}

.tab {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 7px 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  /* The tab bar is the app's only navigation; an unselected label still has
     to be readable, not a hint. */
  color: var(--hint-strong);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: color .15s;
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab[aria-selected="true"] { color: var(--accent); }

/* ---------------------------------------------------------------- loading */

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(90deg,
    var(--card) 25%,
    color-mix(in srgb, var(--card) 60%, var(--hint) 12%) 37%,
    var(--card) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

.skeleton.line { height: 13px; margin: 7px 0; }
.skeleton.block { height: 76px; }

@keyframes shimmer {
  from { background-position: 100% 0; }
  to   { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  * { transition: none !important; }
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 30;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--button-text);
  background: color-mix(in srgb, var(--text) 82%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.more {
  width: 100%;
  border: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--link-ink);
  background: var(--card);
  cursor: pointer;
}
