:root {
  --ink: #14231c;
  --muted: #5c6b63;
  --paper: #f4f0e6;
  --panel: rgba(255, 252, 246, 0.92);
  --line: #d8d0c0;
  --accent: #0c6b4d;
  --accent-deep: #084c37;
  --glow: rgba(12, 107, 77, 0.14);
  --tg-bg: var(--tg-theme-bg-color, var(--paper));
  --tg-text: var(--tg-theme-text-color, var(--ink));
  --tg-button: var(--tg-theme-button-color, var(--accent));
  --tg-button-text: var(--tg-theme-button-text-color, #fff);
  --tg-app-height: 100dvh;
  --tg-safe-inset-top: 0px;
  --tg-safe-inset-bottom: 0px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", system-ui, sans-serif;
  --radius: 18px;
  --shadow: 0 12px 40px rgba(20, 35, 28, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: var(--tg-app-height, 100dvh);
}

body {
  font-family: var(--font-body);
  color: var(--tg-text);
  line-height: 1.5;
  background:
    radial-gradient(1200px 600px at 10% -10%, #dceee4 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #efe6d2 0%, transparent 50%),
    linear-gradient(180deg, #f7f3ea 0%, #ebe4d6 100%);
  background-color: var(--tg-bg);
  padding:
    calc(14px + var(--tg-safe-inset-top))
    16px
    calc(20px + var(--tg-safe-inset-bottom));
  -webkit-overflow-scrolling: touch;
  -webkit-font-smoothing: antialiased;
}

.app-root {
  max-width: 680px;
  margin: 0 auto;
  min-height: calc(var(--tg-app-height, 100dvh) - 40px);
  animation: rise 0.45s ease both;
}

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

.hidden { display: none !important; }

.gate {
  max-width: 420px;
  margin: 14vh auto 0;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  text-align: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  animation: rise 0.4s ease both;
}
.gate-mark,
.brand-mark {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  margin: 0 0 8px;
  font-size: 1.05rem;
}
.gate h1 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.gate p { color: var(--muted); margin: 0; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.brand-block h1 {
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 4vw, 1.85rem);
  margin: 0 0 4px;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.muted { color: var(--muted); margin: 0; font-size: 0.92rem; }

.balance {
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 8px 20px var(--glow);
  font-size: 0.92rem;
  align-self: center;
}

.steps {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0;
  margin: 0 0 16px;
}
.steps__item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255,255,255,0.45);
  border: 1px solid transparent;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.steps__item span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e4ddd0;
  color: var(--ink);
  font-size: 0.68rem;
}
.steps__item.is-active {
  background: #fff;
  color: var(--accent-deep);
  border-color: #c9e5d7;
  box-shadow: 0 4px 14px var(--glow);
}
.steps__item.is-active span {
  background: var(--accent);
  color: #fff;
}
.steps__item.is-done {
  color: var(--accent);
}
.steps__item.is-done span {
  background: #b7dccb;
  color: var(--accent-deep);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.35s ease both;
}
.panel-kicker {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 1.28rem;
  margin: 0 0 14px;
  letter-spacing: -0.02em;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
  background: #fffdf8;
  color: inherit;
  min-height: 46px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
select:focus, textarea:focus {
  outline: none;
  border-color: #8fc4ab;
  box-shadow: 0 0 0 3px var(--glow);
}
textarea {
  resize: vertical;
  min-height: 200px;
  line-height: 1.55;
}

.prompt {
  background: linear-gradient(180deg, #f7f2e7, #f1eadb);
  border: 1px solid #e2d8c4;
  border-radius: 12px;
  padding: 12px;
  font-size: 0.9rem;
  margin: 0 0 14px;
  word-break: break-word;
  color: #3d4a43;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.file-drop {
  display: grid;
  place-items: center;
  gap: 4px;
  margin: 10px 0 12px;
  padding: 22px 14px;
  border: 1.5px dashed #b7c9bc;
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.file-drop:hover,
.file-drop:focus-within {
  border-color: var(--accent);
  background: #f3faf6;
}
.file-drop__title { font-weight: 700; color: var(--ink); }
.file-drop__hint { font-size: 0.82rem; color: var(--muted); font-weight: 500; }

.btn-row {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

button.primary,
button.secondary {
  width: 100%;
  border-radius: 14px;
  padding: 14px;
  font-weight: 700;
  font-size: 1rem;
  margin-top: 8px;
  min-height: 50px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
button.primary {
  border: 0;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: var(--tg-button-text);
  box-shadow: 0 10px 24px var(--glow);
}
button.secondary {
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
}
button.primary:active,
button.secondary:active { transform: scale(0.98); }
button.primary:disabled,
button.secondary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.status-line { min-height: 1.2em; margin-top: 8px; }

.preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.preview img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(20, 35, 28, 0.06);
}

.result-summary {
  white-space: pre-wrap;
  background: linear-gradient(180deg, #edf7f1, #e7f1ea);
  border: 1px solid #c9e5d7;
  border-radius: 14px;
  padding: 14px;
  margin: 0 0 14px;
  font-weight: 500;
}

.criteria-list { margin-bottom: 8px; }
.crit-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.crit-row:last-child { border-bottom: 0; }
.crit-row strong:last-child {
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
  min-width: 2.2em;
  text-align: right;
}
.crit-comment {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
  font-weight: 500;
}

@media (max-width: 420px) {
  body { padding-left: 12px; padding-right: 12px; }
  .top { flex-wrap: wrap; }
  .balance { margin-left: auto; }
  .steps__item { font-size: 0; gap: 0; padding: 8px; }
  .steps__item span { font-size: 0.75rem; width: 22px; height: 22px; }
  .preview { grid-template-columns: repeat(2, 1fr); }
  textarea, select { font-size: 16px; }
}

@media (min-width: 768px) {
  .app-root { padding-top: 8px; }
  .btn-row { grid-template-columns: 1fr 1.2fr; }
}

@media (orientation: landscape) and (max-height: 480px) {
  body { padding-top: calc(8px + var(--tg-safe-inset-top)); }
  .panel { padding: 12px; }
  .steps { margin-bottom: 10px; }
}
