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

:root {
  --purple: #7c3aed;
  --purple-dark: #4f46e5;
  --purple-light: #ede9fe;
  --purple-mid: #c4b5fd;
  --text: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --bg: #ffffff;
  --bg-soft: #f9fafb;
  --bg-card: #ffffff;
  --green: #10b981;
  --red: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(124,58,237,0.12), 0 1px 4px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --text-faint: #6b7280;
    --border: #2d2d3a;
    --bg: #0f0f17;
    --bg-soft: #1a1a26;
    --bg-card: #1e1e2e;
  }
}

html { height: 100%; }

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── App shell ───────────────────────────────────────────── */
#app {
  min-height: 100%;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
}
.screen.active { display: flex; }

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  padding: 16px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(124,58,237,0.3);
}

.app-logo {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.2px;
}
.app-logo span { opacity: 0.8; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.plan-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 9px;
  border-radius: 20px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}
.plan-badge--pro  { background: rgba(251,191,36,0.35); border-color: rgba(251,191,36,0.5); }
.plan-badge--team { background: rgba(16,185,129,0.3);  border-color: rgba(16,185,129,0.5); }

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Scroll body ─────────────────────────────────────────── */
.screen-body {
  flex: 1;
  padding: 20px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
}
.btn-primary:hover  { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  padding: 11px 18px;
  background: var(--bg-soft);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--purple); color: var(--purple); }

.btn-copy {
  padding: 12px 20px;
  background: var(--purple-light);
  color: var(--purple);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
}
.btn-copy:hover { background: var(--purple); color: #fff; }

/* ── Inputs ──────────────────────────────────────────────── */
.label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--bg-soft);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.input:focus { border-color: var(--purple); background: var(--bg); }

.prompt-input {
  width: 100%;
  min-height: 140px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--text);
  background: var(--bg-soft);
  outline: none;
  resize: none;
  font-family: inherit;
  line-height: 1.6;
  transition: border-color 0.15s;
}
.prompt-input:focus { border-color: var(--purple); background: var(--bg); }
.prompt-input::placeholder { color: var(--text-faint); }

/* ── Tone pills ──────────────────────────────────────────── */
.tone-section { }
.tone-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.tone-pill {
  padding: 6px 14px;
  border-radius: 50px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.tone-pill:hover { border-color: var(--purple); color: var(--purple); }
.tone-pill.active {
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  border-color: transparent;
  color: #fff;
  font-weight: 700;
}

/* ── Result area ─────────────────────────────────────────── */
.result-text {
  width: 100%;
  min-height: 160px;
  padding: 14px;
  border: 1.5px solid var(--purple-mid);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--text);
  background: #faf5ff;
  outline: none;
  resize: none;
  font-family: inherit;
  line-height: 1.6;
  transition: border-color 0.15s;
}
@media (prefers-color-scheme: dark) {
  .result-text { background: #1e1530; }
}
.result-text:focus { border-color: var(--purple); }

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.strategy-text {
  font-size: 13px;
  color: var(--purple);
  background: var(--purple-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  line-height: 1.5;
}

.changes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.changes-list li {
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 18px;
  position: relative;
  line-height: 1.5;
}
.changes-list li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--purple);
  font-weight: 700;
}

/* ── Refine row ──────────────────────────────────────────── */
.refine-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.refine-input {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-soft);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.refine-input:focus { border-color: var(--purple); }
.btn-refine-submit {
  padding: 11px 18px;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-refine-submit:hover { opacity: 0.88; }
.btn-refine-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Pro gate banner ─────────────────────────────────────── */
.pro-gate {
  background: var(--purple-light);
  border: 1px solid var(--purple-mid);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--purple);
}
.pro-gate strong { display: block; font-size: 14px; margin-bottom: 6px; }
.pro-gate a {
  display: inline-block;
  margin-top: 8px;
  padding: 7px 16px;
  background: var(--purple);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}

/* ── License screen ──────────────────────────────────────── */
.license-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 28px;
  text-align: center;
  gap: 16px;
}
.license-icon { font-size: 56px; }
.license-title { font-size: 26px; font-weight: 900; color: var(--text); line-height: 1.2; }
.license-subtitle { font-size: 15px; color: var(--text-muted); line-height: 1.6; }
.license-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.license-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.5;
}
.license-footer { font-size: 13px; color: var(--text-faint); }
.license-footer a { color: var(--purple); text-decoration: none; font-weight: 600; }

/* ── Settings screen ─────────────────────────────────────── */
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-title { font-size: 17px; font-weight: 800; margin-bottom: 2px; }
.select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--bg-soft);
  outline: none;
  cursor: pointer;
  font-family: inherit;
}
.select:focus { border-color: var(--purple); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }
.btn-icon-plain {
  padding: 12px;
  background: var(--bg-soft);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-icon-plain:hover { background: var(--border); }

.account-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.account-email { font-size: 13px; color: var(--text-muted); }
.btn-signout {
  font-size: 12px;
  color: var(--red);
  background: none;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-signout:hover { background: #fef2f2; }

/* ── Loading spinner ─────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--purple-light);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e1e2e;
  color: #fff;
  padding: 11px 20px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.25s;
  z-index: 9999;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #065f46; }
.toast.error   { background: #7f1d1d; }

/* ── Install banner ──────────────────────────────────────── */
.install-banner {
  margin: 0 20px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.install-banner button {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.install-banner .dismiss {
  background: none;
  border: none;
  opacity: 0.6;
  font-size: 16px;
  padding: 0 4px;
}

/* ── Divider ─────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); }

/* ── Collapsible ─────────────────────────────────────────── */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}
.collapsible-header .chevron {
  font-size: 12px;
  color: var(--text-faint);
  transition: transform 0.2s;
}
.collapsible-header.open .chevron { transform: rotate(180deg); }
.collapsible-body { display: none; margin-top: 10px; }
.collapsible-body.open { display: block; }

/* ── Spacing helpers ─────────────────────────────────────── */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }

/* ── Safe area (iPhone notch) ────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .screen-body { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .app-header  { padding-top: calc(16px + env(safe-area-inset-top)); }
}
