:root {
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --bg: var(--tg-theme-bg-color, #0f1117);
  --text: var(--tg-theme-text-color, #f5f7fb);
  --hint: var(--tg-theme-hint-color, #8b93a7);
  --secondary: var(--tg-theme-secondary-bg-color, #1a1f2e);
  --border: color-mix(in srgb, var(--text) 12%, transparent);
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 72px;
}

.header { padding: 16px 16px 8px; }

.header-row {
  min-height: 36px;
  margin-bottom: 8px;
}

.back-btn {
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.back-btn:active { transform: scale(0.97); }

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

.brand-icon {
  font-size: 2rem;
  filter: drop-shadow(0 0 12px color-mix(in srgb, var(--accent) 60%, transparent));
}

.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }

.subtitle { color: var(--hint); font-size: 0.8rem; margin-top: 2px; }

#main { flex: 1; padding: 12px 16px 24px; }

.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

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

.view-title { font-size: 1.15rem; margin-bottom: 16px; font-weight: 600; }

.hero-card {
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 18%, var(--secondary)), var(--secondary));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.hero-card h2 { font-size: 1.25rem; margin-bottom: 8px; }

.hero-card p {
  color: var(--hint);
  line-height: 1.5;
  margin-bottom: 20px;
  font-size: 0.92rem;
}

.option-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.option-card {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 8px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s, border-color 0.15s;
}

.option-card:active { transform: scale(0.97); border-color: var(--accent); }

.option-icon { font-size: 1.6rem; }
.option-label { font-size: 0.78rem; font-weight: 500; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 0.82rem; color: var(--hint); }

.input {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  width: 100%;
}

.input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-color: var(--accent);
}

.textarea {
  resize: vertical;
  min-height: 120px;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--secondary); color: var(--text); border: 1px solid var(--border); }
.btn-block { width: 100%; margin-top: 8px; }

.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--secondary);
  margin-bottom: 12px;
  cursor: pointer;
  padding: 20px;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--secondary));
}

.dropzone-icon { font-size: 2rem; }

.hint { color: var(--hint); font-size: 0.82rem; margin-bottom: 12px; }
.hint code { background: var(--secondary); padding: 2px 6px; border-radius: 6px; }

.parse-summary, .confirm-card {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  line-height: 1.5;
  font-size: 0.92rem;
}

.processing { text-align: center; padding: 48px 16px; }

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress-stats, .result-stats {
  margin-top: 16px;
  text-align: left;
  background: var(--secondary);
  border-radius: 12px;
  padding: 14px;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.done-card { text-align: center; padding: 32px 16px; }
.done-icon { font-size: 3rem; display: block; margin-bottom: 12px; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  cursor: pointer;
}

.toggle-row input { width: 44px; height: 24px; accent-color: var(--accent); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  background: color-mix(in srgb, var(--secondary) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--hint);
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border-radius: 10px;
}

.tab.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.tab small { font-size: 0.68rem; }

.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: #e74c3c;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  max-width: 90%;
  z-index: 100;
  box-shadow: var(--shadow);
}

.toast.ok { background: #27ae60; }
