/**
 * Common Puzzle Tiles System
 * Shared styles for WDC word puzzles (Daily Word, Word Chain, etc.)
 */

/* Prevent zoom on mobile */
button, input, select, textarea, .puzzle-key, .puzzle-tile {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

* {
    -webkit-touch-callout: none;
}

/* ============================================
   GAME HEADER (responsive)
   ============================================ */

.puzzle-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--accent-color, #4CAF50);
}

/* Normal layout: single row with back left, title center, buttons right */
.puzzle-header-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.puzzle-header-back {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #555;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1em;
    font-size: 0.95em;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
    min-width: 70px;
}

.puzzle-header-back:hover {
    background: #f0f0f0;
    color: var(--accent-color, #4CAF50);
}

.puzzle-header-actions {
    display: flex;
    gap: 4px;
    min-width: 70px;
    justify-content: flex-end;
}

.puzzle-header-btn {
    padding: 5px 10px;
    font-size: 1em;
    border: 1px solid #ccc;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.puzzle-header-btn:first-child {
    font-weight: bold;
}

.puzzle-header-btn:hover {
    border-color: var(--accent-color, #4CAF50);
    color: var(--accent-color, #4CAF50);
}

/* Title centered in nav row */
.puzzle-header-title {
    font-size: 1.3em;
    font-weight: bold;
    color: var(--accent-color, #4CAF50);
    text-align: center;
    flex: 1;
}

/* Date subtitle under title */
.puzzle-header-date {
    text-align: center;
    font-size: 0.85em;
    color: #888;
    margin-top: 4px;
}

/* Compact header for zoomed viewports - title drops to second row */
@media (max-width: 340px) {
    .puzzle-header-title {
        flex: 0 0 100%;
        order: 3;
        margin-top: 4px;
        font-size: 1.1em;
    }
    
    .puzzle-header-date {
        font-size: 0.75em;
        margin-top: 2px;
    }
    
    .puzzle-header-back {
        font-size: 0.85em;
        padding: 4px 8px;
        min-width: auto;
    }
    
    .puzzle-header-actions {
        min-width: auto;
    }
    
    .puzzle-header-btn {
        padding: 4px 8px;
        font-size: 0.9em;
    }
}

/* ============================================
   TILE ROWS
   ============================================ */

.puzzle-tile-row {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin: 5px 0;
}

/* ============================================
   TILES
   ============================================ */

.puzzle-tile {
    width: 60px;
    height: 60px;
    border: 2px solid #d3d6da;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    color: #000;
    background: #fff;
    text-transform: uppercase;
    user-select: none;
    transition: all 0.2s;
    font-family: 'Arial', sans-serif;
}

/* Filled tile (has a letter) */
.puzzle-tile-filled {
    border-color: #878a8c;
    animation: puzzle-tile-pop 0.1s;
}

/* Active tile (cursor position) */
.puzzle-tile-active {
    border-color: #2196F3;
    border-width: 3px;
    box-shadow: 0 0 8px rgba(33, 150, 243, 0.4);
}

/* ============================================
   TILE ANIMATIONS
   ============================================ */

@keyframes puzzle-tile-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.puzzle-tile-flip {
    animation: puzzle-tile-flip 0.5s;
}

@keyframes puzzle-tile-flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

.puzzle-tile-shake {
    animation: puzzle-tile-shake 0.5s;
}

@keyframes puzzle-tile-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* ============================================
   KEYBOARD
   ============================================ */

.puzzle-keyboard {
    margin: 20px auto;
    max-width: 500px;
}

.puzzle-keyboard-row {
    display: flex;
    justify-content: center;
    margin: 5px 0;
    gap: 4px;
}

.puzzle-key {
    min-width: 40px;
    height: 55px;
    padding: 0 10px;
    border: none;
    border-radius: 4px;
    background: #d3d6da;
    color: #000;
    font-weight: bold;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.1s;
    user-select: none;
}

.puzzle-key:hover {
    background: #bbb;
}

.puzzle-key:active {
    transform: scale(0.95);
}

.puzzle-key-large {
    min-width: 65px;
    font-size: 0.9em;
    background: #8b8d8f;
    color: white;
    font-weight: bold;
}

.puzzle-key-large:hover {
    background: #6e7072;
}

/* Make backspace icon bigger */
.puzzle-key[data-key="Backspace"] {
    font-size: 1.8em;
    line-height: 1;
}

/* Key States (after evaluation in word games) */
.puzzle-key-correct {
    background: #6aaa64;
    color: white;
}

.puzzle-key-present {
    background: #c9b458;
    color: white;
}

.puzzle-key-absent {
    background: #787c7e;
    color: white;
}

/* Keep large keys distinct even when marked absent */
.puzzle-key-large.puzzle-key-absent {
    background: #6e7072;
}

/* ============================================
   STATS MODAL (common styling)
   ============================================ */

.puzzle-stats-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 2147483647;
    animation: puzzle-fadeIn 0.3s;
}

.puzzle-stats-content {
    position: relative;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    background: white;
    padding: 30px;
    border-radius: 10px;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

.puzzle-stats-grid {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
}

.puzzle-stat-box {
    flex: 1;
    text-align: center;
}

.puzzle-stat-value {
    font-size: 2em;
    font-weight: bold;
}

.puzzle-stat-label {
    font-size: 0.9em;
    color: #666;
}

@keyframes puzzle-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================
   MESSAGE DISPLAY
   ============================================ */

.puzzle-message {
    min-height: 30px;
    margin: 15px 0;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
    transition: opacity 0.3s;
}

/* ============================================
   MOBILE RESPONSIVENESS
   ============================================ */

@media (max-width: 600px) {
    .puzzle-tile {
        width: 56px;
        height: 56px;
        font-size: 1.8em;
        border-width: 2px;
    }
    
    .puzzle-tile-row {
        gap: 5px;
        margin: 5px 0;
    }
    
    .puzzle-key {
        min-width: 36px;
        height: 52px;
        padding: 0 8px;
        font-size: 1.05em;
    }
    
    .puzzle-key-large {
        min-width: 60px;
        font-size: 0.85em;
        padding: 0 8px;
        background: #8b8d8f;
        height: 54px;
    }
    
    .puzzle-key[data-key="Backspace"] {
        font-size: 2em;
    }
    
    .puzzle-keyboard-row {
        gap: 4px;
        margin: 4px 0;
    }
    
    .puzzle-message {
        font-size: 1em !important;
        min-height: 25px !important;
    }
}

@media (max-width: 400px) {
    .puzzle-tile {
        width: 48px;
        height: 48px;
        font-size: 1.5em;
        border-width: 1.5px;
    }
    
    .puzzle-tile-row {
        gap: 4px;
    }
    
    .puzzle-key {
        min-width: 30px;
        height: 46px;
        padding: 0 5px;
        font-size: 0.95em;
    }
    
    .puzzle-key-large {
        min-width: 52px;
        font-size: 0.75em;
        padding: 0 6px;
        height: 48px;
    }
    
    .puzzle-key[data-key="Backspace"] {
        font-weight: bold;
        font-size: 1.5em;
    }
    
    .puzzle-key[data-key="Enter"] {
        font-weight: bold;
        font-size: 1.0em;
    }
    
    .puzzle-keyboard-row {
        gap: 3px;
    }
}

/* Extra compact for zoomed viewports */
@media (max-width: 340px) {
    .puzzle-tile {
        width: 42px;
        height: 42px;
        font-size: 1.3em;
        border-width: 1.5px;
    }
    
    .puzzle-tile-row {
        gap: 3px;
        margin: 3px 0;
    }
    
    .puzzle-keyboard {
        margin: 10px auto;
    }
    
    .puzzle-key {
        min-width: 26px;
        height: 40px;
        padding: 0 3px;
        font-size: 0.85em;
        border-radius: 3px;
    }
    
    .puzzle-key-large {
        min-width: 42px;
        font-size: 0.65em;
        padding: 0 4px;
        height: 40px;
    }
    
    .puzzle-key[data-key="Backspace"] {
        font-size: 1.2em;
    }
    
    .puzzle-key[data-key="Enter"] {
        font-size: 0.8em;
    }
    
    .puzzle-keyboard-row {
        gap: 2px;
        margin: 3px 0;
    }
}

/* Very compact for heavily zoomed viewports */
@media (max-width: 300px) {
    .puzzle-tile {
        width: 36px;
        height: 36px;
        font-size: 1.1em;
    }
    
    .puzzle-tile-row {
        gap: 2px;
        margin: 2px 0;
    }
    
    .puzzle-key {
        min-width: 22px;
        height: 34px;
        padding: 0 2px;
        font-size: 0.75em;
    }
    
    .puzzle-key-large {
        min-width: 36px;
        font-size: 0.6em;
        height: 34px;
    }
    
    .puzzle-key[data-key="Backspace"] {
        font-size: 1em;
    }
    
    .puzzle-key[data-key="Enter"] {
        font-size: 0.7em;
    }
    
    .puzzle-keyboard-row {
        gap: 2px;
        margin: 2px 0;
    }
}

/* Ultra compact for extreme zoom */
@media (max-width: 260px) {
    .puzzle-tile {
        width: 30px;
        height: 30px;
        font-size: 0.95em;
    }
    
    .puzzle-tile-row {
        gap: 2px;
        margin: 2px 0;
    }
    
    .puzzle-key {
        min-width: 18px;
        height: 28px;
        padding: 0 1px;
        font-size: 0.65em;
    }
    
    .puzzle-key-large {
        min-width: 30px;
        font-size: 0.5em;
        height: 28px;
        padding: 0 2px;
    }
    
    .puzzle-key[data-key="Backspace"] {
        font-size: 0.85em;
    }
    
    .puzzle-key[data-key="Enter"] {
        font-size: 0.55em;
    }
    
    .puzzle-keyboard-row {
        gap: 1px;
        margin: 2px 0;
    }
}

/* Larger phones */
@media (min-width: 400px) and (max-width: 600px) {
    .puzzle-tile {
        width: 58px;
        height: 58px;
    }
    
    .puzzle-key {
        min-width: 38px;
        height: 54px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .puzzle-tile-flip,
    .puzzle-tile-shake,
    .puzzle-tile-filled {
        animation: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .puzzle-tile {
        border-width: 3px;
    }
}

