:root {
  color-scheme: dark;
  --bg: #020711;
  --bg-soft: #07101d;
  --panel: rgba(8, 15, 28, 0.84);
  --panel-strong: rgba(12, 19, 35, 0.94);
  --line: rgba(93, 135, 210, 0.24);
  --line-strong: rgba(78, 141, 255, 0.44);
  --ink: #f7fbff;
  --muted: #a8b5cb;
  --soft: #7a879b;
  --blue: #1874d9;
  --blue-strong: #0d5fc7;
  --cyan: #56a7ff;
  --shadow: rgba(12, 52, 120, 0.26);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-width: 320px;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background:
    linear-gradient(180deg, #01060f 0%, #020914 54%, #020813 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 88px 88px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.48), transparent 70%);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:disabled {
  cursor: progress;
  opacity: 0.72;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  fill: currentColor;
}

.creator-shell {
  width: min(100% - 42px, 1600px);
  margin: 10px auto 16px;
}

.config-banner {
  display: flex;
  gap: 14px;
  align-items: center;
  border: 1px solid rgba(75, 104, 165, 0.28);
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 12px;
  color: #d9e7fb;
  background: rgba(8, 15, 28, 0.82);
}

.config-banner[hidden] {
  display: none;
}

.config-banner svg {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: #63a6ff;
}

.config-banner strong {
  display: block;
  color: #f4f8ff;
  font-size: 14px;
}

.config-banner p {
  margin: 3px 0 0;
  color: #bfd0e6;
  font-size: 13px;
  line-height: 1.4;
}

.config-banner code {
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.38);
  font-size: 12px;
}

.config-banner a {
  color: #8bc2ff;
  text-decoration: underline;
}

/* ───────── Верхняя единая панель ───────── */
.app-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  min-height: 56px;
  padding: 4px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 15, 28, 0.84);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.brand {
  display: inline-flex;
  align-items: center;
}

.brand-logo {
  display: block;
  width: auto;
  height: 44px;
}

.project-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
  justify-content: center;
}

.project-title input {
  width: min(100%, 280px);
  border: 0;
  padding: 4px 10px;
  border-radius: 8px;
  color: #f7f8ff;
  background: transparent;
  outline: none;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  transition: background 160ms ease;
}

.project-title input:hover,
.project-title input:focus {
  background: rgba(255, 255, 255, 0.04);
}

.page-status {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid rgba(86, 167, 255, 0.28);
  border-radius: 999px;
  padding: 0 12px;
  color: #d9ecff;
  background:
    linear-gradient(180deg, rgba(24, 116, 217, 0.22), rgba(8, 18, 36, 0.92)),
    rgba(13, 25, 46, 0.9);
  font-size: 13px;
  white-space: nowrap;
}

.account-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.credit-pill,
.icon-action,
.avatar-button,
.tool-button,
.button-gradient {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid rgba(83, 144, 255, 0.2);
  border-radius: 10px;
  background: rgba(12, 22, 42, 0.82);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.credit-pill {
  padding: 0 14px;
  color: #f2f3ff;
  font-weight: 700;
  font-size: 13px;
}

.credit-pill svg {
  width: 16px;
  height: 16px;
  color: #63a6ff;
}

.icon-action {
  width: 34px;
  height: 34px;
  padding: 0;
}

.icon-action.small {
  width: 32px;
  height: 32px;
  min-height: 32px;
}

.icon-action svg,
.tool-button svg,
.button-gradient svg {
  width: 18px;
  height: 18px;
}

.avatar-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-color: rgba(83, 144, 255, 0.34);
  background:
    linear-gradient(180deg, rgba(24, 116, 217, 0.3), rgba(11, 26, 50, 0.92)),
    #121833;
}

.avatar {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #ffe1c2;
  font-weight: 900;
  font-size: 14px;
}

.credit-pill:hover,
.icon-action:hover,
.avatar-button:hover,
.tool-button:hover,
.button-gradient:hover {
  transform: translateY(-1px);
  border-color: rgba(87, 155, 255, 0.5);
}

