/* --- Base & Reset --- */
.cfws-container {
    --brand-teal: #003e41;
    --brand-gold: #eac7a1;
    
    box-sizing: border-box;
    max-width: 1000px; 
    width: 100%;
    margin: 1.5rem auto;
    background: #fdf8ef;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #1e293b;
    overflow: hidden;
    box-shadow: 0 10px 30px -15px rgba(0, 62, 65, 0.15);
}

/* --- Top Bar --- */
.cfws-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 20px;
    height: 64px;
    background: var(--brand-teal);
    color: var(--brand-gold);
    border-bottom: 2px solid var(--brand-gold);
}

.cfws-header-left { 
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    justify-content: flex-start;
    position: relative;
}

.cfws-header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.cfws-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
}

/* Hamburger Menu */
.cfws-menu-wrapper {
    position: relative;
}

.cfws-menu-btn {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--brand-gold);
    cursor: pointer;
    padding: 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.cfws-menu-btn:hover { opacity: 1; }

.cfws-menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid var(--brand-teal);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 160px;
    padding: 6px;
}

.cfws-menu-dropdown.show {
    display: block;
}

.cfws-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: none;
    border: none;
    padding: 10px 12px;
    text-align: left;
    font-size: 14px;
    font-weight: 500;
    color: var(--brand-teal);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

.cfws-dropdown-item:hover {
    background: var(--brand-gold);
}

.cfws-dropdown-item i {
    font-size: 14px;
    opacity: 0.7;
}

.cfws-timer {
    font-size: 16px;
    font-weight: 600;
    color: var(--brand-gold);
    font-variant-numeric: tabular-nums;
}

.cfws-timer.is-critical {
    color: #ef4444;
    animation: pulse-text 1s infinite alternate;
}

.cfws-penalty-toast {
    position: absolute;
    left: 85px;
    top: 50%;
    transform: translateY(-50%) translateX(-10px);
    background: #ef4444;
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
}

.cfws-penalty-toast.show {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

@keyframes pulse-text {
    from { opacity: 1; }
    to { opacity: 0.5; }
}

.cfws-score-pill {
    background: var(--brand-gold);
    color: var(--brand-teal);
    padding: 4px 14px;
    border-radius: 99px;
    font-size: 15px;
    font-weight: 700;
    min-width: 60px;
    text-align: center;
}

.cfws-text-btn {
    background: none;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--brand-gold);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.cfws-text-btn:hover { 
    background: rgba(234, 199, 161, 0.1); 
    border-color: var(--brand-gold);
}

/* --- Main Layout --- */
.cfws-main-body { 
    display: flex; 
    gap: 0;
    align-items: stretch;
}

/* --- Grid Area --- */
.cfws-grid-area { 
    flex: 1; 
    display: flex; 
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: #fdf8ef;
}

.cfws-grid-wrapper {
    position: relative;
    background: #ffffff;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid var(--brand-teal);
    width: 100%;
    max-width: 560px;
    aspect-ratio: 1;
    touch-action: none;
    user-select: none;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 62, 65, 0.08);
}

.cfws-grid { 
    display: grid; 
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); 
    grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
    width: 100%; 
    height: 100%;
    gap: 2px;
}

.cfws-cell { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: 600; 
    font-size: clamp(14px, 2.5vw, 20px); 
    color: var(--brand-teal);
    border-radius: 4px;
    cursor: pointer; 
    transition: background 0.15s, color 0.15s; 
    z-index: 0;
}

#cfws-marker-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.cfws-puzzle-footer {
    margin-top: 16px;
    text-align: center;
    font-size: 13px;
    color: #64748b;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cfws-powered-by {
    font-size: 11px;
    color: #94a3b8;
}

/* --- Sidebar --- */
.cfws-sidebar { 
    flex: 0 0 280px; 
    background: #ffffff;
    border-left: 1px solid #e2e8f0;
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.cfws-sidebar-header {
    margin-bottom: 12px;
    border-bottom: 2px solid var(--brand-teal);
    padding-bottom: 8px;
}

.cfws-sidebar-header h2 {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    color: var(--brand-teal);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cfws-word-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 500px;
    overflow-y: auto;
    padding-right: 4px;
}

.cfws-word-list::-webkit-scrollbar { width: 6px; height: 6px; }
.cfws-word-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }

