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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #fafafa;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.8s ease;
}

/* Category background colors (subtle tints) */
body.category-bg-0 { background-color: #e3f2fd; } /* Light Blue */
body.category-bg-1 { background-color: #fff8e1; } /* Light Amber */
body.category-bg-2 { background-color: #e8f5e9; } /* Light Green */
body.category-bg-3 { background-color: #f3e5f5; } /* Light Purple */
body.category-bg-4 { background-color: #fbe9e7; } /* Light Deep Orange */
body.category-bg-5 { background-color: #e0f7fa; } /* Light Cyan */
body.category-bg-6 { background-color: #fce4ec; } /* Light Pink */
body.category-bg-7 { background-color: #f1f8e9; } /* Light Light Green */
body.category-bg-8 { background-color: #fff3e0; } /* Light Orange */
body.category-bg-9 { background-color: #ede7f6; } /* Light Deep Purple */

main {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    position: relative;
}

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

header h1.logo {
    font-size: 2.5rem;
    font-weight: 900;
    font-family: 'Arial Black', sans-serif;
    margin-bottom: 10px;
}

header h1.logo .hodge {
    display: inline-block;
    transform: rotate(-5deg);
}

header h1.logo .hodge span {
    display: inline-block;
    color: #4CAF50;
    text-shadow: 2px 2px 0 #2d7a32;
    animation: logo-bounce 0.6s ease-in-out infinite;
    animation-delay: var(--d, 0s);
}

header h1.logo .podge {
    display: inline-block;
    transform: rotate(5deg);
    margin-left: -0.3em;
}

header h1.logo .podge span {
    display: inline-block;
    color: #2196F3;
    text-shadow: 2px 2px 0 #1565a0;
    animation: logo-bounce 0.6s ease-in-out infinite;
    animation-delay: var(--d, 0s);
}

/* Hodge: left to right */
header h1.logo .hodge span:nth-child(1) { --d: 0s; }
header h1.logo .hodge span:nth-child(2) { --d: 0.08s; }
header h1.logo .hodge span:nth-child(3) { --d: 0.16s; }
header h1.logo .hodge span:nth-child(4) { --d: 0.24s; }
header h1.logo .hodge span:nth-child(5) { --d: 0.32s; }

/* Podge: right to left */
header h1.logo .podge span:nth-child(5) { --d: 0s; }
header h1.logo .podge span:nth-child(4) { --d: 0.08s; }
header h1.logo .podge span:nth-child(3) { --d: 0.16s; }
header h1.logo .podge span:nth-child(2) { --d: 0.24s; }
header h1.logo .podge span:nth-child(1) { --d: 0.32s; }

/* Wiggle rotation on bounce */
header h1.logo .hodge span:nth-child(odd) { --rot: -3deg; }
header h1.logo .hodge span:nth-child(even) { --rot: 3deg; }
header h1.logo .podge span:nth-child(odd) { --rot: 3deg; }
header h1.logo .podge span:nth-child(even) { --rot: -3deg; }

@keyframes logo-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-6px) rotate(var(--rot, 0deg)); }
}

header .date {
    color: #666;
    font-size: 1rem;
}

.hidden {
    display: none !important;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Game Container */
.game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    max-width: 100%;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Instructions */
.instructions {
    text-align: center;
    margin: 0 auto 20px auto;
    max-width: 600px;
}

.instructions p {
    color: #666;
    font-size: 1rem;
    line-height: 1.5;
}

.instructions h2 {
    color: #1a1a1a;
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
}

/* Secondary Button (Back button) */
.secondary-button {
    background-color: #f5f5f5;
    color: #333;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    transition: all 0.2s ease;
}

.secondary-button:hover {
    background-color: #e8e8e8;
    border-color: #d0d0d0;
}

/* Grid Styles */
.grid {
    display: grid;
    gap: 10px;
    margin: 0 auto;
    padding-top: 10px; /* Buffer for bounce animations */
}

.main-grid {
    grid-template-columns: repeat(var(--grid-size, 4), 1fr);
    margin: 0 auto;
    max-width: none;
    width: auto;
    padding-top: 10px; /* Buffer for bounce animations */
}

.deep-dive-grid {
    grid-template-columns: repeat(4, 1fr);
    max-width: 600px;
}

/* Word Button Styles */
.word-button {
    background-color: #ffffff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.word-button:hover {
    border-color: #999;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.word-button.selected {
    background-color: #e3f2fd;
    border-color: #2196f3;
    transform: translateY(-2px);
}

/* Paired words - disabled appearance */
.word-button.paired {
    background-color: #f0f0f0;
    opacity: 0.7;
    cursor: default;
    border-width: 3px;
    border-color: #999; /* Default grey border, overridden by category colors */
}

.word-button.paired:hover {
    transform: none;
    box-shadow: none;
}

/* Category colors for paired words */
.word-button.paired[data-category="0"] {
    border-color: #2196F3; /* Blue */
}

.word-button.paired[data-category="1"] {
    border-color: #FFC107; /* Amber */
}

.word-button.paired[data-category="2"] {
    border-color: #4CAF50; /* Green */
}

.word-button.paired[data-category="3"] {
    border-color: #9C27B0; /* Purple */
}

.word-button.paired[data-category="4"] {
    border-color: #FF5722; /* Deep Orange */
}

.word-button.paired[data-category="5"] {
    border-color: #00BCD4; /* Cyan */
}

.word-button.paired[data-category="6"] {
    border-color: #E91E63; /* Pink */
}

.word-button.paired[data-category="7"] {
    border-color: #8BC34A; /* Light Green */
}

.word-button.paired[data-category="8"] {
    border-color: #FF9800; /* Orange */
}

.word-button.paired[data-category="9"] {
    border-color: #673AB7; /* Deep Purple */
}

.word-button.paired.selected {
    background-color: #fff3cd;
    opacity: 1;
}

.deep-dive .word-button.paired {
    opacity: 0.5;
    cursor: not-allowed;
}

.deep-dive .word-button.paired:hover {
    transform: none;
    box-shadow: none;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-12px); }
    40% { transform: translateX(12px); }
    60% { transform: translateX(-12px); }
    80% { transform: translateX(12px); }
}

.word-button.shake {
    animation: shake 0.4s ease !important;
    background-color: #ffebee !important;
    border-color: #f44336 !important;
    border-width: 3px !important;
}

.match-animation {
    animation: matchJiggle 0.6s ease;
}

@keyframes matchJiggle {
    0% { transform: scale(1) rotate(0deg); }
    15% { transform: scale(1.1) rotate(-5deg); }
    30% { transform: scale(1.1) rotate(5deg); }
    45% { transform: scale(1.1) rotate(-5deg); }
    60% { transform: scale(1.1) rotate(5deg); }
    75% { transform: scale(1.05) rotate(0deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.zoom-out {
    animation: zoomOut 0.5s ease forwards;
}

@keyframes zoomOut {
    from {
        transform: scale(1);
        opacity: 1;
    }
    to {
        transform: scale(0.8);
        opacity: 0;
    }
}

/* Category Complete Notification */
.notification {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    animation: fadeIn 0.3s ease;
}

.notification-content {
    background-color: white;
    padding: 50px 60px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.4s ease;
}

.notification-content h2 {
    font-size: 2.5rem;
    color: #4caf50;
    margin-bottom: 15px;
    font-weight: 700;
}

.notification-content p {
    font-size: 1.5rem;
    color: #1a1a1a;
    margin-bottom: 10px;
    font-weight: 600;
}

.notification-subtitle {
    font-size: 1.1rem !important;
    color: #666 !important;
    font-weight: 400 !important;
    font-style: italic;
}

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

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Hint Tooltip */
.hint-tooltip {
    position: fixed;
    z-index: 1000;
    background: var(--card-bg, #333);
    color: var(--text-primary, #fff);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 280px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.hint-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

.hint-tooltip::before {
    content: '\1F4A1';
    margin-right: 8px;
}

/* Deep Dive */
.deep-dive-header {
    text-align: center;
    margin-bottom: 20px;
}

.deep-dive-header h2 {
    font-size: 2rem;
    color: #1a1a1a;
}

/* Victory Screen */
#victory-screen {
    position: fixed;
    top: 15vh;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    padding: 40px;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: calc(100% - 40px);
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 100;
}

#victory-screen h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #4caf50;
}

#victory-screen #victory-message {
    font-size: 1.2rem;
    color: #666;
    margin-bottom: 30px;
}

/* Victory Categories List */
.victory-categories {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0 30px 0;
    padding: 20px;
    background-color: #f9f9f9;
    border-radius: 8px;
}

.victory-category {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
}

.victory-category-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.victory-category-name {
    color: #333;
    font-weight: 600;
}

#victory-screen #share-content {
    margin-top: 30px;
}

#victory-screen #share-display {
    background-color: #f5f5f5;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    font-size: 1.2rem;
    line-height: 1.8;
    text-align: center;
    margin-bottom: 20px;
    font-family: inherit;
    white-space: pre;
}

#victory-screen button {
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}

#victory-screen button:hover {
    background-color: #1976d2;
}

#share-copy-feedback {
    margin-top: 10px;
    color: #4caf50;
    font-weight: 600;
}

/* Error Screen */
#error-screen {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    padding: 40px;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: calc(100% - 40px);
    z-index: 100;
}

#error-screen button {
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 20px;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.modal-content textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 15px;
}

.modal-content label {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    cursor: pointer;
}

.modal-content input[type="checkbox"] {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

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

.modal-buttons button {
    flex: 1;
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.modal-buttons button:hover {
    background-color: #1976d2;
}

#close-modal {
    background-color: #999;
}

#close-modal:hover {
    background-color: #777;
}

#copy-feedback {
    margin-top: 10px;
    color: #4caf50;
    font-weight: 600;
    text-align: center;
}

/* Grid Size Responsive Scaling */
/* 5x5 and 6x6 grids: slightly smaller */
.main-grid[data-grid-size="5"] .word-button,
.main-grid[data-grid-size="6"] .word-button {
    padding: 16px 8px;
    font-size: 0.95rem;
    min-height: 70px;
}

/* 7x7 and 8x8 grids: more compact */
.main-grid[data-grid-size="7"] .word-button,
.main-grid[data-grid-size="8"] .word-button {
    padding: 14px 6px;
    font-size: 0.9rem;
    min-height: 65px;
}

/* 9x9 and 10x10 grids: most compact */
.main-grid[data-grid-size="9"] .word-button,
.main-grid[data-grid-size="10"] .word-button {
    padding: 12px 4px;
    font-size: 0.85rem;
    min-height: 60px;
}

/* 11x11 and 12x12 grids: extra compact */
.main-grid[data-grid-size="11"] .word-button,
.main-grid[data-grid-size="12"] .word-button {
    padding: 10px 3px;
    font-size: 0.8rem;
    min-height: 55px;
}

/* Tighter gaps for larger grids */
.main-grid[data-grid-size="7"],
.main-grid[data-grid-size="8"],
.main-grid[data-grid-size="9"],
.main-grid[data-grid-size="10"],
.main-grid[data-grid-size="11"],
.main-grid[data-grid-size="12"] {
    gap: 8px;
}

/* Responsive Design */
@media (max-width: 768px) {
    main {
        padding: 10px;
    }

    .game-container {
        width: 100%;
        overflow-x: visible;
        -webkit-overflow-scrolling: touch;
        justify-content: center;
        align-items: center;
        padding-right: 10px;
    }

    .main-grid,
    .deep-dive-grid {
        gap: 6px;
        margin: 0;
    }

    /* Reshape grids 5x5 and larger to 4 columns for vertical scrolling */
    .main-grid[data-grid-size="5"],
    .main-grid[data-grid-size="6"],
    .main-grid[data-grid-size="7"],
    .main-grid[data-grid-size="8"],
    .main-grid[data-grid-size="9"],
    .main-grid[data-grid-size="10"],
    .main-grid[data-grid-size="11"],
    .main-grid[data-grid-size="12"] {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .word-button {
        padding: 12px 8px;
        font-size: 0.85rem;
        min-height: 60px;
    }

    /* Compact styling for large grids */
    .main-grid[data-grid-size="7"] .word-button,
    .main-grid[data-grid-size="8"] .word-button {
        padding: 10px 5px;
        font-size: 0.75rem;
        min-height: 50px;
    }

    .main-grid[data-grid-size="9"] .word-button,
    .main-grid[data-grid-size="10"] .word-button {
        padding: 8px 4px;
        font-size: 0.7rem;
        min-height: 48px;
    }

    .main-grid[data-grid-size="11"] .word-button,
    .main-grid[data-grid-size="12"] .word-button {
        padding: 8px 3px;
        font-size: 0.68rem;
        min-height: 46px;
    }

    .main-grid[data-grid-size="7"],
    .main-grid[data-grid-size="8"] {
        gap: 5px;
    }

    .main-grid[data-grid-size="9"],
    .main-grid[data-grid-size="10"],
    .main-grid[data-grid-size="11"],
    .main-grid[data-grid-size="12"] {
        gap: 4px;
    }

    header h1.logo {
        font-size: 2rem;
    }

    #victory-screen,
    #error-screen {
        padding: 20px;
        width: calc(100% - 30px);
    }

    #victory-screen h2 {
        font-size: 2rem;
    }

    #victory-screen #share-display {
        font-size: 1rem;
        padding: 15px;
        line-height: 1.6;
    }

    .notification-content {
        padding: 30px 40px;
        max-width: 90%;
    }

    .notification-content h2 {
        font-size: 2rem;
    }

    .notification-content p {
        font-size: 1.2rem;
    }

    .notification-subtitle {
        font-size: 1rem !important;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 480px) {
    main {
        padding: 5px;
    }

    header h1.logo {
        font-size: 1.5rem;
    }

    .instructions p {
        font-size: 0.9rem;
    }

    /* Slightly more compact on small screens, but allow scrolling */
    .main-grid[data-grid-size="8"] .word-button {
        padding: 8px 3px;
        font-size: 0.7rem;
        min-height: 48px;
    }

    .main-grid[data-grid-size="9"] .word-button,
    .main-grid[data-grid-size="10"] .word-button {
        padding: 7px 3px;
        font-size: 0.68rem;
        min-height: 46px;
    }

    .main-grid[data-grid-size="11"] .word-button,
    .main-grid[data-grid-size="12"] .word-button {
        padding: 7px 2px;
        font-size: 0.65rem;
        min-height: 44px;
    }

    .main-grid[data-grid-size="8"],
    .main-grid[data-grid-size="9"],
    .main-grid[data-grid-size="10"],
    .main-grid[data-grid-size="11"],
    .main-grid[data-grid-size="12"] {
        gap: 3px;
    }
}

/* Landscape orientation on mobile devices */
@media (max-width: 768px) and (orientation: landscape) {
    #victory-screen {
        top: 5vh;
        max-height: 90vh;
        padding: 20px;
    }

    #victory-screen h2 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }

    #victory-screen #victory-message {
        font-size: 1rem;
        margin-bottom: 20px;
    }

    #victory-screen #share-display {
        font-size: 0.9rem;
        padding: 12px;
        line-height: 1.5;
    }

    .victory-categories {
        gap: 8px;
        margin: 15px 0 20px 0;
        padding: 15px;
    }

    .victory-category {
        font-size: 0.95rem;
        gap: 8px;
    }

    .victory-category-icon {
        font-size: 1.2rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .word-button,
    .shake,
    .match-animation,
    .zoom-out {
        animation: none;
        transition: none;
    }
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: auto;
    font-size: 0.85rem;
}

footer a {
    color: var(--text-secondary, #666);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}