/* ───────── Поповеры (профиль/бургер) ───────── */
.profile-wrap,
.burger-wrap {
  position: relative;
}

.popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 240px;
  border: 1px solid rgba(75, 104, 165, 0.26);
  border-radius: 16px;
  padding: 6px;
  background: rgba(8, 15, 28, 0.98);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.popover[hidden] {
  display: none;
}

.popover-header {
  display: grid;
  gap: 2px;
  padding: 10px 12px 12px;
  border-bottom: 1px solid rgba(75, 104, 165, 0.16);
  margin-bottom: 4px;
}

.popover-header strong {
  font-size: 14px;
}

.popover-header span {
  color: var(--muted);
  font-size: 12px;
}

.save-status {
  min-width: 94px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.save-status.is-saving {
  color: #8bc2ff;
}

.save-status.is-saved {
  color: #7bdc9b;
}

.save-status.is-error {
  color: #ff9b9b;
}

.popover button,
.popover-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  color: #e8eaff;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
}

.popover button svg,
.popover-row svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: #63a6ff;
}

.popover button:hover,
.popover-row:hover {
  background: rgba(20, 41, 74, 0.72);
}

.popover button[disabled] {
  color: var(--soft);
  cursor: not-allowed;
  opacity: 0.5;
}

.popover button[disabled]:hover {
  background: transparent;
}

.popover-divider {
  height: 1px;
  margin: 4px 6px;
  background: rgba(75, 104, 165, 0.16);
}

.popover-row span {
  flex: 1;
}

.popover-row select {
  min-height: 28px;
  width: 80px;
  padding: 0 6px;
  font-size: 12px;
}

/* ───────── Рабочая область ───────── */
.workspace {
  display: grid;
  grid-template-columns: 440px minmax(640px, 1fr) 480px;
  gap: 16px;
  margin-top: 14px;
}

.right-stack {
  --side-pad: 18px;
  --side-control-gap: 12px;

  display: grid;
  gap: 12px;
  align-self: start;
  min-width: 0;
}

