/* Telegram Mini App layout corrections.
   Loaded by telegram-miniapp.js so the same fixes apply on Android, iOS and Desktop. */

:root {
  --tg-safe-top: 0px;
  --tg-safe-right: 0px;
  --tg-safe-bottom: 0px;
  --tg-safe-left: 0px;
  --tg-content-safe-top: 0px;
  --tg-content-safe-right: 0px;
  --tg-content-safe-bottom: 0px;
  --tg-content-safe-left: 0px;
}

html {
  min-width: 0;
  min-height: var(--arara-viewport-height, 100dvh);
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

body {
  width: 100%;
  min-width: 0;
  min-height: var(--arara-viewport-height, 100dvh);
  overflow-x: clip;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-synthesis: none;
  overscroll-behavior-x: none;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

img,
svg {
  display: block;
}

img {
  height: auto;
}

.app-shell {
  width: 100%;
  min-width: 0;
  min-height: var(--arara-viewport-stable-height, 100dvh);
  padding-top: calc(max(var(--safe-top), var(--tg-safe-top), var(--tg-content-safe-top)) + 10px);
  padding-right: calc(max(12px, var(--tg-safe-right), var(--tg-content-safe-right)) + 4px);
  padding-bottom: calc(112px + max(var(--safe-bottom), var(--tg-safe-bottom), var(--tg-content-safe-bottom)));
  padding-left: calc(max(12px, var(--tg-safe-left), var(--tg-content-safe-left)) + 4px);
}

.world,
.loading-screen,
.auth-gate {
  width: 100%;
  height: var(--arara-viewport-height, 100dvh);
  min-height: var(--arara-viewport-height, 100dvh);
}

.screen,
.screen > *,
.prize-card,
.player-strip,
.tap-zone,
.daily-card,
.task-card,
.profile-card,
.ton-card,
.referral-card,
.rules-card,
.section-heading,
.fairness-note,
.rank-explainer {
  min-width: 0;
  max-width: 100%;
}

p,
small,
span,
strong,
h1,
h2,
code {
  overflow-wrap: anywhere;
}

/* Keep the Latin display face only where it is actually available. */
.brand-lockup strong,
.loading-screen strong,
.prize-card__main strong,
.score-lockup strong,
.profile-grid strong,
.referral-code code {
  font-family: Onest, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  width: 100%;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
}

.brand-lockup {
  min-width: 0;
}

.brand-lockup div {
  min-width: 0;
}

.brand-lockup strong,
.brand-lockup span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button svg,
.refresh-button svg,
.bottom-nav svg,
.ton-card__logo svg {
  flex: 0 0 auto;
  aspect-ratio: 1;
}

.prize-card__main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(104px, 38%);
  align-items: end;
  gap: 10px;
}

.prize-card__main > div {
  min-width: 0;
}

.prize-card__main strong {
  font-size: clamp(37px, 12vw, 58px);
  white-space: nowrap;
}

.prize-card__main p {
  width: 100%;
  max-width: none;
  margin-bottom: 5px;
  font-size: clamp(9px, 2.55vw, 11px);
}

.prize-card__stats {
  flex-wrap: wrap;
  row-gap: 4px;
}

.player-strip {
  grid-template-columns: 34px minmax(0, 1fr) minmax(44px, auto) minmax(55px, auto);
  gap: 7px;
  padding-inline: 9px;
}

.player-stat {
  min-width: 0;
  padding-left: 7px;
}

.player-stat span,
.player-strip__name span {
  font-size: clamp(7px, 2vw, 8px);
}

.player-stat strong,
.player-strip__name strong {
  font-size: clamp(10px, 2.8vw, 12px);
}

.player-stat--ticket img {
  flex: 0 0 auto;
  width: 20px;
  height: 14px;
  object-fit: contain;
}

.tap-orbit {
  width: min(calc(100vw - 32px - var(--tg-content-safe-left) - var(--tg-content-safe-right)), 365px);
  max-width: 100%;
}

.tap-orbit__ring,
.tap-orbit__pedestal,
.tap-button__character,
.tap-button__shockwave {
  object-fit: contain;
}

.score-lockup span,
.tap-hint {
  text-align: center;
  line-height: 1.25;
}

.energy-row {
  width: 100%;
  min-height: 58px;
  aspect-ratio: 680 / 143;
}

.energy-row strong {
  white-space: nowrap;
}

.ticket-progress > div:first-child {
  gap: 8px;
}

.ticket-progress strong {
  flex: 0 0 auto;
  text-align: right;
}

.daily-card__copy strong,
.daily-card__copy small,
.task-card__copy strong,
.task-card__copy small,
.fairness-note p,
.rank-explainer p,
.rules-card li span {
  line-height: 1.35;
}

.task-card__copy strong {
  display: -webkit-box;
  overflow: hidden;
  white-space: normal;
  text-overflow: clip;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.task-card__action {
  max-width: 104px;
  white-space: normal;
  line-height: 1.15;
}

.section-heading > div:first-child {
  min-width: 0;
}

.section-heading h1 {
  font-size: clamp(25px, 8vw, 29px);
}

.section-heading__reward {
  flex: 0 0 auto;
  width: clamp(108px, 32vw, 128px);
}

.rank-stage__medals,
.rank-stage__podium {
  max-width: 100%;
  object-fit: contain;
}

.ton-card__heading {
  grid-template-columns: 43px minmax(0, 1fr) auto;
}

.ton-card__state {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ton-wallet strong {
  min-width: 0;
}

.referral-code {
  grid-template-columns: minmax(0, 1fr) auto;
}

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

.gold-button,
.ton-connect-button,
.ton-disconnect-button,
.task-card__action,
.referral-code button {
  max-width: 100%;
}

.bottom-nav {
  width: 100%;
  min-width: 0;
  min-height: calc(86px + max(var(--safe-bottom), var(--tg-safe-bottom), var(--tg-content-safe-bottom)));
  padding-right: calc(12px + max(var(--tg-safe-right), var(--tg-content-safe-right)));
  padding-bottom: calc(9px + max(var(--safe-bottom), var(--tg-safe-bottom), var(--tg-content-safe-bottom)));
  padding-left: calc(12px + max(var(--tg-safe-left), var(--tg-content-safe-left)));
  background-size: 100% calc(88px + max(var(--safe-bottom), var(--tg-safe-bottom), var(--tg-content-safe-bottom)));
}

.bottom-nav button {
  min-width: 0;
  min-height: 58px;
}

.bottom-nav span {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(8px, 2.35vw, 10px);
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast-region {
  top: calc(max(var(--safe-top), var(--tg-safe-top), var(--tg-content-safe-top)) + 12px);
}

@media (max-width: 390px) {
  .app-shell {
    padding-right: calc(max(10px, var(--tg-safe-right), var(--tg-content-safe-right)) + 2px);
    padding-left: calc(max(10px, var(--tg-safe-left), var(--tg-content-safe-left)) + 2px);
  }

  .prize-card {
    padding-inline: 13px;
  }

  .prize-card__main {
    grid-template-columns: minmax(0, 1fr) minmax(92px, 37%);
    gap: 7px;
  }

  .prize-card__stats {
    gap: 10px;
  }

  .player-strip {
    grid-template-columns: 31px minmax(0, 1fr) minmax(39px, auto) minmax(49px, auto);
    gap: 5px;
    padding-inline: 7px;
  }

  .avatar {
    width: 31px;
    height: 31px;
  }

  .avatar img {
    width: 26px;
    height: 26px;
  }

  .player-stat {
    padding-left: 5px;
  }

  .daily-card {
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 10px 8px 6px;
  }

  .daily-card__icon {
    width: 50px;
    height: 52px;
  }

  .daily-card__icon img {
    width: 47px;
    height: 50px;
    object-fit: contain;
  }

  .daily-card .gold-button--small {
    grid-column: 2;
    width: 100%;
    min-height: 32px;
    margin-top: 2px;
  }

  .task-card {
    grid-template-columns: 43px minmax(0, 1fr);
    gap: 8px;
    padding: 12px 13px;
  }

  .task-card__icon {
    width: 42px;
    height: 42px;
  }

  .task-card__action {
    grid-column: 2;
    width: 100%;
    max-width: none;
    min-height: 34px;
    margin-top: 2px;
  }

  .ton-card__heading {
    grid-template-columns: 43px minmax(0, 1fr);
  }

  .ton-card__state {
    grid-column: 2;
    max-width: 100%;
    width: fit-content;
    margin-top: 2px;
  }

  .referral-code {
    grid-template-columns: minmax(0, 1fr);
  }

  .referral-code code {
    min-height: 42px;
    justify-content: center;
    text-align: center;
  }

  .referral-code button {
    width: 100%;
  }
}

@media (max-width: 340px) {
  .brand-lockup span {
    display: none;
  }

  .prize-card__main {
    grid-template-columns: minmax(0, 1fr) 90px;
  }

  .prize-card__main strong {
    font-size: 34px;
  }

  .prize-card__main p {
    font-size: 8px;
  }

  .player-strip {
    grid-template-columns: 30px minmax(0, 1fr) 39px 46px;
  }

  .player-stat span,
  .player-strip__name span {
    letter-spacing: .03em;
  }

  .section-heading__reward {
    width: 102px;
  }

  .bottom-nav {
    padding-inline: 8px;
  }
}

@media (max-height: 700px) and (max-width: 520px) {
  .topbar {
    margin-bottom: 8px;
  }

  .tap-orbit {
    width: min(calc(100vw - 50px), 315px);
  }
}
