:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --bg-elevated: #fbfbfc;
  --surface: #ffffff;
  --surface-soft: #f2f4f6;
  --surface-muted: #eceff2;
  --ink: #0b0d0f;
  --ink-soft: #30363d;
  --muted: #737b84;
  --faint: #a5abb2;
  --line: #e3e6ea;
  --line-strong: #cdd3d9;
  --primary: #050505;
  --primary-ink: #ffffff;
  --accent: #287887;
  --accent-soft: #dff2f4;
  --danger: #b42318;
  --shadow: 0 18px 42px rgba(16, 24, 40, 0.1);
  --shadow-soft: 0 10px 30px rgba(16, 24, 40, 0.07);
  --radius: 8px;
  --pill: 999px;
  --control: 44px;
  --sidebar: 256px;
  --settings: 320px;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315;
  --bg-elevated: #171a1d;
  --surface: #1b1f23;
  --surface-soft: #20252a;
  --surface-muted: #282e34;
  --ink: #f4f6f8;
  --ink-soft: #d8dde2;
  --muted: #a8b0b8;
  --faint: #747e88;
  --line: #2f363d;
  --line-strong: #444c55;
  --primary: #f8fafc;
  --primary-ink: #090b0d;
  --accent: #66bdc8;
  --accent-soft: #19353a;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

img {
  max-width: 100%;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(40, 120, 135, 0.28);
  outline-offset: 2px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.btn,
.tool-pill,
.icon-btn,
.action-pill,
.mini-action,
.upload-chip,
.credit-main,
.nav-pills button,
.tabs button,
.option-grid button,
.workspace-item,
.history-item,
.metric-row button,
.metric-row a {
  min-height: var(--control);
  touch-action: manipulation;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 16px;
  font-weight: 700;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.btn:not([disabled]):active,
.tool-pill:not([disabled]):active,
.icon-btn:not([disabled]):active,
.action-pill:not([disabled]):active,
.mini-action:not([disabled]):active,
.upload-chip:not([disabled]):active,
.credit-main:not([disabled]):active,
.nav-pills button:not([disabled]):active,
.tabs button:not([disabled]):active,
.metric-row button:not([disabled]):active,
.count-control button:not([disabled]):active,
.option-grid button:not([disabled]):active {
  transform: translateY(1px) scale(0.98);
}

.btn-primary,
.btn-dark {
  color: var(--primary-ink);
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover,
.btn-dark:hover {
  background: var(--ink-soft);
  border-color: var(--ink-soft);
}

body[data-theme="dark"] .btn-primary:hover,
body[data-theme="dark"] .btn-dark:hover {
  background: #e5e7eb;
  border-color: #e5e7eb;
}

.btn-secondary {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

.btn.compact {
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--pill);
  font-size: 14px;
}

.btn[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-btn[disabled],
.tool-pill[disabled],
.upload-chip[disabled],
.action-pill[disabled] {
  opacity: 0.5;
}

.icon-btn {
  width: var(--control);
  height: var(--control);
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: var(--pill);
  color: var(--muted);
  background: transparent;
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease;
}

.icon-btn:hover {
  color: var(--ink);
  background: var(--surface-soft);
}

.icon-btn.border {
  border: 1px solid var(--line);
  background: var(--surface);
}

.link-button {
  min-height: 34px;
  border: 0;
  color: var(--faint);
  background: transparent;
  font-size: 13px;
}

.link-button:hover {
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--primary-ink);
  background: var(--primary);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 8px;
}

.field label,
.settings-group > label,
.comment-form label {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field textarea,
.comment-form textarea,
.search-box input,
.custom-size-input {
  width: 100%;
  min-height: var(--control);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
}

.field textarea,
.comment-form textarea {
  resize: vertical;
}

.field-hint {
  color: var(--muted);
  font-size: 13px;
}

.error {
  min-height: 22px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.spinner.small {
  width: 16px;
  height: 16px;
}

.spinner.dark {
  border-color: rgba(11, 13, 15, 0.18);
  border-top-color: var(--ink);
}

body[data-theme="dark"] .spinner.dark {
  border-color: rgba(244, 246, 248, 0.22);
  border-top-color: var(--ink);
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  width: min(420px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: var(--radius);
  color: #fff;
  background: #111315;
  box-shadow: var(--shadow);
}

body[data-theme="dark"] .toast {
  color: #111315;
  background: #f8fafc;
}

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-visual {
  min-height: 560px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 38px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(145deg, rgba(40, 120, 135, 0.12), transparent 40%),
    linear-gradient(315deg, rgba(11, 13, 15, 0.06), transparent 46%),
    var(--bg-elevated);
}

.login-copy .eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-weight: 800;
}

.login-copy h1 {
  max-width: 560px;
  margin: 0 0 16px;
  font-size: 52px;
  line-height: 1.05;
}

.login-copy p {
  max-width: 540px;
  margin: 0;
  color: var(--muted);
}

.login-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-box {
  display: grid;
  gap: 3px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

.stat-box span {
  color: var(--muted);
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 38px;
}

.login-form h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.login-form p {
  margin: -10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface-soft);
}

.auth-switch button {
  min-height: 38px;
  border: 0;
  border-radius: var(--pill);
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.auth-switch button.active {
  color: var(--primary-ink);
  background: var(--primary);
}

.studio-frame {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--settings);
  background: var(--bg);
}

.studio-frame.settings-hidden {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) 0;
}

.studio-sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 12px 12px;
  border-right: 1px solid var(--line);
  background: var(--bg-elevated);
}

.nav-pills {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  box-shadow: var(--shadow-soft);
}

.nav-pills button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: var(--pill);
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.nav-pills button.active {
  color: var(--primary-ink);
  background: var(--primary);
}

.rail-tabs {
  align-self: flex-start;
  margin-bottom: 12px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 18px;
  font-size: 18px;
}

.side-section {
  padding: 12px 8px;
}

.side-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.side-section-head small {
  color: var(--faint);
  font-size: 12px;
  font-weight: 400;
}

.workspace-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
  text-align: left;
}

.drag-dot {
  width: 10px;
  height: 14px;
  flex: 0 0 auto;
  background-image: radial-gradient(currentColor 1px, transparent 1.5px);
  background-size: 5px 5px;
  color: var(--line-strong);
}

.history-section {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.history-empty {
  margin: 22px 0;
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: var(--radius);
  padding: 6px;
  color: var(--ink-soft);
  background: transparent;
  text-align: left;
}

.history-item:hover {
  background: var(--surface);
}

.history-item img {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-muted);
}

.history-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.credit-bar {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  font-size: 13px;
}

.credit-main {
  min-width: 0;
  display: grid;
  gap: 1px;
  border: 0;
  padding: 0;
  text-align: left;
  background: transparent;
}

.credit-main span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.credit-main strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.credit-main:hover strong {
  color: var(--accent);
}

.credit-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.credit-actions .icon-btn {
  width: 34px;
  height: 34px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(9, 11, 13, 0.42);
  backdrop-filter: blur(8px);
}

.modal-panel {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.token-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.studio-main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(420px, 1fr);
  gap: 14px;
  padding: 22px;
}

.workspace-header {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.workspace-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 0 13px;
  color: var(--ink);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  box-shadow: var(--shadow-soft);
  font-size: 14px;
  font-weight: 700;
}

.tool-pill.strong {
  border-color: var(--primary);
}

.prompt-composer {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.composer-top {
  position: relative;
}

.prompt-composer textarea#prompt {
  width: 100%;
  min-height: 118px;
  display: block;
  border: 0;
  resize: vertical;
  padding: 44px 18px 16px;
  color: var(--ink);
  background: transparent;
}

.prompt-composer.expanded textarea#prompt {
  min-height: 260px;
}

.prompt-composer textarea#prompt::placeholder {
  color: var(--faint);
}

