/* PIXAI Atelier — light, compact, left-pane scroll */

:root {
  --bg0: #f6f3ee;
  --bg1: #efe9df;
  --ink: #1a1714;
  --ink-dim: #5f574e;
  --ink-mute: #8a8176;
  --line: rgba(26, 23, 20, 0.08);
  --line-strong: rgba(26, 23, 20, 0.14);
  --glass: rgba(255, 252, 248, 0.78);
  --glass-2: rgba(255, 255, 255, 0.55);
  --panel: rgba(255, 253, 249, 0.88);
  --accent: #ff6b4a;
  --accent-2: #7dd321;
  --accent-3: #3ec7ff;
  --violet: #9b7bff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 50px rgba(70, 50, 30, 0.08);
  --shadow-soft: 0 8px 24px rgba(70, 50, 30, 0.06);
  /* Readable CJK + Latin stack (avoid display/geometric fonts for body UI) */
  --font-display: "Noto Sans SC", "Inter", system-ui, sans-serif;
  --font-ui: "Noto Sans SC", "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Mono", ui-monospace, monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --topbar-h: 58px;
  --gap: 14px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg0: #121018;
  --bg1: #18151f;
  --ink: #f3eee7;
  --ink-dim: #b0a79b;
  --ink-mute: #7a7369;
  --line: rgba(243, 238, 231, 0.1);
  --line-strong: rgba(243, 238, 231, 0.16);
  --glass: rgba(28, 24, 36, 0.72);
  --glass-2: rgba(255, 255, 255, 0.05);
  --panel: rgba(24, 21, 32, 0.82);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.22);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Author display rules (e.g. .text-btn { display:inline-flex }) would
   otherwise override the UA stylesheet for the HTML `hidden` attribute. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* prevent rubber-band horizontal scroll on iOS */
  overflow-x: hidden;
}

body {
  overflow: hidden; /* page itself does not scroll (desktop + mobile shell) */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

/* iOS: avoid auto-zoom on focus (needs >=16px) */
@media (max-width: 900px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: color-mix(in oklab, var(--accent) 55%, white);
  color: #1a1714;
}

/* Atmosphere — softer */
.noise,
.aurora,
.grain-canvas {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
}

.noise {
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.aurora {
  background:
    radial-gradient(55% 45% at 8% 0%, color-mix(in oklab, var(--accent) 16%, transparent), transparent 62%),
    radial-gradient(45% 40% at 92% 8%, color-mix(in oklab, var(--violet) 14%, transparent), transparent 58%),
    radial-gradient(40% 45% at 70% 100%, color-mix(in oklab, var(--accent-3) 12%, transparent), transparent 60%),
    radial-gradient(35% 30% at 20% 90%, color-mix(in oklab, var(--accent-2) 10%, transparent), transparent 55%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  filter: saturate(1.05);
}

.grain-canvas {
  opacity: 0.025;
  mix-blend-mode: soft-light;
}

/* App shell: fixed viewport, no page scroll */
.app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  width: min(1480px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px 0 12px;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  gap: 10px;
  overflow: hidden;
}

/* Compact top bar */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.brand-lockup {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, color-mix(in oklab, var(--accent) 85%, white), var(--violet));
  box-shadow: 0 8px 20px color-mix(in oklab, var(--accent) 22%, transparent);
  color: #1a100e;
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.brand-copy {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-tag {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-mute);
  white-space: nowrap;
}

.mast-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.quota-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 148px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(14px);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.quota-chip > svg {
  width: 15px;
  height: 15px;
  color: var(--accent-2);
  flex: 0 0 auto;
}

.quota-text {
  display: grid;
  gap: 0;
  z-index: 1;
}

.quota-text .label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink-mute);
  font-family: var(--font-ui);
}

.quota-text .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
}

.quota-text .unit {
  margin-left: 0.2em;
  font-size: 0.78em;
  font-weight: 500;
  opacity: 0.72;
}

.quota-text .slash {
  margin: 0 3px;
  color: var(--ink-mute);
  font-weight: 500;
}

.quota-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--line);
}

.quota-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.5s var(--ease-out);
}

.quota-detail {
  font-size: 10px;
  opacity: 0.75;
  font-weight: 400;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  font-size: 12px;
  box-shadow: var(--shadow-soft);
}

