/*
 * S2 platform adaptations
 * Final responsive layer for viewport shape, input method and accessibility.
 * It intentionally preserves each page's art direction and only changes layout
 * when the available space or the user's platform preferences require it.
 */

:root {
  --s2-app-height: 100vh;
  --s2-control-size: 44px;
  --s2-focus-ring: rgba(129, 184, 255, 0.92);
}

@supports (height: 100svh) {
  :root { --s2-app-height: 100svh; }
}

@supports (height: 100dvh) {
  :root { --s2-app-height: 100dvh; }
}

html {
  min-width: 320px;
  color-scheme: dark;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-width: 320px;
  min-height: var(--s2-app-height);
  overflow-x: clip;
  overscroll-behavior-x: none;
}

@supports not (overflow: clip) {
  body { overflow-x: hidden; }
}

img,
video,
svg {
  max-inline-size: 100%;
}

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

:where(button, a, input, select, textarea, [role="button"], [tabindex]):focus-visible {
  outline: 2px solid var(--s2-focus-ring);
  outline-offset: 3px;
}

/* Pointer clicks and scripted focus do not leave a rectangular focus ring. */
html[data-s2-input="pointer"] :where(button, a, input, select, textarea, [role="button"], [tabindex]):focus-visible {
  outline: none !important;
}
html[data-s2-input="pointer"] :where(input, select, textarea):focus {
  box-shadow: none !important;
  border-color: rgba(255,255,255,.2) !important;
}

@supports (scrollbar-gutter: stable) {
  :where(.s2-account-panel, .s2-auth-shell, .s2-checkout-panel, .s2-how-panel, .s2-public-frame) {
    scrollbar-gutter: stable;
  }
}

/* Touch-first platforms: reliable targets and no delayed/ambiguous activation. */
@media (hover: none) and (pointer: coarse) {
  :where(button, [role="button"], summary, input, select, textarea) {
    min-block-size: var(--s2-control-size);
    touch-action: manipulation;
  }

  :where(
    .s2-nav a,
    .s2-hero-actions a,
    .s2-account-nav button,
    .s2-public-tabs button,
    .public-nav a,
    .public-button,
    .legal-toc a,
    .help-categories button,
    .how-back,
    .how-bottom-nav button,
    .admin-nav a
  ) {
    min-block-size: var(--s2-control-size);
    touch-action: manipulation;
  }

  :where(input, select, textarea) {
    font-size: max(16px, 1em);
  }

  /* Keep the compact wallet visuals circular without reducing their tap targets. */
  .s2-balance {
    min-block-size: 33px;
  }

  .s2-plus {
    inline-size: 21px;
    block-size: 21px;
    min-inline-size: 21px;
    min-block-size: 21px;
    aspect-ratio: 1;
  }

  .game-card,
  .chapter-visual,
  .game-result,
  .info-card {
    -webkit-tap-highlight-color: transparent;
  }
}

/* The phone-landscape/tablet-split case needs a layout chosen by height, not width. */
@media (max-height: 520px) and (min-width: 681px) and (max-width: 1024px) {
  .s2-header {
    top: max(10px, var(--s2-safe-top, 0px));
    left: max(18px, var(--s2-safe-left, 0px));
    right: max(18px, var(--s2-safe-right, 0px));
    height: 38px;
    padding: 0;
  }

  .s2-header-left { gap: 14px; }
  .s2-header-left .s2-search { display: none; }
  .s2-actions { gap: 9px; }
  .s2-wordmark { top: -3px; }
  .s2-wordmark img { width: 46px; height: 29px; }

  .s2-hero {
    top: clamp(74px, 22vh, 92px);
    left: max(28px, calc(var(--s2-safe-left, 0px) + 18px));
    width: min(52vw, 470px);
    transform: none;
    text-align: left;
  }

  .s2-hero h1 {
    font-size: clamp(36px, 9.8vh, 46px);
    line-height: 0.88;
  }

  .s2-hero p {
    max-width: 410px;
    margin: 11px 0 0;
    font-size: 11px;
    line-height: 1.4;
  }

  .s2-hero-actions {
    justify-content: flex-start;
    margin-top: 11px;
  }

  #card-deck {
    top: clamp(76px, 21vh, 94px);
    left: 77%;
    width: min(23vw, 188px);
  }

  .s2-mobile-deck-controls {
    right: max(18px, var(--s2-safe-right, 0px));
    bottom: max(8px, var(--s2-safe-bottom, 0px));
    left: auto;
    width: min(236px, 38vw);
    transform: none;
  }

  #s2-auth,
  #s2-account,
  #s2-checkout,
  #s2-how,
  #s2-public-hub {
    padding: max(9px, var(--s2-safe-top, 0px)) max(10px, var(--s2-safe-right, 0px)) max(9px, var(--s2-safe-bottom, 0px)) max(10px, var(--s2-safe-left, 0px));
  }

  .s2-auth-shell,
  .s2-account-panel,
  .s2-checkout-panel,
  .s2-how-panel,
  .s2-public-panel {
    max-height: calc(var(--s2-app-height) - var(--s2-safe-top, 0px) - var(--s2-safe-bottom, 0px) - 18px);
  }

  .s2-auth-shell {
    grid-template-columns: minmax(215px, 0.62fr) minmax(390px, 1.38fr);
    min-height: 0;
    overflow: hidden;
  }

  .s2-auth-aside { min-height: 0; padding: 22px; }
  .s2-auth-aside-copy { margin-top: auto; padding-top: 28px; }
  .s2-auth-aside h1 { max-width: 260px; font-size: 28px; }
  .s2-auth-aside-copy > span,
  .s2-auth-steps { display: none; }
  .s2-auth-main { align-items: flex-start; overflow-y: auto; padding: 40px 34px 24px; }
  .s2-auth-form header p { margin-bottom: 17px; }
  .s2-auth-fields { gap: 9px; }
  .s2-auth-submit { margin-top: 13px; }
  .s2-auth-switch { margin-top: 12px; }
  .s2-auth-notice { margin-top: 12px; }

  .s2-public-panel {
    grid-template-rows: 58px minmax(0, 1fr);
    width: min(1040px, calc(100vw - var(--s2-safe-left, 0px) - var(--s2-safe-right, 0px) - 20px));
    height: calc(var(--s2-app-height) - var(--s2-safe-top, 0px) - var(--s2-safe-bottom, 0px) - 18px);
  }
  .s2-public-toolbar { padding-block: 6px; }
  .s2-public-tabs button { min-height: 36px; }

  .how-header { top: max(12px, env(safe-area-inset-top, 0px)); }
  .how-page {
    min-height: var(--s2-app-height);
    padding-top: 76px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }
  body:not(.is-embed) .how-shell { max-height: calc(var(--s2-app-height) - 86px); }
  .how-content { padding-top: 25px; }
  .how-chapter-intro h1 { font-size: clamp(38px, 10vh, 48px); }

  body.is-embed .how-content {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 24px 28px 16px;
  }
  body.is-embed .how-chapter-grid {
    height: auto;
    min-height: 0;
  }
  body.is-embed .how-chapter-one {
    grid-template-rows: auto auto;
    gap: 16px;
  }
  body.is-embed .how-distribution,
  body.is-embed .how-rarity-spotlight { min-height: 250px; }
  body.is-embed .how-chart { min-height: 138px; }
}

