/**
 * STORMSCAPE — floating overlays: view dock, mini panels, callouts, toasts,
 * modals, and the tilt-shift treatment.
 */

/* ==========================================================================
   VIEW DOCK
   ========================================================================== */

.dockgroup {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(var(--panel-blur)) saturate(var(--panel-saturate));
  -webkit-backdrop-filter: blur(var(--panel-blur)) saturate(var(--panel-saturate));
  box-shadow: var(--shadow-lg), inset 0 1px 0 var(--edge-highlight);
}

.dockbutton {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  color: var(--text-tertiary);
  white-space: nowrap;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.dockbutton:hover {
  background: var(--bg-control-hover);
  color: var(--text-primary);
}

.dockbutton[data-active='true'] {
  background: var(--bg-control-active);
  color: var(--text-primary);
}

.dockbutton--accent[data-active='true'] {
  background: var(--accent-muted);
  color: var(--accent-text);
}

.dockbutton__icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.dockbutton__icon svg {
  width: 16px;
  height: 16px;
}

.dockbutton__caret svg {
  width: 9px;
  height: 6px;
  opacity: 0.7;
}

.dockbutton--icon {
  padding: var(--space-2);
}

/* Labels are the first thing to go when horizontal space runs out — the icons
   are distinct enough to work alone, and the tooltips remain. The breakpoint
   accounts for both side panels being open: at 1600px that leaves roughly
   860px of stage, which is the point where seven labelled camera buttons plus
   the view controls stop fitting. */
@media (max-width: 1600px) {
  .dockgroup:first-child .dockbutton__label {
    display: none;
  }

  .dockgroup:first-child .dockbutton {
    padding: var(--space-2);
  }
}

/* --------------------------------------------------------------------------
   Dock menus
   -------------------------------------------------------------------------- */

/* Fixed and parented to <body>, not to the dock.
   `.viewdock` scrolls horizontally on narrow viewports, and an overflow that is
   not `visible` on one axis forces the other axis to clip too — so a popover
   opening upward out of the dock was being cut off entirely. Escaping to the
   body is what keeps these menus on screen at every width. */
.dockmenu {
  position: fixed;
  z-index: var(--z-sheet);
  min-width: 232px;
  max-width: 300px;
  max-height: min(60dvh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: var(--space-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: var(--bg-panel-solid);
  box-shadow: var(--shadow-xl);
  animation: menu-in var(--duration-normal) var(--ease-out) both;
  transform-origin: bottom left;
}

@keyframes menu-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.dockmenu__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dockmenu__item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background var(--duration-instant) var(--ease-out);
}

.dockmenu__item:hover,
.dockmenu__item:focus-visible {
  background: var(--bg-control-hover);
}

.dockmenu__item[data-active='true'] .dockmenu__label {
  color: var(--accent-text);
}

.dockmenu__label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

.dockmenu__desc {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  color: var(--text-tertiary);
}

.dockmenu__check {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  margin-top: 2px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--bg-inset);
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.dockmenu__item[data-active='true'] .dockmenu__check {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--bg-panel-solid);
}

/* ---- Composed popovers: a slider and shortcuts above the toggle list ------ */

.dockmenu__section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.dockmenu__slider {
  padding: var(--space-2) var(--space-3) 0;
}

.dockmenu__actions {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-1);
}

.dockmenu__action {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-control);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  text-align: center;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.dockmenu__action:hover,
.dockmenu__action:focus-visible {
  background: var(--bg-control-hover);
  color: var(--text-primary);
}

.dockmenu__divider {
  height: 1px;
  background: var(--border-soft);
}

/* ==========================================================================
   MINI PANELS
   ========================================================================== */

.mini {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(var(--panel-blur)) saturate(var(--panel-saturate));
  -webkit-backdrop-filter: blur(var(--panel-blur)) saturate(var(--panel-saturate));
  box-shadow: var(--shadow-lg), inset 0 1px 0 var(--edge-highlight);
  animation: mini-in var(--duration-slow) var(--ease-out) both;
}

@keyframes mini-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.mini__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.mini__title {
  color: var(--text-tertiary);
}

.mini__unit {
  font-size: 9px;
  letter-spacing: var(--tracking-wider);
  color: var(--text-disabled);
}

/* ---- Conditions ---------------------------------------------------------- */

.mini--conditions {
  display: flex;
  gap: var(--space-5);
}

.condition {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 58px;
}

.condition__label {
  font-size: 9px;
  color: var(--text-tertiary);
}

.condition__figure {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.condition__value {
  font-family: var(--font-display);
  font-size: var(--text-md);
  line-height: 1;
  color: var(--text-primary);
}

.condition__value[data-severity='3'] { color: var(--sev-3); }
.condition__value[data-severity='4'] { color: var(--sev-4); }
.condition__value[data-severity='5'] { color: var(--sev-5); }

.condition__unit {
  font-size: 9px;
  color: var(--text-tertiary);
}

/* ---- Radar legend -------------------------------------------------------- */

.mini--legend {
  width: 188px;
}

.legend__scale {
  height: 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-soft);
}

.legend__ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
}

.legend__tick {
  font-size: 9px;
  color: var(--text-disabled);
}

.legend__note {
  margin-top: var(--space-2);
  font-size: 9px;
  line-height: 1.4;
  color: var(--text-tertiary);
}

/* ---- EF damage scale ----------------------------------------------------- */
/* Stepped rather than a gradient, because the EF scale is: a survey assigns a
   whole rating, never a value between two. */

