:root {
  --menu-bg: rgba(255, 255, 255, 0.94);
  --overlay-bg: rgba(255, 255, 255, 0.42);
  --button-green: #498a4a;
  --text-color: #101216;
  /* Use % + safe-area instead of 100vw (vw includes scrollbar / iOS quirks → horizontal overflow). */
  --page-pad-x: max(12px, env(safe-area-inset-left, 0px));
  --page-pad-r: max(12px, env(safe-area-inset-right, 0px));
}

*,
*::before,
*::after {
  box-sizing: border-box;
  /* Stop iOS/Android from “helpfully” enlarging text after async content paints (~1s). */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  /* Stricter than children: WebKit still boosts some subtrees if only html is set. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  min-height: 100svh;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: manipulation;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-color);
  background: #ffffff;
}

.app-root {
  position: relative;
  width: 100%;
  max-width: 100%;
  /* svh = stable; dvh changes when mobile browser chrome hides → layout “zoom” jump */
  min-height: 100svh;
  height: 100svh;
  max-height: 100svh;
  overflow: hidden;
}

.viz-shell {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.viz-shell,
.viz-frame {
  width: 100%;
  max-width: 100%;
  height: 100%;
  border: 0;
}

.viz-frame {
  display: block;
}

.menu-button {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  width: 44px;
  height: 44px;
  border: 1px solid #000;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 10px;
  z-index: 20;
  cursor: pointer;
}

.menu-button span {
  display: block;
  width: 100%;
  height: 2px;
  background: #000;
}

.menu-panel {
  position: fixed;
  top: calc(56px + max(8px, env(safe-area-inset-top)));
  left: var(--page-pad-x);
  width: min(360px, calc(100% - var(--page-pad-x) - var(--page-pad-r)));
  max-width: calc(100% - var(--page-pad-x) - var(--page-pad-r));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  max-height: min(
    70dvh,
    70svh,
    calc(100dvh - 72px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
    calc(100svh - 72px - env(safe-area-inset-top) - env(safe-area-inset-bottom))
  );
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #000;
  border-radius: 14px;
  background: var(--menu-bg);
  padding: 14px;
  z-index: 19;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  pointer-events: none;
  backdrop-filter: blur(4px);
  transition: opacity 220ms ease, transform 220ms ease, visibility 220ms ease;
}

.menu-panel.open {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.menu-close-button {
  border: 1px solid #000;
  border-radius: 8px;
  background: #fff;
  width: 28px;
  height: 28px;
  line-height: 1;
  cursor: pointer;
}

.menu-links {
  display: grid;
  gap: 8px;
}

.menu-link {
  border: 1px solid #000;
  border-radius: 10px;
  background: #f7f8f9;
  text-align: left;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.menu-link.active {
  background: #dde7da;
}

.menu-content {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.menu-content a {
  color: #1a4d8c;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.menu-content--html {
  white-space: normal;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  width: 100%;
  max-width: 100%;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.9);
  opacity: 1;
  visibility: visible;
  transition: opacity 320ms ease, visibility 320ms ease;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  width: 100%;
  max-width: min(740px, 100%);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Height follows content; cap keeps very long copy inside the viewport. */
  max-height: min(
    96dvh,
    96svh,
    calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px),
    calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px),
    1100px
  );
  height: auto;
  margin: auto;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 20px;
  background: var(--overlay-bg);
  backdrop-filter: blur(6px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}

.overlay-text {
  font-size: clamp(13px, 1.6vw, 17px);
  line-height: 1.48;
  white-space: pre-wrap;
  overflow: visible;
  flex: 0 0 auto;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.overlay-text.intro-text--rich {
  white-space: normal;
}

.overlay-text .intro-lead {
  margin: 0 0 1rem;
  font-size: clamp(1.45rem, 3.1vw, 1.95rem);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: -0.03em;
  color: #06090f;
  overflow-wrap: anywhere;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.overlay-text .intro-body {
  margin: 0 0 0.95em;
  font-size: clamp(13px, 1.6vw, 17px);
  line-height: 1.5;
  font-weight: 400;
  color: var(--text-color);
  overflow-wrap: anywhere;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.overlay-text .intro-body:last-child {
  margin-bottom: 0;
}

.lets-go-button {
  flex-shrink: 0;
  align-self: center;
  max-width: 100%;
  border: 2px solid #000;
  border-radius: 999px;
  background: var(--button-green);
  color: #fff;
  font-size: clamp(18px, 4.4vw, 28px);
  font-weight: 700;
  padding: 14px 42px;
  cursor: pointer;
}

@media (max-width: 640px) {
  .menu-button {
    top: max(12px, env(safe-area-inset-top));
    left: var(--page-pad-x);
  }

  .menu-panel {
    top: calc(52px + max(6px, env(safe-area-inset-top)));
    left: var(--page-pad-x);
    width: min(360px, calc(100% - var(--page-pad-x) - var(--page-pad-r)));
    max-height: min(
      75dvh,
      75svh,
      calc(100dvh - 64px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
      calc(100svh - 64px - env(safe-area-inset-top) - env(safe-area-inset-bottom))
    );
  }

  .overlay {
    align-items: flex-start;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: var(--page-pad-x);
    padding-right: var(--page-pad-r);
  }

  .overlay-card {
    width: 100%;
    max-width: 100%;
    max-height: min(
      92dvh,
      92svh,
      calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px),
      calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px),
      1100px
    );
    height: auto;
    padding: 14px;
    gap: 12px;
    border-radius: 16px;
    margin-top: 4px;
  }

  .overlay-text {
    font-size: 13px;
    line-height: 1.44;
  }

  .overlay-text .intro-lead {
    font-size: clamp(1.22rem, 5.4vw, 1.58rem);
    font-weight: 700;
    line-height: 1.26;
    margin-bottom: 0.85rem;
  }

  .overlay-text .intro-body {
    font-size: 13px;
    line-height: 1.44;
  }

  .lets-go-button {
    padding: 12px 24px;
    font-size: clamp(16px, 4.2vw, 22px);
    max-width: 100%;
  }
}
