:root {
  --bg-deep: #071428;
  --bg-mid: #0c2248;
  --surface: #ffffff;
  --surface-muted: #f4f7fc;
  --border: #dbe4f3;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #c8d5ee;
  --primary: #3e73e8;
  --primary-dark: #2f5fc9;
  --primary-soft: #e8efff;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at top right, rgba(62, 115, 232, 0.18), transparent 28%),
    linear-gradient(145deg, var(--bg-deep), var(--bg-mid) 45%, #081a38);
  color: #ffffff;
  min-height: 100vh;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 36px 24px 48px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.brand-block { flex: 1 1 420px; }

.brand {
  display: inline-flex;
  align-items: center;
  margin-bottom: 14px;
}

.brand-logo {
  height: 42px;
  width: auto;
  max-width: 260px;
  display: block;
  object-fit: contain;
}

h1 {
  font-size: clamp(2rem, 4vw, 2.75rem);
  margin: 0;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.subtext {
  color: var(--text-soft);
  margin-top: 10px;
  font-size: 16px;
  max-width: 640px;
  line-height: 1.6;
}

.header-card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 280px;
  flex: 0 1 320px;
}

.header-card label {
  display: block;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

input, textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(62, 115, 232, 0.15);
}

.status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-soft);
  min-height: 18px;
  line-height: 1.5;
}

.status.success { color: #86efac; }
.status.warning { color: #fcd34d; }
.status.error { color: #fca5a5; }

.hidden { display: none !important; }

.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.login-card {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
}

.login-card h1 {
  margin: 16px 0 10px;
}

.login-card p {
  color: var(--text-soft);
  line-height: 1.6;
  margin: 0 0 22px;
}

.login-card .brand-logo {
  height: 42px;
  margin: 0 auto;
}

.google-btn-wrap {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.auth-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.auth-tab {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
  padding: 8px 10px;
}

.auth-tab.active {
  background: #ffffff;
  color: var(--bg-mid);
}

.register-fields { display: none; }
.register-fields.visible { display: block; }

.auth-submit { width: 100%; margin-top: 14px; }

.header-card .header-logout {
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.signed-in-name {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.signed-in-email {
  font-size: 13px;
  color: var(--text-soft);
  margin: 4px 0 8px;
}

.tabs {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 18px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: #ffffff;
  color: var(--bg-mid);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.65);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.card h3 {
  margin: 22px 0 10px;
  font-size: 16px;
}

.helper {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 16px;
  line-height: 1.55;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 18px;
}

textarea { resize: vertical; line-height: 1.55; }

#draft, #output { min-height: 380px; }
#trainingEmails { min-height: 220px; }
#styleOutput { min-height: 180px; background: var(--surface-muted); }

#output {
  background: var(--surface-muted);
  white-space: pre-wrap;
  overflow: auto;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.primary { background: var(--primary); color: #fff; }
.secondary { background: var(--primary-soft); color: #1f3f8b; }
.utility { background: var(--bg-mid); color: #fff; }
.ghost { background: #eef2f7; color: #334155; }

.loading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-style: italic;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 240px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 1000;
  font-size: 14px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
  .header { flex-direction: column; }
}