.eflegend {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.eflegend__band {
  display: grid;
  place-items: center;
  height: 14px;
}

.eflegend__label {
  font-size: 9px;
  font-weight: var(--weight-semibold);
  /* Dark ink on every band: the EF ramp runs light green to magenta, and no
     single light or dark label stays legible across all six. */
  color: rgba(8, 11, 16, 0.82);
}

/* ---- Rain-wrapped alert -------------------------------------------------- */

.mini--alert {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: color-mix(in srgb, var(--danger) 16%, var(--bg-panel-solid));
}

.mini__pulse {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--danger);
  animation: alert-pulse 1.6s var(--ease-in-out) infinite;
}

@keyframes alert-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .mini__pulse { animation: none; }
}

.mini__alert-text {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--danger-text);
}

/* ==========================================================================
   CALLOUTS + TOASTS
   ========================================================================== */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--timeline-height) + env(safe-area-inset-bottom) + var(--space-8));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: min(400px, calc(100vw - var(--space-8)));
  pointer-events: none;
}

.toasts > * {
  pointer-events: auto;
}

.callout {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--accent-border);
  background: var(--bg-panel-solid);
  box-shadow: var(--shadow-xl);
  animation: callout-in var(--duration-slow) var(--ease-out) both;
}

@keyframes callout-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.callout[data-leaving='true'] {
  animation: callout-out var(--duration-normal) var(--ease-in) both;
}

@keyframes callout-out {
  to { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

.callout__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.callout__eyebrow {
  color: var(--accent-text);
}

.callout__close {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-xs);
  color: var(--text-disabled);
}

.callout__close:hover {
  color: var(--text-primary);
  background: var(--bg-control-hover);
}

.callout__close svg {
  width: 11px;
  height: 11px;
}

.callout__label {
  margin-top: 2px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.callout__text {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
}

.toast {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-panel-solid);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity var(--duration-normal) var(--ease-out),
    transform var(--duration-normal) var(--ease-out);
}

.toast[data-open='true'] {
  opacity: 1;
  transform: none;
}

.toast[data-leaving='true'] {
  opacity: 0;
  transform: translateY(-6px);
}

.toast[data-tone='warn'] {
  border-color: color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn-text);
}

.toast[data-tone='error'] {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger-text);
}

/* ==========================================================================
   MODAL
   ========================================================================== */

.modal-root:empty {
  display: none;
}

.modal__scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--bg-scrim);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in var(--duration-normal) var(--ease-out) both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: calc(var(--z-modal) + 1);
  width: min(560px, calc(100vw - var(--space-8)));
  max-height: min(680px, calc(100dvh - var(--space-16)));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-strong);
  background: var(--bg-panel-solid);
  box-shadow: var(--shadow-xl);
  opacity: 0;
  transform: translate(-50%, -48%) scale(0.97);
  transition:
    opacity var(--duration-normal) var(--ease-out),
    transform var(--duration-normal) var(--ease-out);
}

.modal[data-open='true'] {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.modal[data-leaving='true'] {
  opacity: 0;
  transform: translate(-50%, -52%) scale(0.98);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-soft);
}

.modal__title {
  font-size: var(--text-lg);
}

.modal__close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
}

.modal__close:hover {
  background: var(--bg-control-hover);
  color: var(--text-primary);
}

.modal__close svg {
  width: 15px;
  height: 15px;
}

.modal__body {
  padding: var(--space-6);
  overflow-y: auto;
}

.modal__body h3 {
  margin-top: var(--space-5);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.shortcuts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3) var(--space-5);
  align-items: baseline;
}

.shortcuts__key {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-inset);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
}

.shortcuts__desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ==========================================================================
   TILT-SHIFT
   ========================================================================== */

/**
 * A blur gradient across the top and bottom of the stage with a sharp band
 * through the middle. This is the actual optical signature of a tilt-shift
 * lens, and it is what makes a landscape read as a scale model — far more
 * convincing here than a real depth-of-field pass, and it costs no GPU time
 * the storm needs.
 */
.stage[data-miniature]::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  backdrop-filter: blur(5px) saturate(1.35);
  -webkit-backdrop-filter: blur(5px) saturate(1.35);
  mask-image: linear-gradient(
    180deg,
    #000 0%, #000 22%,
    transparent 40%, transparent 60%,
    #000 78%, #000 100%
  );
  -webkit-mask-image: linear-gradient(
    180deg,
    #000 0%, #000 22%,
    transparent 40%, transparent 60%,
    #000 78%, #000 100%
  );
}

/* ==========================================================================
   MOBILE
   ========================================================================== */

@media (max-width: 720px) {
  .toasts {
    bottom: calc(
      var(--sheet-peek) + var(--timeline-height) + env(safe-area-inset-bottom) + var(--space-16)
    );
    width: calc(100vw - var(--space-6));
  }

  .mini--legend {
    width: 158px;
  }

  .mini--conditions {
    gap: var(--space-4);
  }

  .condition {
    min-width: 46px;
  }

  .dockmenu {
    position: fixed;
    left: var(--space-3) !important;
    right: var(--space-3);
    bottom: calc(
      var(--sheet-peek) + var(--timeline-height) + env(safe-area-inset-bottom) + var(--space-12)
    ) !important;
    min-width: 0;
    max-width: none;
    max-height: 52dvh;
    overflow-y: auto;
  }

  .modal {
    width: calc(100vw - var(--space-6));
    max-height: calc(100dvh - var(--space-12));
  }

  .modal__head,
  .modal__body {
    padding: var(--space-4);
  }
}
