:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f0f0f6;
  --text: #0e0e16;
  --muted: #5b5b70;
  --border: #dcdce6;
  --accent-1: #7c3aed;
  --accent-2: #ec4899;
  --accent-3: #f59e0b;
  --grad: linear-gradient(120deg, var(--accent-1), var(--accent-2) 55%, var(--accent-3));
  --glow: 0 10px 40px -10px rgba(124, 58, 237, 0.45);
  --danger: #c0262d;
  --radius: 18px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #08080d;
  --surface: #111118;
  --surface-2: #191922;
  --text: #f5f5fa;
  --muted: #9a9ab0;
  --border: #272733;
  --accent-1: #a78bfa;
  --accent-2: #f472b6;
  --accent-3: #fbbf24;
  --glow: 0 10px 50px -10px rgba(167, 139, 250, 0.55);
  --danger: #ff6b72;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--accent-1); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); font-size: 0.875rem; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1200px; margin: 0 auto; padding: 20px 24px;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.logo {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--grad); color: #fff; font-size: 0.8rem; font-weight: 700; letter-spacing: -0.02em;
  box-shadow: var(--glow);
}
.brand-name { font-family: var(--serif); font-size: 1.25rem; }
.brand-name em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.ghost, .icon-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  transition: border-color 0.2s, transform 0.2s;
}
.icon-btn { width: 40px; padding: 0; justify-content: center; }
.ghost:hover, .icon-btn:hover { border-color: var(--accent-1); }
.pill { min-width: 22px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); font-size: 0.75rem; font-weight: 600; text-align: center; }
[data-theme="dark"] .sun, [data-theme="light"] .moon { display: none; }

/* Layout */
.layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 32px;
  max-width: 1200px; margin: 0 auto; padding: 24px 24px 64px; align-items: start;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; gap: 24px; padding: 8px 16px 48px; }
  .topbar { padding: 16px; }
}

h1 {
  font-family: var(--serif); font-size: clamp(2rem, 4.2vw, 3.1rem); line-height: 1.08;
  letter-spacing: -0.02em; margin: 24px 0 12px;
}
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: var(--muted); font-size: 1.05rem; margin: 0 0 28px; max-width: 46ch; }

textarea {
  width: 100%; min-height: 220px; resize: vertical; padding: 18px 20px;
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea::placeholder { color: var(--muted); opacity: 0.8; }
textarea:focus { outline: none; border-color: var(--accent-1); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-1) 18%, transparent); }

.form-row { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 12px; }

.rhyme-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px; padding: 0 30px; border: 0; border-radius: 14px;
  color: #fff; font-weight: 600; font-size: 1.02rem; letter-spacing: 0.01em;
  background: var(--grad); background-size: 200% 200%;
  box-shadow: var(--glow);
  animation: shimmer 6s ease infinite;
  transition: transform 0.15s ease, box-shadow 0.25s ease;
}
.rhyme-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 50px -8px color-mix(in srgb, var(--accent-2) 65%, transparent); }
.rhyme-btn:active:not(:disabled) { transform: translateY(0); }
.rhyme-btn .spinner { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
.rhyme-btn.loading .spinner { display: inline-block; }
.rhyme-btn.loading { opacity: 0.9; cursor: progress; }
@keyframes shimmer { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes spin { to { transform: rotate(360deg); } }

.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 22px; }
.chip {
  padding: 6px 14px; border-radius: 99px; font-size: 0.85rem;
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  transition: color 0.2s, border-color 0.2s;
}
.chip:hover { color: var(--text); border-color: var(--accent-2); }
.hint { margin-top: 16px; }
kbd { font-family: var(--sans); font-size: 0.75rem; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); }

/* Mode switch */
.mode-switch {
  position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 5px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch label {
  position: relative; z-index: 1; display: grid; gap: 1px; padding: 10px 14px; border-radius: 12px; cursor: pointer;
  text-align: center; transition: color 0.25s;
}
.mode-switch label strong { font-weight: 600; font-size: 0.95rem; }
.mode-switch label span { font-size: 0.78rem; color: var(--muted); }
.mode-switch input:checked + label strong { color: #fff; }
.mode-switch input:checked + label span { color: rgba(255, 255, 255, 0.85); }
.mode-switch input:focus-visible + label { outline: 2px solid var(--accent-1); outline-offset: 2px; }
.mode-thumb {
  position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc(50% - 5px); border-radius: 12px;
  background: var(--grad); box-shadow: var(--glow); transition: transform 0.35s cubic-bezier(.2,.7,.2,1);
}
#modeMnemonic:checked ~ .mode-thumb { transform: translateX(100%); }

/* Verse card */
.output-panel { position: sticky; top: 24px; }
@media (max-width: 880px) { .output-panel { position: static; } }
.verse-card {
  position: relative; overflow: hidden; min-height: 440px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 24px;
  padding: 36px 36px 24px;
}
.verse-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--grad);
}
.card-glow {
  position: absolute; width: 380px; height: 380px; right: -140px; top: -160px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent-2) 22%, transparent), transparent 70%);
  pointer-events: none; opacity: 0; transition: opacity 0.8s ease;
}
.verse-card.revealed .card-glow { opacity: 1; }