.user-chip .user-name {
  font-weight: 600;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Login / redeem sheets — independent of lightbox .modal styles */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(12, 10, 8, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-backdrop.hidden {
  display: none !important;
}

.sheet-card {
  width: min(380px, 100%);
  max-height: min(92dvh, 920px);
  overflow-y: auto;
  padding: 22px 20px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel, var(--glass-2, #fff));
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.sheet-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-sub {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--ink-mute);
}

.sheet-card .field {
  display: grid;
  gap: 4px;
}

.sheet-card .field span {
  font-size: 12px;
  color: var(--ink-mute);
}

.sheet-card .field input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  width: 100%;
  min-height: 44px;
}

.sheet-card .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: var(--glass);
  color: inherit;
}

.sheet-card .btn.primary {
  border: 0;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #1a100e;
}

/* Discord brand button (Blurple #5865F2) */
.sheet-card .btn.btn-discord {
  border: 0;
  background: #5865f2;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12), 0 4px 14px rgba(88, 101, 242, 0.35);
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.sheet-card .btn.btn-discord:hover:not(:disabled) {
  background: #4752c4;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.14), 0 6px 18px rgba(88, 101, 242, 0.4);
}
.sheet-card .btn.btn-discord:active:not(:disabled) {
  background: #3c45a5;
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}
.sheet-card .btn.btn-discord .discord-icon {
  flex: none;
  width: 20px;
  height: 20px;
  display: block;
}
.sheet-card .btn.btn-discord span {
  line-height: 1;
}

.sheet-card .btn.block {
  width: 100%;
}

.sheet-card .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sheet-card .error {
  color: #d14343;
  font-size: 12px;
  margin: 0;
}

.sheet-card .modal-close {
  justify-self: center;
  margin-top: 4px;
  min-height: 40px;
}

.login-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 0;
  color: var(--ink-mute);
  font-size: 12px;
}
.login-or::before,
.login-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.login-or span {
  flex: none;
}

.account-rows {
  display: grid;
  gap: 8px;
  margin: 4px 0 8px;
}
.account-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
}
.account-row .k {
  color: var(--ink-mute);
  flex: none;
}
.account-row .v {
  text-align: right;
  word-break: break-all;
  font-weight: 500;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  display: grid;
  place-items: center;
  transition: transform 0.2s var(--ease-spring), border-color 0.2s, background 0.2s;
  box-shadow: var(--shadow-soft);
}

.icon-btn:hover {
  transform: translateY(-1px) scale(1.03);
  border-color: var(--line-strong);
  background: var(--glass-2);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* Stage: two columns, fill remaining height */
.stage {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(380px, 460px) minmax(0, 1fr);
  gap: var(--gap);
  align-items: stretch;
  overflow: hidden;
}

/* Left console: independent scroll */
.console {
  position: relative;
  min-height: 0;
  height: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(1.1);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.console-glow {
  position: absolute;
  inset: auto -30% -50% -30%;
  height: 50%;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--accent) 12%, transparent), transparent 72%);
  pointer-events: none;
}

/* scrollable body of left pane */
.console-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.console .block {
  position: relative;
  padding: 14px 14px 6px;
  border-bottom: 1px solid var(--line);
}

.console .block:last-child {
  border-bottom: 0;
  padding-bottom: 12px;
}

.block-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.block-title {
  display: flex;
  align-items: center;
  gap: 7px;
}

.block-title h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.block-title svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
}

.block-hint,
.micro-hint {
  margin: 0;
  color: var(--ink-mute);
  font-size: 12px;
}

.micro-hint {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  margin-top: 6px;
  margin-bottom: 4px;
  line-height: 1.4;
}

.micro-hint svg {
  width: 13px;
  height: 13px;
  margin-top: 2px;
  flex: 0 0 auto;
  color: var(--accent-3);
}

/* Presets — tall portrait covers; rail owns its own scroll */
.block-model {
  /* give model block room so covers aren't crushed by outer scroll only */
}

.preset-shell {
  display: grid;
  gap: 10px;
}

.preset-rail {
  display: grid;
  /* 2×2 preview (4 models); full list lives in modal */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  height: auto;
  max-height: none;
  overflow: visible;
  padding: 2px 0 4px;
  outline: none;
  align-content: start;
  align-items: start;
}