.composer-counter {
  position: absolute;
  top: 13px;
  right: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--faint);
  font-size: 13px;
}

.plain-toggle {
  border: 0;
  color: var(--muted);
  background: transparent;
}

.reference-row {
  padding: 0 18px 10px;
}

.upload-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
}

.upload-chip:hover {
  color: var(--ink);
  background: var(--surface-soft);
}

.reference-fields {
  display: grid;
  grid-template-columns: minmax(220px, 0.62fr) minmax(0, 1fr) minmax(220px, 0.42fr);
  gap: 12px;
  padding: 0 18px 14px;
}

.reference-dropzone {
  min-height: 112px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--muted);
  background: var(--surface-soft);
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.reference-dropzone:hover,
.reference-dropzone.is-dragover {
  color: var(--ink);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.reference-dropzone.is-dragover {
  transform: scale(0.99);
}

.dropzone-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.dropzone-copy strong {
  color: var(--ink);
}

.dropzone-copy span:last-child {
  font-size: 12px;
}

.dropzone-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--accent);
  background: var(--surface);
}

.reference-url-field textarea {
  min-height: 112px;
}

.reference-previews {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reference-chip {
  max-width: 260px;
  min-height: 46px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 5px 4px 4px;
  background: var(--surface);
}

.reference-chip img {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-muted);
}

.reference-chip span {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-chip .icon-btn {
  width: 34px;
  height: 34px;
}

.composer-footer {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 10px 20px;
  border-top: 1px solid var(--line);
}

.count-control,
.composer-submit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-control {
  color: var(--muted);
  font-size: 14px;
}

.count-control button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--muted);
  background: var(--surface);
}

