/* ASO Nexus Sandbox - one stylesheet, mobile first.
   Breakpoints: 600 (large phone / small tablet), 820 (iPad portrait),
   1100 (iPad landscape and laptops), 1400 (wide desktop). */

:root {
  --bg: #0b0d13;
  --bg-solid: #0b0d13;
  --bg-2: #141826;
  --surface: rgba(255,255,255,.055);
  --surface-2: rgba(255,255,255,.09);
  --surface-3: rgba(255,255,255,.14);
  --line: rgba(255,255,255,.11);
  --line-strong: rgba(255,255,255,.2);
  --text: #eef1f8;
  --muted: #a2aac1;
  --accent: #6f8cff;
  --accent-2: #b46cff;
  --accent-soft: rgba(111,140,255,.18);
  --ok: #57e0ae;
  --warn: #ffcc66;
  --danger: #ff8792;

  --card-pad: clamp(1rem, 3vw, 1.4rem);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 9px;
  --tap: 46px;
  --tap-sm: 40px;

  --s-1: .25rem;
  --s-2: .5rem;
  --s-3: .75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;

  --fs-xs: .74rem;
  --fs-sm: .84rem;
  --fs-md: .94rem;
  --fs-lg: 1.05rem;

  --shadow-tile: 0 18px 38px -22px rgba(0,0,0,.92), inset 0 1px 0 rgba(255,255,255,.16);
  --shadow-card: 0 22px 48px -34px rgba(0,0,0,.9);
  --ease-out: cubic-bezier(.22,.8,.24,1);
  --spring: cubic-bezier(.2,.9,.3,1.18);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: dark;
  accent-color: var(--accent);
}

* { box-sizing: border-box; }

/* Beats every display rule below, so [hidden] always wins. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--surface-3) transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(120% 78% at 10% -12%, #2a2050 0%, transparent 58%),
    radial-gradient(110% 68% at 98% 2%, #123b52 0%, transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, #070910 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(111,140,255,.36); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

img, video, svg { max-width: 100%; }

h1 {
  font-size: clamp(1.45rem, 1.15rem + 1.4vw, 1.95rem);
  letter-spacing: -.025em; line-height: 1.15; margin: 0; font-weight: 640;
}
h2 {
  font-size: clamp(1rem, .95rem + .3vw, 1.15rem);
  letter-spacing: -.015em; margin: var(--s-6) 0 var(--s-3); font-weight: 620;
}
p { margin: 0 0 var(--s-3); }
p:last-child { margin-bottom: 0; }

code { font-family: var(--mono); font-size: .82em; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.link { color: #9db1ff; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* --- top bar ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; flex-wrap: nowrap;
  gap: var(--s-2);
  padding: .55rem clamp(.9rem, 3.2vw, 1.6rem);
  padding-top: max(.55rem, env(safe-area-inset-top));
  padding-left: max(.9rem, env(safe-area-inset-left));
  padding-right: max(.9rem, env(safe-area-inset-right));
  background: rgba(9,11,18,.74);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: .4rem;
  font-weight: 650; letter-spacing: -.02em; font-size: var(--fs-md);
  flex: 0 0 auto; min-height: var(--tap-sm); padding-right: .2rem;
}
.brand-mark { font-size: 1.05rem; line-height: 1; }
/* Below ~380px the guest badge and the nav need every pixel, so the
   wordmark drops to its glyph. */
@media (max-width: 380px) {
  .brand-name {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
}

.topnav {
  display: flex; align-items: center; gap: .15rem;
  flex: 1 1 auto; min-width: 0;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none; -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  display: inline-flex; align-items: center; white-space: nowrap; flex: 0 0 auto;
  min-height: var(--tap-sm); padding: 0 .7rem; border-radius: 999px;
  color: var(--muted); font-size: var(--fs-sm); font-weight: 520;
  transition: background .16s var(--ease-out), color .16s var(--ease-out);
}
.topnav a:hover { background: var(--surface); color: var(--text); }
.topnav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }

