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

:root {
  --bg: #0a0c14;
  --card-bg: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #e8eaf0;
  --muted: rgba(232, 234, 240, 0.4);
  --accent: #7c6fff;
  --accent-glow: rgba(124, 111, 255, 0.35);
  --btn-hover: #9589ff;
  --error: #ff6b6b;
  --success: #4ecca3;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

/* ── Waves canvas ── */
#waves {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: blur(28px);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ── */
.container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 2rem;

  opacity: 0;
  transform: translateY(18px);
  animation: fadeUp 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.2s forwards;
}

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

/* ── Logo ── */
.logo {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff 30%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  user-select: none;
}

/* ── Card ── */
.card {
  width: 100%;
  max-width: 640px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.75rem;
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Textarea ── */
textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 0.9rem 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

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

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

/* ── Meta row ── */
.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.selects-row {
  display: flex;
  gap: 0.5rem;
}

.char-count {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
  font-family: inherit;
}

select:focus { border-color: var(--accent); }
select option { background: #1a1c2e; }

/* ── Speed row ── */
.speed-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.speed-label {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 100px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

/* ── Button ── */
button#generateBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
  letter-spacing: 0.01em;
  font-family: inherit;
}

button#generateBtn:hover:not(:disabled) {
  background: var(--btn-hover);
  box-shadow: 0 0 24px var(--accent-glow);
}

button#generateBtn:active:not(:disabled) {
  transform: scale(0.98);
}

button#generateBtn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Spinner ── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.hidden { display: none !important; }

/* ── Result ── */
.result {
  width: 100%;
  max-width: 640px;
  animation: fadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.result-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(78, 204, 163, 0.08);
  border: 1px solid rgba(78, 204, 163, 0.25);
  border-radius: 14px;
  padding: 1rem 1.25rem;
}

.result-icon {
  font-size: 1.2rem;
  color: var(--success);
}

.result-text {
  flex: 1;
  font-size: 0.95rem;
  color: var(--success);
}

.download-btn {
  display: inline-block;
  padding: 0.45rem 1.1rem;
  background: var(--success);
  color: #0a0c14;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.2s;
  white-space: nowrap;
}

.download-btn:hover { opacity: 0.85; }

/* ── Error ── */
.error {
  width: 100%;
  max-width: 640px;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.25);
  border-radius: 14px;
  padding: 0.9rem 1.25rem;
  color: var(--error);
  font-size: 0.9rem;
  animation: fadeUp 0.4s ease forwards;
}

#authOverlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
}

#authModal {
  width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: rgba(18, 20, 33, 0.96);
  padding: 1.25rem;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

#authModal h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

#authModal input[type="password"] {
  width: 100%;
  border: 1px solid var(--card-border);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  padding: 0.7rem 0.75rem;
  outline: none;
}

#authModal input[type="password"]:focus {
  border-color: var(--accent);
}

#authModal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.9rem;
}

#authModal .auth-btn {
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  padding: 0.55rem 0.9rem;
}

#authModal .auth-btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

#authError {
  display: none;
  color: var(--error);
  font-size: 0.78rem;
  margin-top: 0.7rem;
}
