:root {
  --bg: #000000;
  --surface-top: #18181b;
  --surface-bar: #1e1e20;
  --surface-popover: #1c1c1e;
  --surface-control: #27272a;
  --surface-active: #3c3c42;
  --border-subtle: #2e2e32;
  --border-light: #3f3f46;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --white: #ffffff;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.underline {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.flow-app {
  position: relative;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Top Bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: 64px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.topbar-left {
  justify-self: start;
}

.topbar-center {
  justify-self: center;
}

.topbar-right {
  justify-self: end;
}

.icon-circle-btn {
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  border: 1px solid #262629;
  background: var(--surface-top);
  color: var(--text-muted);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-circle-btn.icon-ghost {
  background: transparent;
  border-color: transparent;
}

.icon-circle-btn:hover {
  background: #222226;
  color: var(--white);
}

.search-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  width: clamp(220px, 26vw, 350px);
  height: 38px;
  padding: 0 14px;
  border-radius: 9999px;
  background: var(--surface-top);
  border: 1px solid #242428;
  color: var(--text-dim);
}

.search-pill:focus-within {
  border-color: var(--border-light);
}

.search-pill input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 0.875rem;
}

.search-pill input::placeholder {
  color: transparent;
}

.search-pill:focus-within input::placeholder {
  color: var(--text-dim);
}

.filter-wrap {
  position: relative;
}

.dropdown-card {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 210px;
  background: var(--surface-popover);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.85);
}

.dropdown-title {
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 0.84rem;
  cursor: pointer;
}

.dropdown-item:hover,
.dropdown-item.is-selected {
  background: var(--surface-control);
  color: var(--white);
}

.pro-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 10px;
  border-radius: 9999px;
  border: 1px solid #2b2b30;
  background: #111114;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.pro-user-pill:hover {
  border-color: var(--border-light);
}

.pro-chip {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  padding: 2px 7px;
  border-radius: 9999px;
  border: 1px solid #3f3f46;
  background: #1a1a1f;
}

.avatar-ring {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 2px;
  background: conic-gradient(from 140deg, #34d399, #38bdf8, #34d399);
  display: grid;
  place-items: center;
}

.avatar-ring.is-warn {
  background: conic-gradient(from 140deg, #fbbf24, #f87171, #fbbf24);
}

.avatar-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #0d161b;
  color: #e4e4e7;
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Main Center Stage */
.canvas-stage {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 80px 28px 140px;
}

.empty-state {
  margin: auto;
  padding-bottom: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  user-select: none;
}

.pixel-flower {
  color: #f4f4f5;
}

.empty-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 450;
  color: #e4e4e7;
  letter-spacing: -0.01em;
}

/* Responsive Gallery */
.gallery-container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.gallery-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #0d0d10;
  border: 1px solid #1e1e24;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.gallery-card:hover {
  border-color: #3a3a42;
  transform: translateY(-2px);
}

.gallery-card img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 220px;
  max-height: 460px;
  object-fit: cover;
  cursor: zoom-in;
}

.card-overlay {
  position: absolute;
  inset: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.55) 0%,
    transparent 35%,
    transparent 55%,
    rgba(0, 0, 0, 0.85) 100%
  );
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.gallery-card:hover .card-overlay,
.gallery-card:focus-within .card-overlay {
  opacity: 1;
}

.card-top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  pointer-events: auto;
}

.overlay-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(24, 24, 27, 0.85);
  backdrop-filter: blur(8px);
  color: var(--white);
  font-size: 0.76rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.overlay-btn:hover {
  background: var(--white);
  color: #09090b;
}

.card-bottom-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-prompt {
  margin: 0;
  font-size: 0.8rem;
  color: #f4f4f5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-sub {
  font-size: 0.72rem;
  color: #a1a1aa;
}

