/* Дин mini app: one design system for every section.
   Colours are Telegram's own (themeParams → --tg-theme-*, updated live by telegram-web-app.js on themeChanged),
   with light/dark fallbacks for a plain browser. Type is an iOS-like scale; spacing sits on an 8px grid (4px half-steps);
   anything tappable is at least 44px tall. Class names below are shared by all sections: keep them. */
:root {
  /* Fallbacks for a page opened outside Telegram. */
  --fb-bg: #ffffff; --fb-bg2: #f2f2f7; --fb-text: #000000; --fb-hint: #8e8e93; --fb-link: #2470c2; --fb-accent: #2470c2;
  --fb-accent-text: #ffffff; --fb-danger: #d92d20;

  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint-raw: var(--tg-theme-hint-color, var(--fb-hint));
  --hint: var(--hint-raw);
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --sep: rgba(127, 127, 127, .22);
  --fill: rgba(127, 127, 127, .12);        /* quiet buttons, inputs, skeletons */
  --fill-strong: rgba(127, 127, 127, .2);
  --good: #1a7f4b;
  --warn: #a86200;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);

  /* Type scale (px): caption 12 · footnote 13 · subhead 15 · body 16 · headline 17 · title 22 · large title 30. */
  --fs-caption: 12px; --fs-foot: 13px; --fs-sub: 15px; --fs-body: 16px; --fs-head: 17px; --fs-title: 22px; --fs-large: 30px;
  /* Spacing: the 8px grid. */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 16px; --radius-s: 12px;
  --tap: 44px;

  /* Telegram's viewport and safe areas (set by telegram-web-app.js; the env() values for a plain browser). */
  --app-h: var(--tg-viewport-stable-height, 100vh);
  --safe-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
  --nav-h: 56px;                            /* the tab bar without the home-indicator inset; sections may use it */
  --bottom: calc(var(--nav-h) + var(--safe-bottom));
  color-scheme: light;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  /* Telegram's hint colour is often below AA on its own background: pull it 22% toward the text colour. */
  :root { --hint: color-mix(in srgb, var(--hint-raw) 78%, var(--text)); --sep: color-mix(in srgb, var(--hint-raw) 26%, transparent);
    --fill: color-mix(in srgb, var(--hint-raw) 14%, transparent); --fill-strong: color-mix(in srgb, var(--hint-raw) 24%, transparent); }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) { --fb-bg: #1c1c1e; --fb-bg2: #000000; --fb-text: #ffffff; --fb-hint: #98989f; --fb-link: #4da3ff;
    --fb-accent: #3e8ef7; --fb-danger: #ff6961; }
}
:root[data-scheme="dark"] { --good: #3fcf8e; --warn: #f2b33d; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25); color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-scheme]) { --good: #3fcf8e; --warn: #f2b33d; color-scheme: dark; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { overflow-x: hidden; overflow-x: clip; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg2); }
body { margin: 0; padding: 0; background: var(--bg2); color: var(--text); overflow-x: hidden; overflow-x: clip;
  font: var(--fs-body)/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; padding-top: var(--safe-top); padding-bottom: calc(var(--bottom) + var(--s2));
  padding-left: var(--safe-left); padding-right: var(--safe-right); min-height: var(--app-h); }
body.din-no-nav { padding-bottom: calc(var(--safe-bottom) + var(--s2)); }
#top:empty { display: none; }
main { padding: var(--s2) var(--s4) var(--s5); max-width: 720px; margin: 0 auto; min-height: 60vh; }
main > div { min-width: 0; }

h1 { font-size: var(--fs-large); line-height: 1.15; font-weight: 700; letter-spacing: -.02em; margin: var(--s2) var(--s1) var(--s3); overflow-wrap: anywhere; }
h2 { font-size: var(--fs-foot); line-height: 1.3; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: var(--s5) var(--s4) var(--s2); font-weight: 600; }
h3 { font-size: var(--fs-head); line-height: 1.3; font-weight: 600; margin: var(--s2) 0; }
p { margin: var(--s2) 0; }
a { color: var(--link); }
.hint { color: var(--hint); }
.small { font-size: var(--fs-foot); }
.card { background: var(--card); border-radius: var(--radius); padding: var(--s3) var(--s4); margin: 0 0 var(--s3); min-width: 0; overflow-wrap: anywhere; }
.row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; min-height: var(--tap); border-bottom: 1px solid var(--sep); }
.row:last-child { border-bottom: 0; }
.row .grow, .grow { flex: 1; min-width: 0; }
.row .title { overflow-wrap: anywhere; }
.row .sub, .sub { color: var(--hint); font-size: var(--fs-foot); overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.minus { color: var(--text); } .plus { color: var(--good); }

button, .btn { font: inherit; font-size: var(--fs-sub); font-weight: 500; border: 0; border-radius: var(--radius-s); padding: 10px var(--s4);
  min-height: var(--tap); background: var(--fill); color: var(--link); cursor: pointer; touch-action: manipulation;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; line-height: 1.25;
  transition: transform .12s ease, opacity .12s ease, background-color .2s ease; text-decoration: none; }
button:active:not(:disabled), .btn:active { transform: scale(.97); opacity: .8; }
button.main, .btn.main { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger, .btn.danger { color: var(--danger); }
button:disabled { opacity: .4; cursor: default; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-s); }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }

.chips { display: flex; gap: var(--s2); overflow-x: auto; padding: var(--s1) var(--s1) var(--s2); margin: 0 calc(-1 * var(--s1)); scrollbar-width: none;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.chips::-webkit-scrollbar { display: none; }
.chip { position: relative; flex: none; min-height: 36px; padding: 6px 14px; border-radius: 999px; background: var(--card); color: var(--text);
  font-size: var(--fs-sub); font-weight: 500; scroll-snap-align: start; white-space: nowrap; }
.chip::after { content: ""; position: absolute; inset: -4px -2px; }       /* a 44px finger target around a 36px pill */
.chip.on { background: var(--accent); color: var(--accent-text); }
input, select, textarea { font: inherit; font-size: var(--fs-body); color: var(--text); background: var(--fill); border: 0; border-radius: var(--radius-s);
  padding: 10px var(--s3); min-height: var(--tap); width: 100%; }
input::placeholder, textarea::placeholder { color: var(--hint); }
input[type="search"] { -webkit-appearance: none; appearance: none; }

.empty { text-align: center; color: var(--hint); padding: var(--s6) var(--s4); }
.bar { height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* -- the tab bar ------------------------------------------------------------------------------------------------ */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; height: var(--bottom);
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left); background: var(--bg); border-top: .5px solid var(--sep);
  transition: transform .25s ease; }
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) and (color: color-mix(in srgb, red 50%, blue)) {
  #tabs { background: color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
}
body.din-no-nav #tabs { transform: translateY(110%); }
#tabs a { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--hint); text-decoration: none; font-size: 11px; font-weight: 500; line-height: 1.1; letter-spacing: .01em; position: relative; }
#tabs a .i { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; font-size: 22px; line-height: 1;
  transition: transform .2s cubic-bezier(.2, .9, .3, 1.3); }
#tabs a .i svg { width: 26px; height: 26px; }
#tabs a .t { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
#tabs a.on { color: var(--accent); }
#tabs a.on .i { transform: scale(1.06); }
#tabs a:active .i { transform: scale(.88); }
#tabs a:focus-visible { outline-offset: -4px; }

