/* ── Toast ── */
.toast {
    position: fixed; bottom: 1.75rem; right: 1.75rem;
    background: var(--panel2); border: 1px solid var(--accent); border-radius: 7px;
    padding: 0.65rem 1rem; color: var(--cream); font-size: 0.85rem;
    z-index: 9999; animation: fadeUp 0.3s ease; max-width: 290px;
    box-shadow: 0 4px 20px var(--shadow-md);
}
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ── In-app confirm dialog (replaces native confirm()) ── */
.confirm-overlay {
    position: fixed; inset: 0;
    background: var(--scrim);
    display: flex; align-items: center; justify-content: center;
    z-index: 4000;
    backdrop-filter: blur(2px);
    opacity: 0; transition: opacity 0.18s ease;
    pointer-events: none;
}
.confirm-overlay.open { opacity: 1; pointer-events: auto; }
.confirm-dialog {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--seam);
    border-radius: 10px;
    width: min(90vw, 420px);
    padding: 1.5rem 1.5rem 1.25rem;
    box-shadow: 0 24px 60px var(--shadow-lg);
    transform: translateY(6px);
    transition: transform 0.18s ease;
    text-align: center;
}
.confirm-overlay.open .confirm-dialog { transform: translateY(0); }
.confirm-close-btn {
    position: absolute; top: 0.5rem; right: 0.65rem;
    background: none; border: none; padding: 0; line-height: 1;
    color: var(--muted); cursor: pointer; font-size: 1rem;
    transition: color 0.18s;
}
.confirm-close-btn:hover { color: var(--gold); }
.confirm-message {
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem; line-height: 1.6; color: var(--text);
    white-space: pre-line;
    margin-bottom: 1.25rem;
    text-align: center;
}
/* Same input treatment as the story editor's fields (.char-name-input). */
.prompt-input {
    width: 100%;
    background: var(--input-dark); border: none; border-radius: 5px;
    padding: 0.5rem 0.75rem; margin-bottom: 1.25rem;
    color: var(--cream); text-align: center;
    font-family: 'Nunito', sans-serif; font-size: 0.9rem; outline: none;
    /* Keeps the native number spinners dark instead of stock white. */
    color-scheme: dark;
}
.confirm-btns { display: flex; justify-content: center; gap: 0.6rem; }

/* ── Auth overlay ── */
.auth-overlay {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s;
}
.auth-overlay.hidden { opacity: 0; pointer-events: none; }
/* The sign-in screen and alpha gate carry the transparent wordmark, whose art
   is cream and gold — it needs something dark under it. Rather than re-ink
   every element inside, the overlay redefines the palette locally and the rules
   within resolve against it unchanged (same trick as .modal-fullpage).
   Onboarding is excluded: it has no wordmark to protect, and it's the first
   screen of the app, so it follows the theme the app is actually in. */
body.theme-cream .auth-overlay:not(#onboardingOverlay) {
    --bg:         #3a2b1d;
    --panel:      #4e3928;
    --panel2:     #5e4632;
    --border:     #6f5439;
    --modal-bg:   #4e3928;
    --cream:      #f7efe3;
    --text:       #e8dac2;
    --muted:      #b9a288;
    --accent:     #dcc19b;
    --gold:       #e0bd85;
    --input-dark: #2c2016;
    --wash:       rgba(255,255,255,0.06);
    --wash-2:     rgba(255,255,255,0.10);
}
.auth-box {
    background: var(--panel);
    border: 1px solid var(--seam);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 340px;
    display: flex; flex-direction: column; gap: 1rem;
}
/* The wordmark stands in for the <h2> the sign-in and gate screens used to
   have — cropped the same way as the header's, just to the box's width. */
