/* Load after storefront and consent styles. Geometry comes from fixed-tools.js;
   CSS fallbacks keep the warning and native dialogs usable without that script. */
html { scrollbar-gutter: stable; }
html:has(dialog[open]) { overflow: hidden; overscroll-behavior: none; }
:root {
  /* Match the first painted bar to its measured size on tall desktop windows.
     Otherwise Safari can paint a small one-line fallback, then a much larger
     two-line bar while restoring a page from history. */
  --fixed-warning-fallback-font: max(16px, 4.2vw, min(6vw, 6vh));
  /* Before JS measures the real bar, reserve up to three wrapped text rows.
     This is layout clearance, not a legal font-area compliance measurement. */
  --warning-space: max(calc(10vh + 20px), calc(var(--fixed-warning-fallback-font) * 3.45 + 36px + max(8px, env(safe-area-inset-bottom, 0px))));
}

.alcohol-warning {
  position: fixed;
  left: var(--fixed-view-left, 0px);
  right: auto;
  bottom: var(--fixed-view-bottom, 0px);
  width: var(--fixed-view-width, 100vw);
  min-height: calc(var(--fixed-view-height, 100vh) * .1);
  height: auto;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  row-gap: 4px;
  column-gap: 12px;
  background: #000;
  color: var(--gold, #dfc48e);
  /* Use an immediately available platform font for the fixed warning. On
     navigation, a late CJK fallback paint can otherwise leave a black strip
     before the three phrases appear. */
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: var(--fixed-warning-font, var(--fixed-warning-fallback-font));
  font-weight: 700;
  line-height: 1.15;
}

.alcohol-warning > span {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Desktop has no keyboard inset. Keep its first paint independent of JS
   visualViewport custom properties, including during history navigation. */
@media (min-width: 1001px) {
  .alcohol-warning {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-height: 10vh;
  }
}

/* A one-line desktop warning needs ink clearance below the line even after a
   native dialog closes. Grow the bar upward; keep its bottom fixed and its
   text size unchanged. Tall/narrow windows retain the original wrapped bar. */
@media (min-width: 1001px) and (min-aspect-ratio: 13/10) and (max-height: 1100px) {
  .alcohol-warning {
    padding-bottom: max(32px, env(safe-area-inset-bottom, 0px));
    min-height: max(10vh, calc(1.15em + 40px));
  }
}

.consent-banner {
  top: auto;
  left: calc(var(--fixed-view-left, 0px) + 12px);
  right: auto;
  bottom: var(--fixed-overlay-bottom, var(--warning-space, 114px));
  width: min(1080px, calc(var(--fixed-view-width, 100vw) - 24px));
  max-width: none;
  max-height: var(--fixed-panel-height, calc(100vh - 160px));
  margin: 0;
  margin-left: max(0px, calc((var(--fixed-view-width, 100vw) - 1104px) / 2));
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  overflow: hidden;
}

.consent-banner > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-height: max(0px, calc(var(--fixed-panel-height, 400px) - 44px));
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.consent-banner .consent-actions {
  flex: 0 0 360px;
  min-width: 0;
  margin: 0;
}

.consent-dialog,
#image-dialog {
  position: fixed;
  top: var(--fixed-panel-top, 12px);
  right: auto;
  bottom: auto;
  left: calc(var(--fixed-view-left, 0px) + var(--fixed-view-width, 100vw) / 2);
  transform: translateX(-50%);
  margin: 0;
  min-width: 0;
  min-height: 0;
  max-width: calc(var(--fixed-view-width, 100vw) - 24px);
  max-height: var(--fixed-panel-height, calc(100vh - 160px));
  overflow: hidden;
  background: #1b1915;
  border: 1px solid var(--gold, #dfc48e);
}

.consent-dialog {
  width: min(740px, calc(var(--fixed-view-width, 100vw) - 24px));
  padding: 20px;
}

.consent-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: none;
}

.consent-dialog-head {
  flex: 0 0 auto;
  min-width: 0;
}

.consent-dialog-head > div {
  min-width: 0;
}

.consent-dialog-head h2 {
  margin-bottom: 0;
}

.consent-dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 4px 6px 4px 0;
}

