/* crossword.css — wait-overlay project keyword crossword */

/*
 * Full-screen wait overlay — simple document flow inside a scrollable shell.
 * Avoid height:100% + overflow:hidden + flex-center: that clips the TOP row of
 * the board (e.g. the U of UPDRSIII at r=0) so letters appear “missing”.
 */
.grok-wait-overlay,
#grokProcessingOverlay.grok-wait-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    background: rgba(255, 255, 255, 0.95);
    z-index: 99999;
    display: block;              /* not flex-center — keeps top of card reachable */
    overflow-x: hidden;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 12px 10px 28px;
    box-sizing: border-box;
}

.grok-wait-card {
    max-width: 1000px;
    width: 96vw;
    height: auto;
    max-height: none;
    text-align: center;
    padding: 0 16px 16px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
    margin: 0 auto;
    position: relative;
    box-sizing: border-box;
    display: block;
    overflow: visible;
}

.grok-wait-topbar {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 4px 4px;
    margin: 0 -4px 2px;
    background: #fff;
    border: none !important;
    border-bottom: none !important;
    box-shadow: none !important;
}

/* Hide empty subtitle so it does not leave a blank line under the title */
.grok-wait-label:empty,
#stickman-label:empty {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

.grok-wait-topbar-text {
    flex: 1 1 200px;
    text-align: left;
    min-width: 0;
}

.grok-wait-message {
    margin: 0 0 4px;
    font-size: 1.05rem;
    color: #263F3B;
    font-weight: 600;
}

.grok-wait-label {
    margin: 0;
    font-size: 0.85rem;
    color: #6b7c78;
    font-style: italic;
}

.grok-wait-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    flex: 0 0 auto;
}

.grok-wait-close-btn {
    margin-left: 0 !important;
    display: inline-block !important;
    padding: 0 22px !important;
    min-width: 100px !important;
    height: 40px !important;
    font-size: 15px !important;
}

.grok-wait-hint {
    margin: 8px 0 0;
    font-size: 0.78rem;
    color: #8a9e98;
}

/* Crossword stage: natural height, never clip the first row */
#stickman-stage.wait-stage,
#stickman-stage.wait-stage.cw-stage-active,
#stickman-stage.cw-stage-active {
    margin: 0 0 6px 0 !important;
    width: 100%;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    flex: none !important;
    display: block !important;
    overflow: visible !important;
    padding: 0 0 8px !important;
    box-sizing: border-box;
    text-align: center;
}

/*
 * Controls live in #cw-controls-slot — sibling above #stickman-stage.
 * No divider lines; tight gap so the grid sits just under the buttons.
 */
.cw-controls-slot {
    display: block;
    width: 100%;
    position: static !important;
    flex: 0 0 auto;
    background: #fff;
    padding: 0;
    margin: 0;
    border: none !important;
    box-shadow: none !important;
    box-sizing: border-box;
    min-height: 0;
}

.cw-controls-slot:empty {
    display: none;
    margin: 0;
    padding: 0;
    border: 0;
}

.cw-controls {
    display: block;
    width: 100%;
    position: static !important;
    float: none !important;
    clear: both;
    z-index: auto !important;
    background: #fff;
    padding: 2px 0;
    margin: 0;
    border: none !important;
    box-shadow: none !important;
    box-sizing: border-box;
}

/* Kill any leftover divider between title / buttons / grid */
.grok-wait-card > .grok-wait-topbar,
.grok-wait-card > .cw-controls-slot,
.grok-wait-card > #stickman-stage,
.grok-wait-card .cw-controls,
.grok-wait-card .cw-toolbar,
.grok-wait-card .cw-status {
    border: none !important;
    border-top: none !important;
    border-bottom: none !important;
    box-shadow: none !important;
}