.preset-card {
  position: relative;
  border-radius: 16px;
  border: 1px solid var(--line);
  background:
    linear-gradient(160deg, var(--glass-2), transparent 55%),
    color-mix(in oklab, var(--bg1) 55%, white);
  padding: 0;
  text-align: left;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* grid item: size to content, don't stretch/collapse */
  align-self: start;
  width: 100%;
  height: auto;
  min-height: auto;
  transition: transform 0.2s var(--ease-spring), border-color 0.2s, box-shadow 0.2s;
}

/*
 * Empty <span> with only background-image collapses under flex+aspect-ratio.
 * ::before padding-top:100% forces a real 1:1 box on every browser.
 */
.preset-card .p-cover {
  display: block;
  position: relative;
  width: 100%;
  flex: none;
  overflow: hidden;
  background-color: #1c1814;
  background-image: linear-gradient(
    145deg,
    color-mix(in oklab, var(--accent) 18%, #2a2420),
    transparent 70%
  );
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
}

.preset-card .p-cover::before {
  content: "";
  display: block;
  width: 100%;
  padding-top: 100%; /* square */
}

.preset-card.has-cover .p-cover {
  background-color: #14110f;
  /* gradient stays as fallback under url() set inline by JS */
}

.preset-card .p-body {
  position: relative;
  z-index: 1;
  padding: 10px 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 0 0 auto;
  background: color-mix(in oklab, var(--panel) 92%, transparent);
}

html[data-theme="dark"] .preset-card {
  background:
    linear-gradient(160deg, var(--glass-2), transparent 55%),
    color-mix(in oklab, var(--bg1) 80%, black);
}

.preset-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 0 transparent;
  transition: box-shadow 0.2s;
}

.preset-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.preset-card[aria-selected="true"] {
  border-color: color-mix(in oklab, var(--accent) 55%, white);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--accent) 28%, transparent), var(--shadow-soft);
}

.preset-card[aria-selected="true"]::before {
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--accent) 45%, transparent);
}

.preset-card .p-name {
  position: relative;
  display: block;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.35;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-card .p-meta {
  position: relative;
  display: block;
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-mute);
  font-family: var(--font-ui);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-skeleton {
  grid-column: 1 / -1;
  padding: 16px;
  text-align: center;
  color: var(--ink-mute);
  font-size: 12px;
}

/* Segmented controls (Mode / Res / Batch) */
.seg-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.seg-row.compact {
  flex: 1;
  min-width: 0;
}
.seg-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg0) 50%, white);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-dim);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
html[data-theme="dark"] .seg-btn {
  background: color-mix(in oklab, var(--bg0) 80%, transparent);
}
.seg-btn:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}
.seg-btn[aria-pressed="true"] {
  border-color: color-mix(in oklab, var(--accent) 55%, white);
  background: color-mix(in oklab, var(--accent) 14%, white);
  color: var(--ink);
}
html[data-theme="dark"] .seg-btn[aria-pressed="true"] {
  background: color-mix(in oklab, var(--accent) 22%, transparent);
}
.seg-btn.locked {
  opacity: 0.55;
}

/* Size block — PixAI-like rows */
.size-section {
  display: grid;
  gap: 14px;
}
.size-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: start;
}
.size-label {
  padding-top: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-mute);
}

.aspect-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.aspect-card {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 10px 6px 8px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg0) 45%, white);
  transition: border-color 0.15s, box-shadow 0.15s;
}
html[data-theme="dark"] .aspect-card {
  background: color-mix(in oklab, var(--bg0) 75%, transparent);
}
.aspect-card:hover {
  border-color: var(--line-strong);
}
.aspect-card[aria-pressed="true"] {
  border-color: color-mix(in oklab, var(--accent) 55%, white);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--accent) 25%, transparent);
}
.aspect-card.locked {
  opacity: 0.5;
}
.aspect-card .a-frame {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Explicit w/h from JS — do not force all boxes vertical */
.aspect-card .a-box {
  box-sizing: border-box;
  border-radius: 6px;
  border: 1.5px solid color-mix(in oklab, var(--ink) 35%, transparent);
  background: color-mix(in oklab, var(--accent) 12%, transparent);
  flex: 0 0 auto;
}
.aspect-card .a-ratio {
  font-size: 12px;
  font-weight: 600;
}
.aspect-card .a-px {
  font-size: 10px;
  color: var(--ink-mute);
}

/* Style rail */
.style-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 88px;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.style-card {
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--bg1);
  padding: 0;
  text-align: left;
}
.style-card[aria-pressed="true"] {
  border-color: color-mix(in oklab, var(--accent) 55%, white);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--accent) 28%, transparent);
}
.style-card .s-cover {
  display: block;
  width: 100%;
  height: 72px;
  background: #1a1410 center/cover no-repeat;
}
.style-card .s-name {
  display: block;
  padding: 6px 6px 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 500;
}
.toggle-row input {
  width: 16px;
  height: 16px;
}