.side-panel {
  --side-pad: 18px;
  --side-control-gap: 12px;

  display: flex;
  flex-direction: column;
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(8, 15, 28, 0.82);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.left-panel {
  flex: 1;
  min-height: 0;
}

/* ───────── Левая панель: верхние выпадающие кнопки ───────── */
.left-panel-head {
  position: relative;
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px var(--side-pad) 12px;
  border-bottom: 1px solid var(--line);
}

.dropdown {
  position: relative;
  min-width: 0;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(83, 144, 255, 0.24);
  border-radius: 12px;
  background: rgba(12, 22, 42, 0.82);
  color: #e8eaff;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease;
}

.dropdown-toggle:hover {
  border-color: rgba(87, 155, 255, 0.5);
  background: rgba(15, 28, 50, 0.92);
}

.dropdown-toggle[aria-expanded="true"] {
  border-color: rgba(87, 155, 255, 0.78);
  background: rgba(16, 44, 82, 0.54);
  box-shadow: 0 0 24px rgba(24, 116, 217, 0.16);
}

.dropdown-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dropdown-value {
  flex: 1;
  overflow: hidden;
  color: #f5f6ff;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-caret {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: #8aa1c6;
  transition: transform 160ms ease;
}

.dropdown-toggle[aria-expanded="true"] .dropdown-caret {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid rgba(75, 104, 165, 0.32);
  border-radius: 14px;
  background: rgba(8, 15, 28, 0.98);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.dropdown-menu.wide {
  right: auto;
  min-width: 100%;
  width: max(100%, 280px);
  gap: 6px;
}

.dropdown-menu[hidden] {
  display: none;
}

.dropdown-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #e8eaff;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease;
}

.dropdown-item:hover {
  background: rgba(20, 41, 74, 0.72);
}

.dropdown-item.is-selected {
  border-color: rgba(87, 155, 255, 0.6);
  color: #ffffff;
  background: rgba(17, 57, 113, 0.52);
}

.model-option {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(75, 104, 165, 0.22);
  border-radius: 12px;
  background: rgba(12, 22, 42, 0.82);
  color: #cdd1df;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease;
}

.model-option:hover {
  border-color: rgba(87, 155, 255, 0.5);
  background: rgba(15, 28, 50, 0.92);
}

.model-option.is-selected {
  border-color: rgba(87, 155, 255, 0.78);
  background: rgba(16, 44, 82, 0.54);
  box-shadow: 0 0 24px rgba(24, 116, 217, 0.16);
}

.model-option-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.model-option-head strong {
  color: #f5f6ff;
  font-size: 14px;
}

.model-option-head em {
  color: var(--muted);
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ───────── Левая панель: история и AI-кнопка ───────── */
.story-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: var(--side-pad);
}

.story-wrap {
  position: relative;
}

.story-wrap textarea {
  display: block;
  width: 100%;
  resize: none;
}

.story-enhance {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(83, 144, 255, 0.34);
  border-radius: 50%;
  background:
    linear-gradient(135deg, rgba(28, 122, 230, 0.85), rgba(15, 95, 199, 0.78)),
    rgba(20, 24, 48, 0.9);
  box-shadow: 0 12px 28px rgba(14, 78, 171, 0.28);
  color: #ffffff;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.story-enhance:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(14, 78, 171, 0.4);
}

.story-enhance svg {
  width: 18px;
  height: 18px;
}

.field-label {
  display: block;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid rgba(75, 104, 165, 0.2);
  border-radius: 12px;
  color: #f5f6ff;
  background: rgba(5, 11, 22, 0.88);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 14px 16px;
  line-height: 1.55;
}

select,
input {
  min-height: 42px;
  padding: 0 12px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(87, 155, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(24, 116, 217, 0.12);
}

.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 16px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
}

.model-specs {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.model-specs li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.spec-bar {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.spec-bar i {
  width: 16px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.spec-bar.level-1 i:nth-child(1),
.spec-bar.level-2 i:nth-child(-n + 2),
.spec-bar.level-3 i {
  background: var(--bar-color, rgba(255, 255, 255, 0.5));
}

.spec-bar.good {
  --bar-color: #42d686;
}

.spec-bar.good.level-3 i {
  box-shadow: 0 0 6px rgba(66, 214, 134, 0.45);
}

.spec-bar.mid {
  --bar-color: #ffc24e;
}

.spec-bar.bad {
  --bar-color: #ff6b6b;
}

.model-summary {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

/* ───────── Закреплённая CTA ───────── */
.cta-footer {
  margin-top: auto;
  padding: var(--side-pad);
  border-top: 1px solid var(--line);
  background: rgba(6, 12, 24, 0.58);
}

.button-gradient {
  border-color: transparent;
  color: #ffffff;
  background:
    linear-gradient(135deg, #1c7ae6, #0f5fc7),
    rgba(20, 24, 48, 0.9);
  box-shadow: 0 18px 40px rgba(14, 78, 171, 0.28);
  font-weight: 800;
  font-size: 14px;
}

.button-gradient.full {
  width: 100%;
  min-height: 48px;
}

.button-gradient.ghost-gradient {
  background:
    linear-gradient(135deg, rgba(28, 122, 230, 0.22), rgba(15, 95, 199, 0.2)),
    rgba(20, 24, 48, 0.9);
  box-shadow: none;
  border-color: rgba(83, 144, 255, 0.26);
}

.continue-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  padding: 11px 16px;
  border: 1px solid rgba(83, 144, 255, 0.32);
  border-radius: 12px;
  background: rgba(12, 22, 42, 0.82);
  color: #cfe2ff;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, opacity 160ms ease;
}

.continue-button:hover:not(:disabled) {
  border-color: rgba(86, 167, 255, 0.6);
  color: #ffffff;
  background: rgba(20, 40, 76, 0.88);
}

.continue-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.continue-button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.cost-note {
  margin: 10px 0 0;
  color: #9fa5ba;
  text-align: center;
  font-size: 12px;
}

/* ───────── Холст и страницы ───────── */
.comic-stage {
  min-width: 0;
}

.comic-canvas {
  position: relative;
  display: grid;
  overflow: hidden;
  width: min(100%, 615px);
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(24, 116, 217, 0.12), transparent 40%),
    #040a14;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.34);
  transition: width 180ms ease;
}

.comic-canvas img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.comic-loading,
.comic-empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: rgba(3, 5, 13, 0.76);
  text-align: center;
}

.comic-loading[hidden],
.comic-empty[hidden],
.auth-overlay[hidden],
.toast[hidden] {
  display: none;
}

.comic-loading span {
  width: 54px;
  height: 54px;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: #2f8cff;
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.comic-loading strong {
  margin-top: 88px;
  color: #e8e9ff;
}

.comic-empty {
  padding: 30px;
  color: var(--muted);
}

.comic-empty svg {
  width: 48px;
  height: 48px;
  color: #63a6ff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page-strip {
  display: flex;
  align-items: flex-start;
  gap: var(--side-control-gap);
  margin: 0;
  padding: 10px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(13, 25, 46, 0.86), rgba(6, 12, 24, 0.96)),
    rgba(8, 10, 24, 0.9);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.22);
}

.page-thumb-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.page-thumb-remove {
  display: grid;
  place-items: center;
  width: 28px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 99, 99, 0.32);
  border-radius: 8px;
  background: rgba(40, 12, 14, 0.72);
  color: #ff8a8a;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.page-thumb-remove:hover {
  border-color: rgba(255, 99, 99, 0.7);
  background: rgba(82, 18, 22, 0.88);
  color: #ffd2d2;
  transform: translateY(-1px);
}

.page-thumb-remove svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.page-thumb,
.add-page {
  position: relative;
  display: grid;
  width: 66px;
  min-width: 66px;
  aspect-ratio: 0.82;
  place-items: center;
  border: 1px solid rgba(83, 144, 255, 0.22);
  border-radius: 12px;
  background: rgba(8, 15, 28, 0.88);
  cursor: pointer;
  overflow: hidden;
  transition: transform 160ms, border-color 160ms, box-shadow 160ms;
}

.page-thumb:hover,
.add-page:hover {
  transform: translateY(-1px);
  border-color: rgba(87, 155, 255, 0.54);
}

.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page-thumb span {
  position: absolute;
  bottom: 4px;
  left: 50%;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(139, 194, 255, 0.32);
  background:
    linear-gradient(180deg, rgba(24, 116, 217, 0.92), rgba(13, 95, 199, 0.88)),
    rgba(3, 5, 13, 0.76);
  color: #f7fbff;
  box-shadow: 0 8px 18px rgba(12, 52, 120, 0.28);
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 800;
}

.page-thumb.is-active {
  border-color: rgba(87, 155, 255, 0.92);
  box-shadow: 0 0 26px rgba(18, 116, 217, 0.26);
}

.add-page svg {
  width: 24px;
  height: 24px;
  color: #d8d9e7;
}

/* ───────── Правая панель — аккордеон ───────── */
.right-panel {
  flex: 1;
  min-height: 0;
}

.right-panel-head {
  padding: 14px var(--side-pad) 12px;
  border-bottom: 1px solid var(--line);
}

.right-panel-head h2 {
  margin: 0;
  color: #f5f6ff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.accordion-list {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.accordion {
  border-bottom: 1px solid var(--line);
}

.accordion[open] {
  background: rgba(6, 12, 24, 0.42);
}

.accordion > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px var(--side-pad);
  color: #e8eaff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  list-style: none;
  user-select: none;
}