.cw-status:empty {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.cw-wrap,
.cw-main {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-items: flex-start;
    justify-content: center;
    text-align: left;
    max-width: 960px;
    margin: 0 auto;
    max-height: none;
    overflow: visible;
    padding: 0 4px;
    position: static !important;
    clear: both;
    z-index: auto !important;
}

.cw-board-wrap {
    flex: 0 0 auto;
    position: static !important;
    margin-top: 0;
}

.cw-board {
    border-collapse: collapse;
    margin: 0 auto;
    background: #1a2e2a;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.cw-board td {
    width: 28px;
    height: 28px;
    padding: 0;
    position: relative;
    box-sizing: border-box;
    overflow: visible; /* number badge must not clip letter */
}

.cw-board td.cw-block {
    background: #263F3B;
    border: 1px solid #1a2e2a;
}

.cw-board td.cw-cell {
    background: #fffef8;
    border: 1px solid #8a9e98;
}

.cw-board td.cw-cell.cw-active {
    background: #fff3c4;
    box-shadow: inset 0 0 0 2px #c9a227;
}

.cw-board td.cw-cell.cw-related {
    background: #e8f4f0;
}

.cw-board td.cw-cell.cw-correct {
    background: #d4edda;
}

.cw-board td.cw-cell.cw-wrong {
    background: #f8d7da;
}

/* Fully correct word — letters cannot be changed */
.cw-board td.cw-cell.cw-locked {
    background: #d1fae5;
}

.cw-board td.cw-cell.cw-locked.cw-related {
    background: #bbf7d0;
}

.cw-board td.cw-cell.cw-locked .cw-input {
    cursor: default;
    color: #065f46;
    font-weight: 700;
}

.cw-num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 8px;
    line-height: 1;
    color: #333;
    font-weight: 600;
    pointer-events: none;
    z-index: 1;
}

.cw-input {
    position: relative;
    z-index: 2; /* letter sits above clue number so U/P/etc. always visible */
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    color: #1a2e2a;
    padding: 7px 0 0 0;
    box-sizing: border-box;
    caret-color: #263F3B;
}

.cw-input:focus {
    outline: none;
}

.cw-clues {
    flex: 1 1 220px;
    min-width: 200px;
    max-width: 320px;
    font-size: 12.5px;
    color: #263F3B;
}

.cw-clues h4 {
    margin: 0 0 6px 0;
    font-size: 13px;
    color: #263F3B;
    border-bottom: 1px solid #c5d4cf;
    padding-bottom: 3px;
}

.cw-clues ul {
    list-style: none;
    margin: 0 0 12px 0;
    padding: 0;
}

.cw-clues li {
    margin: 0 0 4px 0;
    padding: 3px 6px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.35;
}

.cw-clues li:hover,
.cw-clues li.cw-clue-active {
    background: #e8f4f0;
}

.cw-clues .cw-clue-num {
    font-weight: 700;
    margin-right: 4px;
}

.cw-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    margin: 0 0 6px 0;
    /* Kill any sticky/fixed leftover from older CSS — buttons must not cover the grid */
    position: static !important;
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    float: none !important;
    z-index: auto !important;
    transform: none !important;
    background: #fff;
    padding: 4px 0;
}

.cw-toolbar button,
.wait-mode-bar button {
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 2px solid #263F3B;
    background: #fff;
    color: #263F3B;
    cursor: pointer;
    font-weight: 600;
    position: static !important;
}

.cw-toolbar button:hover,
.wait-mode-bar button:hover {
    background: #e8f4f0;
}

.cw-toolbar button.cw-primary,
.wait-mode-bar button.wait-mode-active {
    background: #263F3B;
    color: #fff;
}

.wait-mode-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.wait-mode-bar .wait-mode-label {
    font-size: 13px;
    color: #6b7c78;
    margin-right: 4px;
}

.cw-status {
    font-size: 12px;
    color: #6b7c78;
    text-align: center;
    margin: 4px 0 0;
    min-height: 1.2em;
}

.cw-empty-msg {
    padding: 24px 16px;
    color: #263F3B;
    font-size: 14px;
    max-width: 420px;
    margin: 0 auto;
    line-height: 1.5;
}

/* When crossword is active, stage does not need huge video min-height */
#stickman-stage.cw-stage-active,
#stickman-stage.wait-stage.cw-stage-active {
    min-height: 0 !important;
    align-items: flex-start !important;
    height: auto !important;
}

/*
 * Cinema mode — short-video waits only (class toggled by short_animations.js).
 * True cardless layout: full black viewport, message + clip only (no panel).
 * Crossword mode never gets .wait-cinema (stays light/readable).
 */
#grokProcessingOverlay.grok-wait-overlay.wait-cinema,
.grok-wait-overlay.wait-cinema {
    background: #000 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden !important;
}

