:root {
  color-scheme: light;
  --bg: #eef3ef;
  --bg-deep: #d8e6df;
  --panel: #fffdf8;
  --panel-soft: #f8f6ee;
  --ink: #192321;
  --ink-soft: #35413e;
  --muted: #6f7a75;
  --line: #d8ded6;
  --line-strong: #bfc9c1;
  --accent: #117a82;
  --accent-dark: #0b5960;
  --accent-soft: #dff0ed;
  --danger: #a53b3b;
  --danger-soft: #fff0ec;
  --gold: #d39a35;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 18px 45px rgb(26 40 37 / 14%);
  --shadow-soft: 0 10px 28px rgb(26 40 37 / 9%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgb(17 122 130 / 12%), transparent 35%),
    linear-gradient(315deg, rgb(211 154 53 / 20%), transparent 34%),
    radial-gradient(circle at 22% 10%, rgb(255 255 255 / 92%) 0 16%, transparent 38%),
    linear-gradient(145deg, #edf4ef 0%, #f8f1df 48%, #dfeeea 100%);
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

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

button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #fffefb, #f4efe2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 0 rgb(255 255 255 / 84%) inset;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

button:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(17 122 130 / 10%);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgb(17 122 130 / 22%);
  outline-offset: 2px;
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.primary-button,
.login-panel button {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), #22a1a0);
  color: white;
  box-shadow: 0 10px 22px rgb(17 122 130 / 24%);
}

.primary-button:hover,
.login-panel button:hover {
  border-color: transparent;
  box-shadow: 0 12px 28px rgb(17 122 130 / 30%);
}

.danger-button {
  border-color: #e2c1ba;
  color: var(--danger);
  background: linear-gradient(180deg, #fffaf7, var(--danger-soft));
}

.danger-button:hover {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgb(165 59 59 / 10%);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgb(255 254 250 / 92%);
  color: var(--ink);
  padding: 10px 12px;
  box-shadow: 0 1px 0 rgb(255 255 255 / 80%) inset;
}

textarea {
  resize: vertical;
  line-height: 1.48;
}

::placeholder {
  color: #9aa29d;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgb(238 243 239 / 72%), rgb(248 241 223 / 86%)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='760' viewBox='0 0 1200 760'%3E%3Crect width='1200' height='760' fill='%23e7efe8'/%3E%3Cpath d='M0 572 C170 508 302 652 486 544 C682 430 842 592 1200 468 L1200 760 L0 760 Z' fill='%238fc2b5'/%3E%3Cpath d='M0 628 C210 540 352 696 594 584 C764 505 914 612 1200 548 L1200 760 L0 760 Z' fill='%23d7a345' opacity='.72'/%3E%3Ccircle cx='968' cy='132' r='78' fill='%23f1bd58'/%3E%3Cpath d='M178 436 Q268 292 374 438 T574 436' fill='none' stroke='%23117a82' stroke-width='28' stroke-linecap='round'/%3E%3Cpath d='M642 448 Q754 310 902 448' fill='none' stroke='%23ffffff' stroke-width='18' stroke-linecap='round' opacity='.66'/%3E%3C/svg%3E");
  background-size: cover;
  background-position: center;
}

.login-panel {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid rgb(255 255 255 / 72%);
  border-radius: var(--radius);
  background: rgb(255 253 248 / 92%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 22px;
}

.login-panel h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.02em;
}

.login-panel label {
  display: block;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.login-panel button {
  width: 100%;
  margin-top: 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
  padding: 12px;
  gap: 12px;
  transition: grid-template-columns 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 68px minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgb(255 255 255 / 16%);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgb(255 255 255 / 9%), transparent 22%),
    linear-gradient(160deg, #183331 0%, #244642 58%, #345445 100%);
  color: white;
  box-shadow: var(--shadow-soft);
}

.sidebar.collapsed {
  width: 68px;
  padding: 12px;
}

.sidebar.collapsed .brand-title,
.sidebar.collapsed .sidebar-actions,
.sidebar.collapsed .workspace-list,
.sidebar.collapsed .user-row {
  display: none;
}

.sidebar.collapsed .brand-toggle {
  justify-content: center;
  padding: 8px;
}

.sidebar.collapsed .brand-toggle-glyph {
  display: none;
}

.brand-row,
.section-heading,
.button-row,
.page-controls,
.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-row {
  width: 100%;
}

.brand-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border-color: rgb(255 255 255 / 14%);
  border-radius: 14px;
  background: rgb(255 255 255 / 8%);
  color: white;
  text-align: left;
}

.brand-toggle:hover {
  border-color: rgb(255 255 255 / 24%);
  box-shadow: 0 0 0 3px rgb(255 255 255 / 8%);
}

.brand-toggle-glyph {
  flex: 0 0 auto;
  color: rgb(255 255 255 / 70%);
  font-size: 15px;
  line-height: 1;
}

.brand-title {
  font-size: 18px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.app-brand-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  box-shadow: 0 10px 24px rgb(17 122 130 / 20%);
  flex: 0 0 auto;
}

.app-brand-icon-small {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  box-shadow: 0 8px 18px rgb(17 122 130 / 18%);
}

.sidebar input {
  border-color: rgb(255 255 255 / 18%);
  background: rgb(255 255 255 / 10%);
  color: white;
}

.sidebar input::placeholder {
  color: rgb(255 255 255 / 56%);
}

.sidebar-actions {
  grid-template-columns: 1fr auto;
  display: grid;
  gap: 8px;
}

.sidebar-actions button,
.user-row button {
  border-color: rgb(255 255 255 / 18%);
  background: rgb(255 255 255 / 10%);
  color: white;
}

.workspace-list {
  overflow: auto;
  padding: 2px;
}

.workspace-item {
  width: 100%;
  margin-bottom: 8px;
  padding: 11px 12px;
  text-align: left;
  color: rgb(255 255 255 / 88%);
  background: rgb(255 255 255 / 8%);
  border-color: rgb(255 255 255 / 12%);
  font-weight: 700;
}

.workspace-item.active {
  background: linear-gradient(135deg, #f7cf7a, #d69b35);
  border-color: rgb(255 255 255 / 34%);
  color: #241d12;
  box-shadow: 0 12px 24px rgb(0 0 0 / 18%);
}

.user-row {
  justify-content: space-between;
  color: rgb(255 255 255 / 82%);
}

.main-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid rgb(255 255 255 / 66%);
  border-radius: var(--radius);
  background: rgb(255 253 248 / 76%);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid rgb(216 222 214 / 82%);
  background: linear-gradient(180deg, rgb(255 253 248 / 92%), rgb(247 248 240 / 78%));
}

.topbar-heading {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.page-title-input {
  width: auto;
  max-width: min(420px, 100%);
  padding: 3px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 21px;
  font-weight: 850;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.page-title-input:focus-visible {
  outline: 0;
  border-color: transparent;
}

.workspace-meta {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.workspace-meta .meta-workspace {
  color: var(--ink-soft);
  font-weight: 700;
}

.workspace-meta .meta-model,
.workspace-meta .meta-size,
.workspace-meta .meta-status {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.workspace-meta .meta-divider {
  color: rgb(111 122 117 / 55%);
}

.page-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.page-controls button {
  min-height: 34px;
  padding: 0 11px;
}

#pageCounter {
  min-width: 40px;
  color: var(--ink-soft);
  font-weight: 800;
  text-align: center;
}

.muted,
.status-line {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.editor-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(360px, 410px);
  gap: 16px;
  padding: 16px;
}

.preview-zone {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: 8px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
}

.preview-toolbar > span,
.tool-section h2 {
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-actions,
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgb(255 253 248 / 72%);
}

.zoom-controls button {
  min-width: 34px;
  min-height: 30px;
  padding: 0 9px;
}

#zoomLevel {
  min-width: 52px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.image-preview {
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: min(62vh, 700px);
  min-height: 280px;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 72%);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgb(17 122 130 / 18%), transparent 34%),
    linear-gradient(315deg, rgb(211 154 53 / 16%), transparent 36%),
    linear-gradient(180deg, #eef4ef, #ddd7c8);
  box-shadow: var(--shadow-soft), 0 1px 0 rgb(255 255 255 / 72%) inset;
  color: var(--muted);
  text-align: center;
}

.image-preview p {
  position: relative;
  z-index: 1;
  max-width: 42ch;
  margin: 0;
  padding: 18px;
  font-weight: 700;
  line-height: 1.45;
}

.image-preview img {
  position: absolute;
  display: block;
  margin: 0;
  border-radius: var(--radius-sm);
  box-shadow: 0 18px 40px rgb(25 35 33 / 22%);
  transition: transform 120ms ease;
  user-select: none;
  touch-action: none;
  opacity: 0;
}

.image-preview img.is-ready {
  opacity: 1;
}

.image-preview.has-image {
  cursor: grab;
}

.image-preview.has-image.is-dragging {
  cursor: grabbing;
}

.variant-strip {
  min-height: 104px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 0 2px 4px;
}

.variant {
  position: relative;
  width: 132px;
  height: 84px;
  flex: 0 0 132px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: white;
  cursor: pointer;
  box-shadow: 0 8px 20px rgb(26 40 37 / 8%);
}

.variant:hover {
  border-color: var(--accent);
}

.variant.active {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.variant img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.variant .selection-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  display: none;
  max-width: calc(100% - 12px);
  padding: 4px 7px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.1;
  box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
}

.variant.active .selection-badge {
  display: block;
}

.variant-actions {
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 5px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.variant:hover .variant-actions,
.variant:focus-within .variant-actions {
  opacity: 1;
  pointer-events: auto;
}

.variant-action {
  min-height: 24px;
  width: 100%;
  padding: 0 5px;
  border-color: rgb(255 255 255 / 72%);
  background: rgb(25 35 33 / 86%);
  color: white;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 2px 8px rgb(0 0 0 / 24%);
}

.variant-action:hover {
  border-color: white;
}

.variant-action.danger {
  background: rgb(165 59 59 / 90%);
}

.tool-panel {
  min-width: 0;
  overflow: visible;
  display: grid;
  align-content: start;
  gap: 14px;
}

.tool-section {
  padding: 14px;
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgb(255 253 248 / 92%), rgb(247 246 237 / 84%));
  box-shadow: var(--shadow-soft);
}

.tool-section h2 {
  margin: 0;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 10px;
}

.button-row {
  margin: 10px 0;
}

.button-row button {
  flex: 1;
}

.option-row {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  margin-bottom: 10px;
}

.field-label {
  padding-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.aspect-ratio-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.aspect-ratio-picker input {
  display: none;
}

.aspect-option {
  display: grid;
  place-items: center;
  gap: 5px;
  min-width: 0;
  min-height: 62px;
  padding: 6px 4px;
  background: linear-gradient(180deg, #fffefb, #f4f1e8);
}

.aspect-option[aria-checked="true"] {
  border-color: var(--accent);
  background: linear-gradient(180deg, #f1fbf9, var(--accent-soft));
  box-shadow: inset 0 0 0 1px var(--accent), 0 8px 18px rgb(17 122 130 / 12%);
  color: var(--accent-dark);
}

.aspect-icon {
  width: calc(30px * var(--aspect-w));
  height: calc(30px * var(--aspect-h));
  min-width: 12px;
  min-height: 12px;
  border: 2px solid currentColor;
  border-radius: 3px;
  background: rgb(17 122 130 / 12%);
}

.aspect-ratio-label {
  max-width: 100%;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #fffefb, #f4efe2);
  cursor: pointer;
  font-weight: 800;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.reference-pool {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.reference-card {
  position: relative;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 1;
  background: white;
  cursor: pointer;
  box-shadow: 0 8px 18px rgb(26 40 37 / 8%);
}

.reference-card:hover {
  border-color: var(--accent);
}

.reference-card.active {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.reference-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reference-card span {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  padding: 4px 6px;
  border-radius: 4px;
  background: rgb(25 35 33 / 66%);
  color: white;
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-selected-badge {
  position: absolute;
  top: 5px;
  left: 5px;
  display: none;
  max-width: calc(100% - 10px);
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--gold);
  color: #241d12;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.1;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgb(0 0 0 / 22%);
}

.reference-card.active .reference-selected-badge {
  display: block;
}

.reference-delete-button {
  position: absolute;
  right: 5px;
  top: 5px;
  display: none;
  min-height: 24px;
  padding: 0 7px;
  border-color: rgb(255 255 255 / 72%);
  background: rgb(165 59 59 / 90%);
  color: white;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 2px 8px rgb(0 0 0 / 24%);
}

.reference-card:hover .reference-delete-button,
.reference-card:focus-within .reference-delete-button {
  display: block;
}

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

.history-item {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffefa;
  text-align: left;
}

.error-text {
  min-height: 20px;
  color: var(--danger);
}

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

@media (max-width: 1180px) {
  .editor-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .tool-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .image-preview {
    max-height: none;
  }
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .sidebar {
    width: 72px;
    padding: 12px;
  }

  .sidebar .brand-title,
  .sidebar .sidebar-actions,
  .sidebar .workspace-list,
  .sidebar .user-row {
    display: none;
  }

  .brand-toggle {
    justify-content: center;
    padding: 8px;
  }

  .brand-toggle-glyph {
    display: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    width: auto;
    min-height: auto;
    grid-template-rows: auto;
  }

  .sidebar .brand-title,
  .sidebar .sidebar-actions,
  .sidebar .workspace-list,
  .sidebar .user-row {
    display: flex;
  }

  .sidebar .workspace-list {
    display: grid;
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-heading {
    align-items: flex-start;
  }

  .page-controls {
    justify-content: flex-start;
  }

  .editor-grid {
    padding: 10px;
  }

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

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .preview-actions {
    flex-wrap: wrap;
  }

  .image-preview {
    min-height: 250px;
  }

  .option-row {
    grid-template-columns: 1fr;
  }

  .field-label {
    padding-top: 0;
  }
}
