/* === Fall game ====================================================
   Companion to js/games/fall.js + games/fall.partial.html.
   Wave-based touchpoint-trace arcade: .fall-lane (right side) holds
   the .fall-char drops; the user traces them on #fall-canvas inside
   .fall-canvas-wrap. Floor line at the bottom of .fall-lane marks
   the failure threshold. Guide lines (the ::before/::after of
   .fall-canvas-wrap) cross at center for stroke alignment.
   ==================================================================== */

.fall-game {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 480px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
    z-index: 2;
}

.fall-game.active {
    opacity: 1;
    pointer-events: auto;
}

.fall-game-header {
    width: 320px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
    padding: 0 4px;
}

.fall-score {
    font-size: 0.85rem;
    color: var(--green);
    font-weight: 600;
}

.fall-stats {
    font-size: 0.8rem;
    color: var(--accent);
}

/* Session progress bar — fills as the user clears chars across all
   waves. Subtler tone than the feedback flash so it doesn't compete
   for attention. 0.3s transition makes rebuild-driven regress
   perceptible rather than abrupt. */
.fall-overall-progress {
    width: 320px;
    height: 4px;
    background: var(--subtle-bg);
    border-radius: 2px;
    overflow: hidden;
    margin: -4px 0 6px;
}
.fall-overall-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    background: var(--green);
    opacity: 0.7;
    transition: width 0.3s ease;
}

.fall-arena {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    position: relative;
    width: 100%;
}

/* Falling lane */
.fall-lane {
    width: 48px;
    height: 290px;
    position: absolute;
    left: calc(50% + 155px);
    top: 0;
    overflow: hidden;
    border-radius: 12px;
    background: var(--subtle-bg);
    border: 1px solid var(--divider);
}

/* Floor line at the bottom */
.fall-lane::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 4px;
    right: 4px;
    height: 2px;
    background: var(--red);
    border-radius: 1px;
}

.fall-char {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    transition: color 0.3s;
    pointer-events: none;
    /* top is animated via JS */
}

.fall-char.active {
    color: var(--heading);
    text-shadow: 0 0 8px var(--accent-active);
}

.fall-char.missed {
    color: var(--red);
}

.fall-char.cleared {
    color: var(--green);
    opacity: 0;
    transition: opacity 0.4s;
}

/* Center writing area */
.fall-canvas-wrap {
    width: 290px;
    height: 290px;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.fall-canvas-wrap.shake-wrong {
    animation: fallShake 0.4s ease-out;
    box-shadow: 0 0 0 3px var(--red), var(--card-shadow);
}
@keyframes fallShake {
    0% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
    100% { transform: translateX(0); }
}

.fall-canvas-wrap canvas {
    width: 260px;
    height: 260px;
    touch-action: none;
    -webkit-touch-callout: none;
}

/* Guide lines — cross at center, dashed */
.fall-canvas-wrap::before, .fall-canvas-wrap::after {
    content: '';
    position: absolute;
    border: 0;
    border-style: dashed;
    border-color: var(--guide-line);
    pointer-events: none;
    z-index: 1;
}

.fall-canvas-wrap::before {
    left: 50%; top: 0; bottom: 0;
    border-left-width: 1.5px;
}

.fall-canvas-wrap::after {
    top: 50%; left: 0; right: 0;
    border-top-width: 1.5px;
}

.fall-prompt {
    min-height: 30px;
    font-size: 0.78rem;
    font-style: italic;
    color: var(--text-faint);
    text-align: center;
    padding: 0 16px;
    line-height: 1.3;
    transition: opacity 0.3s;
}

.fall-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--close-bg);
    border: 1px solid var(--close-border);
    color: var(--close-color);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: all 0.2s;
}

.fall-close:hover {
    background: var(--close-hover);
    color: var(--text-muted);
}

.fall-feedback {
    font-size: 0.85rem;
    font-weight: 700;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    text-align: center;
    /* min-height (not height) so the empty-state reserves space but
       multi-line completion messages can grow without overlapping the
       Continue button below. */
    min-height: 1.2rem;
    line-height: 1.35;
    padding: 0 8px;
}

/* End-of-session continue button — same shape as the Swipe equivalent
   so the post-game CTAs read as a consistent pattern. Hidden during
   play; revealed when fallGameComplete fires. */
.fall-continue-btn {
    display: block;
    margin: 12px auto 0;
    padding: 10px 22px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 0.02em;
    transition: background 0.15s, transform 0.1s;
}
.fall-continue-btn:hover { background: var(--heading); }
.fall-continue-btn:active { transform: translateY(1px); }
.fall-continue-btn[hidden] { display: none; }

/* Game-over / round-complete overlay */
.fall-overlay {
    position: absolute;
    inset: 0;
    background: var(--overlay-bg);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.fall-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