/* Card markup remains for crossword reuse, but cinema strips all panel look */
.grok-wait-overlay.wait-cinema .grok-wait-card {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    max-width: none !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100%;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    box-sizing: border-box;
    overflow: visible;
}

.grok-wait-overlay.wait-cinema .grok-wait-topbar {
    background: transparent !important;
    justify-content: center;
    width: 100%;
    max-width: min(920px, 94vw);
    padding: 20px 16px 8px;
    margin: 0;
    flex: 0 0 auto;
    order: 1;
}

.grok-wait-overlay.wait-cinema .grok-wait-topbar-text {
    text-align: center;
    flex: 1 1 auto;
}

.grok-wait-overlay.wait-cinema .grok-wait-message,
.grok-wait-overlay.wait-cinema #stickman-message {
    color: rgba(255, 255, 255, 0.82) !important;
    font-weight: 500;
    font-size: 1rem;
    letter-spacing: 0.02em;
    margin: 0 0 2px !important;
}

.grok-wait-overlay.wait-cinema .grok-wait-label,
.grok-wait-overlay.wait-cinema #stickman-label {
    color: rgba(255, 255, 255, 0.45) !important;
}

/* Hide “wait style” footer in cinema — less chrome, more calm */
.grok-wait-overlay.wait-cinema .grok-wait-hint,
.grok-wait-overlay.wait-cinema #wait-pref-hint {
    display: none !important;
}

.grok-wait-overlay.wait-cinema .cw-controls-slot {
    display: none !important;
    background: transparent !important;
}

.grok-wait-overlay.wait-cinema .grok-wait-actions {
    justify-content: center;
}

/* Video stage fills the middle; no panel around it */
.grok-wait-overlay.wait-cinema #stickman-stage.wait-stage:not(.cw-stage-active),
.grok-wait-overlay.wait-cinema #stickman-stage.wait-video-mode {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    margin: 0 !important;
    padding: 4px 12px 24px !important;
    order: 2;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent !important;
}

/* Clip sits directly on black — no floating “card” shadow */
.grok-wait-overlay.wait-cinema .wait-clip-video {
    box-shadow: none !important;
    border-radius: 10px;
    background: #000 !important;
}

/*
 * Video wait: stage hugs each clip’s real aspect ratio.
 * No fixed black letterbox — portrait and landscape clips size themselves.
 */
#stickman-stage.wait-stage:not(.cw-stage-active),
#stickman-stage.wait-stage.wait-video-mode:not(.cw-stage-active) {
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 10px 4px 14px !important;
    background: transparent;
}

#stickman-stage.wait-stage:not(.cw-stage-active) .wait-clip-video,
#stickman-stage .wait-clip-video {
    display: block;
    margin: 0 auto;
    /* JS fitWaitClip() sets exact px size from videoWidth/videoHeight.
       max-* keeps a safety cap if metadata is slow; no fixed black box. */
    max-width: min(920px, 92vw);
    max-height: min(640px, 68vh);
    width: auto;
    height: auto;
    min-height: 200px; /* never collapse to an invisible 0-height frame */
    object-fit: contain;
    border-radius: 14px;
    /* Match cinema black (also fine on light card if ever shown without wait-cinema) */
    background: #000;
    box-shadow:
        0 2px 4px rgba(15, 23, 42, 0.06),
        0 16px 40px rgba(15, 23, 42, 0.16);
    /* ALWAYS visible by default — fades are applied via inline style in JS only.
       Never hide with CSS opacity:0 (that caused blank wait cards). */
    opacity: 1;
    transform: scale(1);
    /* Fallback duration; JS setClipOpacity() overrides with CLIP_FADE_MS (1.4s) */
    transition:
        opacity 1.4s ease,
        transform 1.4s ease,
        width 0.4s ease,
        height 0.4s ease;
}

@media (max-width: 640px) {
    #stickman-stage.wait-stage:not(.cw-stage-active) .wait-clip-video,
    #stickman-stage .wait-clip-video {
        max-width: min(100%, 94vw) !important;
        max-height: min(58vh, 520px) !important;
        border-radius: 12px;
    }
}

.cw-root {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    display: block;
    position: static !important;
    text-align: center;
}

@media (max-width: 640px) {
    .cw-board td {
        width: 24px;
        height: 24px;
    }
    .cw-input {
        font-size: 13px;
    }
}
