/*
 * Expand canvas: named shape tiles, the Output block, the stage guide (before a run),
 * the Expanded ⇄ Original view (after a run), and the stage-bar preview chip.
 * Tokens only (css/tokens.css); mixes use color-mix() over tokens. Loaded by index.php when
 * Expand is the page's tool, or by js/tools/extender.js on a client-side switch.
 */

/* ---- Shape tiles: a 3×3 grid, ratio + use name, share of new area on hover/focus ---- */
body.imagestack-page .it-field--shapes { margin: 0; padding: 0; border: 0; min-width: 0; }

.it-shapes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

body.imagestack-page .it-shape {
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  grid-template-rows: 16px 14px;
  align-content: center;
  column-gap: 5px;
  row-gap: 1px;
  min-width: 0;
  height: 46px;
  margin: 0;
  padding: 0 6px 0 8px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out), opacity var(--t-fast) var(--ease-out);
}
body.imagestack-page .it-shape:hover { background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--border-control); }

.it-shape-glyph { grid-row: 1; grid-column: 1; display: grid; place-items: center; width: 16px; height: 16px; }
.it-shape-glyph > span { display: block; border: 1.5px solid var(--text-3); transition: border-color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out); }

.it-shape-text { display: contents; }
.it-shape-ratio { grid-row: 1; grid-column: 2; font-size: var(--fs-label); line-height: 16px; font-weight: 700; color: var(--text); }
.it-shape-name,
.it-shape-pct {
  grid-row: 2;
  grid-column: 1 / -1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs-meta);
  line-height: 14px;
  font-weight: 500;
  color: var(--text-3);
}
/* The share of new area swaps in on hover and keyboard focus; the Output block keeps describing the selection. */
.it-shape-pct { visibility: hidden; }
body.imagestack-page .it-shape:hover .it-shape-pct,
body.imagestack-page .it-seg-input:checked + .it-shape .it-shape-pct,
body.imagestack-page .it-seg-input:focus-visible + .it-shape .it-shape-pct { visibility: visible; }
body.imagestack-page .it-shape:hover .it-shape-name,
body.imagestack-page .it-seg-input:checked + .it-shape .it-shape-name,
body.imagestack-page .it-seg-input:focus-visible + .it-shape .it-shape-name { visibility: hidden; }
/* "Your shape" stays a name, not a number */
body.imagestack-page .it-shape.is-yours .it-shape-pct { visibility: hidden; }
body.imagestack-page .it-shape.is-yours .it-shape-name { visibility: visible; }

body.imagestack-page .it-seg-input:checked + .it-shape {
  background: var(--surface-3);
  box-shadow: var(--e-1), inset 0 0 0 1.5px var(--accent);
}
body.imagestack-page .it-seg-input:checked + .it-shape .it-shape-glyph > span { border-color: var(--accent); background: var(--accent-tint); }
body.imagestack-page .it-seg-input:checked + .it-shape .it-shape-name { color: var(--text-2); }
body.imagestack-page .it-seg-input:checked + .it-shape .it-shape-pct { color: var(--accent); }
body.imagestack-page .it-seg-input:focus-visible + .it-shape { outline: 2px solid var(--accent); outline-offset: 2px; }

.it-shape.is-suggested::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--accent);
}
body.imagestack-page .it-shape.is-yours .it-shape-glyph > span { border-style: dashed; }
body.imagestack-page .it-shape.is-yours .it-shape-ratio { color: var(--text-3); }

/* Locked while a run is in flight: the inspector must describe what is being made */
body.imagestack-page .it-field--shapes:disabled .it-shape,
body.imagestack-page fieldset:disabled .it-seg-option { opacity: .5; cursor: not-allowed; }
body.imagestack-page .it-field--shapes:disabled .it-shape:hover { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }

body.imagestack-page .it-x-suggest {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--lh-meta);
  margin-top: var(--sp-2);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
body.imagestack-page .it-x-suggest.has-dot::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--accent);
}

