/* Mystic Crossword — Front-end Puzzle */

.mcw-puzzle {
    font-family: Georgia, serif;
    max-width: 960px;
    margin: 0 auto 32px;
    box-sizing: border-box;
    width: 100%;
}
.mcw-puzzle *, .mcw-puzzle *::before, .mcw-puzzle *::after {
    box-sizing: border-box;
}

/* Header row: title left, buttons right */
.mcw-puzzle-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 2px solid #222;
    padding-bottom: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.mcw-puzzle .mcw-puzzle-title {
    font-size: 1.4em;
    margin: 0;
    border: none;
    padding: 0;
    flex: 1;
    min-width: 0;
}
.mcw-puzzle-header .mcw-controls {
    margin: 0;
    flex-shrink: 0;
}

/* Active clue bar — sits above everything, always readable */
.mcw-active-clue {
    background: #f4f0e8;
    border-left: 4px solid #8b6914;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    min-height: 40px;
    border-radius: 0 4px 4px 0;
    margin-bottom: 14px;
}

/* ── Desktop layout ── */
.mcw-puzzle-inner {
    display: flex;
    gap: 28px;
    align-items: flex-start;
}

/* Grid scaler: JS sets dimensions; inner div holds the actual grid and gets transform:scale */
.mcw-grid-scaler {
    flex-shrink: 0;
    position: relative;
    /* width + height set by JS */
}
.mcw-grid-scaler-inner {
    transform-origin: top left;
    /* transform: scale() set by JS */
    line-height: 0;
    display: inline-block;
}

.mcw-interactive-grid {
    display: inline-block;
    border: 3px solid #222;
    line-height: 0;
}
.mcw-row { display: flex; }
.mcw-cell {
    width: 36px;
    height: 36px;
    border: 1px solid #aaa;
    position: relative;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
}
.mcw-cell.black {
    background: #222;
    border-color: #222;
    cursor: default;
    pointer-events: none;
}
.mcw-cell.active    { background: #a8d1f5; }
.mcw-cell.selected  { background: #c8e6ff; }
.mcw-cell.correct   { background: #b8f0c8; }
.mcw-cell.incorrect { background: #ffc8c8; }
.mcw-cell.revealed  { background: #fff8c8; }

.mcw-cell-num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 9px;
    line-height: 1;
    font-family: sans-serif;
    color: #333;
    pointer-events: none;
    z-index: 1;
}
.mcw-cell input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    outline: none;
    padding: 0;
    padding-top: 8px;
    cursor: pointer;
    caret-color: transparent;
    color: #111;
    z-index: 2;
    font-size: 16px; /* 16px prevents iOS zoom on focus */
}
.mcw-cell input.revealed-val { color: #a06000; }

/* ── Clue sidebar — desktop ── */
.mcw-clues {
    flex: 1;
    min-width: 220px;
}

/* Desktop: hide tab buttons, show both panels stacked naturally */
.mcw-clue-tabs { display: none; }

.mcw-clue-panels {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.mcw-clue-panel { display: block; }
.mcw-clue-panel h4 {
    margin: 0 0 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 2px solid #222;
    padding-bottom: 4px;
}
.mcw-clue-list {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 13px;
    line-height: 1.7;
}
.mcw-clue-list li {
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
}
.mcw-clue-list li:hover  { background: #f0f0f0; }
.mcw-clue-list li.active { background: #c8e6ff; font-weight: 700; }
.mcw-clue-list li .mcw-cn { font-weight: 700; margin-right: 3px; }

/* ── Controls ── */
.mcw-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.mcw-btn {
    padding: 8px 16px;
    border: 2px solid #222;
    background: #fff;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    border-radius: 3px;
    transition: background .15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.mcw-btn:hover        { background: #f0f0f0; }
.mcw-check-btn        { border-color: #2a7; color: #2a7; }
.mcw-check-btn:hover  { background: #e8fef0; }
.mcw-reveal-btn       { border-color: #a06000; color: #a06000; }
.mcw-reveal-btn:hover { background: #fff8e0; }
.mcw-clear-btn        { border-color: #888; color: #555; }

.mcw-result { font-size: 14px; font-weight: 700; margin-left: 4px; }
.mcw-result.win  { color: #2a7; }
.mcw-result.fail { color: #c00; }

/* ── Mobile ── */
@media (max-width: 600px) {
    .mcw-puzzle-inner {
        flex-direction: column;
        gap: 14px;
    }

    /* Grid scaler takes full puzzle width — JS will scale to fit */
    .mcw-grid-scaler {
        width: 100%;
    }

    .mcw-clues { width: 100%; }

    /* Show tabs, hide stacked panels */
    .mcw-clue-tabs {
        display: flex;
        margin-bottom: 0;
    }
    .mcw-clue-tab {
        flex: 1;
        padding: 8px 0;
        text-align: center;
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .05em;
        cursor: pointer;
        background: #eee;
        border: 1px solid #ccc;
        border-bottom: 2px solid #222;
        color: #555;
        -webkit-tap-highlight-color: transparent;
    }
    .mcw-clue-tab.active {
        background: #fff;
        color: #222;
        border: 2px solid #222;
        border-bottom: 2px solid #fff;
        margin-bottom: -2px;
        position: relative;
        z-index: 1;
    }

    .mcw-clue-panels {
        border: 2px solid #222;
        border-top: none;
    }
    .mcw-clue-panel { display: none; }
    .mcw-clue-panel.active { display: block; }
    .mcw-clue-panel h4 { display: none; }

    .mcw-clue-list {
        max-height: 200px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 6px 0;
    }
    .mcw-clue-list li { padding: 5px 10px; font-size: 14px; }

    .mcw-puzzle-header {
        gap: 8px;
    }
    .mcw-btn {
        padding: 8px 10px;
        font-size: 13px;
    }
    .mcw-result {
        font-size: 13px;
    }
}
