/* ST 映境 studio — layout and components. Builds on ui-base.css tokens.
   Desktop (>1100px): parameters | canvas + composer | discussion.
   Tablet (761–1100px): parameters | canvas + composer, discussion as a drawer.
   Phone (≤760px): single column, bottom tab bar, parameters in a sheet. */

/* ---------- app shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30; flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  height: 52px; padding: 0 16px 0 20px; background: var(--material); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--separator);
}
.brand { justify-self: start; display: inline-flex; align-items: center; gap: 10px; color: var(--label); text-decoration: none !important; border-radius: 10px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; box-shadow: 0 0 0 .5px var(--separator), 0 1px 3px rgba(0,0,0,.12); }
.brand strong { font-family: var(--font-display); font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.primary-nav { display: grid; grid-auto-flow: column; gap: 2px; padding: 2px; border-radius: 10px; background: var(--fill); }
.primary-nav button { min-height: 30px; padding: 0 16px; border-radius: 8px; background: transparent; color: var(--label); font-size: 13px; font-weight: 500; gap: 6px; }
.primary-nav button svg { width: 15px; height: 15px; }
.primary-nav button:hover:not(:disabled) { background: transparent; opacity: .7; }
.primary-nav button:active:not(:disabled) { transform: none; }
.primary-nav { --pill-r: 8px; }
.primary-nav.has-pill button.nav-active, .member-tabs.has-pill button[aria-selected=true] { background: transparent; box-shadow: none; }
.primary-nav button.nav-active { background: var(--surface-raised); box-shadow: 0 3px 8px rgba(0,0,0,.08), 0 0 0 .5px rgba(0,0,0,.04); font-weight: 600; opacity: 1; }
.header-tools { justify-self: end; display: flex; align-items: center; gap: 6px; }
.credit-pill { min-height: 32px; padding: 0 12px 0 10px; border-radius: 999px; background: var(--fill-2); gap: 5px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.credit-pill svg { width: 15px; height: 15px; color: #d68a00; }
.credit-pill .unit { font-weight: 400; color: var(--label-2); }
.account-button { min-height: 32px; padding: 0 16px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; gap: 8px; max-width: 180px; }
.account-button:hover:not(:disabled) { background: var(--accent-hover); }
.account-button .avatar { display: none; }
.account-label { overflow: hidden; text-overflow: ellipsis; }
.signed-in .account-button { padding: 0 12px 0 3px; background: var(--fill-2); color: var(--label); font-weight: 500; }
.signed-in .account-button:hover:not(:disabled) { background: var(--fill); }
.signed-in .account-button .avatar { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg, #5e9cff, #8f6bff); color: #fff; font-size: 12px; font-weight: 700; flex: none; }

@media (min-width: 761px) {
  body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  #create-view, #library-view { flex: 1; min-height: 0; }
}

/* ---------- workspace grid ---------- */
.workspace {
  position: relative; display: grid; grid-template-columns: 300px minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "inspector canvas chat" "inspector composer chat";
}
body.chat-collapsed .workspace { grid-template-columns: 300px minmax(0, 1fr); grid-template-areas: "inspector canvas" "inspector composer"; }
body.chat-collapsed .chat-panel { display: none; }
@media (min-width: 1440px) {
  .workspace { grid-template-columns: 320px minmax(0, 1fr) 360px; }
  body.chat-collapsed .workspace { grid-template-columns: 320px minmax(0, 1fr); }
}

