/* 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); }
.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); }
@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-template-columns: 1fr 1fr; gap: 10px; }
.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; }
.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; }
.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); }
#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; 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);
}
.im-engine { margin: 0; }
.im-go { padding: 0.95rem 1.3rem; font-size: 1.02rem; }

/* ---------- 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; }
.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-wait { position: absolute; inset: 0; }
.im-wait[hidden] { display: none; }
.im-shine {
  display: block; width: 100%; height: 100%;
  background: linear-gradient(110deg, transparent 30%, color-mix(in srgb, var(--accent) 22%, transparent) 50%, transparent 70%);
  background-size: 250% 100%; animation: im-shine 2.2s ease-in-out infinite;
}
@keyframes im-shine { from { background-position: 120% 0; } to { background-position: -120% 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;
}
.im-acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 1.2rem; }
.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; }

/* ---------- 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-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; }
