/* Stage, background layers, cards, focus mode and floating chrome. */

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  outline: none;
  background: color-mix(in srgb, var(--bg) 96%, black);
  transition: background var(--anim) ease;
}

.stage-bg {
  position: absolute;
  inset: -40px; /* hide blurred edges */
  background: center / cover no-repeat;
  filter: blur(var(--bg-blur));
  transition: opacity .6s ease, filter .3s ease;
}
/* Ambient: the first card's image, heavily blurred and darkened so cards stay in front */
.stage-bg.ambient {
  inset: -140px;
  filter: blur(56px) brightness(.55) saturate(1.3);
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent calc(var(--vignette-size) * 100%), rgb(0 0 0 / var(--vignette-strength)) 100%);
}

#stage.drag-over::after {
  content: 'Drop to add';
  position: absolute;
  inset: 16px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  pointer-events: none;
  z-index: 5;
}

/* ---------- Stack & cards ---------- */
/* The stack fills the screen; the auto-hiding bars float over the margins. */
.stack {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 14px;
  width: calc(100vw - 2 * var(--stage-pad-x));
  height: calc(100dvh - 2 * var(--stage-pad-y));
}

/* flex-grow is set per card from the media's aspect ratio (stage.js) */
.card {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
}
.card.exiting { pointer-events: none; z-index: -1; }
/* Off-stage website/HTML cards stay in the DOM (so the page keeps its state) but hidden */
.card.parked { display: none !important; }

/* Text / HTML: a panel that hugs its content */
.card-inner {
  position: relative;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--surface) var(--card-alpha), transparent);
  border: 1px solid color-mix(in srgb, var(--border) calc(var(--card-opacity) * 100%), transparent);
  box-shadow:
    0 16px 40px color-mix(in srgb, #000a calc(var(--card-opacity) * 100%), transparent),
    inset 0 1px 0 color-mix(in srgb, #ffffff10 calc(var(--card-opacity) * 100%), transparent);
  transition: background .3s ease, border-color .3s ease, box-shadow .3s ease;
}
.card-inner.kind-text { width: fit-content; max-width: min(100%, 1100px); }
.card-inner.kind-html,
.card-inner.kind-web { width: 100%; height: 100%; overflow: hidden; }
body.focus-mode .card-inner.kind-web { max-width: none; max-height: none; border-radius: 0; }

/* Website card: our bar on top, the live site below */
.web-card { display: flex; flex-direction: column; width: 100%; height: 100%; }
.web-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  height: 40px;
  padding: 0 48px; /* room for pin / close */
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 96%, #fff 2%);
  cursor: pointer;
  user-select: none;
}
.web-host {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.web-host svg { width: 15px; height: 15px; }
.web-action {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.web-action:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); }
.web-action svg { width: 16px; height: 16px; }
.web-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #fff; }
body.idle .web-bar { opacity: .35; transition: opacity .35s ease; }
/* While dragging a thumbnail onto cards, iframes must not swallow the pointer */
body.dragging-card iframe { pointer-events: none; }

