:root {
  --bg: var(--tg-theme-bg-color, #f5f7f4);
  --bg-card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #0d3d2e);
  --text-muted: var(--tg-theme-hint-color, #6b7c75);
  --accent: var(--tg-theme-button-color, #0f4d3a);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(15, 77, 58, 0.12);
  --danger: #c83030;
  --brand: #0f4d3a;
  --max-width: 640px;
  --surface-soft: rgba(15, 77, 58, 0.04);
  --surface-soft-2: rgba(15, 77, 58, 0.07);
  --accent-soft: rgba(15, 77, 58, 0.10);
  --success: #0f4d3a;
  --success-soft: rgba(15, 77, 58, 0.10);
}

/* Brand header */
.brand {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px 0 8px;
}
.brand img {
  height: 32px;
  width: auto;
  max-width: 70%;
  display: block;
}

* { box-sizing: border-box; margin: 0; padding: 0; touch-action: manipulation; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: none;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.screen { display: none; flex: 1; flex-direction: column; gap: 12px; }
.screen.active { display: flex; }

.card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card.center { align-items: center; text-align: center; }

h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; line-height: 1.3; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-top: -8px; }

.instructions { display: flex; flex-direction: column; gap: 10px; font-size: 15px; }
.instructions b { color: var(--accent); }
.hint { color: var(--text-muted); font-size: 13px; }

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }

/* Progress */
.progress { display: flex; flex-direction: column; gap: 6px; padding: 4px 4px 0; }
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.3s; border-radius: 2px; }
.progress-text { font-size: 13px; color: var(--text-muted); text-align: center; }

/* Pick cards */
.pick-cards { display: flex; flex-direction: column; gap: 10px; }
.pick-card {
  position: relative;
  appearance: none;
  font-family: inherit;
  text-align: left;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 14px 14px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.pick-card:active { transform: scale(0.99); }
.pick-card.active { background: var(--accent-soft); border-color: var(--accent); }

.pick-head { display: flex; align-items: center; gap: 12px; }
.pick-letter {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pick-count {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 28px;
}
.pick-card.active .pick-count { color: var(--accent); }
.pick-text { font-size: 15px; line-height: 1.45; color: var(--text); padding-right: 36px; }

.pick-minus {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
  transition: opacity 0.15s, background 0.12s;
}
.pick-minus:hover { background: var(--surface-soft-2); }
.pick-minus:disabled { opacity: 0.25; cursor: not-allowed; }

.remaining {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  padding: 10px 14px;
  background: var(--surface-soft);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.remaining-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 14px;
  text-align: center;
}
.remaining.done {
  background: var(--success-soft);
  color: var(--success);
}
.remaining.done .remaining-value { color: var(--success); }

/* Scenario text (styles test) */
.scenario {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--surface-soft);
  padding: 12px 14px;
  border-radius: 10px;
  border-left: 3px solid var(--accent);
}

/* Styles result */
.styles-result { display: flex; flex-direction: column; gap: 12px; }
.style-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 10px;
  align-items: center;
}
.style-name { font-size: 15px; font-weight: 600; }
.style-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  grid-row: 1;
}
.style-bar {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.style-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}

.nav-buttons { display: flex; gap: 10px; }
.nav-buttons .btn { flex: 1; }

/* Result */
.result-image {
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: var(--surface-soft);
}

/* Loading */
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-text { color: var(--danger); font-size: 14px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 25, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  overscroll-behavior: contain;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 48px rgba(15, 77, 58, 0.18);
}
.modal h2 { font-size: 19px; }
.modal p { font-size: 14px; line-height: 1.5; color: var(--text-muted); }
.modal .btn { text-align: center; text-decoration: none; }
.modal .btn:first-of-type { margin-top: 6px; }

/* Warning banner on result */
.warning-banner {
  background: rgba(200, 48, 48, 0.08);
  border: 1px solid rgba(200, 48, 48, 0.20);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
}