/* ---- Output block: never truncated, tabular numbers ---- */
.it-x-output { margin-top: var(--sp-3); }
body.imagestack-page .it-x-primary { padding-bottom: var(--sp-4); }
body.imagestack-page .it-x-output .it-label { margin-bottom: 4px; }
body.imagestack-page .it-x-output-value {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px var(--sp-2);
  margin: 0;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: 600;
  color: var(--text);
}
body.imagestack-page .it-x-output-value.is-empty { font-size: var(--fs-meta); line-height: var(--lh-meta); font-weight: 500; color: var(--text-3); }
body.imagestack-page .it-x-output-meta { margin: 2px 0 0; font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--text-2); }
body.imagestack-page .it-x-warn,
body.imagestack-page .it-x-info {
  display: flex;
  gap: var(--sp-2);
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-meta);
  line-height: var(--lh-meta);
}
body.imagestack-page .it-x-warn { color: var(--warning); }
body.imagestack-page .it-x-info { color: var(--text-3); }
.it-x-warn > i, .it-x-info > i { margin-top: 2px; font-size: 11px; }
.it-x-warn[hidden], .it-x-info[hidden] { display: none; }

.it-section > .it-field + .it-advanced { margin-top: var(--sp-4); }

/* Quality: the label sits above a full-width two-segment control, so "Standard" and "Best" are never cut at any
   inspector width (critic r2 N2). */

/* Laptop heights (1366×657, 1280×680, 1440×760): the controls come first. The description, the Quality
   help (kept as the control's accessible description) and the shared result facts give their room back. */
@media (min-width: 960px) and (max-height: 800px) {
  body[data-tool="extender"] #itFacts { display: none !important; }
  body[data-tool="extender"] #itToolDesc { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  body[data-tool="extender"] .it-inspector-head { padding-bottom: var(--sp-3); }
  body.imagestack-page .it-app[data-tool="extender"] [data-control="rendering_speed"] > .it-help { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  body.imagestack-page .it-app[data-tool="extender"] .it-x-primary { padding-top: var(--sp-3); padding-bottom: var(--sp-3); }
  body.imagestack-page .it-app[data-tool="extender"] .it-x-primary + .it-section { padding-top: var(--sp-3); }
  body.imagestack-page .it-app[data-tool="extender"] .it-x-output { margin-top: var(--sp-2); }
}

/* ---- Stage guide (viewport space, positioned from the image's own rect) ---- */
.it-x-frame {
  position: absolute;
  pointer-events: none;
  border-radius: var(--r-sm);
  /* Two-tone hatch: a light and a dark line per stripe, so it reads next to black and white photos. */
  background:
    repeating-linear-gradient(135deg,
      color-mix(in srgb, var(--accent) var(--x-hatch-a, 30%), transparent) 0 1.5px,
      color-mix(in srgb, var(--bg) 60%, transparent) 1.5px 3px,
      transparent 3px 8px),
    color-mix(in srgb, var(--accent) var(--x-wash-a, 10%), var(--stage));
  box-shadow: inset 0 0 0 1.5px var(--accent);
  transition: opacity var(--t-med) var(--ease-out);
  animation: it-x-in var(--t-med) var(--ease-out);
}
.it-x-frame.is-running { opacity: .35; }

/* A 1.2 s sweep after a shape change or first show, so thin new areas are noticed (static under reduced motion) */
.it-x-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(110deg, transparent 30%, color-mix(in srgb, var(--accent) 45%, transparent) 50%, transparent 70%) 0 0 / 250% 100% no-repeat;
  opacity: 0;
  pointer-events: none;
}
.it-x-frame.is-fresh::after { animation: it-x-sweep 1.2s var(--ease-in-out) 1; }
@keyframes it-x-sweep {
  0% { opacity: 1; background-position: 150% 0; }
  85% { opacity: 1; }
  100% { opacity: 0; background-position: -60% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .it-x-frame.is-fresh::after { animation: none; }
  .it-x-frame.is-fresh { box-shadow: inset 0 0 0 2.5px var(--accent); }
}

/* The photo's edge: a 1px light line with a 1px dark halo outside it */
.it-x-edge {
  position: absolute;
  pointer-events: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 85%, transparent), 0 0 0 2px color-mix(in srgb, var(--bg) 85%, transparent);
  z-index: 1;
}
.it-x-frame[hidden], .it-x-edge[hidden], .it-x-label[hidden], .it-x-caption[hidden] { display: none; }

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

