body {
  min-width: 320px;
  min-height: var(--layout-height);
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  position: relative;
  isolation: isolate;
  width: 100%;
  min-height: var(--layout-height);
  background: var(--paper);
  overflow: hidden;
}

.topbar {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(var(--touch), 1fr) auto minmax(var(--touch), 1fr);
  align-items: center;
  height: calc(var(--topbar-height) + var(--safe-top));
  padding: var(--safe-top) max(12px, var(--safe-left), var(--safe-right)) 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.topbar--paper .wordmark {
  color: var(--ink);
  text-shadow: none;
}

.topbar--paper .icon-button {
  background: var(--paper-soft);
  color: var(--ink);
}

.topbar--paper .balance-button {
  border-color: var(--line);
  background: var(--paper-soft);
  color: var(--ink);
  backdrop-filter: none;
}

.topbar__back,
.topbar__gallery {
  grid-column: 1;
  justify-self: start;
}

.wordmark {
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  color: #fff;
  font-family: var(--editorial-font);
  justify-content: center;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.035em;
  text-decoration: none;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
  user-select: none;
}

html[data-frame-adapter="telegram"] .wordmark,
html[data-frame-adapter="fake-telegram"] .wordmark {
  transform: none;
}

.balance-button {
  grid-column: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: end;
  min-width: var(--touch);
  max-width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(18, 16, 14, 0.5);
  backdrop-filter: blur(18px);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.viewport {
  height: var(--layout-height);
  padding-top: calc(var(--safe-top) + var(--topbar-height));
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  overscroll-behavior-y: contain;
}

.viewport::-webkit-scrollbar {
  display: none;
}

.viewport.has-tabbar {
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom));
}

.startup {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: calc(var(--safe-top) + var(--topbar-height)) 20px var(--safe-bottom);
  color: var(--ink-muted);
  font-size: 14px;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 160ms step-end;
}

.startup__signal {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  color: var(--amber);
  animation: startup-pulse 1.2s ease-in-out infinite alternate;
}

.startup-placeholder,
.viewport > [data-screen="loading"] {
  visibility: hidden;
}

.app:has(.viewport > [data-screen]:not([data-screen="loading"])) .startup {
  visibility: hidden;
  opacity: 0;
}

.toast-region {
  position: fixed;
  z-index: 90;
  top: calc(var(--safe-top) + 62px);
  right: 16px;
  left: 16px;
  display: grid;
  justify-items: center;
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(24, 21, 18, 0.88);
  color: #fff;
  box-shadow: var(--shadow-soft);
  font-size: 13px;
  animation: toast-in 180ms ease-out;
}

html[data-keyboard="true"] .tabbar {
  display: none !important;
}

html[data-keyboard="true"] .viewport.has-tabbar {
  padding-bottom: var(--safe-bottom);
}

html[data-keyboard="true"] .studio {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

html[data-keyboard="true"] .canvas {
  height: auto;
  min-height: 0;
}

html[data-keyboard="true"] .studio-panel {
  max-height: min(300px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 8px;
}

.app[data-prompt-focus="true"] .topbar {
  display: none;
}

.app[data-prompt-focus="true"] .viewport {
  padding-top: var(--frame-system-safe-top, 0px);
}

@keyframes startup-pulse {
  to { opacity: 0.3; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
}

@media (min-width: 520px) {
  html:not([data-telegram-native="true"]),
  html:not([data-telegram-native="true"]) body {
    background: #d8d3c6;
  }

  html:not([data-telegram-native="true"]) body {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding: 28px 16px;
    overflow: auto;
  }

  html:not([data-telegram-native="true"]) .app {
    --layout-height: 844px;
    --stable-height: 844px;
    --safe-top: 59px;
    --safe-bottom: 34px;
    width: 390px;
    height: 844px;
    min-height: 844px;
    overflow: hidden;
    border-radius: 44px;
    box-shadow: 0 0 0 11px #111, 0 28px 70px rgba(0, 0, 0, 0.28);
  }
}