.topuser { margin-left: auto; display: flex; align-items: center; gap: .4rem; flex: 0 1 auto; min-width: 0; }
.user {
  color: var(--muted); font-size: var(--fs-sm);
  max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: none;
}
.badge {
  display: inline-block; flex: 0 1 auto; min-width: 0; max-width: 30vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: .3rem .65rem; border-radius: 999px; font-size: var(--fs-xs);
  background: linear-gradient(120deg, rgba(111,140,255,.2), rgba(180,108,255,.2));
  border: 1px solid rgba(111,140,255,.38); color: #d7defc;
}
.topuser form { margin: 0; display: flex; }
.signout {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-width: var(--tap-sm); min-height: var(--tap-sm); padding: 0 .5rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted);
  font: inherit; font-size: var(--fs-sm); cursor: pointer;
  transition: background .16s, color .16s, transform .12s var(--ease-out);
}
.signout:hover { background: var(--surface-2); color: var(--text); }
.signout:active { transform: scale(.94); }
.signout-label { display: none; }
.signout svg { width: 18px; height: 18px; }

@media (min-width: 600px) {
  .topbar { gap: var(--s-3); padding-block: .65rem; }
  .topnav { gap: .25rem; margin-left: .3rem; }
  .topnav a { padding: 0 .85rem; font-size: var(--fs-md); }
  .user { display: inline-block; max-width: 18ch; }
  .badge { max-width: 34ch; font-size: var(--fs-sm); }
  .signout { padding: 0 .9rem; }
  .signout-label { display: inline; }
  .signout svg { display: none; }
}

/* --- page frame ------------------------------------------------------- */
.page {
  width: 100%; max-width: 1240px; margin: 0 auto;
  padding: clamp(1rem, 3.5vw, 2rem);
  padding-left: max(clamp(1rem, 3.5vw, 2rem), env(safe-area-inset-left));
  padding-right: max(clamp(1rem, 3.5vw, 2rem), env(safe-area-inset-right));
  padding-bottom: calc(4rem + env(safe-area-inset-bottom));
}
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-4); flex-wrap: wrap;
}
.section-head h2 { margin-top: 0; }
* + .section-head { margin-top: var(--s-6); }

