/* The Image tool (js/image.js): the pop-up over Home, the words (and the picture to change), the image, the Gallery,
   and the sheet that picks a picture from the Gallery. The theme's own tokens (light, dark, wine). */

/* ---------- the pop-up over Home ---------- */

/* Home stays in sight behind it, softly blurred; a tap anywhere outside the card closes it. */
.ip-scrim {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgb(8 6 10 / 38%); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  animation: ip-fade 0.22s ease both;
}
.ip-scrim[hidden] { display: none; }
.ip-scrim.closing { animation: ip-fade 0.18s ease reverse both; }
.ip-card {
  width: 100%; max-width: 380px; border-radius: 28px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgb(0 0 0 / 35%); padding: 22px 16px 16px; text-align: center; color: var(--ink);
  animation: ip-pop 0.3s cubic-bezier(0.2, 0.9, 0.25, 1.12) both;
}
.ip-scrim.closing .ip-card { animation: ip-pop 0.18s ease reverse both; }
.ip-when { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-3); }
.ip-ask { font: 600 1.6rem/1.15 var(--serif); margin: 0.45rem 0 1.15rem; }
.ip-rows { display: grid; gap: 8px; }
.ip-row {
  display: flex; align-items: center; gap: 13px; width: 100%; padding: 10px 12px 10px 10px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); text-align: left; transition: transform 0.12s ease, border-color 0.15s;
}
.ip-row:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.ip-row:active { transform: scale(0.98); }
/* With Artifex while there is no session yet */
.ip-row:disabled { opacity: 0.42; cursor: default; transform: none; border-color: var(--line); }
.ip-row .tile { width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); display: grid; place-items: center; flex: none; color: var(--ink); }
.ip-row .tile svg { width: 34px; height: 34px; overflow: visible; }
.ip-row b { font: 600 1.25rem/1.1 var(--serif); }
.ip-row .chev { margin-left: auto; width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.ip-card .acc, .imagine .acc { fill: var(--accent); }
.ip-card .accs, .imagine .accs { stroke: var(--accent); }
@keyframes ip-fade { from { opacity: 0; } }
@keyframes ip-pop { from { opacity: 0; transform: translateY(10px) scale(0.94); } }

/* ---------- the screen ---------- */

.imagine { min-height: 100%; display: flex; flex-direction: column; background: var(--bg); }
.im-bar {
  display: flex; align-items: center; gap: 0.6rem; width: 100%; max-width: 760px; margin: 0 auto;
  padding: calc(0.8rem + var(--inset-top)) 16px 0.4rem;
}
.im-title { flex: 1; margin: 0; text-align: center; font: 600 1.6rem/1.1 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-gap { width: 40px; flex: none; }
.im-body { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 0.6rem 16px 1rem; }

/* ---------- the words, and the picture to change ---------- */

.im-compose { display: flex; flex-direction: column; gap: 12px; animation: im-in 0.3s ease both; }
.im-from { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
.im-from button[hidden] { display: none; }
.im-from button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; aspect-ratio: 1 / 0.82;
  border-radius: 22px; border: 1.5px dashed var(--line); background: var(--surface); color: var(--ink); font: 600 1.15rem/1.1 var(--serif);
  transition: border-color 0.15s, transform 0.12s;
}
.im-from button:hover { border-color: var(--accent); }
.im-from button:active { transform: scale(0.97); }
.im-from .ic { width: 52px; height: 52px; border-radius: 16px; background: var(--accent-soft); display: grid; place-items: center; }
.im-from svg { width: 30px; height: 30px; overflow: visible; }
/* three choices (with the camera): narrower tiles, the words may take two lines */
.im-from:has(> #im-camera:not([hidden])) button { aspect-ratio: auto; min-height: 8.6rem; padding: 12px 6px; font-size: 1.05rem; text-align: center; }
.im-photo { position: relative; display: grid; place-items: center; border-radius: 20px; overflow: hidden; background: var(--surface-2); }
.im-photo img { display: block; max-width: 100%; max-height: 42vh; object-fit: contain; }
/* A phone: the screen fits without scrolling (Faris 2026-11-21: "should not be scrollable up or down... only if the
   prompt is too long"). The picture to change takes the height the rest leaves; the words box fills what is left and
   scrolls inside itself when the words run long. */
@media (max-width: 999px) {
  .im-body { display: flex; flex-direction: column; padding-bottom: 0.4rem; }
  .im-compose { flex: 1; }
  .im-compose > #im-prompt { flex: 1 1 auto; min-height: 6.5rem; }
  /* sizes from the screen without the keyboard (--im-full-h, js/image.js): the keyboard covers the bottom, the page
     scrolls; the picture never shrinks for it (Faris 2026-11-22) */
  #image.imagine { min-height: max(100%, var(--im-full-h, 0px)); }
  .im-photo img { max-height: max(calc(var(--im-full-h, 100dvh) * 0.24), calc(var(--im-full-h, 100dvh) - 452px - var(--inset-top) - var(--inset-bottom))); }
  /* Reason's line above Generate takes its height from the picture */
  .imagine:has(#im-reason-on:not([hidden])) .im-photo img {
    max-height: max(calc(var(--im-full-h, 100dvh) * 0.2), calc(var(--im-full-h, 100dvh) - 510px - var(--inset-top) - var(--inset-bottom)));
  }
  .imagine:has(> .im-foot:not([hidden])) { overscroll-behavior: none; }
}
.im-swap {
  position: absolute; right: 10px; bottom: 10px; border: 0; border-radius: 999px; padding: 0.45rem 0.9rem;
  font-weight: 600; font-size: 0.85rem; color: #fff; background: rgb(0 0 0 / 55%); backdrop-filter: blur(8px);
}
.im-error { color: var(--danger); font-size: 0.88rem; margin: 0.2rem 2px 0; }
.im-error:empty { display: none; }
#im-prompt {
  width: 100%; min-height: 9rem; resize: none; border: 1px solid var(--line); border-radius: 18px; background: var(--surface);
  color: var(--ink); padding: 1rem 1.05rem; font: inherit; font-size: 1.05rem; line-height: 1.5; outline: none;
  transition: border-color 0.14s, box-shadow 0.14s;
}
#im-prompt:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* the picked star's colour (--star, set by image.js) carries to the words box, Generate and the waiting picture */
.imagine { --star: var(--accent); }
#im-prompt { border-color: color-mix(in srgb, var(--star) 45%, var(--line)); box-shadow: 0 0 18px color-mix(in srgb, var(--star) 12%, transparent); }
#im-prompt:focus { border-color: color-mix(in srgb, var(--star) 80%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--star) 22%, transparent); }
#im-prompt::placeholder { color: var(--ink-3); }

/* the engine and Generate, at the bottom while the words are written */
.im-foot {
  position: sticky; bottom: 0; z-index: 4; width: 100%; max-width: 760px; margin: 0 auto; display: grid; gap: 10px;
  padding: 10px 16px calc(14px + var(--inset-bottom)); background: linear-gradient(to top, var(--bg) 75%, transparent);
}
/* the engine: a bar with the picked star; it unfolds a night sky (always night, whatever the app's colours) */
/* The sky opens upward from the bar, over the screen, joined to it by a thin gold rule: the page never grows, so
   nothing scrolls, moves or squishes (Faris 2026-11-21: "classic and premium rather than wobbly and cute"). */
.im-engine { position: relative; z-index: 5; margin: 0; }
/* nothing in the picker is text to select: a hold on a star (or on its card) never highlights its name */
.im-engine, .im-star-card { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.im-engine[hidden] { display: none; }
.im-star-bar {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 14px 6px 10px; border-radius: 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; text-align: start;
}
.im-star-ic { width: 32px; height: 32px; display: grid; place-items: center; flex: none; border-radius: 50%; background: #1e0c14; }
/* two stars picked: both, a little overlapped, on one dark oval */
.im-star-ic.two { width: 48px; border-radius: 16px; display: flex; justify-content: center; }
.im-star-ic.two svg + svg { margin-inline-start: -6px; }
/* Generate with two stars: their small icons before the word */
.im-go-stars:not([hidden]) { display: inline-flex; align-items: center; gap: 2px; position: relative; z-index: 2; }
.im-go > span[data-t] { position: relative; z-index: 2; }
.im-star-txt b { font-size: 1rem; }
.im-star-txt span { font-size: 0.82rem; color: var(--ink-3); margin-inline-start: 2px; }
.im-star-chev { width: 18px; height: 18px; margin-inline-start: auto; color: var(--ink-3); transition: transform 0.3s ease; }
.im-engine.open .im-star-chev { transform: rotate(180deg); }
.im-engine.open .im-star-bar { border-top-left-radius: 0; border-top-right-radius: 0; border-top-color: transparent; }
.im-sky-fold {
  position: absolute; left: 0; right: 0; bottom: 100%; pointer-events: none; opacity: 0; transform: translateY(6px);
  transition: opacity 0.26s ease, transform 0.26s ease, visibility 0s linear 0.26s; visibility: hidden;
}
.im-engine.open .im-sky-fold { pointer-events: auto; opacity: 1; transform: none; visibility: visible; transition: opacity 0.26s ease, transform 0.26s ease; }
.im-sky {
  position: relative; height: 230px; border-radius: 18px 18px 0 0; overflow: hidden; box-shadow: 0 -12px 30px rgb(0 0 0 / 35%);
  /* the bar's own line on its top and sides: bar and sky read as one piece, the gold rule where they meet */
  border: 1px solid var(--line); border-bottom: 0; box-sizing: border-box;
  background: radial-gradient(1px 1px at 12% 18%, #e8dccb88, transparent), radial-gradient(1px 1px at 66% 12%, #e8dccb66, transparent),
    radial-gradient(1px 1px at 36% 58%, #e8dccb55, transparent), radial-gradient(1px 1px at 88% 48%, #e8dccb77, transparent),
    radial-gradient(1px 1px at 8% 52%, #e8dccb44, transparent), radial-gradient(1px 1px at 72% 90%, #e8dccb55, transparent),
    radial-gradient(1px 1px at 30% 92%, #e8dccb66, transparent), radial-gradient(1px 1px at 94% 82%, #e8dccb44, transparent),
    radial-gradient(ellipse at 35% 25%, #3a1a2c, #0f050a 72%);
}
/* the rule where the sky meets the bar: a hair of gold, fading at both ends, a small diamond at its middle */
.im-sky-fold::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; z-index: 2;
  background: linear-gradient(90deg, transparent 4%, color-mix(in srgb, #e3b46a 70%, transparent) 30%, #e3b46a 50%, color-mix(in srgb, #e3b46a 70%, transparent) 70%, transparent 96%);
}
.im-sky-fold::before {
  content: ''; position: absolute; left: 50%; bottom: -3px; width: 7px; height: 7px; z-index: 3; transform: translateX(-50%) rotate(45deg);
  background: #e3b46a; box-shadow: 0 0 8px rgb(227 180 106 / 60%);
}
.im-sky-star {
  position: absolute; width: 76px; padding: 0; border: 0; background: none; cursor: pointer; text-align: center; color: #d4bab0;
  font: inherit; font-size: 0.7rem; font-weight: 600; transform: translate(-50%, calc(-50% - 10px)); opacity: 0;
  transition: opacity 0.3s ease;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
.im-engine.open .im-sky-star { opacity: 1; }
.im-engine.open .im-sky-star.dim { opacity: 0.55; }
.im-sky-star.dim .ring { filter: grayscale(0.5) brightness(0.75); }
.im-sky-star .ring { display: inline-grid; place-items: center; padding: 3px; border-radius: 50%; transition: box-shadow 0.3s; }
.im-sky-star:not(.dim) .ring { animation: im-twinkle 3.5s ease-in-out infinite; }
.im-sky-star.on .ring { box-shadow: 0 0 0 1px color-mix(in srgb, var(--oc) 75%, transparent), 0 0 20px color-mix(in srgb, var(--oc) 40%, transparent); }
.im-sky-star .nm { display: block; margin-top: 1px; white-space: nowrap; }
.im-sky-star .nm small { display: block; margin-top: 1px; font-size: 0.62rem; font-weight: 400; color: #a3857c; letter-spacing: 0.01em; }
/* the ⓘ on a star's top right: small to see, a finger's size to tap */
.im-sky-star .ring { position: relative; }
.im-sky-star .info {
  position: absolute; top: -4px; right: -8px; width: 15px; height: 15px; display: grid; place-items: center; border-radius: 50%;
  color: #d4bab0; background: rgb(20 6 12 / 85%); opacity: 0.85;
}
.im-sky-star .info svg { width: 13px; height: 13px; display: block; }
.im-sky-star .info::after { content: ''; position: absolute; inset: -9px; }
.im-sky-star.dim .info { opacity: 1; }
.im-sky-star.on .nm { color: #f5e9df; }
.im-sky-star.shake { animation: im-shake 0.35s; }
@keyframes im-twinkle { 50% { filter: brightness(1.3); } }
@keyframes im-shake { 25% { margin-left: -4px; } 75% { margin-left: 4px; } }
/* hold a star: its card over the sky */
.im-star-card {
  position: absolute; left: 50%; bottom: calc(100% + 14px); z-index: 6; width: min(290px, 100%); transform: translateX(-50%);
  padding: 14px; border-radius: 16px; color: #f5e9df; background: rgb(44 17 27 / 97%);
  border: 1px solid color-mix(in srgb, var(--oc) 45%, transparent);
  box-shadow: 0 10px 30px rgb(0 0 0 / 55%), 0 0 24px color-mix(in srgb, var(--oc) 18%, transparent); animation: im-card 0.22s ease both;
}
.im-star-card[hidden] { display: none; }
@keyframes im-card { from { opacity: 0; transform: translateX(-50%) scale(0.88); } }
.im-star-card .hd { display: flex; align-items: center; gap: 10px; }
.im-star-card .hd b { display: block; font-size: 1rem; }
.im-star-card .hd small { display: block; font-size: 0.78rem; color: #a3857c; }
.im-star-card p { margin: 10px 0 4px; font-size: 0.85rem; }
.im-star-card p.soon { color: #a3857c; }
.im-meter { display: grid; grid-template-columns: 6.5rem 1fr; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.78rem; color: #d4bab0; }
.im-comet { display: block; position: relative; height: 6px; border-radius: 99px; background: rgb(255 255 255 / 8%); }
.im-comet > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: linear-gradient(90deg, transparent, var(--oc)); }
.im-comet > i::after {
  content: ''; position: absolute; right: -3px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 8px 2px var(--oc);
}
/* Generate: a dark button, a light in the star's colour running around its edge (Orbit) */
.im-go {
  padding: 0.95rem 1.3rem; font-size: 1.02rem; position: relative; overflow: hidden; isolation: isolate;
  background: #1e0c14; color: color-mix(in srgb, var(--star) 62%, #fff); border-color: transparent;
}
.im-go::before {
  content: ''; position: absolute; left: 50%; top: 50%; width: 900px; height: 900px; margin: -450px 0 0 -450px; z-index: -2;
  /* a fine, slow light (Faris 2026-11-21: "finer and slower"): a short soft streak, one turn in 7 s */
  background: conic-gradient(from 0deg, transparent 0 72%, color-mix(in srgb, var(--star) 50%, transparent) 88%, rgb(255 255 255 / 80%) 92.5%, transparent 95%);
  animation: im-orbit 7s linear infinite;
}
.im-go::after {
  content: ''; position: absolute; inset: 1px; z-index: -1; border-radius: inherit;
  background: radial-gradient(120% 160% at 50% 0%, color-mix(in srgb, var(--star) 22%, #1e0c14), #1e0c14);
}
.im-go:disabled::before { animation-play-state: paused; opacity: 0.4; }
@keyframes im-orbit { to { transform: rotate(1turn); } }
.im-go-row { display: flex; gap: 10px; }
/* the switch beside Generate: off, Generate goes to the image engine; on, to Artifex (consulting), whose gold the button
   and the words box take. Classic: the knob slides, no bounce. */
.im-consult {
  flex: none; align-self: center; position: relative; width: 62px; height: 36px; padding: 0; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; transition: background 0.25s ease, border-color 0.25s ease;
}
.im-consult[hidden] { display: none; }
.im-consult .knob {
  position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); color: var(--ink-3); box-shadow: 0 1px 4px rgb(0 0 0 / 30%); transition: transform 0.25s ease, background 0.25s ease, color 0.25s ease;
}
.im-consult .knob svg { width: 18px; height: 18px; }
.im-consult .knob .acc { fill: #e3b46a; transition: fill 0.25s ease; }
.im-consult[aria-checked='true'] .knob .acc { fill: currentColor; }
.im-consult[aria-checked='true'] { background: color-mix(in srgb, #e3b46a 30%, var(--surface)); border-color: color-mix(in srgb, #e3b46a 75%, var(--line)); }
.im-consult[aria-checked='true'] .knob { transform: translateX(26px); background: #e3b46a; color: #1e0c14; }
.imagine.consult .im-go { --star: #e3b46a; }
.im-go-row .im-go { flex: 1; }
.im-erase { padding: 0.95rem 1.4rem; font-size: 1.02rem; }
.im-erase[hidden] { display: none; }
/* Reason is on: a quiet line above Generate, an ✕ to stop it */
.im-reason-on {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px 7px 12px; border-radius: 12px; font-size: 0.85rem; color: var(--ink-2);
  border: 1px solid color-mix(in srgb, #e3b46a 45%, var(--line)); background: color-mix(in srgb, #e3b46a 8%, var(--surface));
}
.im-reason-on[hidden] { display: none; }
/* consulting Ignis: the words box takes Ignis's gold, whatever star is picked */
.imagine.consult #im-prompt { border-color: color-mix(in srgb, #e3b46a 70%, var(--line)); box-shadow: 0 0 18px rgb(227 180 106 / 16%); }
.imagine.consult #im-prompt:focus { border-color: #e3b46a; box-shadow: 0 0 0 3px rgb(227 180 106 / 22%); }
/* the Reason button's count: the tries it carries, a small gold circle on its icon's top right */
.im-ic-count { position: relative; display: inline-grid; place-items: center; margin-inline-end: 13px; }
.im-ic-count > svg, .im-minor .btn .im-ic-count > svg { width: 19px; height: 19px; }
.im-count {
  position: absolute; top: -9px; right: -16px; min-width: 15px; height: 15px; padding: 0 4px; box-sizing: border-box; border-radius: 99px;
  display: grid; place-items: center; font-size: 0.62rem; font-weight: 700; line-height: 1; color: #1e0c14; background: #e3b46a;
  box-shadow: 0 0 0 2px var(--bg);
}
.im-reason-on > svg { width: 18px; height: 18px; flex: none; color: #e3b46a; }
.im-reason-on span { flex: 1; min-width: 0; }

/* ---------- Reason: Mine | Ignis ---------- */

.im-pair { display: flex; flex-direction: column; align-items: center; gap: 10px; animation: im-in 0.3s ease both; }
.im-pair-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 900px; }
.im-pair-side { margin: 0; display: grid; gap: 6px; justify-items: center; min-width: 0; }
.im-pair-frame {
  position: relative; width: 100%; aspect-ratio: var(--ratio, 1); max-height: 62vh; padding: 0; border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; background: var(--surface-2); cursor: pointer;
}
.im-pair-frame:disabled { cursor: default; }
.im-pair-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.im-pair-frame img.under { opacity: 0.45; filter: saturate(0.7); }
.im-pair-frame .im-wait { position: absolute; inset: 0; }
.im-pair-note { position: absolute; inset: auto 8px 8px; font-size: 0.78rem; color: var(--danger); text-align: center; }
.im-pair-side figcaption { font-weight: 600; font-size: 0.9rem; color: var(--ink-2); }
.im-pair-side figcaption.gold { color: #e3b46a; }
/* a set (several pictures): two to a row, smaller, the page scrolls */
.im-pair-row.many .im-pair-frame { max-height: 42vh; }
/* Pick: a wax seal on the persona's picture, top right of its frame: open, a dashed place for it; picked, sealed in red wax
   (pressed on once: a short press, no bounce) and the frame takes the gold */
.im-pair-side { position: relative; }
.im-pick {
  position: absolute; top: 6px; right: 6px; z-index: 2; width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; display: grid;
  place-items: center; background: none; cursor: pointer;
}
.im-pick svg { width: 40px; height: 40px; overflow: visible; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 45%)); }
.im-pick.press svg { animation: im-seal 0.32s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
@keyframes im-seal { from { transform: scale(1.35) rotate(-8deg); opacity: 0; } to { transform: none; opacity: 1; } }
.im-pick:disabled { opacity: 0.3; cursor: default; }
.im-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.im-ask-who { display: flex; align-items: center; justify-content: center; gap: 6px; }
.im-ask-who svg { width: 18px; height: 18px; flex: none; }
.im-pair-side.picked .im-pair-frame { border-color: #e3b46a; box-shadow: 0 0 0 1px #e3b46a; }
[dir='rtl'] .im-pick { right: auto; left: 6px; }
.im-pair-why { margin: 2px 0 0; max-width: 640px; color: var(--ink-2); font-size: 0.92rem; line-height: 1.45; text-align: center; }
.im-pair-why:empty { display: none; }

/* ---------- the image ---------- */

.im-result { display: flex; flex-direction: column; align-items: center; animation: im-in 0.3s ease both; }
.im-frame {
  position: relative; width: 100%; max-width: 560px; aspect-ratio: var(--ratio, 1); max-height: 62vh; border-radius: 22px;
  overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow);
}
.im-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* the image zooms: the frame clips, im-out-zoom moves (js/image.js zoomable) */
.im-frame { touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.im-frame.zoomed { touch-action: none; cursor: grab; }
.im-out-zoom { position: absolute; inset: 0; transform-origin: 0 0; }
/* under an edit: Edit more, Discard (thin, under the image) */
/* (more than a phone's width of them: a second line, never off the screen; each on one line) */
.im-minor { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 0.8rem; }
.im-minor:empty { display: none; }
.im-minor .btn { padding: 0.3rem 0.8rem; font-size: 0.8rem; gap: 0.35rem; white-space: nowrap; }
.im-minor .btn svg { width: 14px; height: 14px; }
.im-under { filter: blur(14px) saturate(0.8); opacity: 0.55; transform: scale(1.08); }
.im-under:not([src]), .im-out:not([src]) { display: none; }
.im-out { opacity: 0; transform: scale(1.015); transition: opacity 0.6s ease, transform 0.8s ease; }
.im-out.shown { opacity: 1; transform: none; }
.im-out.lerp { transition: none; }
.im-was:not([src]) { display: none; }
/* before and after, right under the frame (js/image.js lerp) */
.im-lerp { width: 100%; max-width: 560px; display: flex; margin: 8px 0 -2px; padding: 0 4px; box-sizing: border-box; }
.im-lerp[hidden] { display: none; }
.im-wait { position: absolute; inset: 0; }
.im-wait[hidden] { display: none; }
/* the picked star, breathing in the middle of the picture while it is made */
.im-wait-star { position: absolute; left: 50%; top: 50%; translate: -50% -50%; animation: im-breathe 1.6s ease-in-out infinite; }
@keyframes im-breathe { 50% { scale: 1.12; } }
.im-shine {
  display: block; width: 100%; height: 100%;
  background: linear-gradient(110deg, transparent 30%, color-mix(in srgb, var(--star, var(--accent)) 26%, transparent) 50%, transparent 70%);
  background-size: 250% 100%; background-repeat: no-repeat; animation: im-shine 2.2s ease-in-out infinite;
}
/* one band, not tiled: it starts and ends fully outside the box, so the loop never jumps in view (Faris 2026-10-21:
   "it moves smoothly, then cuts and repeats": the tiled copy was in view when it jumped back) */
@keyframes im-shine { from { background-position: 130% 0; } to { background-position: -30% 0; } }
.im-state { margin: 1rem 0 0; color: var(--ink-2); font-weight: 600; text-align: center; }
.im-state:empty { display: none; }
.im-state.bad { color: var(--danger); }
.im-said {
  margin: 0.6rem 0 0; max-width: 560px; color: var(--ink-3); text-align: center; font-size: 0.92rem; line-height: 1.45;
  overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
/* one row: Save, Share, Edit this */
.im-acts { display: flex; flex-wrap: nowrap; justify-content: center; gap: 8px; margin-top: 1.2rem; max-width: 100%; }
.im-acts .btn { padding: 0.62rem 1rem; white-space: nowrap; min-width: 0; }
.im-acts .btn svg { width: 17px; height: 17px; }

/* ---------- the Gallery: the newest image big, then a row for each day ---------- */

.im-gallery { animation: im-in 0.3s ease both; padding-bottom: calc(1rem + var(--inset-bottom)); }
.im-hero { position: relative; display: block; width: 100%; padding: 0; border: 0; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); background: var(--surface-2); }
.im-hero img { display: block; width: 100%; aspect-ratio: 4 / 4.2; object-fit: cover; }
.im-hero .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 44px 16px 14px; text-align: left; color: #fff;
  background: linear-gradient(to top, rgb(0 0 0 / 66%), transparent); font: 600 1.15rem/1.25 var(--serif);
}
.im-hero .cap span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.im-hero .cap small { display: block; font: 500 0.78rem var(--sans); opacity: 0.8; margin-top: 3px; }
.im-day { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-3); margin: 20px 2px 10px; }
.im-row {
  display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 6px; scroll-snap-type: x proximity; scrollbar-width: none;
}
.im-row::-webkit-scrollbar { display: none; }
.im-tile {
  position: relative; flex: none; height: 150px; aspect-ratio: var(--ratio, 1); border: 0; padding: 0; border-radius: 16px; overflow: hidden;
  background: var(--surface-2); box-shadow: var(--shadow); scroll-snap-align: start; transition: transform 0.12s ease;
}
.im-tile:active { transform: scale(0.96); }
.im-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.im-tile .im-shine { position: absolute; inset: 0; }
.im-tile.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.im-none { text-align: center; color: var(--ink-3); padding: 18vh 0 2rem; }

/* ---------- Continue reasoning: the member's Reason sessions ---------- */

.im-reasons { display: grid; gap: 10px; align-content: start; animation: im-in 0.3s ease both; padding-bottom: calc(1rem + var(--inset-bottom)); }
.im-reasons[hidden] { display: none; }
.im-rs {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-align: start; font: inherit; transition: border-color 0.15s, background 0.15s;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.im-rs:hover { border-color: color-mix(in srgb, #e3b46a 55%, var(--line)); }
.im-rs:active { background: color-mix(in srgb, #e3b46a 6%, var(--surface)); }
.im-rs-pics { display: flex; gap: 4px; flex: none; }
.im-rs-pic { position: relative; width: 56px; height: 72px; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.im-rs-pic[data-side='ignis'] { border-color: color-mix(in srgb, #e3b46a 60%, var(--line)); }
.im-rs-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.im-rs-pic .im-shine { position: absolute; inset: 0; }
.im-rs-txt { display: grid; gap: 5px; min-width: 0; }
.im-rs-txt b { font: 600 1.02rem/1.25 var(--serif); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.im-rs-txt small { font-size: 0.78rem; color: var(--ink-3); }
.im-rs-txt small.asks { color: #e3b46a; }

/* ---------- the persona asks: one short question, a few options, and always Something else ---------- */

.im-ask { z-index: 60; }
.im-ask-who { color: #e3b46a; }
.im-ask-q { font-size: 1.4rem; line-height: 1.25; margin-bottom: 1rem; }
.im-ask-opts { display: grid; gap: 8px; }
.im-ask-opt {
  width: 100%; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: 500 1rem/1.3 var(--sans); text-align: center; cursor: pointer; transition: border-color 0.15s ease;
}
.im-ask-opt:hover, .im-ask-opt:focus-visible { border-color: color-mix(in srgb, #e3b46a 65%, var(--line)); }
.im-ask-opt.other { color: var(--ink-2); border-style: dashed; }
.im-ask-opt.other.on { border-color: color-mix(in srgb, #e3b46a 65%, var(--line)); color: var(--ink); }
.im-ask-own { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; }
.im-ask-own[hidden] { display: none; }
#im-ask-text {
  flex: 1; min-width: 0; resize: none; border: 1px solid color-mix(in srgb, #e3b46a 55%, var(--line)); border-radius: 14px; background: var(--bg);
  color: var(--ink); padding: 0.55rem 0.7rem; font: inherit; font-size: 0.95rem; line-height: 1.35; outline: none; text-align: start;
}
#im-ask-text:focus { border-color: #e3b46a; }
#im-ask-send { padding: 0.6rem 1rem; }

/* ---------- From Ignis: the sheet ---------- */

.im-sheet-scrim { position: fixed; inset: 0; z-index: 30; background: rgb(8 6 10 / 45%); animation: ip-fade 0.2s ease both; }
.im-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-height: 82vh; display: flex; flex-direction: column;
  border-radius: 26px 26px 0 0; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -16px 50px rgb(0 0 0 / 35%);
  padding: 10px 16px 0; animation: im-up 0.32s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}
.im-sheet-scrim[hidden], .im-sheet[hidden] { display: none; }
.im-sheet .grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; flex: none; }
.im-sheet h2 { margin: 0 0 12px; text-align: center; font: 600 1.4rem/1.2 var(--serif); }
.im-sheet-body { overflow-y: auto; margin: 0 -16px; padding: 0 16px calc(16px + var(--inset-bottom)); }
.im-sheet-body .im-day:first-child { margin-top: 4px; }
@keyframes im-up { from { transform: translateY(100%); } }

@keyframes im-in { from { opacity: 0; transform: translateY(8px); } }
/* a tile grows into its image (view transitions); the rest crossfades */
::view-transition-group(*) { animation-duration: 0.42s; animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.26s; }
::view-transition-old(im-card), ::view-transition-new(im-card) { height: 100%; object-fit: cover; }
@media (prefers-reduced-motion: reduce) {
  .ip-scrim, .ip-card, .im-sheet, .im-sheet-scrim, .im-compose, .im-result, .im-gallery { animation: none; }
  .im-shine { animation: none; opacity: 0.6; }
  .im-go::before, .im-sky-star .ring, .im-wait-star { animation: none; }
  .im-sky-fold, .im-sky-star { transition: none; }
  .im-out { transition: none; }
}

/* Arabic, right to left: arrows point the other way, and what sits on one side moves to the other. */
[dir='rtl'] #im-back svg, [dir='rtl'] .ip-row .chev { transform: scaleX(-1); }
[dir='rtl'] .ip-row, [dir='rtl'] .im-hero .cap { text-align: right; }
[dir='rtl'] .im-swap { right: auto; left: 10px; }

/* ---------- the small menu (Save's two choices; holding an image: Edit this, Delete), the note, leaving ---------- */

.im-menu-scrim { position: fixed; inset: 0; z-index: 44; }
.im-menu {
  position: fixed; z-index: 45; min-width: 210px; padding: 6px; border-radius: 18px; background: var(--surface);
  border: 1px solid var(--line); box-shadow: 0 18px 44px rgb(0 0 0 / 30%); animation: ip-pop 0.18s cubic-bezier(0.2, 0.9, 0.25, 1.1) both;
}
.im-mi {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border: 0; border-radius: 12px;
  background: none; color: var(--ink); font-weight: 600; font-size: 0.98rem; text-align: start;
}
.im-mi:hover { background: var(--surface-2); }
.im-mi svg { width: 20px; height: 20px; flex: none; color: var(--accent); overflow: visible; }
.im-mi:disabled { color: var(--ink-3); background: none; }
.im-mi:disabled svg { color: var(--ink-3); }
.im-mi.danger, .im-mi.danger svg { color: var(--danger); }
.im-toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--inset-bottom)); transform: translateX(-50%); z-index: 46;
  display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; border-radius: 999px; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.9rem; box-shadow: 0 10px 30px rgb(0 0 0 / 30%);
  animation: im-in 0.22s ease both;
}
.im-toast[hidden] { display: none; }
.im-toast button { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 4px 6px; }
.im-leave-acts { display: grid; gap: 8px; }
.im-leave-acts .btn { width: 100%; }

/* ---------- markers on the picture to change, zoom, and the small card next to a marker ---------- */

/* im-pins is the picture's own box (it clips); im-zoom inside it holds the picture and its markers and is what a pinch
   scales and a drag moves, so a marker's place (in % of the picture) stays put at any zoom. Markers keep their size. */
.im-pins { position: relative; display: block; overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: crosshair; }
.im-pins.zoomed { touch-action: none; cursor: grab; }
.im-zoom { position: relative; transform-origin: 0 0; --z: 1; }
.im-zoom img { pointer-events: none; }
.im-pin {
  position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; padding: 0; display: grid; place-items: center;
  border-radius: 50%; border: 2px solid #fff; background: #e0352b; color: #fff; font: 700 0.72rem/1 var(--sans);
  box-shadow: 0 2px 8px rgb(0 0 0 / 45%); cursor: pointer; scale: calc(1 / var(--z));
  animation: pin-in 0.26s cubic-bezier(0.2, 0.9, 0.25, 1.35) both;
}
.im-pin.open { box-shadow: 0 0 0 3px rgb(255 255 255 / 45%), 0 2px 8px rgb(0 0 0 / 45%); }
/* a marker not said Yes to yet: a small dot with a ring that breathes */
.im-pin.new { width: 14px; height: 14px; margin: -7px 0 0 -7px; }
.im-pin.new::after { content: ''; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid #fff; animation: pin-ring 1.3s ease-out infinite; }
@keyframes pin-in { from { transform: scale(0.2); opacity: 0; } }
@keyframes pin-ring { from { transform: scale(0.5); opacity: 0.9; } to { transform: scale(1.4); opacity: 0; } }

/* the card: slim, so it hides little of the picture */
.im-pin-scrim { position: fixed; inset: 0; z-index: 44; }
.im-pin-scrim[hidden], .im-pin-pop[hidden], .im-pin-ask[hidden], .im-pin-say[hidden], .im-pin-del[hidden] { display: none; }
.im-pin-pop {
  position: fixed; z-index: 45; left: 0; top: 0; max-width: calc(100vw - 24px); padding: 5px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 10px 30px rgb(0 0 0 / 30%); color: var(--ink);
  animation: ip-pop 0.18s cubic-bezier(0.2, 0.9, 0.25, 1.1) both;
}
.im-pin-pop[data-side='above'] { transform-origin: 50% 100%; }
.im-pin-pop[data-side='below'] { transform-origin: 50% 0; }
.im-pin-pop .btn { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.im-pin-ask { display: flex; align-items: center; gap: 6px; padding-inline-start: 8px; }
.im-pin-ask b { font: 600 0.92rem/1.2 var(--serif); white-space: nowrap; margin-inline-end: 4px; }
.im-pin-acts { display: flex; gap: 5px; }
.im-pin-say { width: min(250px, calc(100vw - 36px)); }
.im-pin-head { display: flex; align-items: center; gap: 4px; margin: 1px 1px 5px 5px; }
.im-pin-head label { flex: 1; font: 600 0.82rem/1.2 var(--serif); }
.im-pin-del { flex: none; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--danger); }
.im-pin-del svg { width: 16px; height: 16px; }
.im-pin-row { display: flex; align-items: flex-end; gap: 5px; }
#im-pin-text {
  flex: 1; min-width: 0; resize: none; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
  padding: 0.32rem 0.5rem; font: inherit; font-size: 0.88rem; line-height: 1.35; outline: none; max-height: 7.5em;
}
#im-pin-text:focus { border-color: var(--accent); }
/* consulting: what was written for the spot before (to read, not to change), then a slightly smaller box for what to
   tell the persona about it */
.im-pin-said {
  margin: 1px 1px 7px; padding: 6px 8px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--line);
  font-size: 0.84rem; line-height: 1.35; color: var(--ink-2); max-height: 7.5em; overflow-y: auto;
}
.im-pin-said[hidden] { display: none; }
.im-pin-said small { display: block; font-size: 0.62rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 2px; }
.im-pin-said p { margin: 0; overflow-wrap: anywhere; }
.im-pin-said p + p { margin-top: 3px; padding-top: 3px; border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.im-pin-say.tell .im-pin-head label { color: #e3b46a; font-size: 0.78rem; }
.im-pin-say.tell #im-pin-text { font-size: 0.82rem; padding: 0.26rem 0.45rem; border-color: color-mix(in srgb, #e3b46a 55%, var(--line)); }
.im-pin-say.tell #im-pin-text:focus { border-color: #e3b46a; }
@media (prefers-reduced-motion: reduce) {
  .im-pin, .im-pin-pop { animation: none; }
  .im-pin.new::after { animation: none; opacity: 0.6; }
}

/* ---------- the toolbox under the picture to change: Markers, Select ---------- */

.im-tools { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px 0 2px; }
.im-tools[hidden] { display: none; }
.im-tool-set { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.im-tool-set button {
  display: grid; place-items: center; width: 44px; height: 38px; border: 0; border-radius: 999px; background: none; color: var(--ink-2);
  transition: background 0.15s, color 0.15s;
}
.im-tool-set button[aria-checked='true'] { background: var(--accent); color: var(--accent-ink); }
.im-tool-set svg, .im-tool-mini svg { width: 21px; height: 21px; }
.im-tool-mini {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2);
}
.im-tool-mini[hidden] { display: none; }
.im-tool-mini:disabled { opacity: 0.4; }
.im-tool-mini[aria-checked='true'] { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); }
.im-tool-state { margin: 4px 0 0; min-height: 1.1em; text-align: center; color: var(--ink-3); font-size: 0.8rem; }
.im-tool-state:empty { min-height: 0; margin: 0; }
/* the selection drawn over the picture (it zooms with it) */
.im-sel { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* the wand draws with one finger: the page does not scroll under it */
.im-pins.drawing { touch-action: none; cursor: crosshair; }

/* the picture is busy (the select tool getting ready, reading the picture, looking): a band of blue light sweeps over
   it, its edge glows, the picture dims a little; the words and the download bar sit on it */
.im-busy { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: inherit; z-index: 2; }
.im-busy[hidden] { display: none; }
.im-busy::before {
  content: ''; position: absolute; top: -50%; bottom: -50%; left: -60%; width: 60%; will-change: transform;
  background: linear-gradient(100deg, transparent, rgb(110 170 255 / 0%) 20%, rgb(120 180 255 / 65%) 50%, rgb(110 170 255 / 0%) 80%, transparent);
  mix-blend-mode: screen; animation: im-sweep 1.5s cubic-bezier(0.45, 0, 0.35, 1) infinite;
}
.im-busy::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgb(120 175 255 / 75%), inset 0 0 46px rgb(80 145 255 / 40%); animation: im-glow 1.5s ease-in-out infinite;
}
/* moved by transform only, so it keeps moving while the page is busy reading the picture */
@keyframes im-sweep { from { transform: translateX(0) skewX(-12deg); } to { transform: translateX(290%) skewX(-12deg); } }
@keyframes im-glow { 50% { opacity: 0.45; } }
.im-photo.busy img, .im-frame.busy .im-out { filter: saturate(0.7) brightness(0.9); transition: filter 0.3s; }
.im-busy-text {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 1; max-width: calc(100% - 24px);
  padding: 6px 13px; border-radius: 999px; background: rgb(12 22 44 / 70%); color: #fff; font-size: 0.8rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.im-busy-text:empty { display: none; }
.im-busy-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: rgb(120 180 255); box-shadow: 0 0 10px rgb(120 180 255); transition: width 0.25s; z-index: 1; }
/* the call's AI is the one working (it looks at the picture, or its hands select): the call's green, as its ring
   (Faris: green for her, blue for the app's own work) */
.im-busy.ai::before { background: linear-gradient(100deg, transparent, color-mix(in srgb, var(--live) 0%, transparent) 20%, color-mix(in srgb, var(--live) 65%, transparent) 50%, color-mix(in srgb, var(--live) 0%, transparent) 80%, transparent); }
.im-busy.ai::after { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--live) 75%, transparent), inset 0 0 46px color-mix(in srgb, var(--live) 40%, transparent); }
.im-busy.ai .im-busy-bar { background: var(--live); box-shadow: 0 0 10px var(--live); }
.im-busy.ai .im-busy-text { background: color-mix(in srgb, var(--live) 30%, rgb(10 30 18 / 75%)); }
@media (prefers-reduced-motion: reduce) {
  .im-busy::before { animation-duration: 3s; }
  .im-busy::after { animation: none; }
}

/* ---------- a laptop (a wide screen): the picture big on the left, the words and Generate on the right ---------- */

@media (min-width: 1000px) {
  .imagine:not([hidden]) {
    display: grid; grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: auto 1fr;
    width: 100%; max-width: 1500px; margin: 0 auto;
  }
  .im-bar { grid-column: 1 / -1; max-width: none; padding-inline: 28px; }
  .im-body { grid-column: 1 / -1; grid-row: 2; max-width: none; padding: 0.6rem 28px 1.5rem; }
  /* Generate and the engine sit at the bottom of the right column, over the empty space under the words */
  .im-foot {
    grid-column: 2; grid-row: 2; align-self: end; position: sticky; bottom: 0; z-index: 3; max-width: none;
    padding: 0 28px 24px; background: none;
  }
  .im-compose { display: grid; grid-template-columns: minmax(0, 1fr) 372px; gap: 0 28px; align-items: start; }
  .im-compose > .im-source { grid-column: 1; }
  .im-compose > #im-prompt { grid-column: 2; grid-row: 1; min-height: 16rem; }
  /* a new image has no picture: the words take the left side */
  .im-compose:has(> .im-source[hidden]) > #im-prompt { grid-column: 1; min-height: 55vh; }
  /* Edit image before a picture: the choices alone, across */
  .im-compose:has(> #im-prompt[hidden]) > .im-source { grid-column: 1 / -1; justify-self: center; width: min(100%, 640px); margin-top: 8vh; }
  .im-photo img { max-height: calc(100vh - 200px); }
  .im-from button { aspect-ratio: 1 / 0.6; }
  /* the image: as tall as the screen allows */
  .im-frame { width: auto; max-width: 100%; height: min(calc(100vh - 270px), 1100px); max-height: none; }
  .im-said { max-width: 900px; }
  .im-gallery { max-width: 900px; margin: 0 auto; }
}
