:root {
  color-scheme: dark;
  --bg: #050609;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.24);
  --text: #f7f8fb;
  --muted: rgba(247, 248, 251, 0.62);
  --faint: rgba(247, 248, 251, 0.38);
  --accent: #74a7ff;
  --accent-2: #f1f5ff;
  --danger: #ff8c8c;
  --ok: #8effc1;
  --shadow: 0 32px 90px rgba(0, 0, 0, 0.56);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% -10%, rgba(102, 137, 211, 0.22), transparent 34rem),
    radial-gradient(circle at 12% 22%, rgba(255, 255, 255, 0.08), transparent 18rem),
    linear-gradient(180deg, #090a10 0%, var(--bg) 58%, #020306 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

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

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

button {
  user-select: none;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 84px 84px;
  mask-image: radial-gradient(circle at center, black, transparent 72%);
  opacity: 0.34;
}

.shell {
  position: relative;
  width: min(1180px, calc(100% - 32px));
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 0 calc(38px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(14px, 2vw, 22px);
  animation: enter 640ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.topbar,
.composer,
.image-frame,
.settings-panel,
.modal-panel,
.lightbox-panel {
  backdrop-filter: blur(28px) saturate(130%);
  -webkit-backdrop-filter: blur(28px) saturate(130%);
}

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

.brand,
.top-actions,
.model-pill,
.download-link,
.control-button,
.generate-button,
.mic-button,
.icon-button,
.ghost-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand {
  min-width: 0;
  gap: 11px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 0 34px rgba(255, 216, 0, 0.16);
}

.top-actions {
  gap: 10px;
}

.model-pill {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.stage {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(340px, 1fr) auto auto;
  gap: 12px;
}

.image-frame {
  position: relative;
  min-height: clamp(340px, 60svh, 720px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.032)),
    rgba(255, 255, 255, 0.045);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vw, 22px);
}

.image-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.08), transparent 32rem),
    linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  opacity: 0.48;
  pointer-events: none;
}

.image-frame.drag-over {
  border-color: rgba(255, 255, 255, 0.34);
  box-shadow: 0 0 0 4px rgba(116, 167, 255, 0.1), var(--shadow);
}

.drop-hint {
  position: absolute;
  z-index: 5;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5, 6, 9, 0.74);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.drop-hint.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#resultImage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.48);
  animation: imageReveal 560ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.empty-state,
.loading-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--faint);
  text-align: center;
}

.empty-symbol {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.04);
}

.empty-symbol svg {
  width: 34px;
  height: 34px;
  stroke: rgba(255, 255, 255, 0.56);
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state p,
.loading-layer p,
.status,
.modal-header h2,
.modal-header p {
  margin: 0;
}

.loading-layer {
  z-index: 4;
  background: rgba(4, 5, 8, 0.64);
}

.loader {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent-2);
  animation: spin 840ms linear infinite;
}

.status-row {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.status.error {
  color: var(--danger);
}

.download-link,
.ghost-chip {
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  font-size: 13px;
  font-weight: 650;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.download-link:hover,
.ghost-chip:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--line-strong);
}

.download-link svg,
.control-button svg,
.generate-button svg,
.mic-button svg,
.icon-button svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.preset-bar {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.preset-control {
  position: relative;
}

.preset-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  width: min(280px, calc(100vw - 34px));
  max-height: 330px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(9, 10, 16, 0.84);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  animation: panelIn 180ms ease both;
}

.preset-menu button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 0 11px;
  cursor: pointer;
}

.preset-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.composer {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.078), rgba(255, 255, 255, 0.04));
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  padding: 14px;
}

.prompt-box {
  position: relative;
}

textarea {
  display: block;
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 0;
  outline: 0;
  border-radius: 18px;
  padding: 16px 60px 16px 17px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  line-height: 1.55;
  caret-color: var(--accent);
}

textarea::placeholder {
  color: rgba(247, 248, 251, 0.4);
}

textarea:focus {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 0 0 4px rgba(116, 167, 255, 0.08);
}

.mic-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, color 180ms ease, border-color 180ms ease;
}

.mic-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.mic-button[data-state="listening"] {
  color: var(--ok);
  border-color: rgba(142, 255, 193, 0.55);
  box-shadow: 0 0 0 7px rgba(142, 255, 193, 0.08);
  animation: softPulse 1.3s ease infinite;
}

.mic-button[data-state="transcribing"] {
  color: var(--accent-2);
  border-color: rgba(116, 167, 255, 0.62);
}

.mic-button[data-state="error"] {
  color: var(--danger);
  border-color: rgba(255, 140, 140, 0.52);
}

