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

.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-right)) 0 max(12px, var(--safe-left));
  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 {
  justify-self: start;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--touch);
  color: #fff;
  font-family: var(--editorial-font);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.025em;
  text-decoration: none;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
}

.wordmark__mark,
.boot__mark {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50% 50% 8px 50%;
  transform: rotate(45deg);
}

.balance-button {
  justify-self: end;
  min-width: var(--touch);
  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);
  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));
}

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

.boot {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  min-height: var(--layout-height);
  color: var(--ink-muted);
  font-size: 14px;
}

.boot__mark {
  width: 34px;
  height: 34px;
  color: var(--amber);
  animation: breathe 1.4s ease-in-out infinite;
}

.tabbar {
  position: fixed;
  z-index: 35;
  right: 12px;
  bottom: calc(8px + var(--safe-bottom));
  left: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 58px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--glass-light);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(22px) saturate(1.2);
}

.tabbar__item {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-height: var(--touch);
  border: 0;
  border-radius: 17px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 650;
}

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

.tabbar__item.is-active {
  background: var(--paper-soft);
  color: var(--ink);
}

.native-action {
  position: fixed;
  z-index: 34;
  right: 12px;
  bottom: calc(74px + var(--safe-bottom));
  left: 12px;
  display: grid;
  gap: 5px;
}

.primary-action {
  min-height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: 18px;
  background: var(--amber);
  box-shadow: 0 12px 30px color-mix(in srgb, var(--amber) 26%, transparent);
  color: #1c140b;
  font-size: 16px;
  font-weight: 780;
  letter-spacing: -0.01em;
}

.primary-action:active {
  transform: scale(0.985);
}

.primary-action:disabled {
  opacity: 0.48;
}

.action-caption {
  min-height: 14px;
  margin: 0;
  color: var(--ink-muted);
  font-size: 11px;
  text-align: center;
}

.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,
html[data-keyboard="true"] .native-action {
  display: none !important;
}

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

html[data-keyboard="true"] .studio {
  display: grid;
  grid-template-rows: minmax(120px, 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: max(10px, var(--safe-bottom));
}

@keyframes breathe {
  50% { opacity: 0.48; transform: rotate(45deg) scale(0.88); }
}

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

@media (min-width: 700px) {
  body {
    display: grid;
    place-items: center;
    background: #cfc7bb;
  }

  html[data-theme="dark"] body {
    background: #0d0c0b;
  }

  .app {
    width: min(100%, 430px);
    box-shadow: 0 0 0 1px var(--line), 0 30px 100px rgba(0, 0, 0, 0.28);
  }

  .topbar,
  .tabbar,
  .native-action,
  .toast-region {
    left: 50%;
    width: min(calc(100% - 24px), 406px);
    transform: translateX(-50%);
  }
}