.accordion > summary::-webkit-details-marker {
  display: none;
}

.accordion > summary:hover {
  background: rgba(20, 41, 74, 0.32);
}

.accordion-caret {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: #8aa1c6;
  transition: transform 160ms ease;
}

.accordion[open] > summary .accordion-caret {
  transform: rotate(180deg);
}

.accordion-body {
  display: grid;
  gap: 12px;
  padding: 4px var(--side-pad) 16px;
}

.accordion-body .hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.scene-toolbar {
  display: grid;
  gap: var(--side-control-gap);
}

.full-width {
  width: 100%;
}

.tool-button {
  min-width: 56px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 700;
}

.tool-button.ghost {
  border-color: rgba(83, 144, 255, 0.24);
  background: rgba(12, 22, 42, 0.82);
}

.scene-list {
  display: grid;
  gap: var(--side-control-gap);
}

.scene-list:empty {
  display: none;
}

/* ───────── Персонажи ───────── */
.character-list {
  display: grid;
  gap: var(--side-control-gap);
}

.character-list:empty {
  display: none;
}

.character-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(83, 144, 255, 0.18);
  border-radius: 12px;
  background: rgba(8, 15, 28, 0.62);
}

.character-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.character-card-head input {
  flex: 1;
  min-height: 38px;
}

