/* ── Variables ─────────────────────────────────────── */
:root {
  --color-bg: #14242e;
  --color-input-bg: #a0a0a0;
  --color-primary: #03c7a7;
  --color-accent: #FA6500;
  --color-bad: #c85100;
  --color-good: #029f86;
  --color-action: #284b60;
  --color-text: #ffffff;
  --color-text-dark: #0C161D;
  --color-block-bg: rgba(20, 36, 46, 0.55);
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1.5rem;
}

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: #fff;
  color: var(--color-text);
  min-height: 100vh;
  overflow: hidden;
}
img { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
textarea { font-family: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.hidden { display: none !important; }

/* ── Background ─────────────────────────────────────── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url('../../images/background-graphic.png');
  background-repeat: repeat;
  background-size: cover;
  background-position: center;
  transform: scaleX(-1);
  opacity: 0.75;
  z-index: -1;
}

/* ── Header ─────────────────────────────────────────── */
.header {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 50;
  background: rgba(255,255,255,0.85);
  border-bottom: 1px solid #e5e7eb;
}
.header__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header__back {
  display: flex; align-items: center; gap: 0.5rem;
  color: #000;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.header__back:hover { opacity: 0.8; }
.header__cta {
  font-size: 14px;
  color: #000000;
}
.header__link {
  color: var(--color-accent);
  text-decoration: underline;
}

/* ── Layout ─────────────────────────────────────────── */
.layout {
  display: flex;
  gap: 1rem;
  padding: 1rem 5rem;
  padding-top: calc(56px + 1rem);
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  overflow: hidden;
  background: transparent;
  backdrop-filter: blur(2px);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
  color: var(--color-text-dark);
}

.sidebar--disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* Sidebar header */
.sidebar__header { flex-shrink: 0; }
.sidebar__title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  color: #000;
}
.sidebar__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #000;
}
.sidebar__description {
  font-size: 0.75rem;
  color: #606060;
  margin-bottom: 0.75rem;
  line-height: 1.4;
}
.sidebar__divider {
  border-top: 1px solid var(--color-accent);
  flex-shrink: 0;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-bottom: 1rem;
}
.tab {
  padding: 0.375rem 0.75rem;
  border-radius: 30px;
  font-size: 0.875rem;
  font-weight: 400;
  color: #000;
  background: #FED1B3;
  transition: opacity 0.15s;
}
.tab--active {
  background: var(--color-accent);
  color: #fff;
  font-weight: 600;
}
.tab:not(.tab--active):hover { opacity: 0.8; }

/* Custom prompt card */
.custom-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.custom-card:not(.custom-card--selected):hover { opacity: 0.85; }
.custom-card--selected { background: var(--color-accent); }
.custom-card__label {
  font-size: 0.875rem;
  color: var(--color-accent);
  font-weight: 500;
}
.custom-card--selected .custom-card__label { color: #fff; }
.custom-card__check {
  width: 1.25rem; height: 1.25rem;
  border-radius: 50%;
  border: 1.5px solid var(--color-accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.custom-card--selected .custom-card__check { background: #fff; }

/* Choose label (under tabs) */
.sidebar__choose {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}
.sidebar__choose-text {
  font-size: 0.75rem;
  font-weight: 700;
  color: #000;
}

/* Card grid scroll wrapper */
.card-grid-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.card-grid-wrap { scrollbar-width: none; }
.card-grid-wrap::-webkit-scrollbar { display: none; }

/* Card grid — pure layout, no overflow interactions */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  padding: 3px;
}

/* Style card */
.style-card {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--color-input-bg);
  transition: all 0.15s;
}
.style-card--selected { outline: 2px solid var(--color-accent); outline-offset: 0; }
.style-card--disabled { opacity: 0.5; cursor: not-allowed; }
.style-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: top;
}
.style-card--character img { object-position: center; }
.style-card__label {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 1.75rem;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  display: flex; align-items: center; justify-content: center;
  padding: 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #fff;
  text-align: center;
}
.style-card__remove {
  position: absolute; top: 0.25rem; right: 0.25rem;
  color: var(--color-accent);
  line-height: 0;
  transition: opacity 0.15s;
}
.style-card__remove:hover { opacity: 0.7; }


/* ── Main content ────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  min-width: 0;
}
.main-content { scrollbar-width: none; }
.main-content::-webkit-scrollbar { display: none; }

/* Block (panel) */
.block {
  background: transparent;
  backdrop-filter: blur(2px);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
#uploadBlock { padding: 0.5rem; gap: 0.5rem; }

/* ── Upload row (slots + placeholder text) ───────────── */
.upload-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── Upload slots ────────────────────────────────────── */
.upload-slots {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  flex-shrink: 0;
  flex-wrap: nowrap;
}
.upload-slot {
  position: relative;
  width: 6rem; height: 6rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-input-bg);
  cursor: pointer;
  transition: all 0.15s;
}
.upload-slot--empty {
  background: transparent;
  border: 1px dashed var(--color-accent);
  display: flex; align-items: center; justify-content: center;
}
.upload-slot--empty:hover { background: rgba(250, 101, 0, 0.5); }
.upload-slot--empty:hover .upload-slot__plus { color: #fff; }
.upload-slot__plus { color: var(--color-accent); line-height: 0; transition: color 0.15s; }
.upload-slot img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.upload-slot__remove {
  position: absolute; top: 0.25rem; right: 0.25rem;
  color: var(--color-accent); line-height: 0;
  transition: opacity 0.15s;
}
.upload-slot__remove:hover { opacity: 0.7; }

/* Upload block drag-over */
.upload-block--drag-over {
  outline: 2px dashed var(--color-accent);
  outline-offset: -2px;
  background: rgba(250, 101, 0, 0.06);
}
.upload-block--drag-over .upload-slot--empty {
  background: rgba(250, 101, 0, 0.5);
}
.upload-block--drag-over .upload-slot--empty .upload-slot__plus { color: #fff; }

/* Upload slots locked during generation */
.upload-slots--locked {
  pointer-events: none;
}
.upload-slots--locked .upload-slot__remove { opacity: 0.2; }
.upload-slots--locked .upload-slot--empty { opacity: 0.3; }

/* ── Reference upload ───────────────────────────────── */
.reference-upload {
  position: relative;
  height: 6.25rem;
  border-radius: var(--radius-md);
  border: 2px dashed rgba(250, 101, 0, 0.5);
  background: #DFDFDF;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}
.reference-upload:hover { border-color: var(--color-accent); }
.reference-upload--drag-over { border-color: var(--color-accent); background: rgba(250, 101, 0, 0.1); }
.reference-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-accent);
  font-weight: 500;
}
.reference-preview {
  width: 100%; height: 100%;
  object-fit: cover;
}
.reference-delete {
  position: absolute; bottom: 0.75rem; left: 50%; transform: translateX(-50%);
  width: 220px; height: 35px;
  background: rgba(0,0,0,0.5);
  border: 1px solid #fff;
  border-radius: 10px;
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background 0.15s;
}
.reference-delete:hover { background: rgba(0,0,0,0.7); }

/* ── Info bar ────────────────────────────────────────── */
.info-bar {
  flex: 1;
  font-size: 1rem;
  color: var(--color-accent);
}

/* ── Prompt grid (textarea + reference side by side) ── */
.prompt-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.75rem;
}

/* ── Prompt textarea ────────────────────────────────── */
.prompt-textarea {
  width: 100%;
  min-height: 6rem;
  resize: none;
  background: #DFDFDF;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-text-dark);
  outline: none;
  transition: border-color 0.15s;
}
.prompt-textarea::placeholder { color: rgba(12, 22, 29, 0.5); }
.prompt-textarea:focus { border-color: var(--color-accent); box-shadow: 0 0 0 2px rgba(250,101,0,0.2); }

/* ── Action row (InfoBar + Generate button) ──────────── */
.action-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.time-bar {
  flex: 1;
  font-size: 1rem;
  color: var(--color-text-dark);
}
.generate-btn {
  height: 2.25rem;
  padding: 0 1.5rem;
  min-width: 270px;
  background: var(--color-accent);
  color: #fff;
  border-radius: 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.generate-btn:hover:not(:disabled) { background: #e05800; }
.generate-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Prompt block: action row aligns to the same 2fr 1fr grid as prompt-grid */
#promptBlock .action-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.75rem;
}
#promptBlock .generate-btn {
  min-width: unset;
  width: 100%;
}

/* ── Results ─────────────────────────────────────────── */
.results {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.result-group {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.result-group:not(:first-child) {
  border-top: 2px solid var(--color-accent);
  padding-top: 1.5rem;
}
.result-group__progress {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-dark);
}
.result-group__error {
  color: var(--color-bad);
  font-size: 0.8125rem;
}
.result-group__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

/* Image card */
.image-card {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.image-card__frame {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-input-bg);
}
.image-card__frame--loading { cursor: default; background: rgba(255,255,255,0.15); backdrop-filter: blur(8px); box-shadow: 0 0 0 1px rgba(0,0,0,0.1); }
.image-card__frame--error { background: #3d2622; border: 1px solid rgba(200,81,0,0.3); cursor: default; }
.image-card__frame--ready { cursor: pointer; }
.image-card img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.image-card__lottie {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.image-card__lottie > div {
  width: 90px; height: 90px;
}
.image-card__error-icon {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.375rem;
}
.error-circle {
  width: 2.5rem; height: 2.5rem;
  border-radius: 50%;
  background: rgba(200,81,0,0.2);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-bad);
}
.image-card__error-text {
  font-size: 0.75rem;
  color: var(--color-bad);
  text-align: center;
  padding: 0 0.25rem;
}
.image-card__actions {
  display: flex;
  gap: 0.375rem;
  justify-content: center;
}
.action-btn {
  width: 1.75rem; height: 1.75rem;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  color: #fff;
}
.action-btn--bad { background: rgba(200,81,0,0.5); }
.action-btn--bad:hover, .action-btn--bad--active { background: var(--color-bad); }
.action-btn--good { background: rgba(2,159,134,0.5); }
.action-btn--good:hover, .action-btn--good--active { background: var(--color-good); }
.action-btn--download { background: var(--color-action); }
.action-btn--download:hover { background: #1f3c4d; }
.action-btn--feedback { background: var(--color-action); border: none; cursor: pointer; }
.action-btn--feedback:hover { background: #1f3c4d; }
.action-btn--feedback img { width: 16px; height: 16px; }

/* ── Modal ───────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.75);
}
.modal__content {
  position: relative;
  z-index: 1;
  display: flex; flex-direction: column;
  max-width: min(90vw, 56rem);
  max-height: 90vh;
  background: transparent;
}
.modal__close {
  position: absolute; top: 0.5rem; right: 0.5rem;
  z-index: 2;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.modal__close:hover { background: rgba(0,0,0,0.8); }
.modal__image-wrap {
  flex: 1;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal__image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}
.modal__actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0 1rem 1rem;
}
.modal__btn {
  display: flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  transition: background 0.15s;
  white-space: nowrap;
}
.modal__btn--bad { background: rgba(200,81,0,0.5); }
.modal__btn--bad:hover, .modal__btn--bad--active { background: var(--color-bad); }
.modal__btn--good { background: rgba(2,159,134,0.5); }
.modal__btn--good:hover, .modal__btn--good--active { background: var(--color-good); }
.modal__btn--feedback { background: var(--color-action); }
.modal__btn--feedback:hover { background: #1f3c4d; }
.modal__btn--feedback img { filter: brightness(0) invert(1); }
.modal__btn--download { background: var(--color-action); }
.modal__btn--download:hover { background: #1f3c4d; }

/* ── Error banner ────────────────────────────────────── */
.error-banner {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 300;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
  background: rgba(166, 39, 39, 0.9);
  color: #fff;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}
.error-banner__content {
  display: flex; align-items: center; gap: 0.625rem; flex: 1;
}
.error-banner__close {
  color: #fff; line-height: 0; flex-shrink: 0;
  transition: opacity 0.15s; opacity: 0.9;
}
.error-banner__close:hover { opacity: 1; }

/* ── Error tooltip (on failed image hover in progress line) ── */
.result-error-trigger {
  color: var(--color-bad);
  cursor: help;
}
.result-group__sep {
  margin: 0 0.5rem;
}
.result-group__sep--accent { color: var(--color-accent); }
.error-tooltip {
  position: fixed;
  z-index: 250;
  width: 18rem;
  background: rgba(255,255,255,0.92);
  border: 2px solid var(--color-accent);
  border-radius: 0.5rem;
  padding: 0.75rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.error-tooltip__arrow {
  position: absolute;
  right: 100%; top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-right: 8px solid var(--color-accent);
}
.error-tooltip__item + .error-tooltip__item {
  border-top: 1px solid rgba(250,101,0,0.15);
  padding-top: 0.375rem;
  margin-top: 0.25rem;
}
.error-tooltip__title {
  color: var(--color-accent);
  font-size: 0.75rem;
  font-weight: 600;
}
.error-tooltip__name {
  color: var(--color-text-dark);
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 0.125rem;
}
.error-tooltip__reason {
  color: rgba(12,22,29,0.6);
  font-size: 0.6875rem;
  margin-top: 0.125rem;
}

/* ── Example block ───────────────────────────────────── */
.example-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
}
.example-block__inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  border: 1px solid var(--color-accent);
  border-radius: 30px;
  padding: 1.5rem;
  width: 400px;
  height: 310px;
  max-width: 100%;
}
.example-block__img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  margin-bottom: 1rem;
}
.example-block__text {
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-dark);
  font-weight: 500;
  padding: 0 1rem;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
  body { overflow: auto; }

  .layout {
    flex-direction: column;
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
    padding: 1rem;
    padding-top: calc(56px + 1rem);
    gap: 0.75rem;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 60vh;
  }

  /* Info bar: centered in remaining space next to the empty slot */
  .info-bar {
    font-size: 0.8125rem;
    text-align: center;
  }

  /* Upload slots: constrain to block width, scroll if slots overflow */
  .upload-row:has(#infoBar.hidden) .upload-slots {
    width: 100%;
  }
  .upload-slots {
    flex-shrink: 1;
    min-width: 0;
    overflow-x: auto;
  }

  /* Generate button: full-width, no fixed min-width */
  .generate-btn {
    min-width: unset;
    width: 100%;
  }

  /* Prompt block action row: stack vertically on mobile */
  #promptBlock .action-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  #promptBlock .generate-btn {
    width: 100%;
  }

  /* Style block action row: same treatment */
  #styleBlock .action-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  #styleBlock .generate-btn {
    width: 100%;
  }

  /* Example block: fit mobile width */
  .example-block__inner {
    width: 100%;
    height: auto;
    min-height: 240px;
  }
}