.empty-state { flex: 1; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-icon { font-size: 2rem; margin-bottom: 8px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.verse-card:not(.is-empty) .empty-state { display: none; }
.verse-card.is-empty .card-body { display: none; }
.verse-card.loading .empty-state p::after { content: "…"; }

.card-body { flex: 1; position: relative; }
.eyebrow { margin: 0 0 6px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.card-title { font-family: var(--serif); font-size: clamp(1.6rem, 3vw, 2.1rem); line-height: 1.15; margin: 0 0 22px; letter-spacing: -0.01em; }
.verse { font-family: var(--serif); font-size: 1.18rem; line-height: 1.75; font-weight: 600; margin-bottom: 28px; }
.verse p { margin: 0; }
.verse-card:not(.is-mnemonic) .verse p:nth-child(2n) { padding-left: 1.2em; }
.mnemonic {
  margin: -6px 0 22px; padding: 16px 18px; border-radius: 14px;
  font-family: var(--serif); font-size: 1.3rem; line-height: 1.4; font-weight: 700;
  background: color-mix(in srgb, var(--accent-1) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent-1) 35%, transparent);
}
.is-mnemonic .verse { font-family: var(--sans); font-size: 1rem; font-weight: 500; line-height: 1.5; display: grid; gap: 6px; }
.is-mnemonic .verse b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 700; }
.takeaways { border-top: 1px solid var(--border); padding-top: 18px; }
.takeaways h3 { margin: 0 0 10px; font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.takeaways ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.takeaways li { position: relative; padding-left: 22px; font-size: 0.95rem; }
.takeaways li::before {
  content: ""; position: absolute; left: 2px; top: 0.55em; width: 8px; height: 8px; border-radius: 50%; background: var(--grad);
}

/* Reveal animation */
.reveal { opacity: 0; transform: translateY(10px); filter: blur(4px); animation: rise 0.55s cubic-bezier(.2,.7,.2,1) forwards; animation-delay: var(--d, 0ms); }
@keyframes rise { to { opacity: 1; transform: none; filter: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}

.card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; position: relative; }
.action {
  display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; font-size: 0.9rem; font-weight: 500;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.action:hover:not(:disabled) { border-color: var(--accent-1); transform: translateY(-1px); }
.action.active { border-color: var(--accent-2); color: var(--accent-2); }

.error { margin: 14px 4px 0; color: var(--danger); font-size: 0.92rem; }

/* Deck */
.deck {
  width: min(560px, calc(100vw - 32px)); max-height: min(80vh, 760px); padding: 24px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 22px;
}
.deck::backdrop { background: rgba(5, 5, 10, 0.55); backdrop-filter: blur(4px); }
.deck[open] { animation: rise 0.3s ease forwards; }
.deck-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.deck-head h2 { font-family: var(--serif); margin: 0; }
.deck-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.deck-item { border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; background: var(--surface-2); }
.deck-item h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 1.1rem; }
.deck-item .lines { font-family: var(--serif); font-size: 0.95rem; white-space: pre-line; color: var(--muted); margin: 0 0 10px; }
.deck-item .row { display: flex; gap: 8px; }
.deck-item .row button { height: 32px; padding: 0 12px; font-size: 0.82rem; border-radius: 9px; background: var(--surface); border: 1px solid var(--border); }
.deck-item .row button:hover { border-color: var(--accent-1); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 0.9rem; font-weight: 500;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .brand-name { font-size: 1.05rem; white-space: nowrap; }
  .verse-card { padding: 28px 22px 20px; min-height: 0; }
  .verse { font-size: 1.05rem; }
  .verse-card:not(.is-mnemonic) .verse p:nth-child(2n) { padding-left: 0.8em; }
  .mode-switch label span { display: none; }
  .hint { display: none; }
}