.text-btn.sm {
  padding: 4px 10px;
  font-size: 12px;
}

.thumb.placeholder {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--ink-mute);
  position: relative;
}
.thumb.placeholder .queue-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink-dim);
}
.thumb.placeholder .queue-center .queue-pct {
  font-size: 20px;
  letter-spacing: 0.02em;
}
.thumb.placeholder.fail {
  color: #d14343;
}
.thumb.placeholder svg {
  width: 28px;
  height: 28px;
  animation: spin 1s linear infinite;
}
.thumb.placeholder.fail svg {
  animation: none;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.block-hint.mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.param-stack {
  display: grid;
  gap: 16px;
}
.param-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.param-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}
.param-label .val {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-dim);
}
.param-hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--ink-mute);
}
.help-q {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-left: 4px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-mute);
  vertical-align: middle;
  line-height: 1;
}
.help-q:hover {
  color: var(--ink);
  border-color: var(--accent);
}
.help-pop {
  position: fixed;
  z-index: 80;
  width: min(280px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.5;
}
.help-pop strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}
.help-pop p {
  margin: 0;
  color: var(--ink-dim);
  font-weight: 400;
}

.style-modal-card {
  max-height: min(88vh, 860px);
  display: flex;
  flex-direction: column;
}
.style-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
  padding-right: 40px;
  flex: 0 0 auto;
}
.style-modal-head h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
.style-modal-head .muted {
  margin: 0;
  font-size: 13px;
  color: var(--ink-mute);
}
/* Room between cards — avoid stacked / clipped titles */
.style-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  grid-auto-rows: max-content;
  gap: 32px 22px; /* row column */
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  flex: 1 1 auto;
  padding: 4px 8px 28px;
  align-content: start;
  align-items: stretch;
  box-sizing: border-box;
}

/* Dedicated modal pick card — cover + title as separate rows, no overlap */
.style-pick {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
  overflow: visible;
  padding: 0 0 4px;
  text-align: left;
  height: auto;
  min-height: 0;
  margin: 0;
  box-sizing: border-box;
  position: relative;
}
html[data-theme="dark"] .style-pick {
  background: color-mix(in oklab, var(--bg1) 92%, #000);
}
.style-pick[aria-pressed="true"] {
  border-color: color-mix(in oklab, var(--accent) 55%, white);
  box-shadow: 0 0 0 1px color-mix(in oklab, var(--accent) 28%, transparent);
}
.style-pick-cover {
  display: block;
  position: relative;
  width: 100%;
  flex: none;
  border-radius: 15px 15px 0 0;
  background-color: #1a1410;
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  overflow: hidden;
}

.style-pick-cover::before {
  content: "";
  display: block;
  width: 100%;
  padding-top: 100%; /* square */
}
.style-pick-name {
  display: block;
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 14px 14px 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.55;
  letter-spacing: 0.01em;
  color: var(--ink);
  background: transparent;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow: visible;
  min-height: 3.2em;
}

/* side rail styles stay compact */
.style-rail .style-card .s-cover {
  height: 80px;
}
.style-rail .style-card .s-name {
  font-size: 12px;
}

/* Prevent result card layout thrash */
.result-card .thumb.placeholder {
  min-height: 180px;
}
.result-card img.thumb {
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  display: block;
  background: #1a1410;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px dashed var(--line-strong);
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  transition: background 0.2s, color 0.2s;
}

.text-btn:hover {
  background: var(--glass-2);
  color: var(--ink);
}

.text-btn svg {
  width: 13px;
  height: 13px;
}

/* Fields */
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.field.grow textarea {
  min-height: 84px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink-dim);
  font-family: var(--font-ui);
}

