/* One reachable primary action. This layer changes presentation only; the
   approved gold nine-slice artwork and the original media handlers stay intact. */
:root { --ew-thumb-space: calc(100px + env(safe-area-inset-bottom, 0px)); }
body.storybook .ew-thumb-screen {
  position: relative;
  /* Entrance transforms make fixed descendants relative to the whole stage,
     briefly putting Save below a tall result. Keep only the gentle fade. */
  transform: none !important;
  animation-name: ew-thumb-appear !important;
  padding-bottom: var(--ew-thumb-space);
  scroll-padding-bottom: var(--ew-thumb-space);
}
@keyframes ew-thumb-appear { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  body.storybook .ew-thumb-screen { animation: none !important; }
}
html[data-ew-action-buttons="ready"] body.storybook .ew-thumb-screen .ew-thumb-primary {
  position: fixed !important;
  z-index: 110;
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: calc(12px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px))) !important;
  transform: translateX(-50%);
  width: max-content !important;
  min-width: 160px !important;
  max-width: min(320px, calc(100vw - 32px)) !important;
  min-height: 56px !important;
  margin: 0 !important;
  padding: 13px 24px;
  align-self: center;
}
html[data-ew-action-buttons="ready"] body.storybook .ew-thumb-screen .ew-thumb-primary:active:not(:disabled) {
  transform: translateX(-50%) scale(.98);
}
body.storybook .ew-thumb-screen[data-thumb-primary="true"]::after {
  content: '';
  position: fixed;
  inset: auto 0 0;
  height: var(--ew-thumb-space);
  pointer-events: none;
  z-index: 109;
  background: linear-gradient(transparent, #020610 38%);
}
/* Native modal layers must not reveal the page's bottom action behind them. */
body.storybook:has(dialog:modal) .ew-thumb-screen:not(dialog):not(dialog *) > .ew-thumb-primary,
body.storybook:has(#magic-capture) .ew-thumb-screen:not(#magic-capture):not(#magic-capture *) .ew-thumb-primary {
  visibility: hidden !important;
}
body.storybook:has(dialog:modal) .ew-thumb-primary { visibility: hidden !important; }
body.storybook dialog:modal .ew-thumb-primary { visibility: visible !important; }

/* Secondary actions appear only when requested. Keep the original controls and
   native file/download links, with one compact Options entry near the heading. */
body.storybook .ew-thumb-options {
  position: sticky;
  top: 8px;
  z-index: 120;
  width: max-content;
  max-width: 100%;
  margin: 0 0 8px auto;
  align-self: flex-end;
  grid-column: 1 / -1;
}
body.storybook .ew-thumb-options > summary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 48px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--gold, #f4e5c8);
  font: inherit;
  font-size: 16px !important;
  line-height: 1.3;
  list-style: none;
  cursor: pointer;
  touch-action: manipulation;
}
body.storybook .ew-thumb-options > summary::-webkit-details-marker { display: none; }
body.storybook .ew-thumb-options:not([open]) > :not(summary) { display: none !important; }
body.storybook .ew-thumb-options > summary:focus-visible { outline: 2px solid #DFB87A; outline-offset: 2px; }
body.storybook .ew-thumb-options-panel {
  position: fixed;
  z-index: 121;
  left: 50%;
  bottom: calc(88px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 160px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 20px;
  border: 1px solid #dfb87a55;
  border-radius: 16px;
  background: #020610;
  box-shadow: 0 12px 50px #0009;
  color: var(--gold, #f4e5c8);
}
body.storybook .ew-thumb-option-item:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
body.storybook .ew-thumb-option-item + .ew-thumb-option-item { margin-top: 12px; }
body.storybook .ew-thumb-options-panel .button.secondary {
  width: fit-content !important;
  min-height: 48px !important;
  max-width: 100% !important;
  margin: 0 !important;
}
body.storybook .ew-thumb-options-panel :is(.tree-range, .journey-fine-adjustments, .character-brightness-control) { width: 100%; }
/* Finished photos/videos keep Download reachable without covering the Options
   toggle. Use the already accepted Journey result layout on the other results. */
body.storybook :is(#result-screen, #santa-result, #tree-result).ew-thumb-screen {
  --ew-thumb-space: calc(156px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
}
body.storybook :is(#result-screen, #santa-result, #tree-result) .ew-thumb-options > summary {
  position: fixed;
  z-index: 122;
  right: max(16px, calc((100vw - 520px)/2));
  bottom: calc(84px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
}
body.storybook :is(#result-screen, #santa-result, #tree-result) .ew-thumb-options-panel {
  bottom: calc(148px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
  max-height: calc(100dvh - 180px - max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
}
body.storybook .ew-thumb-screen .result-delivery { display: contents; }
body.storybook :is(#anchor-screen, #journey-editor, #tree-editor).ew-thumb-screen :is(.photo-editor, .journey-editor-layout, .tree-editor-layout) { grid-template-columns: minmax(0,1fr); }
body.storybook #journey-editor .journey-controls { gap: 0; }

/* A camera stays large; its shutter occupies the same reachable bottom spot. */
body.storybook #magic-capture.ew-thumb-screen { position: fixed !important; inset: 0; padding-bottom: var(--ew-thumb-space); }
body.storybook #magic-capture .magic-capture-header { display: grid; grid-template-columns: minmax(0,1fr) auto 48px; gap: 6px; }
body.storybook #magic-capture .magic-capture-eyebrow { display: none; }
body.storybook #magic-capture .magic-capture-heading { grid-column: 1; grid-row: 1; min-width: 0; align-self: center; }
body.storybook #magic-capture .ew-thumb-options { grid-column: 2; grid-row: 1; margin: 0; align-self: center; }
body.storybook #magic-capture .magic-capture-close { grid-column: 3; grid-row: 1; align-self: center; }
body.storybook #magic-capture .magic-capture-controls { margin: 0; }
body.storybook #magic-capture .magic-capture-shutter { line-height: 1.3; }
body.storybook #magic-capture .magic-capture-frame { max-height: calc(100dvh - 240px); }

/* Generated photo-sticker ranges retain their handlers outside closed Options.
   Reserve the same thumb-height row as the video placement screen. */
body.storybook #magic-capture:has(.ew-camera-brightness) {
  --ew-thumb-space: calc(136px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
  overflow: hidden;
}
body.storybook #magic-capture:has(.ew-camera-brightness) .magic-capture-shell {
  display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0;
}
body.storybook #magic-capture:has(.ew-camera-brightness) .magic-capture-header,
body.storybook #magic-capture:has(.ew-camera-brightness) .magic-capture-instruction { flex: 0 0 auto; }
body.storybook #magic-capture:has(.ew-camera-brightness) .magic-capture-frame {
  flex: 1 1 0; min-height: 0; width: 100% !important;
  height: auto; max-height: none; aspect-ratio: auto; margin: 0;
}
body.storybook #magic-capture .ew-camera-brightness {
  position: fixed; z-index: 111; left: 50%;
  bottom: calc(80px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
  transform: translateX(-50%); display: grid;
  grid-template-columns: auto minmax(60px, 1fr) 4ch; align-items: center; gap: 8px;
  width: min(440px, calc(100vw - 32px)); min-height: 44px;
  margin: 0; font-size: 16px; line-height: 1.3; text-align: left;
}
body.storybook #magic-capture .ew-camera-brightness > :is(output, span) {
  grid-column: 3; grid-row: 1; float: none; text-align: right;
}
body.storybook #magic-capture .ew-camera-brightness > input {
  grid-column: 2; grid-row: 1; min-width: 0; width: 100%;
  height: 44px; min-height: 44px; margin: 0; accent-color: #DFB87A;
}
body.storybook #magic-capture:has(.ew-camera-brightness) .ew-thumb-options-panel {
  bottom: calc(136px + max(env(safe-area-inset-bottom, 0px), var(--ew-thumb-keyboard, 0px)));
  max-height: min(48dvh, calc(100dvh - 240px));
}

/* Room choices are a thumb-height sheet. File labels stay linked to their
   original inputs; camera actions still run within the user's actual tap. */
body.storybook dialog.journey-room-choice.ew-thumb-screen {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: 520px;
  max-height: min(80dvh, 520px);
  margin: 0 auto;
  padding: 20px 24px var(--ew-thumb-space);
  border-radius: 20px 20px 0 0;
}
body.storybook dialog.journey-room-choice .ew-thumb-options { margin-bottom: 0; }

/* The phone call keeps its familiar answer/end screen. Only the name setup's
   Make call action adopts the reachable primary placement. */
body.storybook .santa-chat .santa-call-name-screen.ew-thumb-screen { padding-bottom: var(--ew-thumb-space); }
body.storybook .santa-chat .ew-thumb-options { flex: 0 0 auto; }
@media (max-width: 720px) {
  body.storybook .santa-chat { width: calc(100% - 16px); height: calc(100dvh - 16px); max-height: calc(100dvh - 16px); }
  body.storybook .santa-call-name-screen { justify-content: flex-start; }
  body.storybook .santa-call-name-portrait { max-height: 110px; width: auto; }
}
@media (max-height: 500px) {
  body.storybook .ew-thumb-options-panel { max-height: calc(100dvh - 130px); padding: 12px; }
  body.storybook .santa-call-name-portrait { max-height: 80px; width: auto; }
}
