:root {
  color-scheme: dark;
  --bg0: #0c0e12;
  --bg1: #141820;
  --card: rgba(22, 28, 38, 0.92);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5ee0a0;
  --accent-dim: rgba(94, 224, 160, 0.15);
  --danger: #ff6b7a;
  --radius: 16px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg0);
}

body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(94, 224, 160, 0.12);
}

@supports (-webkit-touch-callout: none) {
  html, body {
    min-height: -webkit-fill-available;
  }
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(94, 224, 160, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(80, 120, 255, 0.08), transparent),
    var(--bg0);
  pointer-events: none;
}

.shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
  box-sizing: border-box;
}

.head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.head h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  flex: 1;
  min-width: 0;
}

.head-link {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(94, 224, 160, 0.35);
  background: rgba(94, 224, 160, 0.08);
}

.head-link:hover {
  filter: brightness(1.08);
}

.credit-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(94, 224, 160, 0.18);
  font-size: 0.82rem;
  color: var(--muted);
}

.credit-bar__bal strong {
  color: var(--text);
}

.credit-bar__cta {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.credit-bar__cta:hover {
  text-decoration: underline;
}

.sub {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}

.sub a {
  color: var(--accent);
  text-decoration: none;
}

.sub a:hover {
  text-decoration: underline;
}

.card {
  margin-top: 20px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
}

/* Узже: блок с загрузкой сразу под заголовком */
.head + .card {
  margin-top: 10px;
}

.drop {
  display: block;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  min-height: 160px;
  position: relative;
  scroll-margin-top: 8px;
}

.drop.has-preview {
  scroll-margin-top: 12px;
}

.drop:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 16px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.drop .icon {
  font-size: 1.6rem;
  opacity: 0.7;
}

.drop .hint {
  font-size: 0.75rem;
  opacity: 0.8;
}

.preview {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: #000;
}

.preview.hidden {
  display: none;
}

.drop.has-preview .drop-inner {
  display: none;
}

.row {
  margin-top: 12px;
}

.lbl {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Полный спектр: HSV-плоскость + полоска hue */
.spectrum {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sv-plane {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 0.62;
  max-height: 200px;
  border-radius: 12px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.sv-plane:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sv-plane__bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #fff, hsl(var(--sv-hue, 120), 100%, 50%));
}

.sv-plane__cursor {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  left: 0;
  top: 0;
}

.hue-wrap {
  padding: 0 2px;
}

.hue-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    #f00 0%,
    #ff0 16.66%,
    #0f0 33.33%,
    #0ff 50%,
    #00f 66.66%,
    #f0f 83.33%,
    #f00 100%
  );
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.hue-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.hue-slider:active::-webkit-slider-thumb {
  cursor: grabbing;
}

.hex-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

#colorPicker {
  width: 52px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: transparent;
}

.hex {
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  font-family: ui-monospace, monospace;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

.hex:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  width: 100%;
  margin-top: 18px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(135deg, #4ade80, #22c55e);
  color: #052e14;
  transition: filter 0.15s, transform 0.1s;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Состояние генерации */
.gen-loading {
  margin-top: 18px;
  padding: 16px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(94, 224, 160, 0.2);
  text-align: center;
}

.gen-loading__track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 14px;
}

.gen-loading__bar {
  height: 100%;
  width: 38%;
  max-width: 200px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(94, 224, 160, 0.2),
    rgba(94, 224, 160, 1),
    rgba(94, 224, 160, 0.2)
  );
  animation: gen-bar-sweep 1.4s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}

/* Проценты translate — относительно ширины полоски: «бегает» между краями трека */
@keyframes gen-bar-sweep {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(350%);
  }
}

.gen-loading__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.gen-loading__hint {
  margin: 6px 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
}

.gen-loading__arrow {
  margin: 12px 0 4px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--accent);
}

.gen-loading__chev {
  display: inline-block;
  animation: gen-arrow-nudge 1.1s ease-in-out infinite;
}

@keyframes gen-arrow-nudge {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.85;
  }
  50% {
    transform: translateY(6px);
    opacity: 1;
  }
}