.field-label em {
  font-style: normal;
  color: var(--ink-dim);
}

.field-label .dim {
  opacity: 0.75;
  letter-spacing: 0.02em;
  text-transform: none;
}

textarea,
.input-shell {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg0) 40%, white);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

html[data-theme="dark"] textarea,
html[data-theme="dark"] .input-shell {
  background: color-mix(in oklab, var(--bg0) 70%, transparent);
}

textarea {
  resize: vertical;
  padding: 11px 13px;
  line-height: 1.55;
  font-size: 14px;
  outline: none;
  min-height: 64px;
}

textarea:focus,
.input-shell:focus-within {
  border-color: color-mix(in oklab, var(--accent-3) 50%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent-3) 14%, transparent);
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  min-height: 40px;
}

.input-shell > svg,
.select-shell > svg.chev {
  width: 15px;
  height: 15px;
  color: var(--ink-mute);
  flex: 0 0 auto;
}

.input-shell input,
.input-shell select {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  padding: 10px 0;
  font-variant-numeric: tabular-nums;
}

.input-shell select {
  appearance: none;
  cursor: pointer;
}

.select-shell {
  position: relative;
}

.select-shell .chev {
  pointer-events: none;
}

.seed-shell .ghost-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--ink-dim);
  transition: background 0.15s, color 0.15s, transform 0.2s var(--ease-spring);
}

.seed-shell .ghost-icon:hover {
  background: var(--glass-2);
  color: var(--ink);
  transform: rotate(-10deg);
}

.seed-shell .ghost-icon svg {
  width: 14px;
  height: 14px;
}

.dim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg0) 30%, white);
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-dim);
  transition: transform 0.15s var(--ease-spring), background 0.15s, border-color 0.15s, color 0.15s;
}

html[data-theme="dark"] .chip {
  background: transparent;
}

.chip:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  color: var(--ink);
}

.chip[aria-pressed="true"] {
  background: color-mix(in oklab, var(--accent-2) 16%, white);
  border-color: color-mix(in oklab, var(--accent-2) 45%, var(--line));
  color: var(--ink);
}

html[data-theme="dark"] .chip[aria-pressed="true"] {
  background: color-mix(in oklab, var(--accent-2) 16%, transparent);
}

.chip-row.sizes .chip {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 10px;
}

/* Footer generate — sticky inside left column */
.console-footer {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  min-width: 0;
}

.status-line > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-mute);
}

.status-dot.busy {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.ok {
  background: var(--accent-2);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--accent) 40%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

.generate-btn {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border-radius: 14px;
  color: #1a100e;
  text-align: left;
  transition: transform 0.2s var(--ease-spring), filter 0.15s;
}

.generate-btn .gen-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(120deg, var(--accent), #ff9a6a 42%, var(--accent-2) 88%);
  background-size: 160% 160%;
  animation: gen-shift 6s linear infinite;
}

@keyframes gen-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.generate-btn:hover {
  transform: translateY(-1px) scale(1.01);
  filter: saturate(1.05);
}

.generate-btn:active {
  transform: translateY(0) scale(0.99);
}

.generate-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.15);
}

.generate-btn > svg {
  grid-row: 1 / span 2;
  width: 18px;
  height: 18px;
}

.generate-btn .gen-label {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.generate-btn .gen-kicker {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  opacity: 0.8;
}

/* Gallery — independent scroll if needed */
.gallery {
  min-height: 0;
  height: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  padding: 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.gallery::before {
  content: none;
  display: none;
}

.gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
}

.gallery-head .eyebrow {
  margin: 0 0 2px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink-mute);
}

.gallery-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(20px, 2.4vw, 26px);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.result-stage {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  align-content: start;
  padding-right: 2px;
}

.result-stage.empty {
  display: grid;
  place-items: center;
  grid-template-columns: 1fr;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  max-width: 260px;
}

.empty-orb {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background:
    radial-gradient(circle at 30% 30%, color-mix(in oklab, var(--accent-3) 22%, transparent), transparent 55%),
    var(--glass);
}

