:root {
    --tri-width: 5.5vw;
    --tri-height: 4.76vw;
    --primary-color: #1b365d;
    --accent-color: #b22234;
}

@media (min-width: 1024px) {
    :root {
        --tri-width: 52px;
        --tri-height: 45px;
    }
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f9f9fb;
    color: #333;
    margin: 0;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    text-align: center;
    margin-bottom: 20px;
}

.back-link {
    display: inline-block;
    margin-bottom: 15px;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: color 0.2s, transform 0.2s;
}

.back-link:hover {
    color: var(--accent-color);
    transform: translateX(-3px);
}

h1 {
    color: var(--primary-color);
    margin-bottom: 5px;
    font-size: 1.8rem;
}

.container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1200px;
    width: 100%;
}

@media (min-width: 768px) {
    .container {
        flex-direction: row;
    }
}

.poem-section {
    flex: 1;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border-top: 5px solid var(--accent-color);
}

.poem-text {
    font-style: italic;
    line-height: 1.6;
    font-size: 1rem;
    white-space: pre-line;
}

/* Clickable bold tracking styles */
.poem-text b {
    color: var(--accent-color);
    font-weight: bold;
    text-transform: uppercase;
    cursor: help;
    border-bottom: 1px dashed var(--accent-color);
    display: inline-block;
    transition: all 0.3s ease;
}

/* ⚡ FLASH ANIMATION FOR DISCOVERED POEM WORDS */
@keyframes word-clear-flash {
    0% { background-color: #ffb703; color: black; transform: scale(1.2); }
    50% { background-color: #b22234; color: white; transform: scale(1.2); }
    100% { background-color: transparent; }
}

.poem-word-flashing {
    animation: word-clear-flash 0.6s ease-in-out 2; /* Flashes twice quickly */
}

/* Permanently strikethrough state */
.poem-text b.found-word {
    text-decoration: line-through;
    color: #a0a5aa !important;
    border-bottom: none;
}

.game-section {
    flex: 1.5;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border-top: 5px solid var(--primary-color);
    width: 100%;
    box-sizing: border-box;
}

.grid-container {
    position: relative;
    margin: 15px 0;
    padding-left: calc(var(--tri-width) / 2);
    width: max-content;
}

.grid-row {
    display: flex;
    height: var(--tri-height);
    margin-top: -1px;
}

.triangle-cell {
    position: relative;
    width: var(--tri-width);
    height: var(--tri-height);
    margin-left: calc(var(--tri-width) / -2);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.triangle-cell.point-up {
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    background-color: #e9ecef;
}

.triangle-cell.point-down {
    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
    background-color: #dee2e6;
}

.letter {
    position: absolute;
    width: 100%;
    text-align: center;
    font-weight: bold;
    font-size: calc(var(--tri-width) * 0.38);
    color: #212529;
}

.point-up .letter { bottom: calc(var(--tri-height) * 0.08); }
.point-down .letter { top: calc(var(--tri-height) * 0.08); }

/* 🌟 ACTIVE SELECTION STATE (Golden / Amber yellow) */
.triangle-cell.found {
    background-color: #ffb703 !important;
}

/* 🔒 COMPLETED WORD STATE (Deep Sea Ocean Teal) */
.triangle-cell.word-complete {
    background-color: #1a7572 !important;
}
.triangle-cell.word-complete .letter {
    color: white !important;
}

/* Hint flash rules */
@keyframes hint-flash {
    0% { background-color: #fb8500; transform: scale(1.1); }
    100% { background-color: transparent; }
}
.hint-flashing { animation: hint-flash 1s ease-in-out; }

/* 🏆 STREAMLINED WIN BOX CONFIGURATION */
.win-box {
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    padding: 15px 30px;
    background-color: #e8f5e9;
    border: 2px solid #2e7d32;
    border-radius: 6px;
    width: 90%;
    box-sizing: border-box;
}

.win-box.active {
    display: flex; /* Display inline when activated */
}

.win-text {
    font-size: 1.4rem;
    font-weight: bold;
    color: #2e7d32;
}

.simple-replay-btn {
    background-color: #2e7d32;
    color: white;
    border: none;
    padding: 8px 20px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
}
.simple-replay-btn:hover { background-color: #1b5e20; }

/* Spacing and Layout Polish */
.poem-section h3, 
.game-section h3 {
    margin-top: 0;
    margin-bottom: 12px;
    color: #212529;
}

/* Mobile-specific adjustments for maximum game board real estate */
@media (max-width: 768px) {
    :root {
        --tri-width: 8.5vw;
        --tri-height: 7.36vw;
    }

    body {
        padding: 8px;
    }
    
    header {
        margin-bottom: 12px;
    }
    
    .back-link {
        margin-bottom: 8px;
    }
    
    .container {
        gap: 12px;
    }
    
    .poem-section, 
    .game-section {
        padding: 12px;
    }
    
    .poem-section h3, 
    .game-section h3 {
        margin-bottom: 8px;
    }
    
    .grid-container {
        margin: 8px 0;
    }
}
