/* ============================================================
   Overlays: notes slid over the page. Bottom sheets on phones,
   centred scraps from 600px.
   ============================================================ */
.overlay { position: fixed; inset: 0; display: none; align-items: flex-end; justify-content: center; background: var(--overlay); z-index: 1000; }
.overlay.active { display: flex; }

.sheet {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: 92dvh;
    padding: 22px var(--gutter) calc(16px + var(--safe-bottom));
    background: var(--paper-2);
    background-image: repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.22);
    animation: sheetUp var(--dur-slow) var(--ease-out-expo);
}
.sheet::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    width: 84px;
    height: 24px;
    margin-left: -42px;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.08);
    transform: rotate(-2deg);
}
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet-header h3 { font-size: 1.9rem; color: var(--ink-me); transform: rotate(-1deg); }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-actions { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; }
.sheet-actions .btn { width: 100%; font-family: var(--font-hand); font-weight: 700; font-size: 1.35rem; }

@keyframes sheetUp { from { transform: translateY(30px) rotate(1deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- Chat: scraps passed back and forth -------------------------- */
.chat-sheet { height: 80dvh; }
.chat-messages { display: flex; flex-direction: column; gap: 12px; padding: 6px 4px; }
.chat-message {
    max-width: 82%;
    padding: 8px 12px;
    font-family: var(--font-hand);
    font-weight: 500;
    font-size: 1.3rem;
    line-height: 1.2;
    word-break: break-word;
    box-shadow: var(--shadow-note);
    animation: stickOn 0.4s var(--ease-spring) both;
}
.chat-message.mine { --tilt: 1.2deg; align-self: flex-end; background: var(--sticky-yellow); color: var(--ink-me); }
.chat-message.theirs { --tilt: -1.2deg; align-self: flex-start; background: var(--paper-3); color: var(--ink-them); }
.chat-message.system { align-self: center; max-width: 92%; background: transparent; box-shadow: none; color: var(--ink-3); font-family: var(--font-body); font-size: 0.95rem; text-align: center; animation: fadeUp var(--dur) var(--ease-out-expo); }
.chat-message .message-author { display: block; font-family: var(--font-body); font-size: 0.85rem; color: var(--ink-2); margin-bottom: 2px; }
.chat-message .message-time { display: block; font-family: var(--font-body); font-size: 0.75rem; color: var(--ink-3); margin-top: 4px; text-align: right; }
.chat-input-section { display: flex; align-items: flex-end; gap: 10px; padding-top: 10px; border-top: 2px dashed var(--pencil); }
.chat-input-section .text-input { flex: 1; }
.chat-input-section .btn { padding: 0 16px; font-family: var(--font-hand); font-weight: 700; font-size: 1.25rem; }

/* --- End card: the graded note ---------------------------------- */
.end-card-header { position: relative; margin: -22px calc(var(--gutter) * -1) 18px; padding: 34px 92px 22px 24px; text-align: center; background: var(--sticky-green); }
.end-card-header.defeat { background: var(--sticky-pink); }
.end-card-icon { font-size: 2.4rem; margin-bottom: 4px; display: none; }
.end-card-header h3 { font-size: 2.2rem; line-height: 1.05; color: var(--ink); transform: rotate(-2deg); }
.end-card-header p { color: var(--ink-2); font-size: 1.1rem; margin-top: 6px; }
.stamp {
    position: absolute;
    top: 10px;
    right: 14px;
    padding: 4px 12px;
    border: 3px solid var(--pen-red);
    border-radius: var(--sketch-oval);
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--pen-red);
    transform: rotate(12deg);
    opacity: 0.9;
    animation: stampSlam 0.5s var(--ease-out-expo) 0.25s both;
    mix-blend-mode: multiply;
}
@keyframes stampSlam { 0% { transform: rotate(12deg) scale(2.4); opacity: 0; } 70% { transform: rotate(12deg) scale(0.95); opacity: 1; } 100% { transform: rotate(12deg) scale(1); } }
.game-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-item { text-align: center; padding: 10px 6px; border-bottom: 1.5px dashed var(--pencil); }
.stat-label { font-size: 0.95rem; color: var(--ink-2); margin-bottom: 2px; }
.stat-value { font-family: var(--font-hand); font-weight: 700; font-size: 1.6rem; color: var(--ink); }
.word-reveal { color: var(--ink-me); letter-spacing: 0.14em; }
.collaboration-info { padding: 8px 4px 0; }
.collaboration-info h3 { font-size: 1.4rem; margin-bottom: 8px; }
.player-contributions { display: flex; flex-direction: column; gap: 6px; }
.contribution { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.05rem; line-height: 1.4; }
.contribution .player-name { font-family: var(--font-hand); font-weight: 700; font-size: 1.3rem; line-height: 1.3; color: var(--ink-me); }
.contribution:nth-child(2) .player-name { color: var(--ink-them); }
.contribution .contribution-count { color: var(--ink-2); }

/* --- Word selection: pick a scrap ------------------------------- */
.word-select-sheet { max-height: 88dvh; }
.word-select-sheet .sheet-header { flex-direction: column; align-items: flex-start; gap: 4px; }
.word-select-sheet .sheet-header p { font-size: 1.05rem; color: var(--ink-2); }
.word-cloud-container { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; padding: 10px 0 14px; }
.word-cloud-item {
    --tilt: -2deg;
    min-height: var(--tap);
    padding: 0 16px;
    background: var(--paper-3);
    box-shadow: var(--shadow-note);
    font-family: var(--font-hand);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: 0.1em;
    color: var(--ink);
    transform: rotate(var(--tilt));
    animation: stickOn var(--dur-slow) var(--ease-spring) both;
    transition: transform var(--dur-fast) var(--ease-smooth), background var(--dur-fast) var(--ease-smooth);
}
.word-cloud-item:nth-child(even) { --tilt: 1.6deg; background: var(--paper-2); }
.word-cloud-item:nth-child(3n) { --tilt: 0.6deg; background: var(--sticky-blue); }
.word-cloud-item.selected { background: var(--sticky-yellow); outline: 2.5px solid var(--pen-red); outline-offset: 3px; transform: rotate(0) scale(1.06); }
.word-preview { text-align: center; padding: 10px; border: 2px solid var(--pen-red); border-radius: var(--sketch-oval); }
.preview-label { font-size: 1rem; color: var(--ink-2); }
.preview-word { font-family: var(--font-hand); font-size: 2rem; font-weight: 700; letter-spacing: 0.25em; color: var(--ink-me); }
.progress-btn { position: relative; overflow: hidden; }
.progress-btn .btn-text { position: relative; z-index: 2; }
.progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--highlighter); z-index: 1; }
.progress-btn.auto-progressing .progress-fill { animation: fillProgress var(--select-duration, 10s) linear forwards; }
.progress-btn:disabled { opacity: 1; color: var(--ink-3); }
@keyframes fillProgress { from { width: 0; } to { width: 100%; } }

