/* Rest Monster — read the staff to spell the word. Namespaced rm- (game) / rmm- (monster). */

body { display: block; padding: 0; margin: 0; }

/* overflow:clip contains the monster's tumble-off so it can't flash a
   horizontal scrollbar; everything animated lives inside this box. */
.rm-page { max-width: 960px; margin: 0 auto; padding: 24px 20px 48px; overflow: clip; }

.rm-head { text-align: center; margin-bottom: 18px; }
.rm-head h1 { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 6px; color: var(--text, #0f172a); }
.rm-head p { color: var(--text-light, #64748b); font-size: 15.5px; margin: 0; }

.rm-stage { background: var(--card, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 18px;
    padding: 18px 20px 20px; box-shadow: var(--shadow, 0 1px 3px rgba(0,0,0,.1)); }

.rm-start, .rm-next { font: inherit; font-weight: 800; font-size: 18px; padding: 14px 44px;
    border-radius: 14px; border: 0; cursor: pointer; color: #fff;
    background: linear-gradient(135deg, #14b8a6, #0d9488); box-shadow: 0 6px 18px rgba(13,148,136,.35); }
#rm-start { display: block; margin: 10px auto 0; font-size: clamp(22px, 4vw, 28px); padding: 20px 12px;
    width: min(420px, 100%); animation: rm-pulse 2.2s ease-in-out infinite; }
@keyframes rm-pulse {
    0%, 100% { box-shadow: 0 6px 18px rgba(13,148,136,.35); transform: scale(1); }
    50% { box-shadow: 0 8px 30px rgba(13,148,136,.55); transform: scale(1.02); }
}
.rm-next { padding: 10px 26px; font-size: 16px; }

/* ---------- HUD ---------- */
.rm-hud { display: flex; justify-content: center; align-items: flex-start; gap: 26px; flex-wrap: wrap;
    font-weight: 800; font-size: 17px; color: var(--text, #0f172a); margin-bottom: 10px; }
.rm-hud-group { display: flex; gap: 20px; }
.rm-hud .l { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    color: var(--text-light, #64748b); display: block; text-align: center; }
.rm-hud > div, .rm-hud-group > div { text-align: center; min-width: 64px; }
.rm-team { padding: 4px 12px; border-radius: 10px; border: 2px solid transparent; }
.rm-team.rm-turn { border-color: var(--primary, #0d9488); background: var(--accent-soft, #f0fdfa); }
body.dark-mode .rm-team.rm-turn { background: rgba(13,148,136,.18); }

/* ---------- The board: the word, written on the staff ---------- */
.rm-board { position: relative; padding-bottom: 54px; }
.rm-word { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 8px; }
.rm-slot { display: flex; flex-direction: column; gap: 3px;
    width: clamp(56px, calc((100% - (var(--rm-n, 6) - 1) * 8px) / var(--rm-n, 6)), 122px); }
.rm-slot.rm-grand { width: clamp(66px, calc((100% - (var(--rm-n, 6) - 1) * 8px) / var(--rm-n, 6)), 154px); }
/* aspect-ratios track the crop windows in rest-monster.js (PAD_ABOVE/BELOW) */
.rm-slot-face { aspect-ratio: 110 / 74; display: flex; align-items: center; justify-content: center;
    background: var(--card, #fff); border: 2px solid var(--border, #e2e8f0); border-bottom-width: 4px;
    border-radius: 10px; overflow: hidden; transition: border-color .15s, box-shadow .15s, transform .15s; }
.rm-slot.rm-grand .rm-slot-face { aspect-ratio: 190 / 144; }
.rm-slot-face .rm-vf { width: 100%; }
/* the free letters — the context clue, deliberately quieter than the notes */
.rm-slot.rm-isgiven .rm-slot-face { background: var(--bg, #f8fafc); border-style: dashed; }
.rm-slot-letter { font-size: clamp(24px, 4.6vw, 42px); font-weight: 900; color: var(--text-light, #64748b); line-height: 1; }

/* the one note the class is reading right now */
.rm-slot.rm-active .rm-slot-face { border-color: var(--primary, #0d9488);
    box-shadow: 0 0 0 4px rgba(13,148,136,.22); transform: translateY(-3px); }
.rm-slot.rm-active { animation: rm-bob 1.8s ease-in-out infinite; }
@keyframes rm-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

.rm-slot.rm-solved .rm-slot-face { border-color: var(--primary, #0d9488); }
.rm-slot.rm-eaten .rm-slot-face { border-color: #b45309; border-style: dashed; opacity: .8; }

/* caption row — spells the word as it is read */
.rm-cap { min-height: 24px; text-align: center; font-size: clamp(15px, 2.4vw, 22px); font-weight: 900;
    color: var(--text-light, #64748b); line-height: 1.2; }
.rm-slot.rm-isnote .rm-cap { color: #cbd5e1; }
body.dark-mode .rm-slot.rm-isnote .rm-cap { color: #475569; }
.rm-slot.rm-solved .rm-cap { color: var(--primary, #0d9488); }
.rm-slot.rm-isgiven .rm-cap { color: var(--text, #0f172a); }
.rm-cap-lost { color: #b45309 !important; text-decoration: line-through; }

/* ---------- The monster ---------- */
.rmm-host { position: absolute; inset: 0; pointer-events: none; }
.rmm-monster { position: absolute; width: 54px; left: 0; top: 100%;
    transition: left .4s cubic-bezier(.45,1.4,.45,1), top .4s ease; will-change: left, top, transform; }
.rmm-monster svg { display: block; width: 100%; height: auto; }
.rmm-mouth-open { display: none; }
.rmm-monster.rmm-warning { animation: rmm-lean .5s ease-in-out 2; }
@keyframes rmm-lean {
    0%, 100% { transform: translateY(0) rotate(0); }
    50% { transform: translateY(-7px) rotate(-8deg) scale(1.06); }
}
.rmm-monster.rmm-chomping .rmm-mouth-open { display: block; }
.rmm-monster.rmm-chomping .rmm-mouth-closed { display: none; }
.rmm-monster.rmm-chomping { animation: rmm-chomp .64s ease; }
@keyframes rmm-chomp {
    0% { transform: translateY(0) scale(1); }
    40% { transform: translateY(-10px) scale(1.1); }
    62% { transform: translateY(-26px) scale(1.18); }
    100% { transform: translateY(0) scale(1); }
}
/* Defeat, beat 1: frozen mid-shock — puffed up, mouth open (JS shows the
   open mouth for this class too), a fast tremble. */
.rmm-monster.rmm-shocked { animation: rmm-shock .62s ease; }
.rmm-monster.rmm-shocked .rmm-mouth-open { display: block; }
.rmm-monster.rmm-shocked .rmm-mouth-closed { display: none; }
@keyframes rmm-shock {
    0% { transform: scale(1); }
    20% { transform: scale(1.28) translateY(-10px) rotate(-5deg); }
    35% { transform: scale(1.24) translateY(-10px) rotate(5deg); }
    50% { transform: scale(1.28) translateY(-10px) rotate(-5deg); }
    65% { transform: scale(1.24) translateY(-10px) rotate(5deg); }
    100% { transform: scale(1.22) translateY(-8px); }
}
/* Defeat, beat 2: head-over-heels off the board with a bounce. */
.rmm-monster.rmm-tumble { animation: rmm-tumble 1.45s cubic-bezier(.4, .1, .8, .5) forwards; }
@keyframes rmm-tumble {
    0% { transform: translate(0, -8px) rotate(0) scale(1.2); opacity: 1; }
    30% { transform: translate(16vw, -60px) rotate(240deg) scale(1.05); }
    55% { transform: translate(30vw, 6px) rotate(480deg) scale(.95); }
    72% { transform: translate(38vw, -30px) rotate(620deg) scale(.9); }
    100% { transform: translate(52vw, 30px) rotate(880deg) scale(.75); opacity: 0; }
}
.rmm-monster.rmm-stuffed { animation: rmm-burp 1s ease 2; }
@keyframes rmm-burp {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.16) translateY(-8px); }
}

/* Victory confetti: note glyphs float up over the board while the word plays. */
.rm-conf { position: absolute; bottom: 30%; font-size: clamp(20px, 3vw, 34px); font-weight: 800;
    pointer-events: none; opacity: 0; animation: rm-float 2.3s ease-out forwards; will-change: transform, opacity; }
@keyframes rm-float {
    0% { opacity: 0; transform: translate(0, 10px) rotate(0); }
    18% { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--rm-drift, 0px), -150px) rotate(24deg); }
}

/* ---------- Prompt / feedback / hint ---------- */
.rm-prompt { text-align: center; margin: 4px 0 0; font-size: clamp(14px, 2vw, 17px); font-weight: 700;
    color: var(--text-light, #64748b); min-height: 24px; }
.rm-feedback { text-align: center; min-height: 34px; font-size: clamp(18px, 2.6vw, 22px); font-weight: 800; margin: 4px 0 2px; }
.rm-feedback.good { color: var(--primary, #0d9488); }
.rm-feedback.bad { color: #dc2626; }
.rm-feedback.win { color: var(--primary, #0d9488); font-size: clamp(21px, 3vw, 27px); }
.rm-feedback.lose { color: #b45309; font-size: clamp(19px, 2.8vw, 24px); }

.rm-hintbox { display: flex; align-items: center; gap: 16px; max-width: 620px; margin: 6px auto 2px;
    padding: 10px 16px; border: 2px dashed var(--primary, #0d9488); border-radius: 12px;
    background: var(--accent-soft, #f0fdfa); }
body.dark-mode .rm-hintbox { background: rgba(13,148,136,.12); }
.rm-hint-fig { flex: 0 0 110px; }
.rm-hintbox p { margin: 0; font-size: 13.5px; line-height: 1.55; color: var(--text, #0f172a); }

/* ---------- The A–G keys ---------- */
.rm-keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; max-width: 700px; margin: 10px auto 0; }
.rm-key { font: inherit; font-weight: 800; font-size: clamp(22px, 4vw, 40px); padding: 16px 0;
    border-radius: 14px; border: 2px solid var(--border, #e2e8f0); background: var(--bg, #f8fafc);
    color: var(--text, #0f172a); cursor: pointer; user-select: none; touch-action: manipulation; }
.rm-key:hover:not(:disabled) { border-color: var(--primary, #0d9488); color: var(--primary, #0d9488); }
.rm-key:active:not(:disabled) { transform: scale(.96); }
.rm-key:disabled { opacity: .45; cursor: default; }
.rm-key.rm-wrong { animation: rm-shake .4s ease; border-color: #dc2626; color: #dc2626; }
@keyframes rm-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}
/* The monster's mark: a jagged BITE taken out of the key's top-right
   corner. clip-path removes card + border together, which is exactly
   what a bite should do. Heals when the spotlight moves to a new note. */
.rm-key.rm-bitten { opacity: 1 !important; color: #dc2626; border-color: #dc2626;
    clip-path: polygon(0 0, 55% 0, 58% 14%, 66% 3%, 71% 18%, 79% 6%, 84% 22%, 92% 10%, 96% 26%, 100% 18%,
        100% 100%, 0 100%); }

.rm-play-actions { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.rm-small-btn { font: inherit; font-weight: 700; font-size: 13.5px; padding: 9px 18px; border-radius: 10px;
    border: 2px solid var(--border, #e2e8f0); background: transparent; color: var(--text-light, #64748b); cursor: pointer; }
.rm-small-btn:hover:not(:disabled) { border-color: var(--primary, #0d9488); color: var(--primary, #0d9488); }
.rm-small-btn:disabled { opacity: .4; cursor: default; }
.rm-accent-btn { border-color: var(--amber, #b45309); color: var(--amber, #b45309); }
.rm-accent-btn:hover:not(:disabled) { border-color: var(--amber, #b45309); color: var(--amber, #b45309); background: rgba(180,83,9,.08); }

.rm-call-row { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.rm-call-row label { font-size: 13.5px; font-weight: 700; color: var(--text-light, #64748b); }
.rm-call-row input { font: inherit; font-size: 20px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
    padding: 8px 14px; width: min(280px, 60vw); border-radius: 10px;
    border: 2px solid var(--amber, #b45309); background: var(--card, #fff); color: var(--text, #0f172a); }

/* ---------- Settings ---------- */
.rm-controls-wrap { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border, #e2e8f0); }
.rm-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; margin-bottom: 8px; }
.rm-group-label { display: block; text-align: center; font-size: 10px; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--text-light, #64748b); margin-bottom: 3px; }
.rm-toggle { display: flex; background: var(--bg, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 2px; }
.rm-toggle button { border: 0; background: transparent; font: inherit; font-weight: 700; font-size: 12px;
    color: var(--text-light, #64748b); padding: 5px 10px; min-height: 30px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.rm-toggle button.active { background: var(--primary, #0d9488); color: #fff; }
.rm-lock-note { text-align: center; font-size: 12px; color: var(--text-light, #64748b); margin: 0 auto 8px; max-width: 620px; }
.rm-mode-note { text-align: center; font-size: 12.5px; color: var(--text-light, #64748b); max-width: 620px; margin: 8px auto 0; line-height: 1.6; }

.rm-secret { max-width: 460px; margin: 10px auto 0; font-size: 13px; color: var(--text-light, #64748b); }
.rm-secret summary { cursor: pointer; font-weight: 700; text-align: center; }
.rm-secret p { line-height: 1.6; margin: 8px 0; }
.rm-secret-row { display: flex; gap: 8px; justify-content: center; }
.rm-secret-row input { font: inherit; font-size: 16px; padding: 8px 12px; border-radius: 10px; flex: 1 1 auto; min-width: 0;
    border: 2px solid var(--border, #e2e8f0); background: var(--card, #fff); color: var(--text, #0f172a); }
.rm-secret-err { color: #dc2626; font-weight: 700; text-align: center; min-height: 18px; margin: 6px 0 0; }

/* ---------- Fullscreen: projector mode ---------- */
.rm-stage:fullscreen { display: flex; flex-direction: column;
    border-radius: 0; padding: 3vh 5vw; overflow: auto; }
/* Centering via auto-margin spacers, NOT justify-content:center — a centered
   flex column pushes overflow past the START edge, where overflow:auto cannot
   scroll to it, so the HUD is unreachable on 768px-tall laptops and phones.
   With room to spare the spacers still center the stack. */
.rm-stage:fullscreen::before, .rm-stage:fullscreen::after,
.rm-faux-fs::before, .rm-faux-fs::after { content: ''; flex: 0 0 auto; margin: auto 0; }
.rm-stage:fullscreen .rm-hud { font-size: 26px; gap: 44px; }
.rm-stage:fullscreen .rm-slot { width: clamp(70px, calc((100% - (var(--rm-n, 6) - 1) * 8px) / var(--rm-n, 6)), 180px); }
.rm-stage:fullscreen .rm-slot.rm-grand { width: clamp(82px, calc((100% - (var(--rm-n, 6) - 1) * 8px) / var(--rm-n, 6)), 210px); }
.rm-stage:fullscreen .rmm-monster { width: 74px; }
.rm-stage:fullscreen .rm-board { padding-bottom: 72px; }
.rm-stage:fullscreen .rm-keys { max-width: 1100px; width: 100%; }
.rm-stage:fullscreen .rm-key { font-size: clamp(30px, 3.4vw, 52px); padding: 20px 0; }
/* keep fullscreen focused on the game — drop the explanatory copy */
.rm-stage:fullscreen .rm-mode-note, .rm-faux-fs .rm-mode-note,
.rm-stage:fullscreen .rm-secret, .rm-faux-fs .rm-secret,
.rm-stage:fullscreen .rm-lock-note, .rm-faux-fs .rm-lock-note { display: none; }

/* Faux-fullscreen fallback for iPhone (no element.requestFullscreen there). */
.rm-faux-fs { position: fixed; inset: 0; z-index: 9999; margin: 0; border-radius: 0;
    display: flex; flex-direction: column; overflow: auto;
    padding: 3vh 4vw; background: var(--card, #fff); }
body.rm-faux-fs-lock { overflow: hidden; }
.rm-faux-fs .rm-hud { font-size: 20px; gap: 24px; }
.rm-faux-fs .rm-keys { max-width: 1100px; width: 100%; }

/* ---------- Dark mode ---------- */
/* Colors come from shared.css's slate palette (--bg #0f172a, --card #1e293b,
   --border #475569) so the tiles match the keyboard and the stage card. */
body.dark-mode .rm-slot-face { background: var(--card); border-color: var(--border); }
body.dark-mode .rm-slot.rm-isgiven .rm-slot-face { background: var(--bg); }
body.dark-mode .rm-slot-face svg { filter: invert(1) hue-rotate(180deg); }
body.dark-mode .rm-hint-fig svg { filter: invert(1) hue-rotate(180deg); }

/* ---------- Info copy ---------- */
.rm-info { margin-top: 30px; color: var(--text-light, #64748b); font-size: 15px; line-height: 1.7; }
.rm-info h2 { font-size: 21px; font-weight: 800; color: var(--text, #0f172a); margin: 24px 0 8px; }
.rm-info a { color: var(--primary, #0d9488); font-weight: 700; text-decoration: none; }
.rm-info a:hover { text-decoration: underline; }

/* ---------- Motion + small screens ---------- */
@media (prefers-reduced-motion: reduce) {
    #rm-start { animation: none; }
    .rmm-monster { transition: none; }
    .rmm-monster.rmm-warning, .rmm-monster.rmm-chomping, .rmm-monster.rmm-stuffed,
    .rmm-monster.rmm-shocked { animation: none; }
    .rmm-monster.rmm-tumble { animation: none; opacity: 0; transition: opacity .4s; }
    .rm-slot.rm-active { animation: none; }
    .rm-key.rm-wrong { animation: none; }
    .rm-conf { display: none; }
}

@media (max-width: 760px) {
    .rm-hintbox { flex-direction: column; gap: 8px; text-align: center; }
    .rm-hint-fig { flex: 0 0 auto; width: 130px; }
}

@media (max-width: 560px) {
    .rm-stage { padding: 12px 10px 14px; }
    .rm-controls { gap: 6px; }
    .rm-toggle { flex-wrap: wrap; justify-content: center; max-width: 100%; }
    .rm-toggle button { flex: 1 1 auto; padding: 5px 8px; font-size: 11.5px; }
    .rm-keys { grid-template-columns: repeat(4, 1fr); gap: 8px; }
    .rm-key { padding: 14px 0; font-size: clamp(20px, 6vw, 30px); }
    .rm-hud { gap: 14px; }
    .rm-hud-group { gap: 14px; }
    .rmm-monster { width: 42px; }
    .rm-board { padding-bottom: 46px; }
    /* both wrap at phone width — reserve the wrapped height so the keys
       don't jump under a student's finger between guesses */
    .rm-feedback { min-height: 56px; }
    .rm-prompt { min-height: 40px; }
}
