.cw-intro {
    max-width: 640px;
}

.cw-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.cw-difficulty {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.cw-difficulty-label {
    font-weight: 600;
    margin-right: 4px;
}

.cw-seed,
.cw-timer {
    font-family: monospace;
    color: #6c757d;
    font-size: 0.85rem;
}

.cw-timer {
    margin-left: 10px;
    color: #212529;
    font-weight: 600;
}

.cw-meta {
    display: flex;
    align-items: center;
}

.cw-layout {
    display: flex;
    flex-wrap: wrap;
    gap: 28px;
    align-items: flex-start;
}

.cw-board-wrap {
    flex: 0 1 auto;
    max-width: 100%;
}

.cw-grid {
    /* Fallback before JS measures the container; fitGrid() sets the exact size. */
    --cw-cell: clamp(14px, calc((100vw - 80px) / var(--cw-cols, 13)), 40px);
    display: grid;
    gap: 2px;
    width: max-content;
    max-width: 100%;
    background: transparent;
    touch-action: manipulation;
}

.cw-cell {
    position: relative;
    width: var(--cw-cell);
    height: var(--cw-cell);
    background: #fff;
    border: 1px solid #adb5bd;
    border-radius: 3px;
}

.cw-cell.cw-block {
    background: transparent;
    border-color: transparent;
}

.cw-cell input {
    width: 100%;
    height: 100%;
    border: 0;
    padding: 0;
    text-align: center;
    text-transform: uppercase;
    font-size: calc(var(--cw-cell) * 0.55);
    font-weight: 600;
    background: transparent;
    caret-color: #212529;
    color: #212529;
    border-radius: 3px;
}

.cw-cell input:focus,
.cw-active-cell input {
    outline: 2px solid #212529;
    outline-offset: -2px;
}

.cw-num {
    position: absolute;
    top: 1px;
    left: 3px;
    font-size: calc(var(--cw-cell) * 0.28);
    line-height: 1;
    color: #6c757d;
    pointer-events: none;
    z-index: 1;
}

.cw-active-word {
    background: #e7f1ff;
}

.cw-wrong input {
    color: #dc3545;
}

.cw-revealed input {
    color: #6c757d;
}

.cw-done .cw-cell:not(.cw-block) {
    background: #e6f4ea;
}

.cw-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.cw-hint {
    margin-top: 10px;
    font-size: 0.85rem;
    max-width: 480px;
}

.cw-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(33, 37, 41, 0.55);
}

.cw-modal-open {
    display: flex;
}

.cw-modal-card {
    position: relative;
    max-width: 340px;
    width: 100%;
    padding: 26px 22px 22px;
    background: #fff;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: cw-pop 0.25s ease-out;
}

@keyframes cw-pop {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.cw-modal-card h3 {
    margin: 6px 0 4px;
}

.cw-modal-emoji {
    font-size: 2.4rem;
    line-height: 1;
}

.cw-modal-time {
    font-size: 1.3rem;
    margin: 6px 0 2px;
}

.cw-modal-nohints {
    color: #2e7d32;
    font-weight: 600;
    font-size: 0.95rem;
    margin: 0 0 6px;
}

.cw-modal-preview {
    display: block;
    width: 100%;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin: 8px 0 10px;
}

.cw-modal-text {
    color: #6c757d;
    font-size: 0.9rem;
    margin-bottom: 14px;
}

.cw-modal-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.cw-modal-close {
    position: absolute;
    top: 6px;
    right: 10px;
    border: 0;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: #868e96;
    padding: 4px;
}

.cw-clues {
    flex: 1 1 340px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    min-width: 0;
}

.cw-clues-col {
    flex: 1 1 280px;
    min-width: 0;
}

.cw-clues-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 8px;
}

.cw-clue-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.cw-clue {
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.92rem;
    line-height: 1.35;
}

.cw-clue:hover {
    background: #f1f3f5;
}

.cw-clue-active {
    background: #e7f1ff;
}

.cw-clue-len {
    color: #868e96;
    white-space: nowrap;
}

.cw-about {
    margin-top: 28px;
    max-width: 640px;
}

.cw-panel {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    background: #212529;
    color: #fff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.25);
    padding-bottom: env(safe-area-inset-bottom);
}

.cw-cluebar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 4px;
}

.cw-cluebar-text {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
    line-height: 1.35;
}

.cw-cluebar-text b {
    margin-right: 4px;
}

.cw-cluebar-btn {
    flex: 0 0 auto;
    min-width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    background: transparent;
    color: #fff;
    font-size: 1.3rem;
    line-height: 1;
}

.cw-keyboard {
    padding: 4px 4px 8px;
    user-select: none;
    -webkit-user-select: none;
}

.cw-kb-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 5px;
    padding: 0 2px;
}

.cw-key {
    flex: 1 1 0;
    min-width: 0;
    max-width: 42px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: #495057;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1;
    touch-action: manipulation;
}

.cw-key:active {
    background: #6c757d;
}

.cw-key-back {
    flex: 1.7 1 0;
    max-width: 70px;
    font-size: 1.2rem;
}

@media (max-width: 576px) {
    .cw-layout {
        gap: 18px;
    }
}

/* Action buttons relocated into the dark panel on mobile. */
.cw-panel .cw-actions {
    margin: 8px 10px 0;
    gap: 6px;
}

.cw-panel .cw-actions .btn {
    border: 1px solid rgba(255, 255, 255, 0.45);
    color: #fff;
    background: transparent;
    font-size: 0.78rem;
    padding: 3px 9px;
}

@media (max-width: 768px) {
    .cw-panel {
        display: block;
    }

    /* Fallback; JS sets the exact panel height as padding. */
    .cw-layout {
        padding-bottom: 250px;
    }
}
