:root {
    /* Light mode (default) */
    --bg-color: #fafafa;
    --text-color: #2c3e50;
    --primary-color: #FFD700;
    --primary-dark: #e6c200;
    --accent-color: #2c3e50;
    --cell-bg: #e8e8e8;
    --cell-hover: #dcdcdc;
    --center-cell-bg: #FFD700;
    --error-color: #e74c3c;
    --success-color: #2ecc71;
    --card-bg: white;
    --border-color: rgba(0, 0, 0, 0.05);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
    --shadow-hard: 0 2px 4px rgba(0, 0, 0, 0.1);
    --dot-color: rgba(224, 224, 224, 1);
    --font-main: 'Outfit', sans-serif;
}

body.dark-mode {
    /* Dark mode overrides */
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --cell-bg: #2a2a2a;
    --cell-hover: #3a3a3a;
    --card-bg: #242424;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-hard: 0 2px 4px rgba(0, 0, 0, 0.5);
    --dot-color: rgba(80, 80, 80, 1);

    /* Keep accent colors vibrant */
    --primary-color: #FFD700;
    --center-cell-bg: #FFD700;
    --error-color: #ff6b6b;
    --success-color: #51cf66;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
    background-size: 20px 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 1400px;
    /* Increased max-width for desktop sidebar */
    margin: 0 auto;
    position: relative;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    transition: background-color 0.3s ease;
}

/* Desktop and tablet optimizations */
@media (min-width: 768px) {
    header {
        position: sticky;
        top: 0;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        z-index: 10;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    }

    /* Ensure score box doesn't overlap hexagons on desktop */
    .score-container {
        margin-bottom: clamp(2rem, 3vw, 2.5rem);
    }

    /* Adaptive top padding based on viewport height */
    main {
        padding-top: clamp(2rem, 4vh, 2.5rem);
    }

    /* More space for input area on desktop */
    .input-area {
        margin-bottom: clamp(1rem, 2vh, 1.5rem);
    }

    /* Allow actions to use more space on wider screens */
    .actions {
        max-width: min(95vw, 500px);
    }
}

/* Header */
header {
    padding: 0.8rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(250, 250, 250, 0.5);
    transition: background-color 0.3s ease;
}

body.dark-mode header {
    background: rgba(42, 42, 42, 0.5);
}

h1 {
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: -1px;
    color: var(--text-color);
    text-align: center;
}

.score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.9rem;
    background: var(--card-bg);
    padding: 0.5rem 0.8rem;
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    align-self: center;
    width: 100%;
    max-width: 480px;
    margin-bottom: 0.5rem;
}

.rank {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.2rem;
    color: var(--primary-color);
}

.score-bar-bg {
    width: 100%;
    height: 8px;
    background: linear-gradient(90deg, #e0e0e0 0%, #f5f5f5 100%);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.score-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-radius: 10px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.score-stats {
    margin-top: 0.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    align-items: center;
}

.score-text {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

.score-details {
    font-size: 0.75rem;
    color: #666;
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.score-details .divider {
    color: #ccc;
}

/* Main Game Area */
main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    position: relative;
    width: 100%;
    overflow-y: auto;
    /* Allow scrolling on mobile */
    -webkit-overflow-scrolling: touch;
}

.message-area {
    min-height: 2rem;
    /* Ensure height even when empty */
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-color);
    font-size: 1.1rem;
    text-align: center;
    z-index: 5;
    /* Ensure above other elements */
}

.input-area {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-color);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.05);
    position: relative;
}