.cfws-word-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 10px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    color: var(--brand-teal);
    cursor: pointer;
    transition: all 0.2s;
}

.cfws-word-card.is-selected {
    background: var(--brand-gold);
    border-color: var(--brand-teal);
    box-shadow: inset 0 0 0 1px var(--brand-teal);
}

.cfws-word-card.is-found {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #94a3b8;
    text-decoration: line-through;
    opacity: 0.7;
    cursor: default;
}

.cfws-word-card.is-revealed {
    background: #fef2f2 !important;
    border-color: #fca5a5 !important;
    color: #ef4444 !important;
    text-decoration: line-through;
    opacity: 1 !important;
    cursor: default;
}

.cfws-word-card i { display: none; }

.cfws-word-card.is-revealed i { 
    display: block !important; 
}

.cfws-word-list[data-hide-target="1"] .cfws-word-card.is-found {
    text-decoration: none !important;
    opacity: 1 !important;
    color: var(--brand-teal) !important;
    font-weight: 700;
    background: #ecfdf5;
    border-color: #10b981;
}

/* --- Animations --- */
@keyframes pop-cell {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}
.animate-pop { animation: pop-cell 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

.cfws-cell.is-hint { 
    background-color: var(--brand-gold) !important;
    color: var(--brand-teal) !important; 
    font-weight: 900 !important;
    border-radius: 50% !important;
    box-shadow: 0 0 15px 5px rgba(234, 199, 161, 0.8) !important;
    animation: soft-gold-pulse 0.8s ease-in-out infinite !important; 
    z-index: 50 !important; 
}

@keyframes soft-gold-pulse { 
    0%, 100% { transform: scale(1); box-shadow: 0 0 10px 2px rgba(234, 199, 161, 0.6); } 
    50% { transform: scale(1.2); box-shadow: 0 0 25px 8px rgba(234, 199, 161, 1); } 
}

.cfws-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--brand-teal);
    color: var(--brand-gold);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 999999;
    pointer-events: none;
}

.cfws-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   MODALS
   ============================================================ */
.cfws-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 62, 65, 0.7);
    backdrop-filter: blur(4px);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.cfws-modal-box {
    background: #ffffff;
    width: 100%;
    max-width: 380px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    opacity: 0;
    animation: cfwsPopIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    position: relative;
    border: 2px solid var(--brand-teal);
}

@keyframes cfwsPopIn { to { transform: scale(1); opacity: 1; } }

.cfws-modal-header {
    background: var(--brand-teal);
    height: 80px;
    position: relative;
}

.cfws-modal-icon-wrap {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 60px;
    background: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border: 3px solid #ffffff;
    z-index: 2;
}

.cfws-modal-body {
    padding: 40px 20px 20px;
    text-align: center;
}

.cfws-modal-title {
    margin: 0 0 8px;
    font-size: 22px;
    color: var(--brand-teal);
    font-weight: 800;
}

.cfws-modal-msg {
    font-size: 15px;
    color: #64748b;
    margin-bottom: 20px;
}

.cfws-modal-points {
    display: inline-block;
    background: var(--brand-gold);
    color: var(--brand-teal);
    padding: 6px 18px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 10px;
}

.cfws-modal-footer {
    padding: 0 20px 20px;
    display: flex;
    gap: 12px;
}

.cfws-btn {
    flex: 1;
    padding: 12px 10px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
    text-align: center;
}

.cfws-btn:hover { transform: translateY(-2px); }
.cfws-btn:active { transform: translateY(1px); }

.cfws-btn-primary {
    background: var(--brand-teal);
    color: var(--brand-gold);
}

.cfws-btn-secondary {
    background: #f1f5f9;
    color: var(--brand-teal);
}

.cfws-btn-danger {
    background: #ef4444;
    color: #ffffff;
}

@media (max-width: 380px) {
    .cfws-modal-footer { flex-direction: column-reverse; }
    .cfws-btn { width: 100%; }
}