.gen-loading__down {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

@media (prefers-reduced-motion: reduce) {
  .gen-loading__bar {
    animation: none;
    width: 100%;
    opacity: 0.65;
  }
  .gen-loading__chev {
    animation: none;
  }
}

.err {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.out {
  animation: out-enter 0.45s ease-out both;
  scroll-margin-top: max(16px, env(safe-area-inset-top));
  scroll-margin-bottom: 24px;
}

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

@media (prefers-reduced-motion: reduce) {
  .out {
    animation: none;
  }
}

.out h2 {
  font-size: 1rem;
  margin: 0 0 12px;
}

.result {
  width: 100%;
  border-radius: 12px;
  background: #000;
}

.out-actions {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.btn-dl {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  cursor: pointer;
  border: 1px solid rgba(94, 224, 160, 0.5);
  background: rgba(94, 224, 160, 0.12);
  color: var(--accent);
  font-weight: 600;
  font-size: 1rem;
  border-radius: 12px;
  padding: 12px 28px;
  min-height: 48px;
  min-width: min(100%, 240px);
  max-width: 100%;
  touch-action: manipulation;
  transition: filter 0.15s, transform 0.1s, background 0.15s;
}

.btn-dl:hover {
  filter: brightness(1.08);
  background: rgba(94, 224, 160, 0.2);
}

.btn-dl:active {
  transform: scale(0.98);
}

.shop-balance {
  margin: 0 0 14px;
  font-size: 0.95rem;
  color: var(--text);
}

.pkg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pkg-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
}

.pkg-item__title {
  font-weight: 600;
  font-size: 0.9rem;
}

.pkg-item__meta {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.shop-hint {
  margin: 14px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.shop-external {
  display: inline-block;
  margin-top: 12px;
  font-weight: 600;
  color: var(--accent);
}

.shop-err {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--danger);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  font-size: 0.88rem;
}

.history-item__time {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.history-item__text {
  line-height: 1.4;
}

.admin-secret-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn--secondary {
  background: rgba(94, 224, 160, 0.12) !important;
  color: var(--accent) !important;
  border: 1px solid rgba(94, 224, 160, 0.45) !important;
}

.btn--danger {
  background: rgba(255, 107, 122, 0.12) !important;
  color: #ff9aa4 !important;
  border: 1px solid rgba(255, 107, 122, 0.45) !important;
  margin-top: 16px;
}

.btn--ghost {
  background: transparent !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}

.btn--sm {
  font-size: 0.8rem;
  padding: 8px 12px;
  white-space: nowrap;
}

.auth-card {
  margin-bottom: 14px;
}

.auth-title {
  font-size: 1.05rem;
  margin: 0 0 8px;
}

.auth-sub {
  margin: 0 0 14px;
  font-size: 0.85rem;
  line-height: 1.35;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-pass-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.auth-pass-row .hex {
  flex: 1;
  min-width: 120px;
}

.auth-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-ok__line {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-link-tg {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.auth-err {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 10px 0 0;
}

.auth-deep {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.auth-deep__url {
  font-size: 0.78rem;
  word-break: break-all;
  margin: 10px 0 0;
  line-height: 1.35;
}

.paygate-box {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.paygate-row {
  margin-bottom: 10px;
}

.paygate-row .lbl {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.paygate-result {
  margin-top: 14px;
}

.paygate-amt {
  font-weight: 600;
  margin: 0 0 8px;
}

.paygate-qr {
  max-width: 220px;
  width: 100%;
  height: auto;
  border-radius: 12px;
  margin-top: 10px;
}

.admin-h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
}

.admin-h3 {
  font-size: 0.88rem;
  margin: 18px 0 10px;
  color: var(--muted);
  font-weight: 600;
}

.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-table th,
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.admin-table--sm {
  font-size: 0.8rem;
}

.muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.admin-textarea {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.admin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.admin-row .hex {
  min-width: 100px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.hidden {
  display: none !important;
}

/* ——— Мобильные и узкие экраны ——— */
@media (max-width: 480px) {
  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .head h1 {
    font-size: clamp(1.15rem, 4.8vw, 1.35rem);
  }

  .sub {
    font-size: 0.875rem;
    line-height: 1.42;
  }

  .drop {
    min-height: 148px;
    border-radius: 11px;
  }

  .drop-inner {
    padding: 22px 12px;
    font-size: 0.875rem;
  }

  .preview {
    max-height: min(52vh, 320px);
  }

  .sv-plane {
    max-height: none;
    min-height: 140px;
    aspect-ratio: 1 / 0.58;
  }

  .sv-plane__cursor {
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
  }

  .hue-slider {
    height: 28px;
  }

  .hue-slider::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }

  .hue-slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }

  /* iOS: при font-size < 16px на input страница зумится при фокусе */
  .hex {
    font-size: 16px;
    padding: 12px 12px;
  }

  .hex-row {
    gap: 10px;
  }

  #colorPicker {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 12px;
  }

  .btn {
    min-height: 48px;
    padding: 16px 18px;
    font-size: 1.02rem;
  }

  .gen-loading {
    padding: 14px 12px;
  }

  .out-actions {
    margin-top: 14px;
  }

  .btn-dl {
    min-height: 48px;
    padding: 14px 24px;
  }
}

@media (max-width: 360px) {
  .shell {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .card {
    padding: 12px;
  }

  .spectrum {
    gap: 10px;
  }
}

/* Предпочтение «уменьшенного движения» уже учтено выше для анимаций */
