*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #050508;
  --text: #f4f4f6;
  --muted: rgba(255,255,255,0.52);
  --line: rgba(255,255,255,0.1);
  --glass: rgba(255,255,255,0.04);
  --accent: #8b9cff;
  --accent-soft: rgba(139,156,255,0.14);
}
body {
  margin: 0;
  min-height: 100svh;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
.app { position: relative; min-height: 100svh; }
.bg-stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
#bg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0.55; }
.bg-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 50% 35%, transparent 0%, rgba(5,5,8,0.65) 65%, rgba(5,5,8,0.98) 100%),
    radial-gradient(circle at 50% 20%, rgba(139,156,255,0.07) 0%, transparent 45%);
}
.main {
  position: relative;
  z-index: 10;
  max-width: 28rem;
  margin: 0 auto;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: max(1.25rem, env(safe-area-inset-top)) 1rem max(2rem, env(safe-area-inset-bottom));
}
.brand { text-align: center; margin-bottom: 1.25rem; }
.brand h1 {
  margin: 0;
  font-size: clamp(1.625rem, 7vw, 2.125rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.brand p {
  margin: 0.45rem 0 0;
  font-size: 0.9375rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--muted);
}
.account-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}
.quota-chip, .account-btn {
  min-height: 2rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0,0,0,0.25);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
}
.account-btn {
  cursor: pointer;
  color: var(--text);
  background: var(--accent-soft);
  border-color: rgba(139,156,255,0.4);
}
a.account-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.output-section > a.btn-secondary {
  display: inline-flex;
  margin-top: 0.75rem;
}
.account-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.account-name { color: var(--text); font-size: 0.75rem; }
.welcome-line {
  margin: 0.85rem 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.account-btn-cta {
  background: rgba(139,156,255,0.22);
  border-color: rgba(139,156,255,0.7);
  color: #fff;
}
.account-btn[aria-expanded="true"] {
  border-color: rgba(139,156,255,0.85);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.profile-card, .history-panel {
  margin-top: 0.85rem;
  text-align: start;
}
.history-panel {
  border-radius: 1rem;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 0.85rem;
}
.profile-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 0.9rem;
}
.profile-avatar {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 1rem;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, rgba(139,156,255,0.45), rgba(5,5,8,0.9));
  border: 1px solid rgba(139,156,255,0.35);
}
.profile-photo, .profile-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-logo { object-fit: contain; padding: 0.45rem; }
.profile-who { min-width: 0; }
.profile-who strong { display: block; font-size: 0.95rem; }
.profile-email { display: block; margin-top: 0.2rem; font-size: 0.75rem; color: var(--muted); word-break: break-all; }
.profile-field { display: block; margin-top: 0.65rem; }
.profile-field span {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.42);
}
.profile-input {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9375rem;
}
.profile-input:focus {
  outline: none;
  border-color: rgba(139,156,255,0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.profile-actions { display: flex; align-items: center; gap: 0.65rem; margin-top: 0.85rem; }
.profile-status { font-size: 0.75rem; color: #6ee7b7; }
.history-panel { margin-top: 0.85rem; }
.history-row + .history-row { margin-top: 0.5rem; }
.history-detail {
  margin-top: 0.45rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(139,156,255,0.28);
  border-radius: 0.75rem;
  background: rgba(0,0,0,0.28);
}
.history-detail p { margin: 0 0 0.45rem; font-size: 0.8125rem; line-height: 1.5; }
.history-kicker {
  margin: 0.7rem 0 0.2rem !important;
  font-size: 0.6875rem !important;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.42);
}
.history-kicker:first-child { margin-top: 0 !important; }
.history-chat { color: var(--muted); white-space: pre-wrap; }
.history-item.open { border-color: rgba(139,156,255,0.55); }
.history-section { margin-top: 1.25rem; }
.history-title {
  margin: 0 0 0.65rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.42);
}
.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-item {
  width: 100%;
  text-align: inherit;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--glass);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
.history-item:hover { border-color: rgba(139,156,255,0.4); }
.history-item strong {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.history-item span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
}
.login-card { margin-bottom: 0.85rem; }
.login-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}
.login-hint {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
}
/* Google's branding guidelines: white surface, Roboto-ish label, 40px min. */
.google-btn {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 2.75rem;
  padding: 0.6rem 1rem;
  border: 1px solid #dadce0;
  border-radius: 0.75rem;
  background: #fff;
  color: #1f1f1f;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}
.google-btn:hover { background: #f7f8f8; }
.google-btn:active { background: #eef0f1; }
.google-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.google-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.login-error { margin: 0.75rem 0 0; font-size: 0.8125rem; line-height: 1.5; color: #fbbf24; }
.glass-card {
  border-radius: 1rem;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 1rem;
}
.input-text {
  width: 100%;
  min-height: 132px;
  padding: 0.875rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.875rem;
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.55;
  resize: vertical;
}
.input-text::placeholder { color: rgba(255,255,255,0.32); }
.input-text:focus {
  outline: none;
  border-color: rgba(139,156,255,0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-text:disabled { opacity: 0.65; }
.char-count {
  display: none;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: end;
}
.char-count.visible { display: block; }
.char-count.warn { color: #fbbf24; }
.tone-row { display: flex; gap: 0.5rem; margin-top: 0.875rem; flex-wrap: wrap; }
.tone-btn {
  flex: 1;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}
.tone-btn[aria-pressed="true"] {
  border-color: rgba(139,156,255,0.55);
  background: var(--accent-soft);
  color: var(--text);
}
.btn-transform {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.875rem;
  min-height: 3rem;
  padding: 0.875rem 1rem;
  border: none;
  border-radius: 0.875rem;
  background: var(--text);
  color: #050508;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-transform:disabled { opacity: 0.38; cursor: not-allowed; }
.spinner {
  width: 1rem; height: 1rem;
  border: 2px solid rgba(5,5,8,0.2);
  border-top-color: #050508;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.output-section {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.output-section.visible { opacity: 1; transform: translateY(0); }
.output-card { padding: 1rem 1.125rem; }
.output-card.summary-card {
  border-color: rgba(139,156,255,0.22);
  background: linear-gradient(180deg, rgba(139,156,255,0.08) 0%, rgba(255,255,255,0.03) 100%);
}
.output-label {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.42);
}
.output-value {
  margin: 0.625rem 0 0;
  font-size: 0.9375rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.92);
}
.summary-card .output-value { font-size: 1rem; font-weight: 500; }
.output-value-flush { margin: 0; }
.output-muted { color: rgba(255,255,255,0.48); }
.step-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.625rem;
  cursor: pointer;
  align-items: flex-start;
  min-height: 2.75rem;
}
.step-checkbox {
  width: 1.375rem; height: 1.375rem; flex-shrink: 0; margin-top: 1px;
  border: 1px solid rgba(255,255,255,0.28); border-radius: 0.375rem;
  display: flex; align-items: center; justify-content: center;
}
.step-checkbox.checked { background: var(--text); border-color: var(--text); }
.step-checkbox svg { width: 12px; height: 12px; opacity: 0; }
.step-checkbox.checked svg { opacity: 1; stroke: #050508; }
.message-actions { display: flex; gap: 0.5rem; margin-top: 0.875rem; flex-wrap: wrap; }
.btn-secondary {
  min-height: 2.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-secondary.copied { border-color: #6ee7b7; color: #6ee7b7; }
html[lang="fa"] body { font-family: Inter, system-ui, Tahoma, sans-serif; }
html[lang="fa"] .brand h1 { letter-spacing: 0; }
html[dir="rtl"] .step-row { flex-direction: row-reverse; text-align: right; }
html[dir="rtl"] .char-count { text-align: start; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .output-section { transition: none; }
  .spinner { animation: none; border-top-color: transparent; }
  #bg-canvas { display: none; }
}
