:root {
  --bg: #f5f7fb;
  --card: rgba(255, 255, 255, 0.82);
  --card-solid: #ffffff;
  --card-muted: rgba(250, 251, 255, 0.9);
  --text: #111827;
  --muted: #6b7280;
  --subtle: #9ca3af;
  --border: #e6eaf2;
  --border-strong: #dce3f0;
  --brand: #635bff;
  --brand-hover: #7c75ff;
  --brand-soft: rgba(99, 91, 255, 0.1);
  --success: #16c784;
  --success-soft: #ecfdf5;
  --danger: #ff5c5c;
  --danger-soft: #fff1f1;
  --warning: #b7791f;
  --shadow-card: 0 4px 24px rgba(15, 23, 42, 0.04);
  --shadow-hover: 0 12px 40px rgba(15, 23, 42, 0.08);
  --shadow-button: 0 8px 24px rgba(99, 91, 255, 0.24);
  --radius-card: 24px;
  --radius-control: 14px;
  --radius-image: 18px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="dark"] {
  --bg: #0b1020;
  --card: rgba(17, 24, 39, 0.82);
  --card-solid: #111827;
  --card-muted: rgba(31, 41, 55, 0.74);
  --text: #f9fafb;
  --muted: #9ca3af;
  --subtle: #6b7280;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);
  --brand-soft: rgba(124, 117, 255, 0.18);
  --success-soft: rgba(22, 199, 132, 0.13);
  --danger-soft: rgba(255, 92, 92, 0.14);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.18);
  --shadow-hover: 0 14px 44px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Noto Sans SC", "PingFang SC", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.7;
}

body.viewer-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.66;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.page-shell {
  width: min(1600px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 24px 0 40px;
  animation: page-enter 0.35s var(--ease) both;
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(20px);
}

.brand-block,
.header-actions,
.button-row,
.tabs,
.debug-header,
.panel-header,
.stage-header,
.gallery-header {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 0 12px 30px rgba(99, 91, 255, 0.24);
}

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

.eyebrow,
.panel-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-header h1,
.panel-header h2,
.stage-header h2,
.gallery-header h2 {
  margin: 2px 0 0;
  letter-spacing: 0;
  line-height: 1.2;
}

.app-header h1 {
  font-size: 32px;
  font-weight: 700;
}

.panel-header h2,
.stage-header h2,
.gallery-header h2 {
  font-size: 24px;
  font-weight: 600;
}

.header-actions {
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.status-chip {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.status-chip.is-active {
  background: var(--success-soft);
  color: var(--success);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(255, 92, 92, 0.1);
}

.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(22, 199, 132, 0.13);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
}

.icon-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 0;
  transition: transform 0.25s var(--ease), border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.icon-button:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 91, 255, 0.45);
  box-shadow: var(--shadow-card);
}

.theme-toggle {
  background: var(--card-solid);
  border-color: rgba(99, 91, 255, 0.24);
}

.theme-icon {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 999px;
}

.theme-icon::before,
.theme-icon::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}

.theme-toggle[data-theme-state="light"] .theme-icon {
  background: var(--text);
}

.theme-toggle[data-theme-state="light"] .theme-icon::after {
  inset: -1px -3px 1px 6px;
  background: var(--card-solid);
}

.theme-toggle[data-theme-state="dark"] .theme-icon {
  background: transparent;
  border: 2px solid var(--text);
}

.theme-toggle[data-theme-state="dark"] .theme-icon::before {
  inset: 4px;
  background: var(--text);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.sidebar,
.main-column {
  display: grid;
  gap: 24px;
}

.sidebar {
  position: sticky;
  top: 24px;
}

.main-column {
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
  align-items: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(20px);
  padding: 20px;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), border-color 0.25s var(--ease);
}

.panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.panel-header,
.stage-header,
.gallery-header,
.debug-header {
  justify-content: space-between;
  gap: 16px;
}

.panel-header,
.gallery-header {
  margin-bottom: 20px;
}

.stage-header {
  margin-bottom: 24px;
}

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

.compact-form {
  grid-template-columns: 1fr;
}

.span-all,
.span-2 {
  grid-column: 1 / -1;
}

label {
  min-width: 0;
  display: grid;
  gap: 8px;
}

label > span,
.mask-field > span,
.advanced-title,
.upload-previews p,
.debug-block p {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.help-tip {
  position: relative;
  width: 20px;
  height: 20px;
  min-height: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--card-solid);
  color: var(--muted);
  padding: 0;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.help-tip:hover,
.help-tip:focus-visible {
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 0 0 4px rgba(99, 91, 255, 0.1);
}

.help-popover {
  position: absolute;
  z-index: 80;
  left: 50%;
  bottom: calc(100% + 10px);
  width: min(300px, calc(100vw - 48px));
  transform: translateX(-50%) translateY(4px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-solid);
  color: var(--text);
  box-shadow: var(--shadow-hover);
  opacity: 0;
  pointer-events: none;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.65;
  text-align: left;
  white-space: normal;
}

.help-popover::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 10px;
  height: 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--card-solid);
  transform: translate(-50%, -5px) rotate(45deg);
}