.empty-orb svg {
  width: 26px;
  height: 26px;
  color: var(--ink-dim);
}

.empty-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 24px;
}

.empty-sub {
  margin: 0;
  color: var(--ink-mute);
  font-size: 12px;
  line-height: 1.45;
}

/* Result card */
.result-card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg0) 35%, white);
  transform-origin: center;
  animation: card-in 0.45s var(--ease-out) both;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s;
}

html[data-theme="dark"] .result-card {
  background: color-mix(in oklab, var(--bg0) 60%, transparent);
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.result-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  z-index: 2;
}

.result-card .thumb {
  aspect-ratio: 3 / 4;
  width: 100%;
  object-fit: cover;
  display: block;
  background: linear-gradient(135deg, #ddd5c8, #ebe4d8 40%, #d2c9ba);
}

html[data-theme="dark"] .result-card .thumb {
  background: linear-gradient(135deg, #1a1522, #2a2035 40%, #151018);
}

.result-card .thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--ink-mute);
}

.result-card .thumb.placeholder svg {
  width: 24px;
  height: 24px;
  animation: spin 1.1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.result-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--ink-dim);
}

.result-card .meta-actions {
  display: flex;
  gap: 2px;
}

.result-card .meta-actions button,
.result-card .meta-actions a {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: var(--ink-dim);
  transition: background 0.15s, color 0.15s;
}

.result-card .meta-actions button:hover,
.result-card .meta-actions a:hover {
  background: var(--glass-2);
  color: var(--ink);
}

.result-card .meta-actions svg {
  width: 13px;
  height: 13px;
}

/* Lightbox / style modal shell */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal.hidden {
  display: none;
}

/* Dimmer inside .modal only — never redefines login sheets */
.modal > .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 12, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

html[data-theme="dark"] .modal > .modal-backdrop {
  background: rgba(4, 3, 8, 0.68);
}

.modal > .modal-card {
  position: relative;
  z-index: 1;
  width: min(900px, 100%);
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 14px;
  max-height: min(92dvh, 960px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Must beat .modal-card width */
.modal > .modal-card.style-modal-card {
  width: min(1100px, calc(100vw - 16px)) !important;
  max-width: calc(100vw - 16px) !important;
  max-height: min(90dvh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* scroll lives on .style-modal-grid */
  padding: 24px 22px 16px;
}

.modal-x {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
}

.lightbox-frame {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0f0d12;
  max-height: min(70vh, 780px);
  display: grid;
  place-items: center;
}

.lightbox-frame img {
  display: block;
  max-width: 100%;
  max-height: min(70vh, 780px);
  object-fit: contain;
}

.lightbox-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass-2);
  font-size: 12px;
  font-weight: 600;
  transition: transform 0.15s var(--ease-spring), background 0.15s;
}

.pill-btn:hover {
  transform: translateY(-1px);
}

.pill-btn.primary {
  border-color: transparent;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #1a100e;
}

.pill-btn svg {
  width: 15px;
  height: 15px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(400px, calc(100% - 24px));
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.toast.hidden {
  display: none;
}

.toast svg {
  width: 15px;
  height: 15px;
  color: var(--accent-2);
  flex: 0 0 auto;
}

/* Colophon */
.colophon {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--ink-mute);
  font-size: 11px;
  padding: 0 4px;
  min-height: 18px;
}

.colophon .mono {
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.colophon .sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--ink-mute);
  opacity: 0.5;
}

/* Scrollbars — left pane + gallery */
.console-scroll::-webkit-scrollbar,
.result-stage::-webkit-scrollbar,
.preset-rail::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
.console-scroll::-webkit-scrollbar-thumb,
.result-stage::-webkit-scrollbar-thumb,
.preset-rail::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--ink) 16%, transparent);
  border-radius: 999px;
}
.console-scroll::-webkit-scrollbar-track,
.result-stage::-webkit-scrollbar-track,
.preset-rail::-webkit-scrollbar-track {
  background: transparent;
}

/* Mobile bottom tabs (shown only on narrow viewports) */
.mobile-tabs {
  display: none;
}

.mobile-tab {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 6px 8px 4px;
  border-radius: 12px;
  color: var(--ink-mute);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.15s, background 0.15s;
}