.character-card textarea {
  min-height: 60px;
  resize: vertical;
}

.character-reference {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 8px;
  align-items: center;
}

.character-reference-preview {
  display: grid;
  width: 48px;
  height: 48px;
  overflow: hidden;
  place-items: center;
  border: 1px solid rgba(83, 144, 255, 0.22);
  border-radius: 8px;
  background: rgba(6, 12, 24, 0.72);
}

.character-reference-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.character-reference-preview svg {
  width: 22px;
  height: 22px;
  color: var(--muted);
}

.character-reference-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.character-reference-upload span,
.character-reference-clear {
  display: grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid rgba(83, 144, 255, 0.22);
  border-radius: 8px;
  background: rgba(12, 22, 42, 0.82);
  color: #f5f6ff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.character-reference-clear {
  padding: 0 10px;
}

.character-reference-upload span:hover,
.character-reference-clear:hover {
  border-color: rgba(87, 155, 255, 0.5);
}

.character-remove {
  display: grid;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  place-items: center;
  border: 1px solid rgba(255, 107, 107, 0.24);
  border-radius: 8px;
  background: rgba(40, 14, 14, 0.42);
  color: #ffb5b5;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.character-remove:hover {
  border-color: rgba(255, 107, 107, 0.6);
  background: rgba(60, 18, 18, 0.6);
}

.character-remove svg {
  width: 16px;
  height: 16px;
}

/* ───────── Кол-во страниц ───────── */
.page-count-control {
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
}

.step-btn {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(83, 144, 255, 0.24);
  border-radius: 10px;
  background: rgba(12, 22, 42, 0.82);
  color: #f5f6ff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  transition: border-color 160ms ease, background 160ms ease;
}

.step-btn:hover {
  border-color: rgba(87, 155, 255, 0.5);
  background: rgba(15, 28, 50, 0.92);
}

#pageCountInput {
  width: 64px;
  text-align: center;
  font-weight: 800;
  font-size: 16px;
  appearance: textfield;
  -moz-appearance: textfield;
}

#pageCountInput::-webkit-outer-spin-button,
#pageCountInput::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.scene-empty {
  border: 1px dashed rgba(83, 144, 255, 0.28);
  border-radius: 12px;
  padding: 16px;
  color: var(--muted);
  background: rgba(6, 12, 24, 0.52);
  font-size: 13px;
  line-height: 1.45;
}

.scene-item {
  display: grid;
  grid-template-columns: 22px 64px 1fr 32px;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(83, 144, 255, 0.1);
  border-radius: 12px;
  padding: 8px;
  background: rgba(8, 15, 28, 0.62);
  cursor: pointer;
  transition: background 160ms, border-color 160ms;
}

.scene-item:hover {
  background: rgba(14, 27, 49, 0.78);
  border-color: rgba(83, 144, 255, 0.24);
}

.scene-item.is-selected {
  border-color: rgba(87, 155, 255, 0.84);
  background: rgba(17, 57, 113, 0.26);
}

.drag-handle {
  border: 0;
  color: #6f758d;
  background: transparent;
  cursor: grab;
  padding: 0;
}

.drag-handle svg {
  width: 18px;
  height: 18px;
}

.scene-item img {
  width: 64px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
}

.scene-item h2 {
  margin: 0 0 3px;
  font-size: 13px;
}

.scene-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.selected-scene {
  display: grid;
  gap: 8px;
  padding: 14px 0 0;
  margin-top: 4px;
  border-top: 1px solid var(--line);
}

