:root {
  --bg: #08080e;
  --bg-soft: #0f0f18;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f6f4fb;
  --muted: #a09daf;
  --accent: #ffd166;
  --accent-2: #ff9f43;
  --accent-ink: #1b1405;
  --danger: #ff6b7a;
  --ok: #6ee7b7;
  --radius: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 88% -12%, rgba(255, 209, 102, 0.16), transparent 62%),
    radial-gradient(760px 520px at -12% 6%, rgba(124, 92, 255, 0.17), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(126px + env(safe-area-inset-bottom));
}

/* ---------- шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 23px;
  line-height: 1;
  box-shadow: 0 10px 28px rgba(255, 159, 67, 0.26);
  transform: rotate(-3deg);
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 19px;
  transition: transform 0.15s ease, background 0.2s ease;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.spinning { animation: spin 0.8s linear infinite; }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.3), rgba(124, 92, 255, 0.3));
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- лимит ---------- */

.quota-card {
  padding: 14px 16px 13px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 209, 102, 0.18);
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.11), rgba(124, 92, 255, 0.08)),
    rgba(255, 255, 255, 0.02);
  margin-bottom: 12px;
  animation: rise 0.4s both;
}

.quota-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.quota-top strong { font-size: 24px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

.eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.quota-bar {
  height: 6px;
  margin: 10px 0 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.quota-bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.quota-bar.low i { background: linear-gradient(90deg, #ff6b7a, #ff9f43); }

.quota-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- панели ---------- */

.panel {
  padding: 15px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.064), rgba(255, 255, 255, 0.032));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: rise 0.45s both;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { font-size: 11px; color: var(--muted); text-align: right; line-height: 1.35; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 99px;
  background: rgba(255, 209, 102, 0.13);
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

/* ---------- модели ---------- */

.model-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

.model-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 11px 10px 10px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  text-align: left;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}
.model-card:active { transform: scale(0.98); }
.model-card strong { font-size: 13px; font-weight: 650; letter-spacing: -0.01em; }
.model-card span { font-size: 10.5px; color: var(--muted); }
.model-card.active {
  border-color: rgba(255, 209, 102, 0.55);
  background: rgba(255, 209, 102, 0.11);
  box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.12);
}
.model-card.active span { color: rgba(255, 209, 102, 0.85); }

/* ---------- пропорции ---------- */

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 7px;
}

.ratio-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 56px;
  padding: 7px 3px 6px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease,
    transform 0.12s ease;
}
.ratio-btn:active { transform: scale(0.95); }
.ratio-btn.active {
  color: var(--accent);
  border-color: rgba(255, 209, 102, 0.5);
  background: rgba(255, 209, 102, 0.1);
}
.ratio-shape {
  display: block;
  width: 22px;
  height: 22px;
  border: 1.6px solid currentColor;
  border-radius: 3px;
  opacity: 0.8;
}
.ratio-btn.active .ratio-shape { background: rgba(255, 209, 102, 0.15); opacity: 1; }

/* ---------- разрешение ---------- */

.resolution-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

.res-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 4px 8px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease,
    transform 0.12s ease;
}
.res-btn:active { transform: scale(0.96); }
.res-btn span { font-size: 9.5px; font-weight: 500; color: var(--muted); }
.res-btn.active {
  border-color: rgba(255, 209, 102, 0.5);
  background: rgba(255, 209, 102, 0.11);
  color: var(--accent);
}
.res-btn.active span { color: rgba(255, 209, 102, 0.8); }

/* ---------- промпт ---------- */

.prompt-panel { padding-bottom: 13px; }

#prompt {
  width: 100%;
  min-height: 112px;
  padding: 12px 13px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
#prompt::placeholder { color: rgba(160, 157, 175, 0.75); }
#prompt:focus { border-color: rgba(255, 209, 102, 0.55); background: rgba(0, 0, 0, 0.3); }

.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.example {
  padding: 6px 9px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.example:active { color: var(--accent); border-color: rgba(255, 209, 102, 0.5); }

/* ---------- ошибка ---------- */

.error-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 107, 122, 0.35);
  background: rgba(255, 107, 122, 0.1);
  color: #ffb3ba;
  font-size: 12px;
  line-height: 1.45;
  animation: rise 0.25s both;
}
.error-close {
  margin-left: auto;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #ffb3ba;
  font-size: 15px;
  line-height: 1;
}

/* ---------- загрузка ---------- */

.loading-card {
  padding: 13px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  animation: rise 0.3s both;
}

.shimmer {
  height: 190px;
  border-radius: 15px;
  background: linear-gradient(
    100deg,
    rgba(255, 255, 255, 0.045) 20%,
    rgba(255, 255, 255, 0.1) 38%,
    rgba(255, 255, 255, 0.045) 56%
  );
  background-size: 220% 100%;
  animation: shimmer 1.6s linear infinite;
}