/* Skeleton Loader Cards */
.skeleton-card {
  border-radius: 16px;
  min-height: 280px;
  background: linear-gradient(110deg, #121215 25%, #1c1c21 50%, #121215 75%);
  background-size: 200% 100%;
  border: 1px solid #222228;
  animation: shimmer 1.4s infinite linear;
  display: flex;
  align-items: flex-end;
  padding: 14px;
}

.skeleton-label {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Floating Dock & Prompt Bar */
.floating-dock-wrapper {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 28px));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toast-banner {
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: #231416;
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
  font-size: 0.83rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toast-close {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

/* Floating Settings Popover */
.settings-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 42px;
  width: min(336px, calc(100vw - 28px));
  background: var(--surface-popover);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popover-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 9999px;
  background: var(--surface-control);
}

.popover-tab {
  border: none;
  border-radius: 9999px;
  height: 34px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.popover-tab.is-active {
  background: var(--white);
  color: #09090b;
}

.video-notice {
  font-size: 0.76rem;
  color: #fde68a;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: 10px;
  padding: 7px 10px;
}

/* Aspect Ratio Strip */
.ratio-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-control);
}

.ratio-btn {
  border: none;
  border-radius: 10px;
  padding: 7px 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ratio-btn:hover {
  color: var(--white);
}

.ratio-btn.is-active {
  background: var(--surface-active);
  color: var(--white);
}

.ratio-glyph {
  display: inline-block;
  border: 1.5px solid currentColor;
  border-radius: 2.5px;
}

.r-16-9 {
  width: 16px;
  height: 10px;
}

.r-4-3 {
  width: 14px;
  height: 11px;
}

.r-1-1 {
  width: 12px;
  height: 12px;
}

.r-3-4 {
  width: 11px;
  height: 14px;
}

.r-9-16 {
  width: 9px;
  height: 15px;
}

/* Model Dropdown */
.model-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface-control);
  border: 1px solid #323238;
  border-radius: 12px;
  height: 40px;
}

.model-select-emoji {
  position: absolute;
  left: 12px;
  font-size: 0.9rem;
  pointer-events: none;
}

.model-select {
  width: 100%;
  height: 100%;
  appearance: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 34px 0 36px;
  cursor: pointer;
}

.model-select option {
  background: #1c1c1e;
  color: #f4f4f5;
}

.model-select-chevron {
  position: absolute;
  right: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Segmented Controls */
.popover-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.popover-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.segmented-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-control);
}

.seg-btn {
  border: none;
  border-radius: 8px;
  height: 30px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover {
  color: var(--white);
}

.seg-btn.is-active {
  background: var(--surface-active);
  color: var(--white);
}

.popover-footer {
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  padding-top: 2px;
}

/* Bottom Prompt Bar */
.prompt-bar {
  width: 100%;
  background: var(--surface-bar);
  border: 1px solid var(--border-subtle);
  border-radius: 28px;
  padding: 8px 10px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.85);
}

.ref-preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 2px 6px 8px;
  padding: 4px 8px 4px 4px;
  border-radius: 10px;
  background: #27272c;
  border: 1px solid #35353c;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.ref-preview-chip img {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  object-fit: cover;
}

.ref-remove-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

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

.circle-action-btn,
.circle-submit-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #2a2a2e;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.circle-action-btn:hover,
.circle-submit-btn:hover:not(:disabled) {
  background: #38383f;
  color: var(--white);
}

.circle-submit-btn.is-ready:not(:disabled) {
  background: var(--white);
  color: #09090b;
}

.circle-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.submit-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--white);
  animation: spin 0.75s linear infinite;
}

.circle-submit-btn.is-loading .submit-arrow {
  display: none;
}

.circle-submit-btn.is-loading .submit-spinner {
  display: block;
}

textarea#promptInput {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.4;
  max-height: 140px;
  padding: 6px 2px;
}

textarea#promptInput::placeholder {
  color: var(--text-dim);
}

.settings-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border-radius: 9999px;
  border: 1px solid #313137;
  background: #26262a;
  color: var(--text);
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.settings-pill:hover,
.settings-pill[aria-expanded="true"] {
  background: #313137;
  border-color: #46464f;
}

.pill-ratio-icon {
  display: inline-block;
  border: 1.4px solid var(--text-muted);
  border-radius: 2px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(8px);
}

.lightbox-card,
.info-card {
  position: relative;
  z-index: 1;
  background: var(--surface-popover);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
}

.lightbox-card {
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lightbox-header,
.info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.lightbox-caption {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-actions {
  display: flex;
  gap: 8px;
}

.pill-btn-light,
.pill-btn-dark {
  border-radius: 9999px;
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn-light {
  border: none;
  background: var(--white);
  color: #09090b;
}

.pill-btn-dark {
  border: 1px solid var(--border-light);
  background: var(--surface-control);
  color: var(--text);
}

.lightbox-card img {
  max-width: 86vw;
  max-height: 78vh;
  border-radius: 12px;
  object-fit: contain;
  background: #050507;
}

.info-card {
  width: min(460px, 92vw);
}

.info-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.info-body {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.info-kv {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #27272d;
}

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

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@media (max-width: 680px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    padding: 10px 12px;
  }
  .search-pill {
    width: 100%;
    max-width: 190px;
  }
  .topbar-right .icon-circle-btn:first-child,
  .topbar-right #topRightMoreBtn {
    display: none;
  }
  .settings-popover {
    right: 0;
    width: 100%;
  }
  .settings-pill #pillModelName {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
