/* =============================================
   Word Search Generator — Frontend Styles
   ============================================= */

/* ── Container ── */
.wsg-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    max-width: 720px;
    margin: 24px auto;
    padding: 24px;
    background: var(--wsg-bg, #ffffff);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.1);
    box-sizing: border-box;
}

/* ── Title ── */
.wsg-title {
    margin: 0 0 20px;
    font-size: 1.6rem;
    color: var(--wsg-word, #222);
    text-align: center;
}

/* ── Main layout ── */
.wsg-layout {
    display: flex;
    gap: 28px;
    align-items: flex-start;
    flex-wrap: wrap;
}

/* ── Board ── */
.wsg-board-wrap {
    flex: 0 0 auto;
    position: relative;
    /* The overlay canvas sits on top of this */
}

/*
 * The grid itself — pointer-events are set to none in JS
 * so the transparent canvas overlay catches all input.
 * The table is only for visual rendering.
 */
.wsg-grid {
    border-collapse: collapse;
    display: block; /* ensures consistent getBoundingClientRect */
    user-select: none;
    -webkit-user-select: none;
}

.wsg-grid td {
    width: calc(var(--wsg-fs, 18px) * 2.4);
    height: calc(var(--wsg-fs, 18px) * 2.4);
    text-align: center;
    vertical-align: middle;
    border: 1px solid var(--wsg-grid, #cccccc);
    background: var(--wsg-bg, #ffffff);
    color: var(--wsg-word, #222222);
    font-size: var(--wsg-fs, 18px);
    font-weight: 700;
    font-family: 'Courier New', monospace;
    border-radius: 3px;
    transition: background .15s;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.wsg-grid td.wsg-selected {
    background: rgba(74,144,217,.4) !important;
}

.wsg-grid td.wsg-found-cell {
    background: var(--wsg-found, #90ee90) !important;
    animation: wsgPop .3s ease;
}

@keyframes wsgPop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/*
 * Transparent canvas overlay — sits exactly over the table,
 * captures all mouse/touch events so the page never scrolls
 * during a drag. Rendered and positioned entirely by JS.
 */
.wsg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    /* fully transparent: just an event trap */
    background: transparent;
    touch-action: none; /* prevent ALL browser touch handling */
    -ms-touch-action: none;
    z-index: 10;
}

/* ── Timer bar ── */
.wsg-timer-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f0f4f8;
    border: 1px solid #d0d7e0;
    border-radius: 8px;
    padding: 8px 14px;
    margin-bottom: 14px;
    font-size: .95rem;
    font-weight: 700;
    color: #333;
}
.wsg-timer-icon { font-style: normal; font-size: 1.1rem; }
.wsg-timer-display {
    min-width: 3.5em;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    letter-spacing: .05em;
}
.wsg-timer-track {
    flex: 1;
    height: 8px;
    background: #d0d7e0;
    border-radius: 4px;
    overflow: hidden;
}
.wsg-timer-fill {
    height: 100%;
    width: 100%;
    background: #4a90d9;
    border-radius: 4px;
    transition: width 1s linear, background .5s;
}
.wsg-timer-bar.wsg-timer-urgent .wsg-timer-fill { background: #e74c3c; }
.wsg-timer-bar.wsg-timer-urgent .wsg-timer-display { color: #e74c3c; }
.wsg-success.wsg-timeup {
    color: #e74c3c;
    background: rgba(255,240,240,.95);
}

/* ── Embed section ── */
.wsg-embed-section {
    margin-top: 18px;
    border-top: 1px solid #e8edf2;
    padding-top: 14px;
}
.wsg-embed-toggle {
    background: none;
    border: 1px solid #c0cad6;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: .85rem;
    font-weight: 600;
    color: #4a90d9;
    cursor: pointer;
    transition: background .2s, color .2s;
}
.wsg-embed-toggle:hover {
    background: #f0f4f8;
}
.wsg-embed-box {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.wsg-embed-code {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: .78rem;
    padding: 8px 10px;
    border: 1px solid #d0d7e0;
    border-radius: 6px;
    background: #f7f9fc;
    color: #333;
    resize: none;
    height: 64px;
    line-height: 1.5;
}
.wsg-embed-copy {
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .2s;
}
.wsg-embed-copy:hover { background: #357ab8; }

/* ── Backlink (shown only when embedded on a foreign site) ── */
.wsg-backlink {
    text-align: center;
    margin-top: 10px;
    font-size: .8rem;
}
.wsg-backlink a {
    color: #4a90d9;
    text-decoration: underline;
}

/* ── Warning banner (unplaceable words) ── */
.wsg-warning {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-left: 4px solid #f39c12;
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 18px;
    font-size: .88rem;
    color: #7d5a00;
    line-height: 1.5;
}
.wsg-warning p {
    margin: 0 0 6px;
    font-weight: 700;
}
.wsg-warning ul {
    margin: 0;
    padding-left: 18px;
}
.wsg-warning ul li {
    margin-bottom: 2px;
}

/* ── Words panel ── */
.wsg-words-panel {
    flex: 1 1 140px;
    min-width: 130px;
}

.wsg-wordlist {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wsg-wordlist li {
    background: #f0f4f8;
    padding: 7px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-size: .92rem;
    letter-spacing: .04em;
    transition: all .3s;
    color: #333;
}

.wsg-wordlist li.wsg-word-found {
    background: var(--wsg-found, #90ee90);
    color: #1a5e2a;
    text-decoration: line-through;
    opacity: .75;
}

/* ── Buttons ── */
.wsg-btn {
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 600;
    transition: background .2s, transform .1s;
}

.wsg-reset {
    background: #e74c3c;
    color: #fff;
    width: 100%;
}
.wsg-reset:hover  { background: #c0392b; }
.wsg-reset:active { transform: scale(.97); }

/* ── Actions row (fullscreen button) ── */
.wsg-actions {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.wsg-fullscreen-btn {
    background: #f0f4f8;
    color: #444;
    border: 2px solid #d0d7e0;
    border-radius: 8px;
    padding: 9px 22px;
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, border-color .2s, transform .15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.wsg-fullscreen-btn:hover {
    background: #e0e8f4;
    border-color: #4a90d9;
    color: #1a5aaa;
    transform: scale(1.04);
}
.wsg-fullscreen-btn:active { transform: scale(.97); }

/* ── Success overlay ── */
.wsg-success {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.93);
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #27ae60;
    text-align: center;
    padding: 20px;
    animation: wsgFadeIn .5s ease;
    z-index: 20;
}

@keyframes wsgFadeIn {
    from { opacity: 0; transform: scale(.9); }
    to   { opacity: 1; transform: scale(1); }
}

/* ══════════════════════════════════════
   FULLSCREEN MODE
   Covers both the native Fullscreen API
   and the CSS fallback (.wsg-is-fullscreen)
   ══════════════════════════════════════ */

/* Native API */
.wsg-container:fullscreen,
.wsg-container:-webkit-full-screen,
.wsg-container:-moz-full-screen {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 28px !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
}

/* CSS fallback */
.wsg-container.wsg-is-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 999999 !important;
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100dvh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 28px !important;
    overflow-y: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
}

.wsg-container:fullscreen .wsg-layout,
.wsg-container:-webkit-full-screen .wsg-layout,
.wsg-container.wsg-is-fullscreen .wsg-layout {
    justify-content: center;
}

/* Larger cells in fullscreen */
.wsg-container:fullscreen .wsg-grid td,
.wsg-container:-webkit-full-screen .wsg-grid td,
.wsg-container.wsg-is-fullscreen .wsg-grid td {
    width:  calc(var(--wsg-fs, 18px) * 3.2) !important;
    height: calc(var(--wsg-fs, 18px) * 3.2) !important;
    font-size: calc(var(--wsg-fs, 18px) * 1.5) !important;
}

/* ── Responsive ── */
@media (max-width: 560px) {
    .wsg-container { padding: 12px; }
    .wsg-layout    { flex-direction: column; gap: 16px; }
    .wsg-words-panel { width: 100%; }
    .wsg-wordlist {
        flex-direction: row;
        flex-wrap: wrap;
    }
    /* Slightly larger tap targets on small screens */
    .wsg-grid td {
        width:  calc(var(--wsg-fs, 18px) * 2.8) !important;
        height: calc(var(--wsg-fs, 18px) * 2.8) !important;
    }
}