.count-control strong {
  color: var(--ink);
  font-size: 18px;
}

.result-canvas {
  min-height: 520px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.result-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.result-empty strong {
  color: var(--ink-soft);
  font-weight: 500;
}

.empty-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--faint);
  background: var(--surface-soft);
}

.empty-icon .icon {
  width: 28px;
  height: 28px;
}

.result-canvas.has-results {
  align-items: start;
  padding: 18px;
}

.result-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.image-button {
  width: 100%;
  display: block;
  padding: 0;
  border: 0;
  background: var(--surface-muted);
  text-align: left;
}

.result-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  object-fit: cover;
}

.result-card-meta {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

.mini-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: var(--pill);
  padding: 0 10px;
  color: var(--ink);
  background: var(--surface-soft);
  font-size: 13px;
}

.settings-panel {
  position: sticky;
  top: 0;
  height: 100dvh;
  min-width: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  transition:
    transform 180ms ease,
    opacity 180ms ease;
}

.settings-hidden .settings-panel {
  pointer-events: none;
  opacity: 0;
  transform: translateX(24px);
}

.settings-head {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.settings-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.settings-body {
  display: grid;
  gap: 20px;
  padding: 20px;
}

.settings-group {
  display: grid;
  gap: 9px;
}

.settings-group p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.model-field {
  min-height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface-soft);
  font-size: 13px;
}

.option-grid {
  display: grid;
  gap: 7px;
}

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

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

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

.option-grid button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
}

.option-grid button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.option-grid button.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--surface-soft);
  font-weight: 800;
}

.custom-size-input {
  min-height: 40px;
}

.gallery-page,
.detail-page {
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(40, 120, 135, 0.08), transparent 22%),
    var(--bg);
}

.gallery-top,
.detail-top {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
}

.notification-button {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.notification-button span {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: var(--pill);
  color: #fff;
  background: #e53935;
  font-size: 11px;
  font-weight: 800;
}

.gallery-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 70px 0 90px;
}

.gallery-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  gap: 42px;
  margin-bottom: 40px;
}

.gallery-hero h1 {
  max-width: 760px;
  margin: 36px 0 0;
  font-size: 64px;
  line-height: 1.15;
}

.submission-card {
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-soft);
}

.submission-card h2 {
  margin: 0;
  font-size: 18px;
}

.submission-card p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.button-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.gallery-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 18px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface);
}

.tabs button {
  border: 0;
  border-radius: var(--pill);
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
}

.tabs button.active {
  color: var(--primary-ink);
  background: var(--primary);
}

.search-box {
  width: min(300px, 100%);
}

.search-box input {
  min-height: 42px;
  border-radius: var(--pill);
}

.masonry-grid {
  column-count: 4;
  column-gap: 18px;
}

.gallery-card {
  display: inline-block;
  width: 100%;
  overflow: hidden;
  margin: 0 0 18px;
  break-inside: avoid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.03);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.gallery-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
}

.gallery-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  object-fit: cover;
}

.gallery-card.tall img {
  aspect-ratio: 4 / 5;
}

.gallery-card-body {
  display: grid;
  gap: 9px;
  padding: 13px 14px 14px;
}

.author-row,
.author-line,
.metric-row,
.detail-actions,
.comment-head,
.card-head,
.reference-summary {
  display: flex;
  align-items: center;
}

.author-row {
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.avatar {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 900;
}

.gallery-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
}

.gallery-card p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.metric-row {
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.metric-row > span,
.metric-row > button,
.metric-row > a {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  border-radius: var(--pill);
  padding: 0 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
}

.metric-row > button:hover,
.metric-row > a:hover,
.action-pill:hover,
.mini-action:hover,
.count-control button:hover {
  color: var(--ink);
  background: var(--surface-muted);
}

.metric-row .icon {
  width: 14px;
  height: 14px;
}

.metric-row button.liked,
.action-pill.liked {
  color: #d92d20;
}

.empty-gallery {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--bg-elevated);
}

.empty-gallery strong {
  color: var(--ink-soft);
}

.detail-shell {
  width: min(1220px, calc(100% - 32px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 24px;
  margin: 0 auto;
  padding: 36px 0 90px;
}

.detail-media,
.detail-info {
  min-width: 0;
}

.detail-image {
  width: 100%;
  max-height: 58dvh;
  display: block;
  object-fit: contain;
  border-radius: var(--radius);
  background: #111315;
  box-shadow: var(--shadow);
}

.detail-actions {
  gap: 8px;
  margin: 12px 0;
}

.action-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  font-weight: 700;
}

.detail-card {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-soft);
}

.card-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.card-head small {
  color: var(--faint);
  font-weight: 500;
}