/* A native modal remains modal; its transparent backdrop leaves the separate
   warning visible. The dialog surface itself stays opaque and bounded above it. */
body:has(.alcohol-warning) dialog::backdrop {
  background: transparent;
}

/* Native backdrops sit above all ordinary fixed elements. Keep this top-layer
   surface transparent so it cannot cover the legally visible warning. Dim the
   rest of the page with a separate ordinary layer that stops above the bar. */
body:has(.alcohol-warning) .consent-dialog::backdrop {
  background: transparent;
}

body:has(.consent-dialog[open]):has(.alcohol-warning)::before {
  content: "";
  position: fixed;
  inset: 0 0 var(--warning-space, 110px);
  z-index: 99;
  background: rgb(0 0 0 / .68);
  pointer-events: none;
}

#image-dialog {
  width: min(1400px, calc(var(--fixed-view-width, 100vw) - 24px));
  padding: 12px;
}

#image-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#image-dialog > form {
  flex: 0 0 auto;
  margin: 0;
  text-align: right;
}

#image-dialog > img {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: max(0px, calc(var(--fixed-panel-height, 500px) - 84px));
  margin: 0 auto;
  object-fit: contain;
}

.site-back-to-top,
[data-back-to-top] {
  position: fixed;
  z-index: 60;
  right: calc(100vw - var(--fixed-view-left, 0px) - var(--fixed-view-width, 100vw) + max(12px, env(safe-area-inset-right, 0px)));
  bottom: var(--fixed-overlay-bottom, var(--warning-space, 114px));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  max-width: calc(var(--fixed-view-width, 100vw) - 24px);
  padding: 8px 12px;
  border: 1px solid var(--consent-gold, #d5b274);
  border-radius: 6px;
  background: #211e18;
  color: var(--consent-paper, #f9f5ed);
  font: inherit;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
}

.site-back-to-top[hidden],
[data-back-to-top][hidden] {
  display: none !important;
}

@media (max-width: 1000px) and (orientation: portrait) {
  :root {
    --fixed-warning-fallback-font: max(16px, 7.2vw, 4.3vh);
  }
}

@media (max-width: 767px) {
  .consent-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  .consent-banner > div:first-child {
    max-height: max(0px, calc(var(--fixed-panel-height, 400px) - 88px));
  }

  .consent-banner .consent-actions {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin: 0;
  }

  .consent-banner .consent-button {
    min-height: 44px;
    padding: 8px 5px;
  }

  .consent-dialog {
    padding: 14px;
  }

  .consent-dialog[open] {
    gap: 8px;
  }

  .consent-dialog-head h2 {
    font-size: 21px;
  }

  .consent-dialog-body {
    padding-right: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-back-to-top,
  [data-back-to-top],
  .consent-dialog[open] {
    transition: none;
    animation: none;
  }
}

/* In a short visual viewport, keep real content and controls available rather
   than reserving all space for an ornamental header. The warning stays outside. */
:root[data-fixed-compact="true"] .consent-dialog {
  padding: 6px;
}
:root[data-fixed-compact="true"] .consent-dialog[open] {
  gap: 4px;
}
:root[data-fixed-compact="true"] .consent-dialog-head .consent-eyebrow {
  display: none;
}
:root[data-fixed-compact="true"] .consent-dialog-head h2 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
}
:root[data-fixed-compact="true"] .consent-dialog-body {
  padding: 0 2px 0 0;
}
:root[data-fixed-compact="true"] .consent-banner {
  padding: 6px;
  gap: 6px;
}
:root[data-fixed-compact="true"] .consent-banner > div:first-child {
  max-height: max(0px, calc(var(--fixed-panel-height, 200px) - 64px));
}
:root[data-fixed-compact="true"] #image-dialog {
  padding: 6px;
}
:root[data-fixed-compact="true"] #image-dialog > img {
  max-height: max(0px, calc(var(--fixed-panel-height, 200px) - 74px));
}