/* Media: the image itself is the card */
.card-inner.has-media {
  width: 100%;
  height: 100%;
  overflow: visible;
  background: none;
  border: 0;
  box-shadow: none;
}
.media-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.media {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow:
    0 18px 44px rgb(0 0 0 / calc(.55 * var(--card-opacity))),
    0 0 0 1px rgb(255 255 255 / calc(.07 * var(--card-opacity)));
  opacity: 0;
  transition: opacity .25s ease;
  user-select: none;
}
.media.loaded { opacity: 1; }
.card.drop-target .media,
.card.drop-target .card-inner:not(.has-media) { outline: 3px dashed var(--accent); outline-offset: 6px; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid color-mix(in srgb, var(--muted) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-block {
  padding: 22px 28px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: clamp(20px, 3vw, 44px);
  line-height: 1.35;
  text-shadow: 0 1px 12px rgb(0 0 0 / .5);
}
.stack:not([data-mode="1"]) .text-block { font-size: clamp(16px, 1.7vw, 28px); padding: 16px 20px; }
.text-block a { color: beige; }

.html-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

/* Pin / close buttons, anchored to the visible media rect (set by card.js) */
.card-btn {
  position: absolute;
  top: calc(var(--media-top, 8px) + 4px);
  z-index: 3;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(6px);
  color: var(--ink);
  cursor: pointer;
  opacity: 0;
  transform: scale(.9);
  transition: opacity .15s, transform .15s, border-color .15s, background .15s;
}
.card-btn svg { width: 16px; height: 16px; }
.card-btn.pin { left: calc(var(--media-left, 8px) + 6px); top: var(--pin-top, calc(var(--media-top, 8px) + 4px)); }
.card-btn.close { right: calc(var(--media-right, 8px) + 6px); top: var(--close-top, calc(var(--media-top, 8px) + 4px)); }
/* Mouse movement over a live website never reaches us, so keep its buttons visible */
.card:has(.kind-web) .card-btn { opacity: 1; transform: none; }
.card-btn.visible, .card-btn:focus-visible, .card-btn.pin.active { opacity: 1; transform: none; }
.card-btn:hover { border-color: var(--accent); }
.card-btn.close:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 35%, var(--surface)); }
.card-btn.pin.active { color: var(--accent); border-color: var(--accent); }

.annotation {
  position: absolute;
  z-index: 2;
  width: 10px;
  height: 10px;
  border: 2px solid;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: .8;
  pointer-events: none;
  transition: opacity .5s ease;
}
.annotation.fade { opacity: 0; }

/* ---------- Focus mode ---------- */
body.focus-mode #stage { background: #000; }
body.focus-mode .stage-bg,
body.focus-mode .vignette { opacity: 0; }
body.focus-mode .stack .card:not(.exiting):not(.parked) { position: fixed; inset: 0; z-index: 10; }
body.focus-mode .media { border-radius: 0; box-shadow: none; transition: opacity .2s ease; }
body.focus-mode .card-inner:not(.has-media) { max-width: min(1100px, 92vw); max-height: 92vh; }
.card.zoomed .media { cursor: grab; }
.card.zoomed .media:active { cursor: grabbing; }

.zoom-pill, .busy-pill {
  position: fixed;
  left: 50%;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-float);
  font: 600 13px var(--mono);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition: opacity .18s ease, transform .18s var(--ease);
}
.zoom-pill { bottom: 24px; }
.busy-pill { top: 24px; font-family: var(--font); }
.busy-pill .spinner { width: 14px; height: 14px; border-width: 2px; }
.zoom-pill.visible, .busy-pill.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Floating chrome: corner buttons + bottom controls ---------- */
.corner { position: fixed; top: var(--edge); z-index: 40; }
.corner.left { left: var(--edge); }
.corner.right { right: var(--edge); }
body.focus-mode .corner { opacity: .3; }
body.focus-mode .corner:hover { opacity: 1; }
body.fs .corner { display: none; }

.controls {
  position: fixed;
  left: 50%;
  bottom: var(--edge);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .2s ease, transform .2s var(--ease);
}
.controls.visible { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.controls .icon-btn { border-color: transparent; background: transparent; }
.controls .icon-btn:hover { border-color: var(--accent); }
.controls .position { min-width: 72px; text-align: center; font: 600 13px var(--mono); color: var(--muted); }
.controls .layouts { display: flex; gap: 2px; }
.divider-v { width: 1px; align-self: stretch; margin: 4px 4px; background: var(--border); }
body.is-empty .stack { display: none; }
.controls .icon-btn[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--ink); }

/* ---------- Presentation (idle) mode ---------- */
body.idle, body.idle * { cursor: none !important; }
body.idle .corner,
body.idle .controls,
body.idle .topbar,
body.idle .card-btn:not(.active) { opacity: 0 !important; pointer-events: none !important; }
body.idle .card-btn.active { opacity: .5; }
.corner { transition: opacity .35s ease; }
