/* css/rw.css — shared styles for the Reading & Writing section (Dictée now,
   the Reading tools docs/reading-writing.md scopes next reuse this same
   file). Pure shared.css tokens throughout so every theme is respected
   automatically — never a hardcoded color in here except a couple of
   deliberately new accent hues shared.css has no token for yet. */

/* ── Toast (same visual language as tool-e's inline toast) ─────────────── */
.rw-toast-wrap { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 999; pointer-events: none; }
.rw-toast {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: .65rem 1.25rem; font-size: .85rem; font-weight: 600;
    opacity: 0; transition: opacity .3s, transform .3s; transform: translateY(8px); pointer-events: none; white-space: nowrap;
}
.rw-toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.rw-toast.ok   { border-color: var(--green); color: var(--green); }
.rw-toast.err  { border-color: var(--red); color: var(--red); }
.rw-toast.info { border-color: var(--teal); color: var(--teal-text); }

/* ── Tooltip — no equivalent existed anywhere in the app before this.
   Usage: <span class="rw-tip" tabindex="0" data-tip="explanation">?</span>
   CSS-only, so :hover works with a mouse and :focus (via tabindex="0")
   makes it reachable on touch/keyboard too. ─────────────────────────────── */
.rw-tip {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 1.1em; height: 1.1em; border-radius: 50%; background: var(--surface-2); color: var(--text-muted);
    font-size: .75rem; font-weight: 700; cursor: help;
}
.rw-tip::after {
    content: attr(data-tip); position: absolute; bottom: 140%; left: 50%; transform: translateX(-50%);
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .45rem .65rem; font-size: .75rem; font-weight: 500; white-space: normal; width: max-content; max-width: 220px;
    box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 50;
}
.rw-tip:hover::after, .rw-tip:focus::after { opacity: 1; }
/* M639: a hidden tooltip still takes layout room, so near the right edge of a
   phone it widened the page (journal). Render it only while shown. */
.rw-tip:not(:hover):not(:focus)::after { display: none; }
.rw-tip::after { max-width: min(220px, calc(100vw - 32px)); }

/* ── Streak / stat hero (same pattern as fluency-dashboard.html's streak-hero) ── */
.rw-streak-hero {
    padding: 1.5rem; display: flex; align-items: center; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.rw-streak-fire { font-size: 3rem; line-height: 1; }
.rw-streak-info h2 { font-family: var(--font-display); font-size: 2.5rem; font-weight: 800; color: var(--purple); line-height: 1; }
.rw-streak-info p { color: var(--text-muted); font-size: .88rem; margin-top: .2rem; }
.rw-streak-meta { margin-left: auto; text-align: right; }
.rw-streak-meta-v { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--teal-text); }
.rw-streak-meta-l { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; }

/* Phone: one compact row (streak + 4 stats) instead of a 400px-tall stack */
@media (max-width: 600px) {
    .rw-streak-hero { display: grid; grid-template-columns: auto repeat(4, 1fr); gap: .4rem .6rem; padding: .7rem .8rem; margin-bottom: 1rem; align-items: center; }
    .rw-streak-fire { font-size: 1.5rem; grid-row: 1 / span 2; }
    .rw-streak-info { grid-column: 2 / -1; display: flex; align-items: baseline; gap: .4rem; }
    .rw-streak-info h2 { font-size: 1.4rem; }
    .rw-streak-info p { margin: 0; }
    .rw-streak-meta { margin-left: 0; text-align: center; }
    .rw-streak-meta-v { font-size: 1rem; }
    .rw-streak-meta-l { font-size: .58rem; line-height: 1.15; }
}

/* ── Word-diff feedback (Dictée grading; future Reading tools can reuse this
   for click-to-gloss/annotation highlighting) ──────────────────────────── */
.rw-word { display: inline-block; margin: .1rem .15rem; padding: .05rem .3rem; border-radius: 6px; }
.rw-word-match   { color: var(--text); }
.rw-word-close   { background: var(--accent-soft); color: var(--accent-text); text-decoration: underline dotted; }
/* Capitals are NOTED, not charged (M338), so they get their own colour rather
   than sharing the accent one — the legend claims three tiers and the score
   now actually has three. Kept visually quieter than an accent error. */