/* Small phones: preserve content order and leave room for browser chrome/keyboard. */
@media (max-width: 380px) {
  .s2-auth-main,
  .s2-account-content,
  .s2-checkout-copy {
    padding-right: max(14px, var(--s2-safe-right, 0px));
    padding-left: max(14px, var(--s2-safe-left, 0px));
  }

  .s2-auth-name-row { grid-template-columns: 1fr; }
  .s2-auth-provider-row { gap: 6px; }
  .s2-auth-provider-row button { padding-inline: 8px; }

  .s2-public-panel { border-radius: 20px; }
  .s2-public-toolbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .s2-public-tabs { max-width: 148px; }

  .legal-copy h1,
  .redeem-main h1,
  .public-hero h1 {
    overflow-wrap: anywhere;
  }

  body.is-embed .how-content {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
  body.is-embed .how-chapter-grid {
    height: auto;
    min-height: 0;
  }
  body.is-embed .how-chapter-one { grid-template-rows: auto auto; }
}

/* Extremely short windows, split-screen and software-keyboard states. */
@media (max-height: 430px) {
  :where(.s2-account-panel, .s2-auth-shell, .s2-checkout-panel, .s2-how-panel, .s2-public-panel) {
    border-radius: 18px;
  }

  .s2-auth-close,
  .s2-account-close,
  .s2-checkout-close,
  .s2-how-close,
  .s2-public-close {
    width: 44px;
    height: 44px;
  }
}

/* Large and ultra-wide displays keep a readable optical field. */
@media (min-width: 1800px) {
  .s2-header {
    right: max(60px, calc((100vw - 1680px) / 2));
    left: max(60px, calc((100vw - 1680px) / 2));
  }

  .s2-hero { width: min(780px, 44vw); }
  .s2-public-panel { width: min(1240px, 76vw); }
  .public-window { max-width: 1320px; }
}

/* Slow GPUs and transparency-reduction preferences get a stable opaque surface. */
@media (prefers-reduced-transparency: reduce) {
  :where(#s2-auth, #s2-account, #s2-checkout, #s2-how, #s2-public-hub) {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(2, 3, 5, 0.96) !important;
  }

  :where(.s2-mobile-deck-controls, .s2-public-toolbar, .admin-topbar) {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

/* Motion preferences apply to every S2 surface, including interaction feedback. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  #sprites { display: none !important; }
  .chapter-visual,
  .public-backdrop,
  .s2-auth-scene,
  .how-grid { transform: none !important; }
}

/* Header avatar: keep the crop square even when the uploaded file is panoramic or portrait. */
.s2-avatar .s2-avatar-media {
  position: relative;
  display: block;
  flex: none;
  width: 34px !important;
  height: 34px !important;
  min-width: 34px;
  min-height: 34px;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: #16191f;
}
.s2-avatar .s2-avatar-media > img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: cover;
  object-position: center;
  border-radius: inherit;
}
.s2-avatar .s2-avatar-initials {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #fff;
  font: 700 11px/1 Inter, sans-serif;
}

/* Windows High Contrast / forced colors: retain structure and focus visibility. */
@media (forced-colors: active) {
  :where(button, input, select, textarea, [role="button"], .game-card img) {
    border: 1px solid ButtonText;
  }

  :where(button, a, input, select, textarea, [role="button"]):focus-visible {
    outline: 3px solid Highlight;
  }
}

