/* Loaded after page styles: keep artwork edge-to-edge and content clear of cutouts. */
/* The saved iPhone app suppresses double-tap zoom without canceling tap events.
   Manipulation still allows scrolling; the app's script handles pinch changes. */
:root[data-iphone-standalone="true"],
:root[data-iphone-standalone="true"] * {
  touch-action: manipulation;
}

/* Keep editable text readable at normal size to avoid iPhone focus zoom. */
:root[data-iphone-standalone="true"] :is(input, select, textarea, [contenteditable="true"]) {
  font-size: max(16px, 1em);
}

:root {
  --iphone-canvas-artwork: url('/blue-drips.webp');
  --iphone-canvas-height: 100vh;
  --iphone-canvas-size: cover;
  /* Size the canvas image against the viewport, not a tall document. Content
     still overflows normally; repeated artwork paints any exposed canvas. */
  height: var(--iphone-canvas-height);
  background-color: transparent;
  background-image: var(--iphone-canvas-artwork);
  background-position: center;
  background-size: var(--iphone-canvas-size);
  background-repeat: repeat;
}

@supports (height: 100lvh) {
  :root {
    --iphone-canvas-height: 100lvh;
  }
}

:root:has(> body[data-background="blue"]) {
  --iphone-canvas-artwork: url('/blue-drips.webp');
}

:root:has(> body[data-background="yellow"]) {
  --iphone-canvas-artwork: url('/yellow-drips.webp');
}

:root:has(> body[data-background="red"]) {
  --iphone-canvas-artwork: url('/red-drips.webp');
}

:root:has(> body[data-background="green"]) {
  --iphone-canvas-artwork: url('/green-drips.webp');
}

:root:has(> body[data-background="purple"]) {
  --iphone-canvas-artwork: url('/purple-drips.webp');
}

:root:has(> body[data-background="orange"]) {
  --iphone-canvas-artwork: url('/orange-drips.webp');
}

:root:has(> body[data-background="halloween"]) {
  --iphone-canvas-artwork: url('/halloween-pumpkins.png');
}

:root:has(> body[data-background="headowner"]) {
  --iphone-canvas-artwork: url('/head-owner-dragons.png');
}

@media (max-width: 780px), (hover: none) and (pointer: coarse) {
  :root {
    /* The artwork is ~16:9. Use the same viewport crop for canvas and page. */
    --iphone-canvas-size: max(120vw, calc(var(--iphone-canvas-height) * 1.2 * 16 / 9)) auto;
  }

  body {
    min-height: 100dvh;
  }

  body::before,
  body::after {
    inset: 0;
    bottom: auto;
    height: var(--iphone-canvas-height);
    min-height: 0;
    background-position: center;
    background-size: var(--iphone-canvas-size);
    background-repeat: no-repeat;
  }
}

/* These bases match the page styles; zero safe-area insets retain their spacing. */
.game-page {
  --iphone-page-top: 90px;
  --iphone-page-side: 24px;
  --iphone-page-bottom: 28px;
}

.admin-page {
  --iphone-page-top: 95px;
  --iphone-page-side: 24px;
  --iphone-page-bottom: 40px;
}

.admin-page.panel-page {
  --iphone-page-top: 24px;
}

.auth-page {
  --iphone-page-top: 40px;
  --iphone-page-side: 16px;
  --iphone-page-bottom: 40px;
}

.ban-page {
  --iphone-page-top: 32px;
  --iphone-page-side: 18px;
  --iphone-page-bottom: 32px;
}

.inbox-page {
  --iphone-page-top: 94px;
  --iphone-page-side: 24px;
  --iphone-page-bottom: 30px;
}

.game-page,
.admin-page,
.admin-page.panel-page,
.auth-page,
.ban-page,
.inbox-page {
  padding: calc(var(--iphone-page-top) + env(safe-area-inset-top, 0px))
    calc(var(--iphone-page-side) + env(safe-area-inset-right, 0px))
    calc(var(--iphone-page-bottom) + env(safe-area-inset-bottom, 0px))
    calc(var(--iphone-page-side) + env(safe-area-inset-left, 0px));
}

.account-bar {
  --iphone-header-left: 24px;
  --iphone-header-right: 175px;
}

.admin-page .account-bar,
.inbox-page > .account-bar {
  --iphone-header-right: 24px;
}

.account-bar,
.admin-page .account-bar,
.inbox-page > .account-bar {
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(var(--iphone-header-left) + env(safe-area-inset-left, 0px));
  right: calc(var(--iphone-header-right) + env(safe-area-inset-right, 0px));
}

.background-menu {
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
}

@media (max-width: 780px) {
  .game-page {
    --iphone-page-top: 135px;
    --iphone-page-side: 12px;
    --iphone-page-bottom: 24px;
  }

  .admin-page {
    --iphone-page-top: 135px;
    --iphone-page-side: 12px;
    --iphone-page-bottom: 20px;
  }

  .admin-page.panel-page {
    --iphone-page-top: 16px;
    --iphone-page-bottom: 24px;
  }

  .account-bar {
    --iphone-header-left: 12px;
    --iphone-header-right: 150px;
  }

  .admin-page .account-bar {
    --iphone-header-right: 12px;
  }
}

@media (max-width: 760px) {
  .inbox-page {
    --iphone-page-top: 90px;
    --iphone-page-side: 12px;
    --iphone-page-bottom: 22px;
  }

  .inbox-page > .account-bar {
    --iphone-header-right: 12px;
  }
}

@media (max-width: 375px) {
  .game-page:has(> .account-bar > .owner-badge):has(> .account-bar > .vip-panel-link) {
    padding-top: calc(185px + env(safe-area-inset-top, 0px));
  }
}