/* --- Confirm / inactivity ------------------------------------------ */
.dialog-sheet { text-align: center; }
.dialog-sheet h3 { font-size: 1.7rem; margin-bottom: 8px; color: var(--ink); }
.dialog-sheet p { color: var(--ink-2); font-size: 1.1rem; line-height: 1.4; }
.dialog-sheet .countdown-inline { font-family: var(--font-hand); font-weight: 700; font-size: 1.4rem; color: var(--pen-red); }

@media (min-width: 600px) {
    .overlay { align-items: center; padding: 24px; }
    .sheet { width: min(100%, 460px); max-height: 85vh; padding: 26px 26px 24px; transform: rotate(-0.6deg); animation-name: dialogIn; }
    .chat-sheet { height: min(600px, 80vh); }
    .sheet-actions { flex-direction: row; flex-wrap: wrap; }
    .sheet-actions .btn { flex: 1 1 calc(50% - 6px); min-width: 0; white-space: normal; font-size: 1.2rem; line-height: 1.1; padding: 8px 14px; }
    .end-card-header { margin: -26px -26px 18px; }
    .player-contributions { flex-direction: row; justify-content: space-around; }
    .contribution { flex-direction: column; align-items: center; gap: 2px; }
}
@keyframes dialogIn { from { transform: rotate(-0.6deg) scale(0.94); opacity: 0; } to { transform: rotate(-0.6deg); opacity: 1; } }

/* Desktop: the chat page. Visible in the lobby and the game as the right
   page of the notebook; the drawn keys sit under the input during a game. */
@media (min-width: 1024px) {
    .app.screen-game-room #chat-overlay,
    .app.screen-game #chat-overlay {
        display: flex;
        position: static;
        padding: 0;
        background: none;
        align-items: stretch;
        z-index: 1;
    }
    .app.screen-game-room #chat-overlay .sheet,
    .app.screen-game #chat-overlay .sheet {
        width: 100%;
        height: 100%;
        max-height: none;
        padding: 44px 44px 30px 52px;
        background: transparent;
        box-shadow: none;
        transform: none;
        animation: none;
        border-radius: 0;
    }
    .app.screen-game-room #chat-overlay .sheet::before,
    .app.screen-game #chat-overlay .sheet::before { display: none; }
    .app.screen-game-room #close-chat,
    .app.screen-game #close-chat,
    .app.screen-game #chat-fab { display: none; }
    .app.screen-game #chat-overlay .chat-messages { flex: 1; }
    /* keys under the chat input during a game */
    #chat-overlay .keyboard { padding: 0; margin-top: 10px; }
    #chat-overlay .keyboard::before { content: 'or just type'; display: block; text-align: center; font-family: var(--font-hand); font-size: 1rem; color: var(--ink-3); margin-bottom: 6px; }
    .app:not(.screen-game) #chat-overlay .keyboard { display: none; }
}