.auth-box .brand-banner {
    width: 100%; height: 62px;
    object-fit: cover; object-position: center;
    display: block; margin-bottom: 0.25rem;
}
.auth-box h2 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.6rem; font-weight: 300;
    color: var(--accent); letter-spacing: 0.2em;
    text-align: center; margin-bottom: 0.25rem;
}
.auth-box .auth-sub {
    font-size: 0.72rem; color: var(--muted);
    text-align: center; letter-spacing: 0.1em;
}
.auth-input {
    background: var(--panel2); border: 1px solid var(--border-strong);
    border-radius: 6px; padding: 0.6rem 0.8rem;
    color: var(--cream); font-family: 'Nunito', sans-serif;
    font-size: 0.88rem; outline: none; width: 100%;
    transition: border-color 0.18s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-btn {
    background: var(--btn-grad);
    border: 1px solid var(--btn-border); border-radius: 6px;
    color: var(--btn-ink); font-family: 'Nunito', sans-serif;
    font-size: 0.88rem; padding: 0.65rem; cursor: pointer;
    transition: all 0.18s; width: 100%;
}
.auth-btn:hover { background: var(--btn-grad-hi); }
.auth-btn.google {
    background: var(--panel2); border-color: var(--border-strong);
    color: var(--text); display: flex; align-items: center;
    justify-content: center; gap: 0.5rem;
}
.auth-divider {
    display: flex; align-items: center; gap: 0.75rem;
    font-size: 0.68rem; color: var(--muted);
}
.auth-divider::before, .auth-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border-strong);
}
.auth-toggle {
    font-size: 0.75rem; color: var(--muted);
    text-align: center; cursor: pointer;
}
.auth-toggle span { color: var(--accent); text-decoration: underline; }
.auth-error {
    font-size: 0.75rem; color: var(--danger);
    text-align: center; min-height: 1rem;
}

/* ── Onboarding modal ── */
#onboardingOverlay .onboarding-box { position: relative; }
/* A little grain over the panel — enough to take the flatness off the fill
   without reading as texture. */