/* -- page transitions --------------------------------------------------------------------------------------------- */
.din-page { min-width: 0; }
.din-in-fwd { animation: din-fwd .26s cubic-bezier(.2, .8, .2, 1) both; }
.din-in-back { animation: din-back .26s cubic-bezier(.2, .8, .2, 1) both; }
.din-in-fade { animation: din-fade .2s ease both; }
@keyframes din-fwd { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes din-back { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes din-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* -- «Ещё» -------------------------------------------------------------------------------------------------------- */
.din-more { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.din-tile { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2); background: var(--card); border-radius: var(--radius);
  padding: var(--s4); min-height: 128px; color: var(--text); text-decoration: none; min-width: 0; transition: transform .12s ease; }
.din-tile:active { transform: scale(.97); }
.din-tile .ic { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 22px;
  margin-bottom: var(--s1); }
.din-tile .ic svg { width: 24px; height: 24px; }
.din-tile b { font-size: var(--fs-head); font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.din-tile span { font-size: var(--fs-foot); color: var(--hint); line-height: 1.3; overflow-wrap: anywhere; }
.din-back { display: inline-flex; min-height: var(--tap); align-items: center; gap: 2px; color: var(--link); text-decoration: none;
  font-size: var(--fs-head); margin: 0 0 0 calc(-1 * var(--s1)); padding: 0 var(--s1); background: none; }

/* -- skeleton (Din.skeleton) -------------------------------------------------------------------------------------- */
.sk { display: block; border-radius: 8px; background: var(--fill); position: relative; overflow: hidden; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .35), transparent); animation: sk 1.3s ease-in-out infinite; }
:root[data-scheme="dark"] .sk::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .07), transparent); }
@keyframes sk { to { transform: translateX(100%); } }
.sk-title { height: 30px; width: 46%; margin: var(--s3) var(--s1) var(--s4); }
.sk-row { display: flex; gap: var(--s3); align-items: center; padding: var(--s3) 0; }
.sk-row + .sk-row { border-top: 1px solid var(--sep); }
.sk-dot { width: 36px; height: 36px; border-radius: 10px; flex: none; }
.sk-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.sk-line { height: 12px; width: 82%; }
.sk-line.short { width: 48%; }
.sk-block { height: 180px; border-radius: var(--radius); margin-bottom: var(--s3); }

/* -- toast (Din.toast) -------------------------------------------------------------------------------------------- */
.toast { position: fixed; left: calc(var(--s3) + var(--safe-left)); right: calc(var(--s3) + var(--safe-right)); bottom: calc(var(--bottom) + var(--s3));
  max-width: 560px; margin: 0 auto; background: rgba(28, 28, 30, .94); color: #fff; border-radius: 14px; padding: var(--s1) var(--s1) var(--s1) var(--s4);
  display: flex; gap: var(--s2); align-items: center; min-height: 52px; z-index: 30; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  font-size: var(--fs-sub); overflow: hidden; animation: toast-in .28s cubic-bezier(.2, .9, .3, 1.2) both; }
body.din-no-nav .toast { bottom: calc(var(--safe-bottom) + var(--s3)); }
:root[data-scheme="dark"] .toast { background: rgba(58, 58, 60, .96); }
.toast.out { animation: toast-out .2s ease both; }
.toast.error { box-shadow: inset 4px 0 0 #ff6961, 0 10px 30px rgba(0, 0, 0, .25); }
.toast .grow { flex: 1; min-width: 0; padding: var(--s2) 0; overflow-wrap: anywhere; }
.toast button { background: transparent; color: #8ec5ff; font-weight: 600; min-height: 44px; padding: 0 12px; flex: none; }
.toast .left { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: rgba(255, 255, 255, .5); transform-origin: left;
  animation: toast-left linear both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px); } }
@keyframes toast-left { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* -- an in-page main button where Telegram's own is missing (Din.mainButton) -------------------------------------- */
.din-mainbtn { position: fixed; left: calc(var(--s4) + var(--safe-left)); right: calc(var(--s4) + var(--safe-right)); bottom: calc(var(--bottom) + var(--s3));
  z-index: 15; max-width: 560px; margin: 0 auto; min-height: 50px; border-radius: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }
body.din-has-mainbtn main { padding-bottom: 88px; }

@media (prefers-reduced-motion: reduce) {
  .din-in-fwd, .din-in-back, .din-in-fade, .toast, .toast.out { animation: none; }
  .sk::after { animation: none; }
  button, .btn, #tabs, #tabs a .i, .din-tile { transition: none; }
}
@media (min-width: 560px) { .din-more { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