/* --- buttons ---------------------------------------------------------- */
.btn, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: var(--tap); padding: 0 1.15rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--fs-md); font-weight: 560; cursor: pointer;
  text-align: center; white-space: nowrap;
  transition: transform .12s var(--ease-out), background .16s, border-color .16s, box-shadow .16s;
}
.btn:hover, .btn-ghost:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active, .btn-ghost:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(122deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 12px 26px -14px rgba(0,0,0,.9);
}
.btn-primary:hover { background: linear-gradient(122deg, #7f99ff, #c07dff); border-color: transparent; }
.btn-block { width: 100%; }
.btn-ghost {
  min-height: var(--tap-sm); padding: 0 .8rem;
  font-size: var(--fs-sm); font-weight: 540; background: transparent; color: var(--muted);
}
.btn-ghost:hover { color: var(--text); }

/* --- cards, alerts ---------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--card-pad);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.alert, .ok {
  padding: .7rem .95rem; border-radius: var(--radius-sm);
  font-size: var(--fs-md); margin: 0 0 var(--s-4);
}
.alert { background: rgba(255,111,125,.13); border: 1px solid rgba(255,111,125,.34); color: #ffc9ce; }
.ok { background: rgba(70,214,160,.13); border: 1px solid rgba(70,214,160,.34); color: #bff2de; }

/* --- login and standalone notices ------------------------------------- */
.login { min-height: 68dvh; display: grid; place-items: center; padding: var(--s-4) 0; }
.login-card {
  width: min(400px, 100%); text-align: center; display: grid; gap: .8rem;
  box-shadow: var(--shadow-card);
}
.login-mark { font-size: 2.4rem; line-height: 1; }
.login-card h1 { font-size: clamp(1.25rem, 1.1rem + 1vw, 1.5rem); }
.login-card .btn { margin-top: .2rem; }
.notice-page {
  display: grid; place-items: center; min-height: 100dvh;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem;
}
.notice { width: min(440px, 100%); text-align: center; display: grid; gap: var(--s-4); }

/* --- dashboard -------------------------------------------------------- */
.home { display: grid; gap: var(--s-6); }
.home-head { display: grid; gap: .2rem; margin-bottom: calc(-1 * var(--s-3)); }
.home-head p { margin: 0; }
.home > * { min-width: 0; }
.recent { min-width: 0; }
.app-grid {
  display: grid; gap: clamp(1rem, 3.5vw, 1.6rem) clamp(.9rem, 3vw, 1.4rem);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.app-tile {
  display: grid; justify-items: center; align-content: start; gap: .45rem;
  text-align: center; min-width: 0;
}
.app-icon {
  display: grid; place-items: center;
  width: 100%; max-width: 150px; aspect-ratio: 1;
  font-size: clamp(2.2rem, 11vw, 3.1rem); line-height: 1;
  border-radius: 27%;
  background: linear-gradient(155deg, rgba(255,255,255,.17), rgba(255,255,255,.04) 62%), rgba(255,255,255,.03);
  box-shadow: var(--shadow-tile);
  transition: transform .2s var(--spring), box-shadow .2s var(--ease-out);
}
.app-name { font-size: var(--fs-md); font-weight: 580; letter-spacing: -.01em; }
.app-tagline {
  font-size: var(--fs-xs); color: var(--muted); line-height: 1.35;
  max-width: 20ch;
}
.app-tile:hover .app-icon { transform: translateY(-4px) scale(1.035); box-shadow: 0 26px 46px -22px rgba(0,0,0,.95), inset 0 1px 0 rgba(255,255,255,.2); }
.app-tile:active .app-icon { transform: scale(.93); }
.app-tile.is-disabled { cursor: default; }
.app-tile.is-disabled .app-icon {
  background: rgba(255,255,255,.035);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07);
  filter: grayscale(1); opacity: .5;
}
.app-tile.is-disabled .app-name { color: var(--muted); font-weight: 540; }
.app-tile.is-disabled .app-tagline {
  color: #7d8599; text-transform: uppercase; letter-spacing: .1em; font-size: .64rem;
}
.app-tile.is-disabled:hover .app-icon { transform: none; box-shadow: inset 0 1px 0 rgba(255,255,255,.07); }

.recent-strip {
  display: flex; gap: .6rem; overflow-x: auto; padding-bottom: .4rem;
  scroll-snap-type: x proximity; scrollbar-width: thin;
}
.recent-strip .thumb { flex: 0 0 clamp(92px, 26vw, 130px); scroll-snap-align: start; }

@media (min-width: 520px) { .app-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 820px) { .app-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .app-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1400px) { .app-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* --- gallery ---------------------------------------------------------- */
.tabs {
  display: flex; gap: .2rem; margin-bottom: var(--s-4);
  padding: .25rem; border-radius: 999px;
  background: rgba(0,0,0,.28); border: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
  width: fit-content; max-width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 1 0 auto; white-space: nowrap;
  min-height: var(--tap-sm); padding: 0 .95rem; border-radius: 999px;
  font-size: var(--fs-sm); font-weight: 540; color: var(--muted);
  transition: background .16s var(--ease-out), color .16s var(--ease-out);
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: var(--surface-2); color: var(--text);
  box-shadow: 0 6px 14px -10px rgba(0,0,0,.9), inset 0 1px 0 rgba(255,255,255,.12);
}

.grid { display: grid; gap: .5rem; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid > p { grid-column: 1 / -1; }
.tile { margin: 0; display: grid; gap: .3rem; min-width: 0; }
.tile figcaption {
  font-size: .68rem; color: var(--muted); text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.thumb {
  display: block; aspect-ratio: 1; max-width: 100%;
  border-radius: var(--radius-xs); overflow: hidden;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  transition: transform .18s var(--ease-out), border-color .18s;
}
.thumb:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-sm { width: 54px; flex: 0 0 54px; aspect-ratio: 1; }

@media (min-width: 600px) { .grid { gap: .65rem; grid-template-columns: repeat(4, minmax(0, 1fr)); } .tile figcaption { font-size: var(--fs-xs); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid { gap: .75rem; grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (min-width: 1400px) { .grid { grid-template-columns: repeat(8, minmax(0, 1fr)); } }

/* --- forms ------------------------------------------------------------ */
.form { margin-bottom: var(--s-5); }
.form-row { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: end; }
.form-row > .btn { flex: 1 1 auto; }
label { display: grid; gap: .3rem; font-size: var(--fs-sm); color: var(--muted); flex: 1 1 200px; min-width: 0; }
label.narrow { flex: 1 1 130px; }
input, select, textarea {
  font: inherit; font-size: var(--fs-md); color: var(--text);
  background: rgba(0,0,0,.3); border: 1px solid var(--line);
  border-radius: var(--radius-xs); padding: .6rem .75rem;
  min-height: var(--tap); width: 100%;
  transition: border-color .16s, background .16s;
}
input::placeholder, textarea::placeholder { color: #7f8699; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
textarea { min-height: 3.2rem; resize: vertical; line-height: 1.5; }
select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23a2aac1' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .85rem center; background-size: 12px 8px;
}
input[type=checkbox] {
  width: 22px; height: 22px; min-height: 0; padding: 0;
  accent-color: var(--accent); cursor: pointer;
}
input[type=number] { font-variant-numeric: tabular-nums; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}

/* --- tables ----------------------------------------------------------- */
.table-wrap {
  overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { text-align: left; padding: .7rem .85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th {
  color: var(--muted); font-weight: 560; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
}
.table tbody tr { transition: background .16s; }
.table tbody tr:hover { background: rgba(255,255,255,.03); }
.table tr:last-child td { border-bottom: none; }
.table .center { text-align: center; }
.table.models input, .table.models textarea { min-width: 150px; }
.table td { font-variant-numeric: tabular-nums; }
.is-expired td { color: var(--muted); }
.is-expired td a.link { color: #8a93ad; }

.url-cell { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.url-cell code {
  color: var(--muted); min-width: 0; flex: 0 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.url-cell .btn-ghost { flex: 0 0 auto; border: 1px solid var(--line); }

.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .55rem 1.2rem; margin: 0; font-size: var(--fs-md); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }

.status {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .18rem .6rem; border-radius: 999px; font-size: var(--fs-xs); font-weight: 560;
  border: 1px solid var(--line); white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-done { color: var(--ok); border-color: rgba(70,214,160,.38); background: rgba(70,214,160,.1); }
.status-failed { color: var(--danger); border-color: rgba(255,111,125,.38); background: rgba(255,111,125,.1); }
.status-queued, .status-analysing, .status-rendering {
  color: var(--warn); border-color: rgba(255,204,102,.38); background: rgba(255,204,102,.1);
}

/* Tables become stacked cards on phones. */
@media (max-width: 659px) {
  .table-wrap { border: none; border-radius: 0; background: none; overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tbody tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: .35rem .9rem; margin-bottom: .6rem;
  }
  .table tbody tr:hover { background: var(--surface); }
  .table td {
    border-bottom: 1px solid var(--line); padding: .55rem 0;
    display: grid; grid-template-columns: minmax(7rem, auto) minmax(0, 1fr);
    gap: .4rem 1rem; align-items: center;
  }
  .table tr td:last-child { border-bottom: none; }
  .table td::before {
    content: attr(data-label); color: var(--muted);
    font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em;
  }
  .table td:empty { display: none; }
  .table.models td { grid-template-columns: minmax(0, 1fr); gap: .3rem; }
  .table .center { text-align: left; }
  .table.models input, .table.models textarea { min-width: 0; }
  .table td.url-cell { display: grid; grid-template-columns: minmax(0, 1fr); gap: .45rem; }
  .url-cell code { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
  .url-cell .btn-ghost { justify-self: start; min-height: var(--tap); padding: 0 1.1rem; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: .1rem; }
  .facts dt { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; margin-top: .6rem; }
  .facts dt:first-child { margin-top: 0; }
  .facts dd.url-cell { display: grid; gap: .45rem; justify-items: start; }
  /* The rows are already cards, so the form around them stops being one. */
  .settings .form.card { background: none; border: none; padding: 0; backdrop-filter: none; }
  .settings .form.card > h2 { margin-top: 0; }
}

/* --- lightbox --------------------------------------------------------- */
.lightbox {
  border: none; padding: 0; margin: 0; background: transparent;
  width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  color: var(--text); overflow: hidden;
}
.lightbox[open] {
  display: grid; place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
           max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.lightbox::backdrop { background: rgba(4,6,12,.9); backdrop-filter: blur(8px); }
.lightbox img {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  display: block; border-radius: var(--radius);
  box-shadow: 0 40px 80px -40px rgba(0,0,0,1);
  animation: reveal .32s var(--ease-out) both;
}
.lightbox-close {
  position: fixed;
  top: max(.75rem, env(safe-area-inset-top)); right: max(.75rem, env(safe-area-inset-right));
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line); cursor: pointer;
  font-size: 1.5rem; line-height: 1;
  background: rgba(12,14,22,.8); color: #fff;
  backdrop-filter: blur(8px);
}
.lightbox-close:active { transform: scale(.93); }

@keyframes reveal {
  from { opacity: 0; transform: scale(.985); filter: blur(10px); }
  to { opacity: 1; transform: none; filter: none; }
}

/* --- htmx ------------------------------------------------------------- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }
[disabled] { opacity: .6; cursor: progress; }

/* --- product shot ----------------------------------------------------- */
.ps-layout { display: grid; gap: var(--s-5); align-items: start; }
.ps-form { display: grid; gap: var(--s-4); }
.ps-results { display: grid; gap: var(--s-4); min-width: 0; align-content: start; }
.ps-results > div:empty { display: none; }
.ps-results h2 { margin: 0; }

.ps-capture {
  display: grid; justify-items: center; gap: .35rem; text-align: center;
  padding: clamp(1.4rem, 7vw, 2.2rem) 1rem;
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  background: radial-gradient(120% 100% at 50% 0%, rgba(111,140,255,.12), transparent 70%), rgba(0,0,0,.22);
  cursor: pointer;
  transition: border-color .18s, background .18s;
}
.ps-capture:hover, .ps-capture.is-over { border-color: var(--accent); background: var(--accent-soft); }
.ps-capture-icon { color: #b9c3e8; line-height: 0; }
.ps-capture-icon svg { width: clamp(34px, 9vw, 42px); height: auto; }
.ps-capture-title { font-weight: 580; font-size: var(--fs-lg); margin: .2rem 0 0; letter-spacing: -.015em; }
.ps-capture-hint { margin: 0; }
.ps-capture-actions {
  display: flex; flex-wrap: wrap; gap: .55rem; justify-content: center;
  width: 100%; margin-top: .8rem;
}
.ps-capture-actions .btn { flex: 1 1 auto; min-width: 9.5rem; max-width: 16rem; }
.ps-preview {
  width: 100%; max-height: 260px; object-fit: contain;
  border-radius: var(--radius-sm); background: rgba(0,0,0,.3);
  animation: reveal .35s var(--ease-out) both;
}
.ps-capture.has-photo { padding: .8rem; border-style: solid; background: rgba(0,0,0,.24); }
.ps-capture.has-photo .ps-capture-icon,
.ps-capture.has-photo .ps-capture-hint { display: none; }
.ps-capture.has-photo .ps-capture-title { font-size: var(--fs-md); color: var(--muted); font-weight: 520; }

.ps-cam { display: grid; gap: .6rem; }
.ps-cam video { width: 100%; border-radius: var(--radius-sm); background: #000; aspect-ratio: 4 / 3; object-fit: cover; }
.ps-cam-actions { display: flex; gap: .6rem; }
.ps-cam-actions .btn, .ps-cam-actions .btn-ghost { flex: 1 1 0; }

.ps-field { border: none; padding: 0; margin: 0; min-width: 0; display: grid; gap: .5rem; }
.ps-field legend { font-size: var(--fs-sm); color: var(--muted); padding: 0 0 .4rem; }
.ps-chips {
  display: flex; gap: .55rem; overflow-x: auto; padding-bottom: .45rem;
  scroll-snap-type: x mandatory; scrollbar-width: none;
}
.ps-chips::-webkit-scrollbar { display: none; }
.chip {
  display: block; position: relative; cursor: pointer; margin: 0; min-width: 0;
  flex: 0 0 min(74%, 15rem); scroll-snap-align: start;
  padding: .7rem .85rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .16s, background .16s, transform .12s var(--ease-out);
}
.chip:active { transform: scale(.98); }
/* The radio covers its chip: the whole card is the hit area and the control
   still has a real box for the keyboard and for test drivers. */
.chip input {
  position: absolute; inset: 0; margin: 0; padding: 0;
  width: 100%; height: 100%; min-height: 0;
  appearance: none; -webkit-appearance: none;
  opacity: 0; cursor: pointer;
}
.chip:has(input:checked) {
  border-color: rgba(111,140,255,.8); background: var(--accent-soft);
  box-shadow: 0 8px 18px -12px rgba(0,0,0,.85);
}
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-body { display: grid; gap: .15rem; }
.chip-name { font-size: var(--fs-md); font-weight: 570; color: var(--text); }
.chip-blurb { display: block; line-height: 1.35; }

.ps-submit {
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 calc(-1 * var(--card-pad)) calc(-1 * var(--card-pad));
  padding: .7rem var(--card-pad) max(.7rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(10,12,19,.97) 58%, rgba(10,12,19,0));
  border-radius: 0 0 var(--radius) var(--radius);
}
.ps-spin {
  width: 15px; height: 15px; flex: 0 0 15px;
  border: 2px solid rgba(255,255,255,.38); border-top-color: #fff; border-radius: 50%;
  animation: ps-spin .7s linear infinite;
}
@keyframes ps-spin { to { transform: rotate(360deg); } }

.ps-generations { display: grid; gap: var(--s-4); }
.ps-generations:has(.ps-gen) .ps-empty { display: none; }
.ps-empty {
  padding: 1.6rem 1rem; text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.ps-gen {
  display: grid; gap: .7rem; padding: .9rem; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  animation: reveal .3s var(--ease-out) both;
}
.ps-gen-head { display: flex; gap: .7rem; align-items: center; min-width: 0; }
.ps-gen-meta { display: grid; gap: .15rem; min-width: 0; }
.ps-gen-line { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.ps-gen-line .small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-bar { height: 7px; border-radius: 999px; background: rgba(0,0,0,.4); overflow: hidden; }
.ps-bar-fill {
  height: 100%; border-radius: 999px; transition: width 1.4s linear;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent));
  background-size: 220% 100%; animation: ps-shimmer 2.2s linear infinite;
}
@keyframes ps-shimmer { to { background-position: -220% 0; } }
.ps-bar-copy { margin: 0; display: flex; justify-content: space-between; gap: 1rem; }
.ps-pct { font-variant-numeric: tabular-nums; }
.ps-result { display: block; border-radius: var(--radius-sm); overflow: hidden; background: rgba(0,0,0,.3); }
.ps-result img { width: 100%; display: block; animation: reveal .55s var(--ease-out) both; }
.ps-actions { margin: 0; }
.ps-prompt { border-top: 1px solid var(--line); padding-top: .55rem; }
.ps-prompt summary {
  cursor: pointer; font-size: var(--fs-sm); color: var(--muted);
  list-style: none; display: flex; align-items: center; gap: .4rem;
  min-height: 28px;
}
.ps-prompt summary::-webkit-details-marker { display: none; }
.ps-prompt summary::before {
  content: ""; width: 0; height: 0; flex: 0 0 auto;
  border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transition: transform .18s var(--ease-out);
}
.ps-prompt[open] summary::before { transform: rotate(90deg); }
.ps-prompt summary:hover { color: var(--text); }
.ps-prompt p { white-space: pre-wrap; margin: .5rem 0 0; color: var(--muted); }
.ps-retry { margin: 0; }

/* Phones get the toast at the bottom, where it never covers a page title;
   from tablet up it sits under the bar, clear of the left-aligned heading. */
#toast {
  position: fixed; z-index: 40; pointer-events: none;
  bottom: calc(max(1rem, env(safe-area-inset-bottom)) + .4rem);
  left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 2rem);
}
@media (min-width: 700px) {
  #toast { bottom: auto; top: calc(max(.65rem, env(safe-area-inset-top)) + 4rem); }
}
.toast {
  padding: .6rem 1.05rem; border-radius: 999px;
  font-size: var(--fs-sm); font-weight: 540; text-align: center;
  background: rgba(13,30,25,.93); border: 1px solid rgba(70,214,160,.45); color: #bff2de;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 40px -20px rgba(0,0,0,.95);
  animation: ps-toast 4s var(--ease-out) forwards;
}
@keyframes ps-toast {
  0% { opacity: 0; transform: scale(.94); }
  9%, 82% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: scale(.98); visibility: hidden; }
}

@media (min-width: 700px) {
  .ps-generations { grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); }
  .ps-empty { grid-column: 1 / -1; }
}

@media (min-width: 600px) {
  .ps-chips {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    overflow: visible; padding-bottom: 0;
  }
  .chip { flex: none; }
}

@media (min-width: 1000px) {
  .ps-layout { grid-template-columns: minmax(320px, 27rem) minmax(0, 1fr); gap: var(--s-6); }
  /* A pinned column taller than the screen would hide its own submit
     button, so the form scrolls inside its sticky frame. */
  .ps-form {
    position: sticky; top: 5.2rem;
    max-height: calc(100dvh - 6.5rem);
    overflow-y: auto; overscroll-behavior: contain;
  }
  .ps-chips { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