.mobile-tab svg {
  width: 20px;
  height: 20px;
}

.mobile-tab.is-active {
  color: var(--ink);
  background: color-mix(in oklab, var(--accent) 12%, transparent);
}

.mobile-tab-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 28px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a100e;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ========== Responsive: tablet ========== */
@media (max-width: 1100px) {
  .stage {
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  }

}

/* ========== Responsive: phone / small tablet (tabbed shell) ========== */
@media (max-width: 900px) {
  :root {
    --topbar-h: auto;
    --gap: 0px;
    --mobile-tabs-h: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  html,
  body {
    height: 100%;
    height: 100dvh;
    overscroll-behavior: none;
  }

  body {
    overflow: hidden;
  }

  .app {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding:
      max(6px, env(safe-area-inset-top, 0px))
      max(10px, env(safe-area-inset-right, 0px))
      0
      max(10px, env(safe-area-inset-left, 0px));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px;
    overflow: hidden;
  }

  .topbar {
    height: auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 10px;
    padding: 2px 0 4px;
  }

  .brand-lockup {
    min-width: 0;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .brand-mark svg {
    width: 16px;
    height: 16px;
  }

  .brand-name {
    font-size: 14px;
  }

  .brand-tag {
    display: none;
  }

  .mast-meta {
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
  }

  /* very tight: stack meta under brand */
  @media (max-width: 360px) {
    .topbar {
      grid-template-columns: 1fr;
    }
    .mast-meta {
      justify-content: space-between;
      width: 100%;
    }
  }

  .quota-chip {
    min-width: 0;
    flex: 0 1 auto;
    max-width: 100%;
    padding: 5px 10px;
    gap: 6px;
  }

  .quota-chip > svg {
    width: 14px;
    height: 14px;
  }

  .quota-text .label {
    font-size: 10px;
  }

  .quota-text .value {
    font-size: 13px;
  }

  .quota-detail {
    display: none; /* too cramped on phone */
  }

  .user-chip {
    padding: 3px 6px 3px 10px;
    gap: 4px;
    max-width: 100%;
  }

  .user-chip .user-name {
    max-width: 5.5rem;
    font-size: 12px;
  }

  .user-chip .text-btn.sm {
    padding: 6px 10px;
    min-height: 32px;
    font-size: 12px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
  }

  /* Single pane at a time */
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    overflow: hidden;
    gap: 0;
  }

  .stage .console,
  .stage .gallery {
    min-height: 0;
    height: 100%;
    max-height: 100%;
    border-radius: 14px;
  }

  /* default: show console */
  .stage[data-mobile-view="console"] .gallery {
    display: none !important;
  }

  .stage[data-mobile-view="gallery"] .console {
    display: none !important;
  }

  .console {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .console-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .console .block {
    padding: 12px 12px 6px;
  }

  .console-footer {
    flex: 0 0 auto;
    padding: 10px 12px;
    box-shadow: 0 -8px 24px rgba(40, 30, 20, 0.06);
  }

  .param-row input[type="range"] {
    height: 28px;
  }

  .status-line {
    font-size: 10px;
  }

  /* prevent any child from forcing horizontal page scroll */
  .console,
  .gallery,
  .console-scroll,
  .block,
  .field,
  textarea,
  .input-shell {
    max-width: 100%;
    min-width: 0;
  }

  html[data-theme="dark"] .console-footer {
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
  }

  .generate-btn {
    min-height: 52px;
  }

  .gallery {
    padding: 12px;
    overflow: hidden;
  }

  .gallery-head {
    margin-bottom: 10px;
  }

  .gallery-title {
    font-size: 18px;
  }

  .result-stage {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .result-stage.empty {
    grid-template-columns: 1fr;
  }

  .result-card .thumb {
    aspect-ratio: 3 / 4;
  }

  .result-card img.thumb {
    max-height: none;
  }

  .result-card .meta {
    padding: 6px 8px;
    font-size: 9px;
  }

  .result-card .meta-actions button,
  .result-card .meta-actions a {
    width: 32px;
    height: 32px;
  }

  /* Model rail: 2×2 square covers, no inner scroll */
  .preset-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
    max-height: none;
    gap: 8px;
    padding-right: 0;
    overflow: visible;
  }

  .preset-card {
    border-radius: 12px;
    width: 100%;
    height: auto;
    min-height: auto;
  }

  .preset-card .p-body {
    padding: 8px 9px 10px;
  }

  .preset-card .p-name {
    font-size: 12px;
  }

  .preset-card:hover {
    transform: none; /* avoid hover lift on touch */
  }

  .result-card:hover {
    transform: none;
  }

  .aspect-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .aspect-card {
    padding: 8px 4px 6px;
  }

  .aspect-card .a-frame {
    height: 44px;
  }

  .size-row {
    grid-template-columns: 44px 1fr;
    gap: 8px;
  }

  .size-label {
    padding-top: 8px;
    font-size: 11px;
  }

  .seg-btn {
    padding: 10px 10px;
    min-height: 42px;
    font-size: 13px;
  }

  .style-rail {
    grid-auto-columns: 76px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
  }

  .style-card .s-cover,
  .style-rail .style-card .s-cover {
    height: 64px;
  }

  .field.grow textarea {
    min-height: 96px;
  }

  #prompt {
    min-height: 110px;
  }

  .dim-grid {
    grid-template-columns: 1fr;
  }

  /* Bottom tab bar */
  .mobile-tabs {
    display: flex;
    align-items: stretch;
    gap: 4px;
    flex: 0 0 auto;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: color-mix(in oklab, var(--panel) 94%, transparent);
    backdrop-filter: blur(16px) saturate(1.1);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
    z-index: 20;
  }

  .colophon {
    display: none;
  }

  /* Modals full-width friendly */
  .modal {
    padding: max(8px, env(safe-area-inset-top)) 8px
      max(8px, env(safe-area-inset-bottom)) 8px;
    align-items: end;
  }

  .modal > .modal-card {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 12px 12px;
    padding: 12px;
    max-height: min(92dvh, 100%);
  }

  .modal > .modal-card.style-modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(92dvh, 100%);
    padding: 16px 12px 12px;
    border-radius: 16px 16px 12px 12px;
  }

  .style-modal-head {
    margin-bottom: 12px;
    padding-right: 36px;
  }

  .style-modal-head h3 {
    font-size: 17px;
  }

  .style-modal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 10px;
    padding: 2px 2px 16px;
    align-items: start;
  }

  .style-pick {
    overflow: hidden; /* clip square cover corners cleanly */
  }

  .style-pick-name {
    padding: 10px 10px 12px;
    font-size: 13px;
    min-height: 2.6em;
  }

  .lightbox-frame {
    max-height: min(62dvh, 640px);
  }

  .lightbox-frame img {
    max-height: min(62dvh, 640px);
  }

  .lightbox-actions {
    gap: 8px;
  }

  .pill-btn {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 44px;
    padding: 12px 14px;
  }

  .toast {
    bottom: calc(var(--mobile-tabs-h, 56px) + 12px);
    left: 12px;
    right: 12px;
    max-width: none;
    transform: none;
    width: auto;
    border-radius: 14px;
    justify-content: center;
  }

  .help-pop {
    width: min(300px, calc(100vw - 20px));
  }

  .sheet-backdrop {
    align-items: end;
    place-items: end center;
    padding: 0;
  }

  .sheet-card {
    width: 100%;
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    max-height: min(90dvh, 100%);
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }

  /* Reduce expensive effects on mobile */
  .noise,
  .grain-canvas {
    display: none;
  }

  .console,
  .gallery,
  .quota-chip,
  .user-chip,
  .icon-btn {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
}

/* ========== Extra-narrow phones ========== */
@media (max-width: 400px) {
  .app {
    padding-left: 8px;
    padding-right: 8px;
  }

  .brand-name {
    font-size: 13px;
  }

  .quota-text .unit {
    display: none;
  }

  .user-chip .user-name {
    max-width: 4rem;
  }

  .aspect-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-stage {
    grid-template-columns: 1fr 1fr;
  }

  .style-modal-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Landscape phones: keep usable height */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .mobile-tab {
    flex-direction: row;
    gap: 6px;
    min-height: 40px;
  }

  .generate-btn {
    min-height: 44px;
  }

  .sheet-card {
    max-height: 95dvh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