.help-tip:hover .help-popover,
.help-tip:focus-visible .help-popover {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

input,
select,
textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  outline: none;
  background: var(--card-solid);
  color: var(--text);
  padding: 0 16px;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease);
}

select {
  appearance: none;
  border-radius: 999px;
  padding-right: 46px;
  background-color: var(--card-solid);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) 23px,
    calc(100% - 16px) 23px;
  background-repeat: no-repeat;
  background-size: 6px 6px, 6px 6px;
}

select.native-select-hidden {
  display: none;
}

.custom-select {
  position: relative;
  width: 100%;
}

.custom-select-button {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-solid);
  color: var(--text);
  padding: 0 16px 0 20px;
  font-weight: 700;
  box-shadow: none;
}

.custom-select-button:hover,
.custom-select.is-open .custom-select-button {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(99, 91, 255, 0.1);
}

.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-arrow {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.25s var(--ease);
}

.custom-select.is-open .custom-select-arrow {
  transform: translateY(2px) rotate(225deg);
}

.custom-select-menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  display: none;
  max-height: 280px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--card-solid);
  box-shadow: var(--shadow-hover);
  backdrop-filter: blur(20px);
}

.custom-select.is-open .custom-select-menu {
  display: grid;
  gap: 4px;
}

.custom-select-option {
  width: 100%;
  min-height: 42px;
  justify-content: flex-start;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  padding: 0 14px;
  box-shadow: none;
  font-weight: 700;
  text-align: left;
}

.custom-select-option:hover,
.custom-select-option.is-selected {
  background: var(--brand-soft);
  color: var(--brand);
}

textarea {
  min-height: 140px;
  resize: vertical;
  padding: 18px;
  line-height: 1.7;
}

input::placeholder,
textarea::placeholder {
  color: var(--subtle);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(99, 91, 255, 0.1);
}

.upload-field {
  position: relative;
}

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

.upload-field input[type="file"] {
  position: absolute;
  inset: 28px 0 0;
  z-index: 2;
  width: 100%;
  height: calc(100% - 28px);
  min-height: 0;
  border: 0;
  opacity: 0;
  padding: 0;
  cursor: pointer;
}

.upload-dropzone {
  min-height: 118px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--border-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--card-solid), var(--card-muted));
  color: var(--brand);
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.upload-dropzone strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 999px;
  background: var(--brand-soft);
  padding: 0 18px;
  font-size: 15px;
}

.mask-field {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.mask-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.mask-option-card {
  min-height: 118px;
}

.mask-create-button {
  display: grid;
  place-items: center;
  border: 2px dashed var(--border-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, var(--card-solid), var(--card-muted));
  color: var(--brand);
  padding: 0;
}

.mask-create-button strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 999px;
  background: var(--brand-soft);
  padding: 0 18px;
  font-size: 15px;
}

.mask-create-button:hover {
  border-color: var(--brand);
  background: rgba(99, 91, 255, 0.03);
  box-shadow: 0 0 0 4px rgba(99, 91, 255, 0.08);
}

.upload-field:hover .upload-dropzone {
  border-color: var(--brand);
  background: rgba(99, 91, 255, 0.03);
  box-shadow: 0 0 0 4px rgba(99, 91, 255, 0.08);
}

.button-row {
  flex-wrap: wrap;
  gap: 12px;
}

button,
.link-button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  padding: 0 24px;
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease),
    border-color 0.25s var(--ease), color 0.25s var(--ease);
}

.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  color: #fff;
  box-shadow: var(--shadow-button);
}

.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(99, 91, 255, 0.32);
}

.primary-large {
  min-width: 150px;
}

.ghost,
.tab,
.link-button {
  background: var(--card-solid);
  border-color: var(--border);
  color: var(--text);
}

.ghost:hover,
.tab:hover,
.link-button:hover {
  border-color: rgba(99, 91, 255, 0.42);
  color: var(--brand);
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.tabs {
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-muted);
}

.tab {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  white-space: nowrap;
}

.tab.is-active {
  border-color: transparent;
  background: #111827;
  color: #fff;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
}

html[data-theme="dark"] .tab.is-active {
  background: #f9fafb;
  color: #111827;
}

.action-panel {
  display: none;
}

.action-panel.is-active {
  display: block;
}

.prompt-field {
  margin-bottom: 4px;
}

.advanced {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card-muted);
}

.advanced-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

#generate-form .advanced-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card-muted);
}

.status-card strong,
.gallery-empty strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
  line-height: 1.4;
}

.status-card p,
.gallery-empty p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.status-card.loading {
  border-color: rgba(99, 91, 255, 0.32);
  background: var(--brand-soft);
}

.status-card.success {
  border-color: rgba(22, 199, 132, 0.3);
  background: var(--success-soft);
}

.status-card.error {
  border-color: rgba(255, 92, 92, 0.3);
  background: var(--danger-soft);
}

.debug-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.debug-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.debug-meta,
.meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.debug-meta {
  margin-bottom: 12px;
}

.debug-chip,
.meta-item {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-solid);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.debug-block + .debug-block {
  margin-top: 12px;
}

.debug-block p {
  margin: 0;
}