.rw-word-case    { background: rgba(201,162,39,.14); color: #8a6d12; text-decoration: underline dotted; }
.result-notes    { margin-top: .5rem; }
.result-note     { margin: .2rem 0; font-size: .82rem; color: var(--text-muted, #666); line-height: 1.5; }
.rw-word-missing { background: var(--red-soft); color: var(--red); text-decoration: line-through; }
.rw-word-extra   { background: var(--red-soft); color: var(--red); opacity: .75; }

/* ── Confetti (js/rw/fx.js) — plain DOM spans, no canvas library ───────── */
.rw-confetti-wrap { position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden; }
.rw-confetti-piece {
    position: absolute; top: -10px; border-radius: 2px;
    animation-name: rw-confetti-fall; animation-timing-function: cubic-bezier(.25,.46,.45,.94); animation-fill-mode: forwards;
}
@keyframes rw-confetti-fall {
    to { transform: translateY(100vh) translateX(var(--drift, 0px)) rotate(720deg); opacity: 0; }
}

/* ── Standardized Gamification HUD Strip (.gx-strip) ──────────────────── */
.gx-strip {display: flex;align-items: center;gap: 1.1rem;padding: 1rem 1.25rem;margin-bottom: 1.1rem;box-shadow: 0 4px 18px rgba(0,0,0,0.12);position: relative;overflow: hidden;flex-wrap: wrap;}
.gx-strip::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, var(--teal), var(--purple), var(--accent));
}
.gx-ring {
    --p: 0;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: conic-gradient(var(--green) calc(var(--p)*1%), var(--surface-2) 0);
    display: grid;
    place-items: center;
    position: relative;
    flex-shrink: 0;
}
.gx-ring::before {
    content: "";
    position: absolute;
    inset: 7px;
    border-radius: 50%;
    background: var(--surface);
}
.gx-ring span {
    position: relative;
    font-size: .74rem;
    font-weight: 800;
    color: var(--text);
    text-align: center;
    line-height: 1.15;
}
.gx-rank {
    flex: 1 1 160px;
    min-width: 140px;
}
.gx-rank-name {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .4rem;
}
.gx-rank-sub {
    font-size: .76rem;
    color: var(--text-muted);
    margin: .15rem 0 .45rem;
}
.gx-bar {
    height: 8px;
    border-radius: 99px;
    background: var(--surface-2);
    overflow: hidden;
}
.gx-bar i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 99px;
    background: linear-gradient(90deg, var(--purple), var(--teal));
    transition: width .5s ease-out;
}
.gx-stat {
    flex: 0 0 auto;
    text-align: center;
    min-width: 58px;
}
.gx-stat b {
    display: block;
    font-size: 1.25rem;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    font-weight: 800;
}
.gx-stat small {
    font-size: .68rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
}

/* ── Interactive Companion Mascot Coach Stage (.gx-mascot-box) ────────── */
.gx-mascot-box, .pilot-mascot-box {
    display: flex;
    align-items: center;
    gap: 1.15rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .9rem 1.25rem;
    margin-bottom: 1.25rem;
    position: relative;
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}
.mascot-slot, .mascot-avatar-slot {
    width: 76px;
    height: 76px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform .2s ease;
}
.mascot-slot:hover, .mascot-avatar-slot:hover {
    transform: scale(1.08) rotate(3deg);
}
.mascot-slot svg, .mascot-avatar-slot svg {
    width: 76px;
    height: 76px;
}
.mascot-speech-bubble {
    flex: 1;
    position: relative;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .75rem 1rem;
}
.mascot-speech-bubble::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 8px 8px 8px 0;
    border-style: solid;
    border-color: transparent var(--border) transparent transparent;
}
.mascot-speech-bubble::after {
    content: "";
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 7px 7px 7px 0;
    border-style: solid;
    border-color: transparent var(--surface-2) transparent transparent;
}
.mascot-bubble-title {
    font-size: .75rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--teal-text);
    letter-spacing: .5px;
    margin-bottom: .25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.mascot-bubble-text {
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
    margin: 0;
}
.mascot-bubble-sub {
    font-size: .76rem;
    color: var(--text-muted);
    margin-top: .25rem;
    margin-bottom: 0;
}

/* ── Floating XP Animation ────────────────────────────────────────────── */
.xp-floater {
    position: fixed;
    font-size: 1.25rem;
    font-weight: 900;
    color: #f5b02e;
    text-shadow: 0 0 10px rgba(245,176,46,0.6);
    pointer-events: none;
    z-index: 10000;
    animation: floatFadeUp 1.2s forwards cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes floatFadeUp {
    0% { opacity: 0; transform: translateY(0) scale(0.7); }
    20% { opacity: 1; transform: translateY(-15px) scale(1.15); }
    100% { opacity: 0; transform: translateY(-70px) scale(1); }
}

@media (max-width: 640px) {
    .gx-mascot-box, .pilot-mascot-box { flex-direction: column; text-align: center; }
    .mascot-speech-bubble::before, .mascot-speech-bubble::after { display: none; }
}

/* M639: toast fits the phone and clears the tab bar / home indicator. */
.rw-toast-wrap { max-width: calc(100vw - 32px); }
@media (max-width: 768px) {
    .rw-toast { white-space: normal; text-align: center; }
    .rw-toast-wrap { bottom: calc(16px + env(safe-area-inset-bottom)); }
    body.has-tabbar .rw-toast-wrap { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