.loading-text { display: flex; align-items: center; gap: 11px; margin-top: 12px; }
.loading-text b { display: block; font-size: 13px; font-weight: 600; }
.loading-text small { display: block; margin-top: 2px; font-size: 10.5px; color: var(--muted); }

.spinner {
  width: 23px;
  height: 23px;
  flex: 0 0 23px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 209, 102, 0.22);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

/* ---------- результат ---------- */

.result-card {
  padding: 14px;
  margin-bottom: 12px;
  border-radius: 22px;
  border: 1px solid rgba(255, 209, 102, 0.22);
  background: linear-gradient(180deg, rgba(255, 209, 102, 0.07), rgba(255, 255, 255, 0.035));
  box-shadow: var(--shadow);
  animation: rise 0.45s both;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.result-head h2 {
  margin: 3px 0 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: none;
  color: var(--text);
}

.image-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border-radius: 16px;
  overflow: hidden;
  background: #050509;
}
.image-frame img {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: contain;
}

.result-prompt {
  margin: 10px 2px;
  font-size: 12.5px;
  line-height: 1.5;
  color: rgba(246, 244, 251, 0.78);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.action-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }

.action {
  padding: 11px 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
}
.action:active { transform: scale(0.97); }
.action.accent {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  box-shadow: 0 8px 22px rgba(255, 159, 67, 0.22);
}
.action.ghost { background: transparent; color: var(--muted); }
.action:disabled { opacity: 0.45; cursor: default; transform: none; }

/* ---------- история ---------- */

.history-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.history-strip::-webkit-scrollbar { display: none; }

.history-item {
  position: relative;
  flex: 0 0 92px;
  width: 92px;
  height: 92px;
  padding: 0;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #050509;
  overflow: hidden;
  scroll-snap-align: start;
}
.history-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.history-item .ratio-tag {
  position: absolute;
  left: 5px;
  bottom: 5px;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.footer-note {
  margin: 18px 10px 8px;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--muted);
}

/* ---------- нижняя кнопка ---------- */

.cta-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: 100%;
  max-width: 560px;
  transform: translateX(-50%);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 58%, rgba(8, 8, 14, 0.86) 82%, transparent);
  pointer-events: none;
}
.cta-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 9px 10px 9px 13px;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: rgba(20, 20, 32, 0.94);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.cta-cost { display: flex; flex-direction: column; gap: 2px; min-width: 92px; }
.cta-cost span { font-size: 9px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.cta-cost b { font-size: 12.5px; font-weight: 650; white-space: nowrap; }
.cta-cost b small { font-weight: 500; color: var(--muted); }

.generate-btn {
  flex: 1;
  min-height: 50px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 750;
  letter-spacing: -0.01em;
  box-shadow: 0 10px 26px rgba(255, 159, 67, 0.24);
  transition: transform 0.12s ease, opacity 0.15s ease, filter 0.15s ease;
}
.generate-btn:active { transform: scale(0.98); }
.generate-btn:disabled { opacity: 0.5; cursor: default; transform: none; filter: saturate(0.6); }
.generate-btn.loading { position: relative; color: transparent; }
.generate-btn.loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  border: 2.5px solid rgba(27, 20, 5, 0.25);
  border-top-color: var(--accent-ink);
  animation: spin 0.8s linear infinite;
}

/* ---------- заглушка доступа ---------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 22px 22px;
  text-align: center;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
  box-shadow: var(--shadow);
  animation: rise 0.45s both;
}
.brand-mark.big {
  width: 66px;
  height: 66px;
  flex: 0 0 66px;
  margin: 0 auto 16px;
  border-radius: 21px;
  font-size: 35px;
}
.gate-card h1 { margin: 0 0 10px; font-size: 20px; letter-spacing: -0.02em; }
.gate-card p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.55; }
.gate-hint {
  margin-top: 14px !important;
  padding: 10px 11px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  font-size: 10.5px !important;
}
.gate-card .action { width: 100%; margin-top: 16px; }

/* ---------- модальное окно ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 14px;
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  background: #12121c;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  animation: rise 0.3s both;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}
.modal-meta {
  margin-bottom: 10px;
  font-size: 10.5px;
  color: var(--muted);
}

/* ---------- тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(94px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(28, 28, 42, 0.96);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- первичная загрузка ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 40;
}
.boot-card { width: min(100%, 420px); }
.skeleton { border-radius: 12px; background: rgba(255, 255, 255, 0.06); }
.skeleton-title { width: 45%; height: 24px; margin-bottom: 22px; }
.skeleton-line { width: 70%; height: 12px; margin-bottom: 22px; }
.skeleton-block { width: 100%; height: 190px; border-radius: 20px; animation: pulse 1.5s ease-in-out infinite; }

/* ---------- анимации ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (max-width: 380px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .panel { padding: 13px; }
  .ratio-grid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
  .model-card strong { font-size: 12px; }
  .cta-cost { min-width: 78px; }
  .cta-cost b { font-size: 11.5px; }
}

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