/* --- Legacy Leaderboard Styles --- */
.cfws-leaderboard { max-width: 600px; margin: 2rem auto; background: #fff; border-radius: 12px; padding: 30px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); font-family: system-ui, -apple-system, sans-serif; }
.cfws-leaderboard h3 { margin: 0 0 20px; text-align: center; color: var(--brand-teal); font-size: 24px; font-weight: 800; }
.cfws-lb-list { list-style: none; padding: 0; margin: 0; }
.cfws-lb-list li { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid #eee; font-size: 16px; }
.cfws-lb-list li:last-child { border-bottom: none; }
.cfws-lb-rank { width: 32px; height: 32px; background: var(--brand-teal); color: var(--brand-gold); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; margin-right: 16px; }
.cfws-lb-list li:nth-child(1) .cfws-lb-rank { background: #FFD700; color: #000; }
.cfws-lb-list li:nth-child(2) .cfws-lb-rank { background: #C0C0C0; color: #000; }
.cfws-lb-list li:nth-child(3) .cfws-lb-rank { background: #CD7F32; color: #fff; }
.cfws-lb-name { flex: 1; font-weight: 600; color: #333; }
.cfws-lb-time { font-family: monospace; font-weight: 700; color: #666; font-size: 15px; text-align: right; }

/* ============================================================
   MOBILE UI OPTIMIZATION (Neat labels + touch logic)
   ============================================================ */
@media (max-width: 768px) {
    .cfws-container { margin: 0 auto; border-radius: 8px; overflow: visible; touch-action: pan-y; overscroll-behavior: contain; }
    .cfws-header, .cfws-main-body, .cfws-grid-area, .cfws-sidebar { touch-action: pan-y; }
    
    .cfws-header { padding: 0 10px; height: 64px; border-radius: 8px 8px 0 0; }
    .cfws-header-left { gap: 8px; }
    .cfws-timer { font-size: 15px; letter-spacing: 0.5px; }
    .cfws-score-pill { font-size: 14px; padding: 4px 14px; border: 1px solid var(--brand-gold); }
    
    .cfws-header-right { gap: 2px; }
    .cfws-text-btn { 
        padding: 4px 6px; 
        flex-direction: column; 
        gap: 10px; 
    }
    .cfws-btn-text { 
        display: block; 
        font-size: 9px; 
        line-height: 1;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    .cfws-text-btn i { font-size: 16px; }
    
    .cfws-main-body { flex-direction: column; }
    .cfws-grid-area { padding: 0 6px; touch-action: pan-y; }
    .cfws-grid-wrapper { touch-action: none !important; max-width: 100%; max-height: 55vh; padding: 2px; border-radius: 4px; border: none; box-shadow: none; }
    .cfws-grid { grid-template-rows: repeat(var(--rows), minmax(0, 1fr)); gap: 1px; }
    .cfws-cell { font-size: clamp(14px, 4vw, 22px); }
    .cfws-puzzle-footer { display: none; }
    
    .cfws-sidebar { border-left: none; border-top: 2px solid var(--brand-teal); padding: 12px; background: #fdf8ef; border-radius: 0 0 8px 8px; touch-action: pan-y; }
    .cfws-sidebar-header { display: none; }
    .cfws-word-list { display: grid; grid-auto-flow: column; grid-template-rows: repeat(4, 40px); grid-auto-columns: minmax(140px, 160px); gap: 8px; overflow-x: auto; overflow-y: hidden; padding-bottom: 8px; width: 100%; box-sizing: border-box; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; touch-action: pan-x pan-y; }
    .cfws-word-list::-webkit-scrollbar { height: 6px; }
    .cfws-word-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
    .cfws-word-card { padding: 0 8px; font-size: 13px; justify-content: center; text-align: center; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; height: 40px; width: 100%; box-sizing: border-box; background: #ffffff; border: 1px solid #cbd5e1; }
    .cfws-word-card.is-selected { background: var(--brand-gold); border-color: var(--brand-teal); box-shadow: inset 0 0 0 1px var(--brand-teal); }
    .cfws-word-card.is-found { background: #f1f5f9; border-color: #e2e8f0; color: #94a3b8; }
    .cfws-word-card.is-revealed { background: #fef2f2; border-color: #fca5a5; color: #ef4444; }
}

/* ============================================================
   DESKTOP: WORD LIST BENEATH PUZZLE (Opt-in via Admin)
   ============================================================ */
@media (min-width: 769px) {
    .cfws-container.cfws-layout-below .cfws-main-body { flex-direction: column; align-items: stretch; }
    .cfws-container.cfws-layout-below .cfws-grid-area { flex: 0 0 auto; padding-bottom: 16px; }
    .cfws-container.cfws-layout-below .cfws-puzzle-footer { display: none; }
    .cfws-container.cfws-layout-below .cfws-sidebar { flex: 0 0 auto; border-left: none; border-top: 2px solid var(--brand-teal); background: #fdf8ef; padding: 12px 20px; }
    .cfws-container.cfws-layout-below .cfws-sidebar-header { margin-bottom: 8px; border-bottom: none; padding-bottom: 0; }
    .cfws-container.cfws-layout-below .cfws-sidebar-header h2 { font-size: 12px; letter-spacing: 0.8px; color: #64748b; }
    .cfws-container.cfws-layout-below .cfws-word-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); grid-auto-rows: 32px; gap: 6px; max-height: 200px; overflow-y: auto; padding-right: 4px; }
    .cfws-container.cfws-layout-below .cfws-word-list .cfws-empty-words { grid-column: 1 / -1; }
    .cfws-container.cfws-layout-below .cfws-word-card { padding: 0 8px; font-size: 12px; justify-content: center; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; height: 32px; box-sizing: border-box; line-height: 1; }
}

/* ============================================================
   DESKTOP: FLUSH GRID & EXPANDED SIDEBAR (Sidebar Layout Only)
   ============================================================ */
@media (min-width: 769px) {
    .entry-content:has(.cfws-container),
    .entry-summary:has(.cfws-container),
    .post-content:has(.cfws-container),
    .site-content:has(.cfws-container) {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .cfws-container:not(.cfws-layout-below) .cfws-main-body {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 190px;
        grid-template-rows: auto auto;
        align-items: start;
    }

    .cfws-container:not(.cfws-layout-below) .cfws-grid-area {
        display: contents; 
    }

    .cfws-container:not(.cfws-layout-below) .cfws-grid-wrapper {
        grid-column: 1;
        grid-row: 1;
        justify-self: start;
        width: 100%;
        max-width: 570px;
        border: none !important;
        padding: 12px 5px !important;
    }

    .cfws-container:not(.cfws-layout-below) .cfws-puzzle-footer {
        grid-column: 1;
        grid-row: 2;
        justify-self: start;
        width: 100%;
        max-width: 560px;
        text-align: center;
        margin-top: 16px;
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .cfws-container:not(.cfws-layout-below) .cfws-sidebar {
        grid-column: 2;
        grid-row: 1;
        height: 0; 
        min-height: 100%; 
        padding: 4px !important;
        min-width: 120px;
        display: flex;
        flex-direction: column;
        overflow: hidden; 
    }

    .cfws-container:not(.cfws-layout-below) .cfws-word-list {
        flex: 1;
        overflow-y: auto;
        max-height: none;
        min-height: 0;
        padding-right: 4px;
    }
}

@media (max-width: 768px) {
    .cfws-modal-overlay {
        padding: 120px 15px 20px 15px !important;
        align-items: flex-start;
    }

    .cfws-modal-box {
        max-height: calc(100dvh - 140px) !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .cfws-modal-header {
        height: 60px !important;
    }

    .cfws-modal-header h3 {
        margin-top: 0 !important;
        line-height: 60px !important;
        text-align: center !important;
        font-size: 18px !important;
    }

    #cfws-close-instructions {
        top: 15px !important; 
    }

    .cfws-modal-body {
        overflow-y: auto !important;
        flex: 1;
        padding: 20px 15px 15px !important;
    }

    .cfws-modal-footer {
        flex-shrink: 0;
    }
}

/* ============================================================
   MOBILE: ALLOW SCROLLING ON GRID AFTER GAME OVER
   ============================================================ */
@media (max-width: 768px) {
    .cfws-container.game-over .cfws-grid-wrapper,
    .cfws-container.game-over .cfws-grid {
        touch-action: pan-y !important; /* Restores vertical page scrolling */
    }
}