.debug-panel pre {
  max-height: 240px;
  margin: 8px 0 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: #0f172a;
  color: #dbeafe;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.upload-previews {
  margin: 2px 0 4px;
}

.preview-panel {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card-muted);
}

.upload-previews p {
  margin: 0 0 10px;
}

.preview-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-image);
  background: var(--border);
}

.preview-item img,
.image-preview-grid img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius-image);
  background: var(--border);
}

.preview-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.78);
  color: #fff;
  opacity: 0;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  transform: translateY(-2px);
}

.preview-item:hover .preview-remove {
  opacity: 1;
  transform: translateY(0);
}

.preview-remove:focus-visible {
  opacity: 1;
  transform: translateY(0);
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px;
}

.meta-bar {
  margin-bottom: 16px;
}

.gallery-empty {
  min-height: 360px;
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 30px;
  border: 1px dashed var(--border-strong);
  border-radius: 22px;
  background: var(--card-muted);
  text-align: center;
}

.empty-art {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  opacity: 0.14;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.gallery-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card-solid);
  box-shadow: var(--shadow-card);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.gallery-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.gallery-image-wrap {
  position: relative;
  overflow: hidden;
  background: var(--border);
  cursor: zoom-in;
}

.gallery-image-wrap > img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--border);
  transition: transform 0.25s var(--ease);
}

.gallery-card:hover .gallery-image-wrap > img {
  transform: scale(1.01);
}

.image-magnifier {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 152px;
  height: 152px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  background-repeat: no-repeat;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.24);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s var(--ease);
}

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

.gallery-card-body strong {
  font-size: 15px;
}

.gallery-card-body small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

.gallery-card-body .button-row {
  justify-content: space-between;
}

.gallery-card-body .primary,
.gallery-card-body .link-button {
  min-height: 40px;
  padding: 0 14px;
  font-size: 13px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  background: rgba(15, 23, 42, 0.76);
  backdrop-filter: blur(10px);
  padding: 72px;
}

.image-viewer.is-open {
  display: grid;
  place-items: center;
}

.image-viewer-stage {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: visible;
}

.image-viewer-image {
  display: block;
  max-width: min(100%, 1440px);
  max-height: min(100%, 82vh);
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  transition: transform 0.12s var(--ease);
  cursor: zoom-in;
}

.image-viewer-toolbar {
  position: fixed;
  top: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-viewer-scale,
.image-viewer-close {
  min-height: 42px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #111827;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
}

.image-viewer-scale {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
}

.image-viewer-close {
  width: 42px;
  border: 0;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.mask-maker {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(12px);
}

.mask-maker.is-open {
  display: grid;
}

.mask-maker-panel {
  width: min(1180px, 100%);
  max-height: min(900px, calc(100vh - 56px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--card-solid);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.26);
}

.mask-maker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.mask-maker-header h2 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

#mask-maker-close {
  font-size: 24px;
  line-height: 1;
}

.mask-maker-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  padding: 18px;
}

.mask-canvas-shell {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 22px;
  background:
    linear-gradient(45deg, rgba(99, 91, 255, 0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(99, 91, 255, 0.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(99, 91, 255, 0.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(99, 91, 255, 0.08) 75%),
    var(--card-muted);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  padding: 16px;
}

#mask-maker-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 190px);
  border-radius: 16px;
  box-shadow: 0 16px 46px rgba(15, 23, 42, 0.18);
  cursor: crosshair;
  touch-action: none;
}

.mask-maker-loupe {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 4;
  width: 132px;
  height: 132px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 22px;
  background-repeat: no-repeat;
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.28);
  opacity: 0;
  pointer-events: none;
}

.mask-maker-tools {
  display: grid;
  align-content: start;
  gap: 16px;
}

.mask-hint {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card-muted);
}

.mask-hint strong {
  display: block;
  margin-bottom: 6px;
}

.mask-hint p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

#mask-brush-size {
  min-height: 42px;
  padding: 0;
  accent-color: var(--brand);
}

@media (max-width: 1320px) {
  .main-column {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

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

}

@media (max-width: 760px) {
  .page-shell {
    width: min(100vw - 28px, 1600px);
    padding-top: 14px;
  }

  .app-header,
  .stage-header,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header h1 {
    font-size: 26px;
  }

  .header-actions,
  .status-chip,
  .tabs {
    width: 100%;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .status-chip {
    justify-content: center;
  }

  .tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .sidebar,
  .form-grid,
  .advanced-grid,
  #generate-form .advanced-grid,
  .upload-grid,
  .mask-option-grid,
  .upload-previews {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 16px;
  }

  .gallery-empty {
    min-height: 260px;
  }

  .image-viewer {
    padding: 62px 18px 34px;
  }

  .image-viewer-toolbar {
    top: 14px;
    right: 14px;
  }

  .mask-maker {
    padding: 12px;
  }

  .mask-maker-body {
    grid-template-columns: 1fr;
  }

  .mask-maker-panel {
    max-height: calc(100vh - 24px);
  }
}

@media (hover: none) {
  .preview-remove {
    opacity: 1;
    transform: translateY(0);
  }
}