/* ---------- inspector ---------- */
.inspector { grid-area: inspector; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--separator); }
.panel-heading { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 12px 0 20px; flex: none; }
.panel-heading h2 { flex: 1; min-width: 0; font-size: 17px; font-weight: 700; letter-spacing: -.015em; }
#model-guide { min-width: 0; max-width: 70%; }
#model-guide svg { flex: none; }
#model-guide span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-heading h2 { min-width: 0; overflow-wrap: anywhere; }
.inspector .inspector-toggle { display: none; }
.inspector-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 20px 12px; }
.settings-section { padding: 18px 0; border-top: 1px solid var(--separator); display: grid; gap: 8px; align-content: start; }
.settings-section:first-of-type { border-top: 0; padding-top: 4px; }
.field-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--label); }
.settings-section > .field-label:first-child, .settings-section > div:first-child > .field-label:first-child { margin-top: 0; }
.field-label small { margin-left: 6px; margin-right: auto; font-weight: 400; color: var(--label-3); }
.field-label output, .field-value { font-weight: 500; color: var(--label-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.field-note { font-size: 12px; line-height: 1.6; color: var(--label-2); }
.field-note.subtle { color: var(--label-3); }
.field-note:empty { display: none; }
.inline-tools { display: flex; gap: 4px; }
.inspector-footer { flex: none; padding: 8px 12px 10px; border-top: 1px solid var(--separator); }
.inspector-footer .text-button { font-size: 12px; }

.family-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.family-switch button {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 8px; row-gap: 1px; align-items: center; justify-items: start;
  min-height: 60px; padding: 10px 12px; border-radius: var(--radius); background: var(--fill-2); text-align: left; white-space: normal;
  box-shadow: inset 0 0 0 1px transparent;
}
.family-switch button svg { grid-row: 1 / 3; width: 20px; height: 20px; color: var(--label-2); }
.family-switch button b { font-size: 14px; font-weight: 600; line-height: 1.25; }
.family-switch button span { font-size: 11px; font-weight: 400; line-height: 1.3; color: var(--label-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.family-switch button > * { min-width: 0; }
.family-switch button[aria-pressed=true] { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.family-switch button[aria-pressed=true] svg, .family-switch button[aria-pressed=true] b { color: var(--accent-text); }
.mode-switch { margin-top: 8px; }

.ratios { display: grid; grid-template-columns: repeat(auto-fit, minmax(68px, 1fr)); gap: 8px; }
.ratios button { display: grid; justify-items: center; gap: 3px; min-height: 76px; padding: 10px 6px 8px; border-radius: var(--radius); background: var(--fill-2); box-shadow: inset 0 0 0 1px transparent; }
.ratios button b { font-size: 13px; font-weight: 600; }
.ratios button small { font-size: 11px; color: var(--label-3); font-weight: 400; }
.ratios button[aria-pressed=true] { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.ratios button[aria-pressed=true] b { color: var(--accent-text); }
.ratios button[data-extra-ratio] { min-height: 40px; font-size: 13px; }
.ratio-icon { display: block; border: 1.6px solid currentColor; border-radius: 3px; color: var(--label-3); margin-bottom: 2px; }
.ratio-icon.portrait { width: 14px; height: 20px; }
.ratio-icon.square { width: 18px; height: 18px; }
.ratio-icon.landscape { width: 22px; height: 15px; margin-top: 2px; margin-bottom: 5px; }
[aria-pressed=true] > .ratio-icon { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.field-row .field-label { margin: 0; }
.stepper { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 999px; background: var(--fill-2); }
.stepper button { width: 32px; min-width: 32px; min-height: 32px; padding: 0; border-radius: 50%; background: transparent; }
.stepper button:hover:not(:disabled) { background: var(--surface); box-shadow: var(--shadow-sm); }
.stepper button svg { width: 15px; height: 15px; }
.stepper input[type=number] { width: 36px !important; min-height: 32px !important; padding: 0 !important; border: 0 !important; background: transparent !important; box-shadow: none !important; text-align: center; font-weight: 600; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.upload-zone { display: grid; justify-items: center; gap: 4px; padding: 18px 12px; border: 1.5px dashed var(--separator-strong); border-radius: var(--radius); color: var(--label-2); text-align: center; cursor: pointer; transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease); }
.upload-zone:hover, .upload-zone.is-dragging { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.upload-zone.is-busy { opacity: .6; pointer-events: none; }
.upload-zone svg { width: 22px; height: 22px; }
.upload-zone span { font-size: 13px; font-weight: 600; }
.upload-zone small { font-size: 11px; color: var(--label-3); }
#reference-preview, .reference-list { display: grid; gap: 8px; }
.reference-item { display: grid; grid-template-columns: 48px minmax(0,1fr); align-items: center; gap: 8px 12px; padding: 8px; border-radius: 12px; background: var(--fill-2); }
.reference-item button { min-width: 44px; min-height: 44px; padding: 0; border-radius: 10px; background: transparent; color: var(--label-2); }
.reference-item button:hover:not(:disabled) { background: var(--fill); color: var(--label); }
.reference-item .reference-open { width: 48px; height: 48px; overflow: hidden; background: var(--fill); }
.reference-open img { display: block; width: 48px; height: 48px; object-fit: cover; }
.reference-loading { display: block; padding: 2px; font-size: 11px; line-height: 1.4; }
.reference-info { min-width: 0; display: grid; gap: 4px; }
.reference-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.reference-actions { display: flex; gap: 8px; }
.reference-actions svg { width: 18px; height: 18px; }
.reference-actions [data-reference-action=remove] { margin-left: auto; color: var(--red); }
.reference-actions [data-reference-action=remove]:hover:not(:disabled) { background: var(--red-soft); color: var(--red); }
.reference-weight { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0,1fr) 30px; align-items: center; gap: 8px; font-size: 12px; color: var(--label-2); }
.reference-weight output { text-align: right; font-variant-numeric: tabular-nums; }
.dimension-fields { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 6px; }
.dimension-fields label { display: grid; gap: 4px; font-size: 12px; color: var(--label-2); }
#swap-dimensions { margin-bottom: 2px; }
#custom-dimensions, #nai-parameters, #general-parameters { display: grid; gap: 8px; }
#nai-parameters .field-label .mini-button { margin-left: auto; }
.character-row { display: grid; gap: 8px; padding: 10px; border-radius: 12px; background: var(--fill-2); }
.character-row textarea { background: var(--surface) !important; }
.coordinate-fields { display: flex; align-items: center; gap: 8px; }
.coordinate-fields label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--label-2); }
.coordinate-fields input { width: 72px !important; min-height: 32px !important; padding: 4px 8px !important; background: var(--surface) !important; }
.coordinate-fields button { margin-left: auto; }
#character-rows { display: grid; gap: 8px; }
#character-rows:empty { display: none; }

/* ---------- canvas ---------- */
.canvas-area { grid-area: canvas; position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; min-height: 0; padding: 16px 24px 12px; overflow: hidden; }
#job-list { width: 100%; max-width: 720px; flex: none; }
#job-list:empty { display: none; }
.art-stage { position: relative; flex: 1; min-height: 160px; width: 100%; }
.art-wrap { position: absolute; inset: 0; }
#main-image { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: 0 0 0 .5px var(--separator), 0 12px 40px rgba(0,0,0,.12); cursor: zoom-in; background: var(--fill-2); animation: image-in 420ms var(--ease-out); }
#main-image:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
@keyframes image-in { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }
#empty-canvas { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px; text-align: center; }
#empty-canvas .empty-mark { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 10px; border-radius: 20px; background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 16%, transparent), color-mix(in srgb, var(--purple) 16%, transparent)); color: var(--accent-text); }
#empty-canvas .empty-mark svg { width: 28px; height: 28px; stroke-width: 1.6; }
#empty-canvas h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
#empty-canvas p { color: var(--label-2); font-size: 14px; }
.canvas-area.is-pending #empty-canvas .empty-mark { animation: breathe 2.4s var(--ease) infinite; }
.canvas-area.is-pending #empty-canvas .empty-mark { position: relative; }
.canvas-area.is-pending #empty-canvas .empty-mark::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; background: conic-gradient(from 0deg, transparent 0 58%, color-mix(in srgb, var(--accent) 75%, transparent) 100%); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px)); mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px)); animation: spin 1.3s linear infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.94); opacity: .7; } }
#preview-feedback { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: 999px; background: var(--orange-soft); color: var(--label); font-size: 13px; }
#preview-feedback button { min-height: 28px; border-radius: 999px; font-size: 12px; background: var(--surface); }
.image-tools { display: flex; align-items: center; gap: 2px; flex: none; padding: 3px; border-radius: 999px; background: var(--surface); box-shadow: 0 0 0 .5px var(--separator), var(--shadow-sm); }
.canvas-area:has(#main-image[hidden]) .image-tools { display: none; }
.image-tools .icon-button { width: 32px; min-width: 32px; min-height: 32px; }
.image-tools .icon-button svg { width: 18px; height: 18px; }
#image-counter { min-width: 52px; text-align: center; font-size: 12px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.tool-divider { width: 1px; height: 18px; margin: 0 4px; background: var(--separator-strong); }
.tool-button { min-height: 32px; padding: 0 12px; border-radius: 999px; background: transparent; color: var(--label); font-size: 13px; gap: 5px; }
.tool-button:hover:not(:disabled) { background: var(--fill-2); }
.tool-button svg { width: 16px; height: 16px; }
.filmstrip { display: flex; justify-content: center; gap: 8px; flex: none; max-width: 100%; padding: 2px; overflow-x: auto; scrollbar-width: none; }
.filmstrip::-webkit-scrollbar { display: none; }
.filmstrip-image { width: 46px; min-width: 46px; height: 46px; min-height: 46px; padding: 0; border-radius: 10px; overflow: hidden; background: var(--fill-2); box-shadow: 0 0 0 .5px var(--separator); }
.filmstrip-image:hover:not(:disabled) { background: var(--fill-2); transform: translateY(-1px); box-shadow: 0 0 0 .5px var(--separator), var(--shadow); }
.composer.nudge { animation: nudge 420ms cubic-bezier(.36, .07, .19, .97) both; }
@keyframes nudge { 15%, 85% { transform: translateX(-2px); } 30%, 70% { transform: translateX(4px); } 45%, 55% { transform: translateX(-6px); } 50% { transform: translateX(6px); } }
.filmstrip-image.fresh { animation: tile-in 480ms var(--ease-out) both; }
.filmstrip-pending { position: relative; display: grid; place-items: center; flex: none; width: 46px; height: 46px; border-radius: 10px; background: linear-gradient(110deg, var(--fill-2) 30%, var(--fill) 50%, var(--fill-2) 70%) 0 0 / 250% 100%; box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 35%, transparent); animation: shimmer 1.6s linear infinite, tile-in 360ms var(--ease-out) both; }
.pending-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: spin .9s linear infinite; }
.filmstrip-pending b { position: absolute; right: 3px; bottom: 2px; font-size: 10px; font-weight: 700; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.filmstrip-image.current { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.media-preview { display: block; width: 100%; height: 100%; }
.media-preview img { width: 100%; height: 100%; object-fit: cover; animation: fade-in var(--medium) var(--ease); }
.media-loading { display: grid; place-items: center; width: 100%; height: 100%; min-height: 40px; color: transparent; font-size: 11px; background: linear-gradient(100deg, var(--fill-2) 30%, var(--fill) 50%, var(--fill-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
.media-unavailable .media-loading { color: var(--label-3); animation: none; background: var(--fill-2); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Generation status */
.generation-status { display: grid; gap: 6px; padding: 10px 14px; border-radius: var(--radius); background: var(--surface); box-shadow: 0 0 0 .5px var(--separator), var(--shadow-sm); animation: reveal var(--medium) var(--ease-out); }
.generation-status { position: relative; }
.generation-dismiss { position: absolute; top: 8px; right: 8px; width: 26px; min-width: 26px; min-height: 26px; padding: 0; border-radius: 50%; background: var(--fill-2); color: var(--label-3); }
.generation-dismiss:hover:not(:disabled) { background: var(--fill); color: var(--label); }
.generation-dismiss svg { width: 13px; height: 13px; }
.generation-heading { display: flex; align-items: center; gap: 8px; min-width: 0; padding-right: 28px; }
.generation-heading strong { font-size: 14px; font-weight: 600; }
#generation-elapsed { margin-left: auto; font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); animation: pulse 1.6s var(--ease) infinite; }
.generation-status[data-stage=done] .status-dot { background: var(--green); animation: none; }
.generation-status:is([data-stage=failed], [data-stage=unknown]) .status-dot { background: var(--red); animation: none; }
.generation-status[data-stage=cancelled] .status-dot { background: var(--label-4); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
#generation-description { font-size: 13px; color: var(--label-2); line-height: 1.5; }
.generation-progress { position: relative; height: 3px; border-radius: 2px; background: var(--fill); overflow: hidden; }
.generation-progress > span { position: absolute; top: 0; bottom: 0; width: 36%; border-radius: 2px; background: var(--accent); animation: indeterminate 1.5s var(--ease) infinite; }
@keyframes indeterminate { from { left: -36%; } to { left: 100%; } }
.generation-status:is([data-stage=done], [data-stage=failed], [data-stage=cancelled], [data-stage=unknown]) .generation-progress { display: none; }
.generation-footer { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.generation-footer > span { margin-right: auto; font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.generation-footer button { min-height: 26px; padding: 0 8px; border-radius: 999px; background: transparent; color: var(--accent-text); font-size: 12px; }
.generation-footer button:hover:not(:disabled) { background: var(--accent-soft); }
#generation-again { background: var(--accent-soft); font-weight: 600; }
#generation-again:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 18%, transparent); }
#generation-cancel { color: var(--red); }
#generation-connection { font-size: 12px; color: var(--orange); }
#generation-connection:empty { display: none; }
/* A finished job collapses into a single quiet line. */
.generation-status[data-stage=done] { grid-template-columns: auto 1fr auto; align-items: center; column-gap: 6px; padding: 6px 8px 6px 14px; border-radius: 999px; }
.generation-status[data-stage=done] .generation-heading { padding-right: 0; }
.generation-status[data-stage=done] .generation-dismiss { position: static; }
.generation-status[data-stage=done] #generation-description { display: none; }
.generation-status[data-stage=done] .generation-footer { justify-content: flex-end; }
.generation-status[data-stage=done] .generation-footer > span { margin-right: 4px; }
.generation-status[data-stage=done] #generation-details { display: none; }

/* ---------- composer ---------- */
.composer {
  grid-area: composer; justify-self: center; width: calc(100% - 48px); max-width: 880px; margin: 0 0 20px; padding: 12px 14px 12px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; border-radius: var(--radius-xl); background: var(--surface); box-shadow: 0 0 0 .5px var(--separator), var(--shadow);
  transition: box-shadow var(--medium) var(--ease);
}
.composer:focus-within { box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent), 0 0 0 5px color-mix(in srgb, var(--accent) 10%, transparent), var(--shadow); }
.composer-top { display: flex; align-items: center; gap: 8px; }
.prompt-tabs { width: auto; }
.prompt-tabs:not(:has(> button:not([hidden]) ~ button:not([hidden]))) { display: none; }
.prompt-tabs > button { padding: 0 14px; min-height: 28px; font-size: 12px; }
.status-chip { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; min-height: 26px; padding: 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 500; }
.status-chip svg { width: 13px; height: 13px; }
button.status-chip { background: var(--fill-2); color: var(--label-2); }
button.status-chip[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-text); }
.prompt-editor-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.composer > textarea {
  min-height: 68px; max-height: 32vh; padding: 6px 4px !important; border: 0 !important; background: transparent !important; box-shadow: none !important;
  font-size: 16px !important; line-height: 1.6 !important; resize: none; field-sizing: content;
}
.composer > textarea::placeholder { color: var(--label-4); }
.prompt-editor-hint { font-size: 12px; color: var(--label-3); padding: 0 4px; }
#raw-notice { font-size: 12px; color: var(--orange); padding: 0 4px; }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; }
.composer-meta { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.generation-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.generate-button { min-height: 42px; padding: 0 8px 0 18px; gap: 8px; font-size: 15px; }
.generate-button svg { width: 18px; height: 18px; }
button.generate-button.needs-credits, button.generate-button.needs-credits:hover:not(:disabled), button.generate-button.needs-credits:active:not(:disabled) { background: var(--fill); color: var(--label); box-shadow: none; }
.generate-button.needs-credits .price { background: rgba(255,149,0,.16); color: #c93400; }
@media (prefers-color-scheme: dark) { .generate-button.needs-credits .price { color: #ffb340; } }
.generate-button .price { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: rgba(255,255,255,.2); gap: 3px; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
#discuss-first { min-height: 42px; }
#mobile-quick-settings { display: grid; gap: 10px; margin-top: 4px; }

/* ---------- discussion ---------- */
.chat-panel { grid-area: chat; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--separator); }
.chat-panel .panel-heading { padding-right: 8px; }
.conversation-toolbar { padding: 0 16px 10px; flex: none; }
.conversation-toolbar select { min-height: 34px; font-size: 13px; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.chat-empty { margin: auto 0; padding: 24px 8px; text-align: center; color: var(--label-2); }
.chat-empty strong { display: block; margin-bottom: 6px; font-size: 15px; color: var(--label); }
.chat-empty p { font-size: 13px; line-height: 1.65; }
.message { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 92%; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message-author { font-size: 11px; color: var(--label-3); padding: 0 6px; }
.message.user .message-author, .message:not(.user) + .message:not(.user) .message-author { display: none; }
.message:not(.user) p { border-bottom-left-radius: 6px; }
.message p { padding: 9px 13px; border-radius: 18px; background: var(--fill-2); font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user p { background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.message.assistant p { border-bottom-left-radius: 6px; }
.message .library-item { width: 140px; }
.pending-message p { opacity: .75; }
.typing-message, .pending-message { animation: tile-in 260ms var(--ease-out) both; }
.message p.typing-dots { display: flex; gap: 4px; align-items: center; height: 38px; padding: 0 14px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--label-3); animation: typing 1.2s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.message-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 2px 2px 0; }
#chat-form { flex: none; display: grid; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--separator); }
#chat-attachments { display: flex; gap: 8px; flex-wrap: wrap; }
#chat-attachments:empty { display: none; }
.chat-attachment { position: relative; width: 56px; height: 56px; }
.chat-attachment img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.chat-attachment button { position: absolute; top: -6px; right: -6px; width: 22px; min-width: 22px; min-height: 22px; padding: 0; border-radius: 50%; background: var(--label); color: var(--bg); font-size: 14px; line-height: 1; box-shadow: 0 0 0 2px var(--surface); }
.chat-compose { display: flex; align-items: flex-end; gap: 4px; padding: 4px; border-radius: 22px; background: var(--fill-2); transition: box-shadow var(--fast) var(--ease), background-color var(--fast) var(--ease); }
.chat-compose:focus-within { background: var(--surface); box-shadow: 0 0 0 1px var(--accent), var(--ring); }
.chat-compose textarea { flex: 1; min-height: 34px !important; max-height: 180px; padding: 7px 4px !important; border: 0 !important; background: transparent !important; box-shadow: none !important; resize: none; font-size: 14px; }
.chat-compose .icon-button { width: 34px; min-width: 34px; min-height: 34px; }
.send-button { width: 34px; min-width: 34px; min-height: 34px; padding: 0; border-radius: 50%; background: var(--accent); color: #fff; }
.send-button:hover:not(:disabled) { background: var(--accent-hover); }
.send-button svg { width: 18px; height: 18px; stroke-width: 2.4; }
#chat-form.is-sending .send-button svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#chat-form .field-note { padding: 0 6px; }
#chat-attachments:empty + #chat-image-note { display: none; }
#open-chat[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- gallery ---------- */
#library-view { overflow-y: auto; padding: 32px clamp(16px, 4vw, 48px) 48px; }
.library-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; max-width: 1480px; margin: 0 auto 20px; flex-wrap: wrap; }
.library-heading h1 { font-size: 34px; }
.library-heading p { margin-top: 4px; color: var(--label-2); font-size: 14px; }
#library-count { font-variant-numeric: tabular-nums; color: var(--label); font-weight: 600; }
#library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; max-width: 1480px; margin: 0 auto; }
#gallery-empty { max-width: 1480px; margin: 12vh auto 64px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--label-2); font-size: 14px; }
#gallery-empty[hidden] { display: none; }
#gallery-empty strong { color: var(--label); font-size: 21px; font-weight: 600; letter-spacing: -.01em; }
#gallery-empty .empty-glyph { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 8px; border-radius: 18px; background: var(--accent-soft); color: var(--accent-text); }
#gallery-empty .empty-glyph svg { width: 30px; height: 30px; }
#gallery-empty button { margin-top: 14px; min-height: 40px; padding: 0 22px; }
#load-more-images { display: flex; margin: 28px auto 0; }
.gallery-selection { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.gallery-selection:not(.is-selecting) .gallery-selection-summary { display: none; }
.gallery-selection-summary { display: flex; flex-direction: column; margin-right: 8px; }
#gallery-selected { font-size: 14px; font-weight: 600; }
#gallery-selection-help { font-size: 12px; color: var(--label-3); }
#gallery-selection-help:empty { display: none; }
.gallery-selection-controls, .gallery-selection-actions { display: flex; align-items: center; gap: 8px; }
.gallery-selection button { min-height: 34px; border-radius: 999px; padding: 0 14px; font-size: 13px; }
.gallery-selection button svg { width: 16px; height: 16px; }
.gallery-selection.is-selecting #gallery-select { background: var(--accent); color: #fff; }
#gallery-delete:not(:disabled) { color: var(--red); }
.library-item { position: relative; border-radius: 12px; overflow: hidden; background: var(--fill-2); isolation: isolate; animation: tile-in 420ms var(--ease-out) both; }
@keyframes tile-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.open-library-image { display: block; width: 100%; aspect-ratio: 1; min-height: 0; padding: 0; border-radius: 0; background: transparent; }
.open-library-image:hover:not(:disabled) { background: transparent; }
.open-library-image:active:not(:disabled) { transform: none; }
.open-library-image img { transition: transform 500ms var(--ease-out); }
.library-item:hover .open-library-image img { transform: scale(1.03); }
.library-caption { position: static; display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; align-items: center; gap: 4px; padding: 8px; background: var(--surface); color: var(--label); }
.library-caption small { grid-column: 1 / -1; min-width: 0; display: flex; justify-content: space-between; gap: 4px; color: var(--label-2); font-size: 12px; line-height: 1.4; }
.library-caption .image-dimensions { font-size: 11px; font-variant-numeric: tabular-nums; }
.library-caption button { width: 44px; min-width: 44px; min-height: 44px; padding: 0; border-radius: 10px; background: var(--fill-2); color: var(--label-2); }
.library-caption .save-picture { grid-column: 2; }
.library-caption .delete-picture { grid-column: 3; }
.library-caption .reuse-picture { grid-column: 1 / -1; width: 100%; color: var(--accent-text); background: var(--accent-soft); font-size: 13px; }
.library-caption button:hover:not(:disabled) { background: var(--fill); }
.library-caption button svg { width: 18px; height: 18px; }
.library-caption .favorite-picture { position: absolute; top: 8px; right: 8px; z-index: 3; border-radius: 50%; color: #fff; background: rgba(0,0,0,.55); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.favorite-picture[aria-pressed="true"] svg { fill: currentColor; }
.library-caption .favorite-picture[aria-pressed="true"] { color: #ffb2bf; background: rgba(35,8,14,.8); }
#gallery-filters { max-width: 1480px; margin: 0 auto 18px; }
.gallery-filter-scope { display: inline-flex; gap: 4px; padding: 3px; border-radius: 999px; background: var(--fill); margin-bottom: 12px; }
.gallery-filter-scope button { min-height: 44px; padding: 0 18px; border-radius: 999px; background: transparent; font-size: 14px; }
.gallery-filter-scope button[aria-pressed="true"] { background: var(--surface-raised); color: var(--label); box-shadow: var(--shadow-sm); }
.gallery-filter-scope svg { width: 17px; height: 17px; }
.gallery-search-form { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.gallery-search-form button, .gallery-date-filter summary { min-height: 44px; font-size: 14px; }
.gallery-keyword { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; min-width: 0; border: 1px solid var(--separator); border-radius: 12px; padding-left: 12px; background: var(--surface); }
.gallery-keyword svg { flex: 0 0 18px; width: 18px; height: 18px; color: var(--label-2); }
.gallery-keyword input { min-height: 44px; min-width: 0; width: 100%; border: 0; background: transparent; border-radius: 12px; }
.gallery-keyword:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.gallery-date-filter summary { display: flex; align-items: center; padding: 0 14px; border-radius: 999px; color: var(--label-2); background: var(--fill); cursor: pointer; list-style: none; }
.gallery-date-filter summary::-webkit-details-marker { display: none; }
.gallery-date-filter[open] { flex-basis: 100%; order: 3; }
.gallery-date-filter[open] summary { width: fit-content; background: var(--accent-soft); color: var(--accent-text); }
.gallery-date-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; align-items: end; gap: 12px; max-width: 600px; margin-top: 12px; }
.gallery-date-fields label { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 13px; color: var(--label-2); }
.gallery-date-fields input { min-width: 0; width: 100%; min-height: 44px; }
.gallery-save-note, .gallery-filter-status { font-size: 12px; color: var(--label-2); line-height: 1.6; margin-top: 10px; }
.gallery-filter-status:empty { display: none; }
.local-badge { position: absolute; top: 8px; left: 8px; z-index: 2; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.5); color: #fff; font-size: 11px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); pointer-events: none; }
.selecting .library-caption { opacity: .4; pointer-events: none; }
.selecting .favorite-picture { display: none; }
.image-select { position: absolute; top: 8px; right: 8px; z-index: 3; display: none; cursor: pointer; }
.selecting .image-select { display: block; }
.image-select input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.image-select-mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid #fff; background: rgba(0,0,0,.18); box-shadow: 0 1px 4px rgba(0,0,0,.25); transition: background-color var(--fast) var(--ease), transform var(--fast) var(--spring); }
.image-select-mark svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.image-select input:checked + .image-select-mark { background: var(--accent); border-color: #fff; transform: scale(1.06); }
.image-select input:checked + .image-select-mark svg { opacity: 1; }
.image-select input:focus-visible + .image-select-mark { box-shadow: var(--ring); }
.library-item.selected .open-library-image { opacity: .72; }
.library-item.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.selecting .open-library-image { cursor: pointer; }

/* ---------- dialogs: task history, details, guides, auth ---------- */
.task-list { margin: 0 -4px; border-radius: 14px; background: var(--fill-2); overflow: hidden; }
.task-history-row { position: relative; display: grid; grid-template-columns: 44px minmax(0,1fr) auto; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 12px 10px 12px; border-radius: 0; background: transparent; text-align: left; white-space: normal; font-weight: 400; color: var(--label); }
.task-history-row + .task-history-row::before { content: ''; position: absolute; top: 0; left: 68px; right: 0; border-top: .5px solid var(--separator); }
.task-history-row:hover:not(:disabled) { background: var(--fill); }
.task-thumb { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; overflow: hidden; background: var(--fill); color: var(--label-3); }
.task-thumb svg { width: 18px; height: 18px; }
.task-thumb[data-status=running] svg { animation: spin 1.2s linear infinite; }
@media (prefers-reduced-motion: reduce) { .task-thumb[data-status=running] svg { animation: none; } }
.task-thumb[data-status=failed] { color: var(--red); } .task-thumb[data-status=running], .task-thumb[data-status=queued] { color: var(--accent); }
.task-thumb .media-preview { display: block; width: 100%; height: 100%; }
.task-thumb .media-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.task-thumb .media-loading { font-size: 0; }
.task-text { display: grid; gap: 4px; min-width: 0; }
.task-prompt { font-size: 14px; line-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.task-meta .job-status { font-size: 11px; padding: 1px 7px; }
.task-chevron { width: 16px; height: 16px; color: var(--label-3); }
.job-summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--label-2); }
.job-summary time { font-variant-numeric: tabular-nums; color: var(--label-3); }
.job-summary .mini-button { margin-left: auto; }
.job-status { padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; font-size: 12px; }
.job-status[data-status=done] { background: var(--green-soft); color: var(--green); }
.job-status:is([data-status=failed], [data-status=unknown]) { background: var(--red-soft); color: var(--red); }
.job-status[data-status=cancelled] { background: var(--fill); color: var(--label-2); }
.job-error { padding: 10px 14px; border-radius: 12px; background: var(--red-soft); color: var(--red); font-size: 13px; line-height: 1.6; }
.job-error small { display: block; margin-top: 2px; color: var(--label-2); font-size: 12px; }
.task-date, .task-size-note { color: var(--label-3); font-size: 12px; }
#job-images { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
#job-images:empty { display: none; }
/* Task details: keep save/delete visible so touch users are never left guessing. */
#job-images .library-caption { display: grid; }
.job-prompt { display: grid; gap: 8px; padding-top: 8px; }
.job-prompt h3 { font-size: 13px; color: var(--label-2); font-weight: 600; margin-top: 8px; }
.job-prompt summary { cursor: pointer; color: var(--accent-text); font-size: 13px; padding: 6px 0; }
.job-prompt details[open] { display: grid; gap: 8px; }
.prompt-preview { padding: 12px 14px; border-radius: 12px; background: var(--fill-2); font-family: var(--font); font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto; }
#reuse-job-prompt { justify-self: start; }
#reuse-job-settings, #reuse-job-prompt { min-height: 44px; }
.model-guide-row, .info-list section { padding: 14px 0; border-top: 1px solid var(--separator); margin: 0 !important; }
.model-guide-row:first-child, .info-list section:first-child { border-top: 0; padding-top: 4px; }
.model-guide-row h3, .info-list h3 { margin-bottom: 6px; }
.model-guide-row p, .info-list p { color: var(--label-2); line-height: 1.7; white-space: pre-wrap; }
#auth-form { display: grid; gap: 14px; }
.auth-identity { display: grid; justify-items: center; gap: 4px; padding: 4px 0 10px; text-align: center; }
.auth-identity img { width: 60px; height: 60px; border-radius: 15px; margin-bottom: 8px; box-shadow: 0 0 0 .5px var(--separator), 0 6px 18px rgba(0,0,0,.14); }
.auth-identity strong { font-family: var(--font-display); font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.auth-identity span { color: var(--label-2); font-size: 14px; }
#auth-form > .primary { min-height: 46px; font-size: 16px; margin-top: 4px; }
#auth-form .dialog-field > span, #auth-form .dialog-field > label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 500; color: var(--label-2); }
#auth-form .dialog-field small { font-size: 12px; font-weight: 400; color: var(--label-3); }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; letter-spacing: .12em; font-variant-numeric: tabular-nums; }
.code-row input::placeholder { letter-spacing: 0; }
.code-row > button { flex: none; min-width: 112px; min-height: 40px; padding: 0 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-size: 13px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.code-row > button:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.code-row > button:disabled { background: var(--fill-2); color: var(--label-3); opacity: 1; }
#auth-form + .dialog-actions { justify-content: center; gap: 4px; margin-top: 12px; }
#auth-form + .dialog-actions button { background: transparent; color: var(--accent-text); min-height: 32px; font-size: 13px; }
#auth-form + .dialog-actions button:hover:not(:disabled) { background: var(--accent-soft); }
@media (min-width: 761px) { #dialog:has(#auth-form) { width: min(420px, calc(100vw - 32px)); } }
#dialog:has(#auth-form) .dialog-heading h2 { visibility: hidden; }
/* The account center keeps one height so switching tabs never makes the window jump. */
#dialog:has(.member-center) { height: min(800px, calc(100dvh - 64px)); }
@media (max-width: 760px) { #dialog:has(.member-center) { height: 90dvh; } }

/* ---------- account center ---------- */
.member-center { display: grid; }
.member-center input:not([type=hidden]):not([type=checkbox]) { min-height: 44px; }
.member-center .primary { min-height: 44px; }
.member-identity { position: relative; display: flex; align-items: center; gap: 14px; padding: 4px 0 20px; min-width: 0; }
.member-avatar { width: 52px; height: 52px; display: grid; place-items: center; flex: none; border-radius: 50%; background: linear-gradient(135deg, #5e9cff, #8f6bff); color: #fff; font-size: 22px; font-weight: 700; }
.member-identity > div:nth-child(2) { flex: 1; min-width: 0; }
.member-identity strong { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.member-identity span { display: block; margin-top: 2px; font-size: 13px; color: var(--label-2); overflow-wrap: anywhere; }
.member-identity .member-role { display: inline-block; margin: 0; padding: 1px 8px; border-radius: 999px; background: var(--fill); color: var(--label-2); font-size: 11px; font-weight: 600; }
.member-edit-profile { width: 34px; min-width: 34px; min-height: 34px; padding: 0; border-radius: 50%; background: var(--fill-2); color: var(--label-2); }
.member-edit-profile svg { width: 15px; height: 15px; }
.member-admin-link { display: inline-flex; align-items: center; gap: 5px; min-height: 34px; padding: 0 12px; border-radius: 999px; background: var(--fill-2); color: var(--label); font-size: 13px; font-weight: 500; text-decoration: none !important; }
.member-admin-link:hover { background: var(--fill); }
.member-admin-link svg { width: 15px; height: 15px; }
.member-identity .member-joined { display: block; margin-top: 1px; white-space: nowrap; font-size: 12px; color: var(--label-3); }
.member-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill); }
.member-tabs button { min-width: 0; min-height: 32px; padding: 0 6px; border-radius: 7px; background: transparent; color: var(--label); font-size: 13px; gap: 5px; }
.member-tabs button:hover:not(:disabled) { background: transparent; opacity: .72; }
.member-tabs button:active:not(:disabled) { transform: none; }
.member-tabs button[aria-selected=true] { background: var(--surface-raised); box-shadow: 0 3px 8px rgba(0,0,0,.08), 0 0 0 .5px rgba(0,0,0,.04); font-weight: 600; opacity: 1; }
.member-tabs svg { width: 15px; height: 15px; }
#account-panel { min-height: 300px; }
.member-panel-enter { animation: reveal var(--medium) var(--ease-out); }
.member-credit-summary { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 16px 24px; margin-top: 20px; padding: 22px; border-radius: var(--radius-lg); background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, var(--surface)), color-mix(in srgb, var(--purple) 8%, var(--surface))); }
.member-credit-main > span { font-size: 13px; color: var(--label-2); font-weight: 500; }
.member-credit-main > strong { display: block; margin-top: 4px; font-family: var(--font-display); font-size: 40px; font-weight: 700; line-height: 1.05; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.member-credit-summary dl { display: grid; gap: 6px; min-width: 150px; }
.member-credit-summary dl > div { display: flex; justify-content: space-between; gap: 20px; font-size: 13px; }
.member-credit-summary dt { color: var(--label-2); }
.member-credit-summary dd { font-weight: 600; font-variant-numeric: tabular-nums; }
.member-balance-note { flex-basis: 100%; font-size: 12px; line-height: 1.6; color: var(--label-2); }
.member-section { padding: 22px 0; border-top: 1px solid var(--separator); }
.member-credit-summary + .member-section { border-top: 0; }
.member-section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.member-section h3, .member-section-title h3 { font-size: 16px; font-weight: 650; }
.member-section-title > span { font-size: 12px; color: var(--label-3); }
.member-buy-points { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: 0; max-width: 65%; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none !important; transition: background-color var(--fast) var(--ease); }
.member-buy-points:hover { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.member-buy-points span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.member-buy-points svg { width: 16px; height: 16px; flex: none; }
.member-buy-points svg:last-child { width: 14px; height: 14px; }
.member-purchase-note { margin: -4px 0 14px; color: var(--label-2); font-size: 13px; line-height: 1.6; }
.member-redeem-note { margin-top: 10px; color: var(--label-3); font-size: 12px; line-height: 1.6; }
.member-label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 500; color: var(--label-2); }
.member-redeem .member-label { margin-top: 0; }
.member-redeem-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.member-code-input { display: flex; align-items: center; min-height: 44px; border-radius: var(--radius-sm); background: var(--fill-2); border: 1px solid transparent; transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background-color var(--fast) var(--ease); }
.member-code-input:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: var(--ring); }
.member-center .member-code-input input { flex: 1; min-width: 0; border: 0 !important; background: transparent !important; box-shadow: none !important; font-family: var(--mono); font-size: 14px; }
.member-code-input button { margin-right: 4px; min-height: 34px; padding: 0 10px; border-radius: 8px; background: transparent; color: var(--accent-text); font-size: 13px; gap: 4px; }
.member-code-input button:hover:not(:disabled) { background: var(--accent-soft); }
.member-code-input button svg { width: 15px; height: 15px; }
#redeem-confirm[aria-busy=true] svg { animation: spin 1s linear infinite; }
.member-message { margin-top: 10px; font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
.member-message.error { color: var(--red); }
.member-message.success { color: var(--green); }
.member-stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.member-stat-row > div { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius); background: var(--fill-2); min-width: 0; }
.member-stat-row strong { font-family: var(--font-display); font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.member-stat-row span { font-size: 12px; color: var(--label-2); }
.member-total-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.member-total-row > div { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius); background: var(--fill-2); }
.member-total-row > div > span { font-size: 12px; color: var(--label-2); }
.member-total-row strong { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.member-total-row strong small { margin-left: 2px; font-size: 12px; font-weight: 400; color: var(--label-3); letter-spacing: 0; }
.member-link { min-height: 28px; padding: 0 6px; border-radius: 999px; background: transparent; color: var(--accent-text); font-size: 13px; gap: 2px; }
.member-link:hover:not(:disabled) { background: var(--accent-soft); }
.member-link svg { width: 14px; height: 14px; }
.member-footnote { display: flex; gap: 8px; align-items: flex-start; padding-top: 16px; border-top: 1px solid var(--separator); color: var(--label-3); font-size: 12px; line-height: 1.6; }
.member-footnote svg { width: 15px; height: 15px; margin-top: 2px; }
.member-record-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 20px 0 12px; }
.member-record-kind { display: grid; grid-auto-flow: column; gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill); }
.member-record-kind button { min-height: 28px; padding: 0 14px; border-radius: 7px; background: transparent; font-size: 13px; }
.member-record-kind button:hover:not(:disabled) { background: transparent; opacity: .72; }
.member-record-kind button[aria-pressed=true] { background: var(--surface-raised); box-shadow: 0 3px 8px rgba(0,0,0,.08); font-weight: 600; opacity: 1; }
.member-record-filter select, .member-pagination select { width: auto; min-height: 32px; padding: 4px 30px 4px 10px; font-size: 13px; background-position: right 10px center; }
.member-record-list { border-radius: var(--radius); background: var(--fill-2); padding: 0 14px; }
.member-record { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--separator); }
.member-record:last-child { border-bottom: 0; }
.member-record-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--fill); color: var(--label-2); flex: none; }
.member-record-icon svg { width: 16px; height: 16px; }
.member-record-icon.income { background: var(--green-soft); color: var(--green); }
.member-record > div { flex: 1; min-width: 0; }
.member-record strong { display: block; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.member-record time { display: block; margin-top: 2px; font-size: 12px; color: var(--label-3); }
.member-record > b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.member-record > b.income { color: var(--green); }
.member-record-note { margin: 12px 0 4px !important; }
.member-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 0 0; color: var(--label-3); font-size: 12px; }
.member-pagination > span:first-child { margin-right: auto; }
.member-pagination button { width: 32px; min-width: 32px; min-height: 32px; padding: 0; border-radius: 50%; }
.member-empty, .member-loading, .member-load-error { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 180px; padding: 20px; color: var(--label-3); text-align: center; font-size: 14px; line-height: 1.6; }
.member-empty > svg, .member-load-error > svg { width: 30px; height: 30px; color: var(--label-4); }
.member-secondary { border-radius: 999px; min-height: 36px; padding: 0 16px; }
.member-security-section { border-top: 0; padding-top: 22px; }
.member-profile-section { border-top: 0 !important; padding-top: 20px !important; }
.member-form-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.member-description { font-size: 13px; color: var(--label-2); line-height: 1.7; margin: 0 0 14px; }
.member-signout { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 14px; }
.member-signout > div { flex: 1; min-width: 160px; }
.member-signout h3 { margin-bottom: 4px; }
.member-signout p.member-description { margin: 0; }
.member-signout > .member-message { width: 100%; }
#sign-out { color: var(--red); border-radius: 999px; }
.member-inline-form { display: flex; gap: 8px; align-items: stretch; }
.member-inline-form input { flex: 1; }
.member-inline-form button { flex: none; min-height: 44px; border-radius: 999px; padding: 0 18px; }
.member-device-list { display: grid; gap: 0; margin: 4px 0 12px; border-radius: var(--radius); background: var(--fill-2); padding: 0 14px; }
.member-device { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--separator); animation: reveal var(--medium) var(--ease-out) both; }
.member-device:last-child { border-bottom: 0; }
.member-device-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--surface); color: var(--label-2); box-shadow: var(--shadow-sm); }
.member-device.current .member-device-icon { background: var(--accent); color: #fff; }
.member-device-icon svg { width: 18px; height: 18px; }
.member-device > div { flex: 1; min-width: 0; }
.member-device strong { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; }
.member-device > div > span, .member-device > div > small { display: block; margin-top: 2px; font-size: 12px; color: var(--label-2); overflow-wrap: anywhere; }
.member-device > div > small { color: var(--label-3); }
.member-device-badge { padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 11px; font-weight: 600; }
.member-device-revoke { min-height: 30px; padding: 0 12px; border-radius: 999px; background: transparent; color: var(--red); font-size: 13px; }
.member-device-revoke:hover:not(:disabled) { background: var(--red-soft); }
.member-device-revoke.confirming { background: var(--red); color: #fff; }
.member-security-log { display: grid; border-radius: var(--radius); background: var(--fill-2); padding: 0 14px; }
.member-log-row { display: grid; grid-template-columns: 8px 1fr auto; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--separator); }
.member-log-row:last-child { border-bottom: 0; }
.member-log-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.member-log-row.failed .member-log-dot { background: var(--red); }
.member-log-row strong { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; }
.member-log-row strong b { padding: 0 6px; border-radius: 999px; background: var(--red-soft); color: var(--red); font-size: 11px; }
.member-log-row > div > span { display: block; margin-top: 1px; font-size: 12px; color: var(--label-3); overflow-wrap: anywhere; }
.member-log-row time { font-size: 12px; color: var(--label-3); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- mobile parameter sheet ---------- */
#parameter-dialog { width: 100vw; max-width: 100vw; height: 92dvh; max-height: 92dvh; margin: auto 0 0; padding: 0; border: 0; border-radius: 22px 22px 0 0; background: var(--surface); box-shadow: var(--shadow-lg); overflow: hidden; }
#parameter-dialog { transform: translateY(100%); transition: transform 240ms cubic-bezier(.4, 0, 1, 1), overlay 240ms allow-discrete, display 240ms allow-discrete; }
#parameter-dialog[open] { display: flex; flex-direction: column; transform: none; transition-duration: 380ms; transition-timing-function: var(--ease-out); }
@starting-style { #parameter-dialog[open] { transform: translateY(100%); } }
#parameter-dialog::backdrop { opacity: 0; transition: opacity 240ms var(--ease), overlay 240ms allow-discrete, display 240ms allow-discrete; }
#parameter-dialog[open]::backdrop { opacity: 1; }
@starting-style { #parameter-dialog[open]::backdrop { opacity: 0; } }
#parameter-dialog .inspector { flex: 1; min-height: 0; border: 0; display: flex; }
#parameter-dialog .inspector .inspector-toggle { display: inline-flex; }
#parameter-dialog .inspector-footer { display: none; }
.parameter-dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--separator); background: var(--material-thick); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); }
#parameter-summary { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }

/* ---------- tablet ---------- */
@media (max-width: 1100px) and (min-width: 761px) {
  .workspace, body.chat-collapsed .workspace { grid-template-columns: 280px minmax(0, 1fr); grid-template-areas: "inspector canvas" "inspector composer"; }
  .chat-panel { position: fixed; top: 52px; right: 0; bottom: 0; z-index: 25; width: min(380px, 90vw); box-shadow: var(--shadow-lg); animation: drawer-in var(--medium) var(--ease-out); }
  @keyframes drawer-in { from { transform: translateX(100%); } to { transform: none; } }
  .composer { width: calc(100% - 32px); margin-bottom: 16px; }
  .canvas-area { padding: 14px 16px 10px; }
  .family-switch button { grid-template-columns: 1fr; }
  .family-switch button svg { display: none; }
  .inline-tools .mini-button span { display: none; }
  .inline-tools .mini-button { width: 28px; padding: 0; }
}

/* ---------- phone ---------- */
@media (max-width: 760px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .app-header { grid-template-columns: 1fr auto; height: 48px; padding: 0 10px 0 14px; gap: 8px; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
  /* The blur lives on a pseudo-element so the fixed bottom tab bar inside the header keeps the viewport as its containing block. */
  .app-header::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--material); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); pointer-events: none; }
  /* A filtered ancestor would become the containing block of the fixed tab bar. */
  .brand img { width: 28px; height: 28px; }
  .brand strong { font-size: 16px; }
  .primary-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: 1fr 1fr; gap: 0; padding: 4px 24px env(safe-area-inset-bottom);
    border-radius: 0; background: var(--material); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border-top: 1px solid var(--separator);
  }
  .primary-nav button { flex-direction: column; gap: 2px; min-height: 54px; padding: 4px 0; font-size: 10px; font-weight: 500; color: var(--label-3); background: transparent !important; box-shadow: none !important; }
  .primary-nav button svg { width: 24px; height: 24px; stroke-width: 1.7; }
  .primary-nav button.nav-active { color: var(--accent); font-weight: 600; }
  .primary-nav.has-pill::before { display: none; }
  .header-tools { gap: 2px; }
  .credit-pill { min-height: 30px; padding: 0 10px 0 8px; font-size: 12px; }
  .credit-pill .unit { display: none; }
  .signed-in .account-button { padding: 0; background: transparent; }
  .signed-in .account-button .account-label { display: none; }
  .signed-in .account-button .avatar { width: 30px; height: 30px; }
  .account-button { min-height: 30px; padding: 0 14px; }

  .workspace { display: flex; flex-direction: column; gap: 12px; padding: 12px 12px 16px; }
  .workspace > .inspector { display: none; }
  #mobile-model-host { order: 1; }
  #mobile-model-host .model-section { padding: 14px; border: 0; border-radius: var(--radius-lg); background: var(--surface); box-shadow: 0 0 0 .5px var(--separator); }
  #mobile-model-host .field-label[for=model] { display: none; }
  .composer { order: 2; width: 100%; margin: 0; padding: 12px; border-radius: var(--radius-lg); }
  .canvas-area { order: 3; padding: 4px 0 0; overflow: visible; }
  .chat-panel { order: 4; border: 0; border-radius: var(--radius-lg); box-shadow: 0 0 0 .5px var(--separator); overflow: hidden; }
  body.chat-collapsed .chat-panel { display: flex; }
  #close-chat, #open-chat { display: none !important; }
  .chat-messages { max-height: 60dvh; min-height: 120px; overscroll-behavior-y: auto; }
  .art-stage { flex: none; min-height: 0; }
  .art-wrap { position: relative; inset: auto; min-height: 240px; display: grid; place-items: center; }
  #main-image { position: static; max-height: 70dvh; width: auto; }
  #main-image:not([hidden]) + #empty-canvas { display: none; }
  #empty-canvas { position: static; padding: 36px 16px; }
  .canvas-area:has(#main-image[hidden]) .art-stage { display: none; }
  .canvas-area:has(#main-image[hidden]):not(:has(.generation-status:not([hidden]))) { display: none; }
  .image-tools { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .image-tools .tool-button:not(:has(span)) { width: 34px; padding: 0; }
  .image-tools .tool-button:has(span) { padding: 0 10px; }
  .family-switch button { min-height: 54px; padding: 8px 10px; }
  .composer > textarea { min-height: 96px; }
  .canvas-area { scroll-margin-top: 60px; }
  body:not(:has(dialog[open])) #toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .composer-bottom { flex-direction: column; align-items: stretch; gap: 8px; }
  /* The generate action rides above the tab bar while the composer is on screen, then settles into place. */
  .composer-bottom { position: sticky; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 6; margin: 0 -12px -12px; padding: 14px 12px 12px; border-radius: 0 0 var(--radius-lg) var(--radius-lg); background: linear-gradient(to bottom, transparent, var(--surface) 14px); }
  .composer-meta { text-align: center; }
  .generation-actions { width: 100%; }
  .generation-actions > button { flex: 1; }
  button.generate-button { min-height: 50px; justify-content: center; padding: 0 10px; font-size: 16px; }
  #mobile-quick-settings { padding: 12px; border-radius: var(--radius); background: var(--fill-2); }
  #mobile-quick-settings .settings-section { padding: 0; border: 0; }
  #mobile-quick-settings .settings-section + .settings-section { margin-top: 4px; padding-top: 14px; border-top: 1px solid var(--separator); }
  #mobile-quick-settings select { background-color: var(--surface); }
  #mobile-quick-settings .ratios button, #mobile-quick-settings .stepper { background: var(--surface); }
  #mobile-quick-settings .ratios button[aria-pressed=true] { background: var(--accent-soft); }
  #mobile-quick-settings #resolution-hint { display: none; }
  #mobile-quick-settings #resolution-hint.nai-resolution-hint:not([hidden]) { display: block; }
  #mobile-quick-settings .inline-tools .mini-button { background: var(--surface); }
  .quick-settings-heading { display: flex; align-items: center; justify-content: space-between; }
  .quick-settings-heading strong { font-size: 14px; }
  #mobile-settings { min-height: 30px; padding: 0 6px 0 10px; border-radius: 999px; background: transparent; color: var(--accent-text); font-size: 13px; gap: 2px; }
  #mobile-settings svg { width: 16px; height: 16px; }
  #parameter-mode-host { padding: 0 0 8px; }

  #library-view { padding: 20px 4px 24px; }
  .library-heading { padding: 0 12px; margin-bottom: 14px; align-items: center; }
  .library-heading h1 { font-size: 30px; }
  #library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 12px; }
  #gallery-filters { margin: 0 12px 18px; }
  .gallery-keyword { flex-basis: 160px; }
  .gallery-date-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .gallery-date-fields button { grid-column: 1 / -1; }
  .library-item { border-radius: 0; }
  .gallery-selection button { min-height: 32px; padding: 0 12px; }
  .gallery-selection.is-selecting { position: fixed; left: 12px; right: 12px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 35; justify-content: space-between; padding: 8px 8px 8px 16px; border-radius: 999px; background: var(--material-thick); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); box-shadow: var(--shadow-lg); }
  .gallery-selection.is-selecting #gallery-selection-help, .gallery-selection.is-selecting #gallery-select-all { display: none; }
  .gallery-selection.is-selecting .gallery-selection-controls { order: 3; }
  .gallery-selection.is-selecting { flex-wrap: nowrap; gap: 6px; }
  .gallery-selection.is-selecting .gallery-selection-summary { margin-right: auto; min-width: 0; }
  .gallery-selection.is-selecting #gallery-selected { white-space: nowrap; font-size: 14px; }
  .gallery-selection.is-selecting .gallery-selection-actions { gap: 6px; }
  .gallery-selection.is-selecting button { padding: 0 11px; gap: 4px; }
  .member-tabs button { flex-direction: column; gap: 2px; min-height: 48px; font-size: 11px; }
  .member-redeem-row { grid-template-columns: 1fr; }
  .member-credit-main > strong { font-size: 34px; }
  .member-stat-row > div, .member-total-row > div { padding: 12px; }
  .member-stat-row strong { font-size: 20px; }
  .member-log-row { grid-template-columns: 8px 1fr; }
  .member-log-row time { grid-column: 2; }
  .member-form-actions .primary { width: 100%; }
  .member-admin-link { width: 34px; padding: 0; justify-content: center; }
  .member-admin-link span { display: none; }
  .member-identity { flex-wrap: nowrap; }
}
@media (hover: none) {
  .library-caption { display: grid; }
}
@media (max-width: 480px) {
  /* Keep the whole toolbar on one screen: universal icons drop their labels, the two feature actions keep theirs. */
  :is(#download-image, #use-as-reference, #inspect-prompt) span { display: none; }
  .image-tools :is(#download-image, #use-as-reference, #inspect-prompt) { width: 36px; padding: 0; }
}

@media(max-width:760px){.generation-actions{min-width:0;align-items:stretch}.generation-actions>button{min-width:0}button.generate-button{flex-wrap:wrap;gap:4px 6px;padding-block:8px}button.generate-button svg{flex:none}button.generate-button .generate-label{flex:1;min-width:64px;white-space:normal;overflow-wrap:anywhere;line-height:1.35}button.generate-button .price{min-width:0;max-width:100%;flex-shrink:1}button.generate-button #price{min-width:0;overflow-wrap:anywhere}}

@media (max-width: 760px) {
  /* Keep general-model actions compact without shrinking mobile touch targets. */
  .general-model .composer-bottom { gap: 6px; padding-top: 10px; padding-bottom: 10px; background: linear-gradient(to bottom, transparent, var(--surface) 10px); }
  .general-model #discuss-first { flex: none; min-height: 44px; padding: 0 12px; gap: 5px; font-size: 13px; }
  .general-model #discuss-first svg { width: 16px; height: 16px; }
  .general-model button.generate-button { min-height: 44px; padding: 6px 10px; font-size: 14px; }
  .general-model button.generate-button > svg { display: none; }
  .general-model button.generate-button .generate-label { flex: 0 1 auto; min-width: 0; }
  .general-model button.generate-button .price { min-height: 24px; padding: 0 7px; font-size: 11px; }
}

@media (max-width: 430px) {
  .library-caption .image-dimensions { display: none; }
  .library-caption small { font-size: 11px; }
  #job-images { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
