@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Playfair+Display:wght@600;700&display=swap');

:root {
    --bg-color: #1a1a1a;
    --text-color: #e5e5e5;
    --tile-bg: #2d2d2d;
    --tile-selected: #5a5a5a;
    --tile-text: #ffffff;

    /* Difficulty Colors */
    --level-1: #c8b653;
    /* Muted Gold */
    --level-2: #6f8f72;
    /* Sage Green */
    --level-3: #6a8ca3;
    /* Faded Denim */
    --level-4: #9c7c9e;
    /* Dusty Purple */

    --font-serif: 'Playfair Display', serif;
    --font-sans: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.logo {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
}

.streak-container {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.settings-icon {
    cursor: pointer;
    opacity: 0.7;
}

/* Game Container */
.game-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Grid */
.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    margin-bottom: 20px;
}

.tile {
    background-color: var(--tile-bg);
    color: var(--tile-text);
    aspect-ratio: 1;
    /* Square tiles usually, but can be rectangular if needed */
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    /* Adjust for small screens */
    padding: 5px;
    text-transform: uppercase;
    transition: background-color 0.2s, transform 0.1s;
    user-select: none;
    word-break: break-word;
    /* Ensure long words wrap */
}

@media (min-width: 400px) {
    .tile {
        font-size: 0.9rem;
        aspect-ratio: 4/3;
        /* Slightly rectangular usually looks better for words */
    }
}

/* Mobile specific adjustments */
@media (max-width: 600px) {
    body {
        padding: 10px;
        /* Less padding on smaller screens */
    }

    .game-header {
        margin-bottom: 10px;
        /* Reduce header margin */
    }

    .grid-container {
        gap: 5px;
        /* Smaller gap between tiles */
    }

    .tile {
        font-size: 0.65rem;
        /* Smaller font on mobile */
        padding: 3px;
        /* Less padding inside tiles */
        min-height: 48px;
        /* Ensure sufficient touch target */
        aspect-ratio: 1;
        /* Force square on mobile */
    }

    .controls-container {
        margin-bottom: 10px;
        /* Less space below controls */
    }
}

.tile.selected {
    background-color: var(--tile-selected);
    color: #fff;
}

.tile.solved {
    cursor: default;
}

/* Solved Group Banner */
.solved-group {
    grid-column: span 4;
    padding: 10px;
    border-radius: 6px;
    text-align: center;
    color: #000;
    /* Text needs to be dark on pastel backgrounds */
    font-weight: bold;
    margin-bottom: 0;
}

.solved-group .category-name {
    display: block;
    font-family: var(--font-serif);
    font-size: 1rem;
    margin-bottom: 4px;
}

.solved-group .category-items {
    font-size: 0.8rem;
    font-weight: normal;
}

/* Controls */
.controls-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
    padding: 0 10px;
}

.lives-container {
    display: flex;
    gap: 8px;
}

.current-streak-container {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.life-bubble {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #555;
    transition: background-color 0.3s;
}

.life-bubble.filled {
    background-color: var(--text-color);
}

.buttons-row {
    display: flex;
    gap: 10px;
}

.control-btn {
    background: transparent;
    border: 1px solid #555;
    color: var(--text-color);
    padding: 12px 16px;
    /* Larger touch target */
    border-radius: 20px;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.2s;
    flex: 1;
    /* Distribute space evenly */
}

.control-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.action-btn {
    background-color: var(--text-color);
    color: var(--bg-color);
    border: none;
    font-weight: 700;
}

.action-btn:hover {
    opacity: 0.9;
    background-color: #fff;
}

/* Ad Space */
.ad-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: auto;
    width: 100%;
}

.ad-label {
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ad-box {
    width: 300px;
    height: 250px;
    background-color: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed #444;
}

.ad-placeholder {
    color: #555;
    font-size: 0.9rem;
}

/* Animations */
@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    50% {
        transform: translateX(5px);
    }

    75% {
        transform: translateX(-5px);
    }

    100% {
        transform: translateX(0);
    }
}

.shake {
    animation: shake 0.4s ease-in-out;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: #222;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    border: 1px solid #444;
}

.modal-content h2 {
    font-family: var(--font-serif);
    margin-bottom: 10px;
}

.modal-stats {
    margin: 15px 0;
    font-size: 1.1rem;
}

.modal-ad-space {
    width: 100%;
    height: 150px;
    /* Smaller ad for modal */
    background-color: #111;
    border: 1px dashed #333;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-action-btn {
    background-color: var(--text-color);
    color: var(--bg-color);
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

.modal-action-btn:hover {
    transform: scale(1.05);
}

/* Toast */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 900;
    transition: opacity 0.3s;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Thematic Additions */

/* Puzzle Theme Header */
.puzzle-theme {
    width: 100%;
    text-align: center;
    font-family: var(--font-serif);
    font-size: 1.2rem;
    color: var(--level-1);
    margin-bottom: 15px;
    padding-bottom: 5px;
    border-bottom: 1px solid #333;
    letter-spacing: 1px;
}

/* Immersion Section */
.immersion-container {
    width: 100%;
    max-width: 500px;
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.separator-banner {
    width: 100%;
    height: auto;
    border-radius: 8px;
    opacity: 0.8;
    border: 1px solid #333;
}

/* Archivist's Note */
.archivist-note {
    background-color: #262626;
    /* Dark card background */
    padding: 25px;
    border-radius: 4px;
    width: 100%;
    border: 1px solid #444;
    font-family: 'Courier New', Courier, monospace;
    /* Typewriter feel */
    position: relative;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.archivist-note h3 {
    font-family: var(--font-serif);
    color: var(--text-color);
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 1rem;
    border-bottom: 1px dashed #555;
    padding-bottom: 10px;
}

.note-content {
    color: #ccc;
    font-size: 0.9rem;
    line-height: 1.6;
}

.note-content p {
    margin-bottom: 12px;
}

.note-content strong {
    color: #fff;
}

/* Footer */
.game-footer {
    width: 100%;
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #333;
    font-size: 0.8rem;
    color: #666;
    font-family: var(--font-serif);
}

.game-footer a {
    color: #888;
    text-decoration: none;
    transition: color 0.2s;
}

.game-footer a:hover {
    color: var(--level-1);
    text-decoration: underline;
}

/* Settings Modal */
.danger-btn {
    background-color: #8b0000;
    border-color: #ff4444;
    color: #fff;
    margin-bottom: 10px;
}

.danger-btn:hover {
    background-color: #a00000;
    transform: scale(1.02);
}

.secondary-btn {
    background-color: transparent;
    border: 1px solid #666;
    margin-top: 20px;
    color: var(--text-color);
}

.warning-text {
    font-size: 0.8rem;
    color: #ff6666;
    margin-top: 5px;
    font-style: italic;
}

.settings-actions {
    margin: 20px 0;
    padding: 15px;
    border: 1px dashed #444;
    background: rgba(0, 0, 0, 0.2);
}

/* Granular Settings */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #444;
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-row span {
    font-family: var(--font-serif);
    color: #ccc;
    font-size: 0.95rem;
}

.small-btn {
    padding: 6px 14px;
    font-size: 0.85rem;
    margin: 0;
    width: auto;
}

.danger-zone {
    margin-top: 10px;
}