.input-area::before {
    content: '|';
    color: var(--primary-color);
    margin-right: 4px;
    animation: blink 1s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Hive Grid - True Hexagons with Responsive Sizing */
.hive-container {
    margin-bottom: 0.5rem;
    position: relative;
    /* Responsive sizing: scale with viewport but cap at 350px */
    width: min(85vw, 350px);
    height: min(85vw, 350px);
    max-width: 350px;
    max-height: 350px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Enable scaling calculations */
    --container-size: min(85vw, 350px);
}

.hive {
    position: relative;
    /* Full container - cells will be absolutely positioned within */
    width: 100%;
    height: 100%;
}

.cell {
    /* Cells scale with container - 24% gives good hexagon size */
    width: 24%;
    aspect-ratio: 1 / 0.866;
    /* Flat-top aspect ratio (width > height) */
    background-color: var(--cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Font scales with container */
    font-size: clamp(1.2rem, calc(var(--container-size) * 0.055), 1.9rem);
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    position: absolute;
    /* Hexagon Shape - Flat Top */
    /* Points: TopLeft(25% 0%), TopRight(75% 0%), Right(100% 50%), BottomRight(75% 100%), BottomLeft(25% 100%), Left(0% 50%) */
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    transition: transform 0.1s, background-color 0.2s;
    -webkit-tap-highlight-color: transparent;
    color: var(--text-color);
}

/* Removed old fixed-size transform media queries - now using responsive min() */

.cell:active {
    transform: translate(-50%, -50%) scale(0.9) !important;
}

.cell:hover {
    background-color: var(--cell-hover);
}

.cell.center {
    background-color: var(--center-cell-bg);
    color: #000;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.cell.center:hover {
    background-color: var(--primary-dark);
}

/* Positioning the outer cells */
/* In HTML: cells 1,2,3 then center(0), then cells 4,5,6 */
/* So nth-child: 1,2,3,4(center),5,6,7 */
.cell.outer:nth-child(1) {
    top: 15%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* cell-1: Top */
.cell.outer:nth-child(2) {
    top: 35%;
    left: 75%;
    transform: translate(-50%, -50%);
}

/* cell-2: Top Right */
.cell.outer:nth-child(3) {
    top: 65%;
    left: 75%;
    transform: translate(-50%, -50%);
}

/* cell-3: Bottom Right */
/* cell-0: Center */
.cell.outer:nth-child(5) {
    top: 85%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* cell-4: Bottom */
.cell.outer:nth-child(6) {
    top: 65%;
    left: 25%;
    transform: translate(-50%, -50%);
}

/* cell-5: Bottom Left */
.cell.outer:nth-child(7) {
    top: 35%;
    left: 25%;
    transform: translate(-50%, -50%);
}

/* cell-6: Top Left */

/* Game Actions - Responsive Wrapping Layout */
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
    margin-top: 0rem;
    margin-bottom: 0.8rem;
    width: 100%;
    /* Scale with viewport but cap at reasonable size */
    max-width: min(90vw, 450px);
    padding: 0 1rem;
}

.action-btn {
    /* Flexible sizing with minimum touch target */
    padding: clamp(0.6rem, 2vw, 0.8rem) clamp(1rem, 3vw, 1.2rem);
    border-radius: 50px;
    border: 2px solid var(--border-color);
    background: rgba(250, 250, 250, 0.5);
    font-weight: 600;
    font-size: clamp(0.85rem, 2.5vw, 0.9rem);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
    color: var(--text-color);
    flex: 1 1 auto;
    min-width: max(25%, 80px);
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-soft);
    -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
    transform: scale(0.95);
    background-color: #f5f5f5;
}

body.dark-mode .action-btn {
    background: rgba(42, 42, 42, 0.5);
}

.action-btn.primary {
    background-color: var(--primary-color);
    border-color: var(--primary-dark);
    color: #2c3e50;
    font-weight: 800;
}

.action-btn.primary:active {
    background-color: var(--primary-dark);
}

/* Removed old small-screen vertical stack - actions now wrap intelligently with flex-wrap */

/* Controls */
.controls {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.btn {
    padding: 0.8rem 2rem;
    border-radius: 50px;
    border: 2px solid #eee;
    background: white;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
    box-shadow: var(--shadow-soft);
    color: var(--text-color);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.btn:active {
    transform: translateY(0);
}

.btn.icon {
    padding: 0.8rem;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Word List Sidebar - Mobile defaults */
.found-words {
    width: 100%;
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(250, 250, 250, 0.5);
    border-radius: 15px;
}

.found-words h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: #666;
    font-weight: 600;
}

.word-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.word-list li {
    padding: 0.4rem 1rem;
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 0.95rem;
    text-transform: capitalize;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Toast */
.toast-container {
    position: fixed;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    pointer-events: none;
}

.toast {
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-weight: 600;
    font-size: 1rem;
    animation: slideDown 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), fadeOut 0.5s ease 2s forwards;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.success {
    background: var(--card-bg);
    color: var(--text-color);
    border: 2px solid var(--primary-color);
}

@keyframes slideDown {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Responsive */
/* Responsive Grid Layout */
@media (min-width: 768px) {
    .game-container {
        /* No fixed height/width hacks, let flex/grid handle it */
        border-radius: 30px;
        margin: 1rem auto;
        height: calc(100dvh - 2rem);
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.5);
        overflow: hidden;
    }

    header {
        /* Normal flow header, no absolute positioning */
        position: relative;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        padding: 1rem 2rem;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    /* Main Content Grid */
    main {
        display: grid;
        grid-template-columns: 1fr 350px;
        /* Game Area | Sidebar */
        /* Rows: Hive (flexible), Input, Message, Actions */
        grid-template-rows: 1fr auto auto auto;
        grid-template-areas:
            "hive sidebar"
            "input sidebar"
            "message sidebar"
            "actions sidebar";
        padding: 0;
        overflow: hidden;
    }

    /* Grid Areas */
    .hive-container {
        grid-area: hive;
        align-self: center;
        justify-self: center;
        width: min(50vh, 400px);
        /* Scale with height on desktop */
        height: min(50vh, 400px);
        margin: 0;
    }

    .found-words {
        grid-area: sidebar;
        grid-row: 1 / -1;
        /* Span all rows */
        height: 100%;
        overflow-y: auto;
        border-left: 1px solid rgba(0, 0, 0, 0.05);
        padding: 1.5rem;
        background: rgba(250, 250, 250, 0.5);
        display: flex;
        flex-direction: column;
    }

    .input-area {
        grid-area: input;
        align-self: end;
        margin-bottom: 0.5rem;
    }

    .message-area {
        grid-area: message;
        align-self: end;
        margin-bottom: 0.5rem;
    }

    .actions {
        grid-area: actions;
        align-self: start;
        margin-bottom: 1rem;
    }
}

/* New Seed Info Style in Settings */
.current-seed-info {
    margin-top: 1rem;
    padding: 0.8rem;
    background: #f8f9fa;
    border-radius: 10px;
    text-align: center;
    font-size: 0.9rem;
    color: #666;
    border: 1px solid #eee;
}

.current-seed-info span {
    font-weight: 600;
    color: var(--text-color);
}