.prompt-detail p,
.author-detail p {
  margin: 0;
  color: var(--ink-soft);
  white-space: pre-wrap;
}

.reference-summary {
  gap: 12px;
}

.reference-summary img {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-muted);
}

.reference-summary div {
  min-width: 0;
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 13px;
}

.reference-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-info {
  position: sticky;
  top: 84px;
  align-self: start;
}

.author-detail {
  margin-top: 0;
}

.author-line {
  gap: 10px;
  margin-bottom: 16px;
}

.author-line > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.author-line > div > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.author-line .icon {
  width: 14px;
  height: 14px;
}

.author-detail h1 {
  margin: 0 0 12px;
  font-size: 26px;
  line-height: 1.25;
}

.comments-card {
  display: grid;
  gap: 12px;
}

.comment-count {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.comment-empty {
  margin: 4px 0 10px;
  color: var(--muted);
}

.comment {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.comment-head {
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.comment p {
  margin: 8px 0 0;
  color: var(--ink-soft);
  white-space: pre-wrap;
}

.comment-form {
  display: grid;
  gap: 9px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

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

@media (max-width: 1240px) {
  :root {
    --sidebar: 230px;
    --settings: 300px;
  }

  .masonry-grid {
    column-count: 3;
  }
}

@media (max-width: 1020px) {
  .login-panel,
  .gallery-hero,
  .detail-shell {
    grid-template-columns: 1fr;
  }

  .login-visual {
    min-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .studio-frame,
  .studio-frame.settings-hidden {
    grid-template-columns: 1fr;
  }

  .studio-sidebar {
    position: static;
    height: auto;
    gap: 12px;
  }

  .rail-tabs {
    margin-bottom: 0;
  }

  .history-section {
    margin-top: 0;
  }

  .credit-bar {
    align-self: flex-start;
    width: min(260px, 100%);
  }

  .settings-panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 60;
    width: min(340px, 100vw);
    box-shadow: var(--shadow);
  }

  .settings-hidden .settings-panel {
    transform: translateX(100%);
  }

  .detail-info {
    position: static;
  }

  .gallery-hero h1 {
    margin-top: 16px;
  }

  .submission-card {
    max-width: 520px;
  }
}

@media (max-width: 760px) {
  .login-shell {
    padding: 12px;
  }

  .login-panel {
    grid-template-columns: 1fr;
  }

  .login-visual,
  .login-form {
    padding: 24px;
  }

  .login-copy h1,
  .gallery-hero h1 {
    font-size: 42px;
  }

  .login-stats,
  .reference-fields {
    grid-template-columns: 1fr;
  }

  .studio-main {
    grid-template-rows: auto auto minmax(360px, 1fr);
    padding: 14px;
  }

  .workspace-header,
  .gallery-tools,
  .detail-top,
  .gallery-top,
  .composer-footer {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .workspace-actions,
  .composer-submit,
  .count-control,
  .gallery-tools {
    width: 100%;
  }

  .tool-pill {
    flex: 1 1 auto;
  }

  .composer-submit {
    justify-content: space-between;
  }

  .result-canvas {
    min-height: 390px;
  }

  .gallery-shell {
    width: min(100% - 24px, 1220px);
    padding-top: 34px;
  }

  .gallery-hero {
    gap: 22px;
    margin-bottom: 24px;
  }

  .masonry-grid {
    column-count: 2;
    column-gap: 12px;
  }

  .gallery-card {
    margin-bottom: 12px;
  }

  .detail-shell {
    width: min(100% - 24px, 1220px);
    padding-top: 18px;
  }
}

@media (max-width: 560px) {
  :root {
    --control: 42px;
  }

  .nav-pills {
    width: 100%;
  }

  .nav-pills button {
    flex: 1;
    padding: 0 10px;
  }

  .side-section.history-section {
    display: none;
  }

  .studio-sidebar {
    padding: 12px;
  }

  .workspace-header h1 {
    font-size: 20px;
  }

  .workspace-actions {
    gap: 6px;
  }

  .tool-pill span {
    display: none;
  }

  .prompt-composer textarea#prompt {
    min-height: 150px;
    padding-top: 50px;
  }

  .composer-counter {
    left: 14px;
    right: 14px;
    justify-content: space-between;
  }

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

  .gallery-top,
  .detail-top {
    padding: 10px 12px;
  }

  .gallery-shell {
    padding-bottom: 44px;
  }

  .gallery-hero h1 {
    font-size: 36px;
  }

  .gallery-tools .tabs,
  .search-box,
  .gallery-tools .icon-btn {
    width: 100%;
  }

  .tabs button {
    flex: 1;
  }

  .masonry-grid {
    column-count: 1;
  }

  .detail-image {
    max-height: 62dvh;
  }

  .detail-card {
    padding: 14px;
  }
}