.onboarding-box::before {
    content: '';
    position: absolute; inset: 0;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0.05;
    mix-blend-mode: overlay;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.onboarding-box {
    width: min(760px, calc(100vw - 2rem));
    max-height: 90vh;
    overflow-y: auto;
    padding: 2.6rem 2.25rem 1.75rem;
    gap: 1.5rem;
    border-radius: 18px;
    border-color: var(--border);
    background:
        radial-gradient(130% 90% at 50% -25%, var(--gold-wash), transparent 62%),
        var(--panel);
    box-shadow: 0 12px 32px rgba(50,35,20,0.16), 0 2px 6px rgba(50,35,20,0.08);
    animation: onboarding-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes onboarding-rise {
    from { opacity: 0; transform: translateY(16px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}
/* The box arrives first and its contents follow in reading order, so the eye
   is led down to the two cards rather than handed the whole panel at once. */
.onboarding-box > * {
    animation: onboarding-fade-up 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.onboarding-box > *:nth-child(1) { animation-delay: 0.10s; }
.onboarding-box > *:nth-child(2) { animation-delay: 0.16s; }
.onboarding-box > *:nth-child(3) { animation-delay: 0.22s; }
.onboarding-box > *:nth-child(4) { animation-delay: 0.28s; }
.onboarding-box > *:nth-child(5) { animation-delay: 0.34s; }
@keyframes onboarding-fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}
.onboarding-box h2 {
    background: linear-gradient(135deg, var(--cream), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 2rem;
    letter-spacing: 0.06em;
    margin-bottom: 0;
}
/* The one line that tells a first-time visitor what any of this is. */
.onboarding-tagline {
    max-width: 27rem;
    margin: -0.85rem auto 0.5rem;
    text-align: center;
    font-size: 0.94rem; line-height: 1.55;
    color: var(--text);
}

/* The premade world is the front door: one cinematic destination, with the
   custom-generation route presented afterward as a useful secondary action. */
.onboarding-hero {
    position: relative;
    width: 100%; min-width: 0;
    height: 320px;
    display: flex; align-items: flex-end;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(221,168,120,0.28);
    border-radius: 16px;
    background: #0c0805;
    font-family: 'Nunito', sans-serif;
    text-align: start;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.onboarding-hero:hover,
.onboarding-hero:focus-visible {
    transform: translateY(-2px);
    border-color: #e0bd85;
    box-shadow: 0 14px 30px rgba(50,35,20,0.3);
    outline: none;
}
.onboarding-hero:active { transform: translateY(-1px); }
.onboarding-hero-art {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform 0.45s;
}
.onboarding-hero:hover .onboarding-hero-art,
.onboarding-hero:focus-visible .onboarding-hero-art { transform: scale(1.035); }
.onboarding-hero::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(to top,
        rgba(6,4,3,0.94) 0%, rgba(6,4,3,0.68) 37%, rgba(6,4,3,0.1) 76%);
}
.onboarding-hero-body {
    position: relative; z-index: 1;
    width: min(31rem, 82%);
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem;
    padding: 1.5rem;
}
.onboarding-hero-badge {
    margin-bottom: 0.1rem;
    padding: 0.22rem 0.5rem;
    border: 1px solid rgba(224,189,133,0.55);
    border-radius: 999px;
    color: #e0bd85;
    font-size: 0.58rem; font-weight: 600; letter-spacing: 0.15em;
    text-transform: uppercase;
}
.onboarding-hero-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 2rem; font-weight: 400; line-height: 1; letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #f7efe3;
}
.onboarding-hero-description {
    color: rgba(247,239,227,0.78);
    font-size: 0.78rem; line-height: 1.45;
}
.onboarding-hero-cta {
    margin-top: 0.55rem;
    padding: 0.62rem 1rem;
    border-radius: 7px;
    background: linear-gradient(135deg, #d8a85f, #b77b36);
    color: #1b1109;
    font-size: 0.74rem; font-weight: 600; letter-spacing: 0.025em;
    box-shadow: 0 4px 14px rgba(0,0,0,0.22);
}
.onboarding-hero-cta::after { content: ' →'; }
[dir="rtl"] .onboarding-hero-cta::after { content: ' ←'; }

.onboarding-create {
    display: flex; align-items: center; gap: 1rem;
    width: min(31rem, 100%);
    margin: -0.25rem auto 0;
    padding: 0.15rem 0.5rem;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: 'Nunito', sans-serif;
    text-align: start;
    cursor: pointer;
}
.onboarding-create-copy {
    flex: 1;
    display: flex; flex-direction: column; gap: 0.15rem;
}
.onboarding-create-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.18rem; line-height: 1.2;
    color: var(--text);
    transition: color 0.18s;
}
.onboarding-create-description {
    font-size: 0.7rem; line-height: 1.4;
    color: var(--muted);
}
.onboarding-create-arrow {
    color: var(--muted);
    transition: color 0.18s, transform 0.18s;
}
[dir="rtl"] .onboarding-create-arrow { transform: scaleX(-1); }
.onboarding-create:hover .onboarding-create-title,
.onboarding-create:focus-visible .onboarding-create-title,
.onboarding-create:hover .onboarding-create-arrow,
.onboarding-create:focus-visible .onboarding-create-arrow { color: var(--gold); }
.onboarding-create:hover .onboarding-create-arrow { transform: translateX(3px); }
[dir="rtl"] .onboarding-create:hover .onboarding-create-arrow { transform: scaleX(-1) translateX(3px); }
.onboarding-create:focus-visible {
    outline: 1px solid var(--gold);
    outline-offset: 5px;
    border-radius: 4px;
}
@media (max-width: 560px) {
    .onboarding-box { padding: 2rem 1rem 1.35rem; gap: 1.25rem; }
    .onboarding-hero { height: 300px; }
    .onboarding-hero-body { width: 100%; padding: 1.1rem; }
    .onboarding-hero-title { font-size: 1.65rem; }
}
.onboarding-skip {
    text-align: center;
    margin-top: -0.7rem;
}
.onboarding-skip span {
    font-size: 0.72rem;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.18s;
}
.onboarding-skip span:hover { color: var(--gold); }


/* ── In-story dictionary ──
   Both float over the feed from the same anchor — the chip is the offer, the
   card is the answer, and only ever one of them is on screen. Placement is
   JS's (it follows the highlighted range); everything else is here. */
.gloss-chip, .gloss-card {
    position: fixed;
    transform: translateX(-50%);
    z-index: 500;
    background: var(--panel2);
    border: 1px solid var(--border-strong); border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow-md);
    animation: glossUp 0.18s ease;
}
/* Its own rise, because the shared fadeUp would animate the transform that
   holds the box centred over the word and drop it half a width to the right. */
@keyframes glossUp {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}
.gloss-chip {
    padding: 0.3rem 0.7rem;
    color: var(--muted); font-size: 0.75rem;
    cursor: pointer; white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}
.gloss-chip:hover { color: var(--accent); border-color: var(--accent); }
.gloss-card {
    padding: 0.7rem 0.9rem;
    max-width: min(20rem, calc(100vw - 2rem));
    border-color: var(--accent);
    cursor: default;
}
/* The word as the reader highlighted it — quiet, since they can already see it
   in the prose; the answer under it is what they stopped for. */
.gloss-word {
    color: var(--muted); font-size: 0.7rem;
    letter-spacing: 0.06em; text-transform: uppercase;
}
.gloss-translation {
    margin-top: 0.15rem;
    color: var(--cream); font-size: 1rem;
    font-family: 'Cormorant Garamond', serif;
}
.gloss-sense {
    margin-top: 0.3rem;
    color: var(--text); font-size: 0.8rem; line-height: 1.45;
}
.gloss-failed { color: var(--danger); }
