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

:root {
  --accent:         #7c6af7;
  --accent-hover:   #6b58f0;
  --accent-light:   rgba(124, 106, 247, 0.08);
  --accent-glow:    rgba(124, 106, 247, 0.18);
  --bg:             #f3f4f6;
  --surface:        #ffffff;
  --border:         rgba(0, 0, 0, 0.09);
  --border-focus:   rgba(124, 106, 247, 0.45);
  --text:           #1a1a2e;
  --text-soft:      #6b7280;
  --text-muted:     #9ca3af;
  --error:          #f43f5e;
  --error-bg:       rgba(244, 63, 94, 0.06);
  --error-border:   rgba(244, 63, 94, 0.2);
  --success-bg:     #f5f3ff;
  --success-border: rgba(124, 106, 247, 0.25);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

/* ── Base ────────────────────────────────────────────────────── */

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* Desktop: center vertically, no page scroll */
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 20px;
}

/* ── Container (phone frame) ─────────────────────────────────── */

.container {
  width: 100%;
  max-width: 480px;
  /* Fit in viewport — scroll internally when result appears */
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Subtle scrollbar on desktop */
  scrollbar-width: thin;
  scrollbar-color: rgba(124, 106, 247, 0.25) transparent;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.05);
  padding: 24px 22px 22px;
}

.container::-webkit-scrollbar {
  width: 4px;
}
.container::-webkit-scrollbar-thumb {
  background: rgba(124, 106, 247, 0.25);
  border-radius: 4px;
}
.container::-webkit-scrollbar-track {
  background: transparent;
}

/* ── Header ──────────────────────────────────────────────────── */

header {
  text-align: center;
  margin-bottom: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #7c6af7, #a855f7);
  border-radius: 13px;
  margin-bottom: 12px;
  box-shadow: 0 4px 16px rgba(124, 106, 247, 0.35);
}

.logo svg {
  width: 24px;
  height: 24px;
}

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
  margin-bottom: 5px;
}

.subtitle {
  font-size: 0.84rem;
  color: var(--text-soft);
  line-height: 1.5;
  margin-bottom: 9px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(124, 106, 247, 0.08);
  border: 1px solid rgba(124, 106, 247, 0.2);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

/* ── Section ─────────────────────────────────────────────────── */

.section {
  margin-bottom: 12px;
}

/* ── Form ────────────────────────────────────────────────────── */

form {
  display: block;
}

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 7px;
}

textarea {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  padding: 11px 13px;
  resize: none;
  line-height: 1.5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--accent);
}

textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea::placeholder {
  color: var(--text-muted);
}

.examples-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin: 9px 0 7px;
}

#examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.example-btn {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-soft);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.example-btn:hover {
  border-color: rgba(124, 106, 247, 0.35);
  color: var(--accent);
  background: var(--accent-light);
}

button[type="submit"] {
  display: block;
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s, box-shadow 0.15s;
  font-family: var(--font);
  box-shadow: 0 4px 14px rgba(124, 106, 247, 0.3);
}

button[type="submit"]:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 6px 20px rgba(124, 106, 247, 0.4);
}

button[type="submit"]:active:not(:disabled) {
  transform: scale(0.99);
}

button[type="submit"]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Loader ──────────────────────────────────────────────────── */

#loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0;
  color: var(--text-soft);
  font-size: 13px;
  margin-bottom: 12px;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ── Result ──────────────────────────────────────────────────── */

#result {
  display: block;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  animation: fadeUp 0.25s ease both;
}

.result-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 7px;
}

#result-text {
  font-size: 0.875rem;
  line-height: 1.75;
  color: var(--text);
}

#result-text strong {
  color: var(--accent);
  font-weight: 600;
}

/* ── Error ───────────────────────────────────────────────────── */

#error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 10px;
  padding: 10px 13px;
  margin-bottom: 12px;
  animation: fadeUp 0.2s ease both;
}

#error::before {
  content: "⚠️";
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 1px;
}

#error-text {
  font-size: 13px;
  color: var(--error);
  line-height: 1.5;
}

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

[hidden] {
  display: none !important;
}

/* ── Mobile (iPhone & small screens) ────────────────────────── */

@media (max-width: 520px) {
  body {
    display: block;
    padding: 0;
    min-height: 100dvh;
  }

  .container {
    max-width: 100%;
    max-height: none;
    overflow-y: visible;
    border-radius: 0;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    min-height: 100dvh;
    padding: 20px 18px;
    /* iPhone safe areas */
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }

  h1 { font-size: 1.3rem; }
  textarea { font-size: 16px; } /* prevent iOS zoom on focus */
}

/* ── Very small screens (SE, older iPhones) ──────────────────── */

@media (max-width: 375px) {
  .logo { width: 40px; height: 40px; border-radius: 11px; }
  .logo svg { width: 20px; height: 20px; }
  h1 { font-size: 1.2rem; }
}