.import-tray {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 12px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
}

.import-tray img {
  width: 58px;
  height: 58px;
  border-radius: 13px;
  object-fit: cover;
}

.import-tray strong,
.import-tray span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-tray strong {
  font-size: 13px;
}

.import-tray span {
  color: var(--muted);
  font-size: 12px;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.secondary-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.control-button,
.generate-button {
  min-height: 46px;
  border-radius: 999px;
  gap: 9px;
  cursor: pointer;
  line-height: 1;
  font-weight: 650;
  letter-spacing: 0;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, opacity 180ms ease, border-color 180ms ease, color 180ms ease;
}

.control-button {
  padding: 0 17px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.control-button.compact {
  min-height: 36px;
  padding: 0 13px;
  font-size: 12px;
}

.control-button:hover,
.control-button[aria-expanded="true"] {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--line-strong);
}

.control-button.is-loading {
  color: var(--accent-2);
}

.control-button.is-loading::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid currentColor;
  border-top-color: transparent;
  animation: spin 700ms linear infinite;
}

.generate-button {
  border: 0;
  padding: 0 22px 0 24px;
  min-width: 142px;
  color: #05070d;
  background: linear-gradient(135deg, #ffffff, #a9c8ff 52%, #78aaff);
  box-shadow: 0 12px 34px rgba(116, 167, 255, 0.28);
}

.generate-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 42px rgba(116, 167, 255, 0.36);
}

.control-button:active,
.generate-button:active,
.mic-button:active,
.icon-button:active {
  transform: translateY(0) scale(0.985);
}

.generate-button:disabled,
.control-button:disabled,
.mic-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

.settings-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.055);
  padding: 14px;
  animation: panelIn 220ms ease both;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr 0.6fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.24);
  color: var(--text);
  padding: 0 12px;
  outline: 0;
}

select:focus,
input:focus {
  border-color: rgba(255, 255, 255, 0.26);
  box-shadow: 0 0 0 4px rgba(116, 167, 255, 0.08);
}

.modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  padding: clamp(12px, 3vw, 32px);
  background: rgba(1, 2, 5, 0.62);
  display: grid;
  place-items: center;
  animation: fadeIn 180ms ease both;
}

.modal-panel {
  width: min(1120px, 100%);
  max-height: min(86svh, 900px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(9, 10, 16, 0.82);
  box-shadow: var(--shadow);
  padding: clamp(14px, 2vw, 22px);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.modal-header h2 {
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.1;
}

.modal-header p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  cursor: pointer;
  flex: 0 0 auto;
}

.icon-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
}

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

.gallery-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.045);
  overflow: hidden;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.gallery-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.065);
}

.gallery-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.gallery-meta {
  display: grid;
  gap: 5px;
  padding: 12px 12px 8px;
}

.gallery-meta strong {
  font-size: 12px;
}

.gallery-meta span {
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 0 12px 12px;
}

.card-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.card-actions button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.gallery-empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
}

.lightbox-panel {
  position: relative;
  max-width: min(1180px, 100%);
  max-height: 90svh;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(9, 10, 16, 0.78);
  padding: 12px;
}

.lightbox-panel img {
  display: block;
  max-width: 100%;
  max-height: calc(90svh - 24px);
  border-radius: 16px;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  z-index: 2;
  top: 18px;
  right: 18px;
  background: rgba(0, 0, 0, 0.48);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

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

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes imageReveal {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes softPulse {
  50% {
    box-shadow: 0 0 0 11px rgba(142, 255, 193, 0.02);
  }
}

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

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: calc(12px + env(safe-area-inset-top));
    gap: 14px;
  }

  .topbar {
    min-height: 42px;
  }

  .brand {
    font-size: 13px;
  }

  .brand-logo {
    width: 28px;
    height: 28px;
  }

  .model-pill {
    display: none;
  }

  .stage {
    grid-template-rows: minmax(310px, 50svh) auto auto;
  }

  .image-frame {
    min-height: 310px;
    border-radius: 22px;
    padding: 10px;
  }

  .status-row,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-actions,
  .preset-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .preset-control,
  .download-link,
  .control-button,
  .generate-button,
  .ghost-chip {
    width: 100%;
  }

  .preset-menu {
    width: 100%;
  }

  .panel-grid,
  .card-actions {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 132px;
    font-size: 16px;
  }

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

@media (max-width: 420px) {
  .secondary-actions,
  .preset-bar,
  .gallery-grid {
    grid-template-columns: 1fr;
  }

  .top-actions .control-button span {
    display: none;
  }
}