.it-x-label,
.it-x-caption {
  position: absolute;
  z-index: var(--z-stage-ui);
  transform: translateX(-50%);
  max-width: calc(100% - 16px);
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: var(--badge-ground);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: var(--fs-meta);
  line-height: var(--lh-meta);
  white-space: nowrap;
  pointer-events: none;
}
.it-x-label { font-weight: 600; color: var(--text); }
.it-x-caption { font-weight: 500; color: var(--text-2); }

/* The preview note in the stage bar, when the stage can't carry it */
.it-x-previewchip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 28px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--fs-meta);
  line-height: var(--lh-meta);
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.it-x-previewchip[hidden] { display: none; }
.it-x-previewchip > i { font-size: 11px; color: var(--accent); }
.it-x-previewchip.is-warn { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.it-x-previewchip.is-warn > i { color: var(--warning); }
.it-x-previewchip-long { overflow: hidden; text-overflow: ellipsis; }
.it-x-previewchip-short { display: none; }
@media (max-width: 1279px) {
  .it-x-previewchip-long { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .it-x-previewchip-short { display: inline; }
}

/* Shared hints never stack with the guide or the Original view; a transparent input previews on white (what is sent) */
.it-viewport:has(.it-x-frame:not([hidden])) .it-stagehint,
.it-viewport:has(.it-canvas.it-x-toggle) .it-stagehint { display: none; }
.it-app[data-tool="extender"].is-x-alpha [data-bg-swatches] { display: none !important; }

/* ---- After a run: Expanded ⇄ Original. Original is its own fitted layer, not aligned to the result. ---- */
.it-viewport:has(.it-canvas.it-x-toggle) .it-compare,
.it-viewport:has(.it-canvas.it-x-toggle) .it-badge,
.it-viewport:has(.it-canvas.it-x-toggle) .it-divider-edge { display: none !important; }
.it-canvas.it-x-toggle .it-before { display: none; }
.it-canvas.it-x-toggle .it-after { clip-path: none !important; visibility: visible !important; }

.it-canvas.it-x-toggle { transition: opacity 200ms var(--ease-in-out); }
.it-viewport.is-x-original .it-canvas.it-x-toggle { opacity: 0; }

.it-x-original {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  background: var(--stage);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms var(--ease-in-out), visibility 0s linear 200ms;
}
.it-x-original[hidden] { display: none; }
.it-x-original img { display: block; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--r-sm); box-shadow: var(--e-2); }
.it-viewport.is-x-original .it-x-original { opacity: 1; visibility: visible; transition: opacity 200ms var(--ease-in-out), visibility 0s; }
.it-viewport.is-x-cut .it-canvas.it-x-toggle,
.it-viewport.is-x-cut .it-x-original { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .it-canvas.it-x-toggle, .it-x-original { transition: none !important; }
  .it-x-frame { animation: none; }
}
@media (max-width: 767px) {
  .it-x-original { padding: var(--sp-3); }
}

/* The view control sits in the stage bar, never over generated pixels */
.it-x-viewtoggle[hidden] { display: none; }
body.imagestack-page .it-x-viewtoggle .it-segmini-btn { gap: 6px; min-width: 0; padding: 0 var(--sp-2); }
body.imagestack-page .it-x-viewtoggle .it-segmini-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.it-x-viewthumb { width: 20px; height: 20px; object-fit: cover; border-radius: var(--r-sm); box-shadow: 0 0 0 1px var(--border-control); }