.selected-scene[hidden] {
  display: none;
}

.selected-scene header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.selected-scene h3 {
  margin: 0;
  color: #f5f6ff;
  font-size: 14px;
  font-weight: 800;
}

.selected-scene header span,
.selected-scene label span {
  color: var(--muted);
  font-size: 12px;
}

.selected-scene label {
  display: block;
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--side-control-gap);
}

.selected-scene .button-gradient.full {
  margin-top: var(--side-control-gap);
}

.inline-field textarea {
  min-height: 72px;
}

/* ───────── Индикация загрузки кнопки ───────── */
.is-busy {
  position: relative;
  opacity: 0.72;
  pointer-events: none;
}

.is-busy::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

/* ───────── Тост ───────── */
.toast {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 40;
  max-width: 420px;
  border: 1px solid rgba(83, 144, 255, 0.32);
  border-radius: 14px;
  padding: 12px 16px;
  color: #f5f6ff;
  background: rgba(8, 15, 28, 0.96);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  font-size: 13px;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(3, 7, 15, 0.78);
  backdrop-filter: blur(8px);
}

.auth-panel {
  display: grid;
  width: min(100%, 420px);
  gap: 16px;
  border: 1px solid rgba(83, 144, 255, 0.28);
  border-radius: 14px;
  padding: 24px;
  color: #f7fbff;
  background: rgba(8, 15, 28, 0.98);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.52);
  text-align: center;
}

.auth-mark {
  display: grid;
  width: 46px;
  height: 46px;
  margin: 0 auto;
  border: 1px solid rgba(83, 144, 255, 0.28);
  border-radius: 12px;
  place-items: center;
  background: rgba(24, 116, 217, 0.16);
  color: #8bc2ff;
}

.auth-mark svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.auth-panel h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.auth-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auth-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid rgba(83, 144, 255, 0.3);
  border-radius: 10px;
  color: #f7fbff;
  background: rgba(12, 25, 46, 0.96);
  font-weight: 800;
  text-decoration: none;
}

.auth-button:hover {
  border-color: rgba(87, 155, 255, 0.58);
}

.auth-error {
  color: #ffb3b3;
  font-size: 13px;
}

.creator-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  margin: 22px 0 0;
  border-top: 1px solid var(--line);
  padding: 14px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.creator-footer p {
  margin: 0;
  color: #7f8a9e;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  color: #c7d0df;
  font-weight: 600;
}

.footer-links a {
  color: inherit;
  transition: color 160ms ease;
}

.footer-links a:hover {
  color: #ffffff;
}

.footer-links span {
  color: #657189;
}

/* ───────── Адаптив ───────── */
@media (max-width: 1640px) {
  .workspace {
    grid-template-columns: 410px minmax(0, 1fr) 450px;
  }

  .comic-canvas {
    width: min(100%, 590px);
  }
}

@media (max-width: 1380px) {
  .workspace {
    grid-template-columns: 360px minmax(0, 1fr) 390px;
  }

  .comic-canvas {
    width: min(100%, 510px);
  }
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 350px minmax(0, 1fr) 380px;
    gap: 12px;
  }
}

@media (max-width: 1140px) {
  .app-bar {
    grid-template-columns: auto auto;
    row-gap: 10px;
    padding: 12px 16px;
  }

  .project-title {
    grid-column: 1 / -1;
    order: 3;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .comic-stage {
    order: -1;
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .creator-shell {
    width: min(100% - 20px, 640px);
  }

  .project-title input {
    width: min(100%, 200px);
    font-size: 16px;
  }

  .save-status {
    width: 100%;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }

  .comic-canvas {
    aspect-ratio: 0.82;
  }

  .left-panel-head {
    grid-template-columns: 1fr;
  }

  .scene-item {
    grid-template-columns: 20px 56px 1fr;
  }

  .scene-item .icon-action {
    display: none;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
  }

  .creator-footer {
    justify-content: flex-start;
    text-align: left;
  }

  .footer-links {
    justify-content: flex-start;
  }
}
