:root {
    --bg-color: #f0f2f5;
    --board-bg: #e4e6eb;
    /* Board-width-driven responsive layout */
    --board-max-width: 400px;
    --board-width: min(calc(100vw - 40px), var(--board-max-width));
    --gap: 8px;
    --board-padding: 4px;
    /* Derive tile size from board width: (board - padding*2 - gaps) / 5 cols */
    --tile-size: calc((var(--board-width) - var(--board-padding) * 2 - 5 * var(--gap)) / 5);
    --text-color: #1a1a1a;
    --primary-color: #6366f1;
    --success-color: #22c55e; /* Green */
    --warning-color: #eab308; /* Yellow */
    --neutral-color: #ffffff; /* White */
    --hole-color: #cbd5e1;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --font-family: 'Outfit', sans-serif;
    --modal-bg: #ffffff;
    --modal-text: #4b5563;
    --nav-inactive: #9ca3af;
    --nav-active: #374151;
    --icon-btn-bg: #ffffff;
    --moves-value-color: #374151;
    --results-bg: #fdfbf7;
    --results-heading: #374151;
    --comp-label-color: #5f6b36;
    --stat-val-color: #374151;
    --stat-sub-color: #6b7280;
    --share-btn-bg: #fcd34d;
    --share-btn-text: #1f2937;
    --play-btn-bg: #84cc16;
    --play-btn-text: #1f2937;
    --toggle-bg: #cbd5e1;
}

body.dark-mode {
    --bg-color: #1a1625;
    --board-bg: #2d2640;
    --text-color: #e5e7eb;
    --primary-color: #8b5cf6; /* Purple */
    --success-color: #3b82f6; /* Blue */
    --warning-color: #ef4444; /* Red */
    --neutral-color: #3f3854;
    --hole-color: #4a4458;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);
    --modal-bg: #2d2640;
    --modal-text: #d1d5db;
    --nav-inactive: #d1d5db;
    --nav-active: #f3f4f6;
    --icon-btn-bg: #3f3854;
    --moves-value-color: #f3f4f6;
    --results-bg: #2d2640;
    --results-heading: #f3f4f6;
    --comp-label-color: #a78bfa;
    --stat-val-color: #f3f4f6;
    --stat-sub-color: #9ca3af;
    --share-btn-bg: #8b5cf6;
    --share-btn-text: #ffffff;
    --play-btn-bg: #3b82f6;
    --play-btn-text: #ffffff;
    --toggle-bg: #4a4458;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Prevent text selection during drag */
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 10px;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('forest_background_1763838777701.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: -1;
    transition: filter 0.3s ease;
}

body.dark-mode::before {
    filter: brightness(0.5) saturate(0.9) hue-rotate(130deg);
}

.app-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

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

h1 {
    font-weight: 800;
    letter-spacing: -0.05em;
    font-size: 2rem;
    color: var(--primary-color);
}

.controls {
    display: flex;
    gap: 10px;
}

.icon-btn {
    background: var(--icon-btn-bg);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s, box-shadow 0.1s;
    color: var(--text-color);
}

.icon-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.game-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 10px;
    font-weight: 600;
}

.stars-container {
    display: flex;
    gap: 4px;
    color: #fbbf24; /* Gold */
}

.game-board-container {
    /* Removed white frame - let the board breathe */
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(5, calc(var(--tile-size) + var(--gap))); /* Will be overridden by JS */
    gap: 0; /* No gap - handled by cell wrappers */
    background-color: transparent;
    width: var(--board-width);
    max-width: var(--board-max-width);
    padding: var(--board-padding);
    border-radius: 12px;
    position: relative;
    touch-action: none; /* Prevent browser scrolling on the board */
    box-shadow: var(--shadow-lg);
    overflow: hidden; /* Clip cell wrappers to rounded corners */
}

.cell-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--gap) / 2);
    background-color: var(--board-bg);
}

/* Punch through cell-wrapper background for holes to see the background image */
/* Creates a frame mask with rounded inner corners using radial gradients at corners + linear edges */
.cell-wrapper:has(.hole) {
    --frame: calc(var(--gap) / 2);
    --radius: 8px;
    --corner-size: calc(var(--frame) + var(--radius));
    --edge-length: calc(100% - 2 * var(--corner-size));
    /* Extend slightly to prevent subpixel gaps on bottom/right edges */
    margin-right: -1px;
    margin-bottom: -1px;
    padding-right: calc(var(--gap) / 2 + 1px);
    padding-bottom: calc(var(--gap) / 2 + 1px);

    -webkit-mask:
        /* Four corners with rounded inner edges */
        radial-gradient(circle at bottom right, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) top left / var(--corner-size) var(--corner-size) no-repeat,
        radial-gradient(circle at bottom left, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) top right / var(--corner-size) var(--corner-size) no-repeat,
        radial-gradient(circle at top right, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) bottom left / var(--corner-size) var(--corner-size) no-repeat,
        radial-gradient(circle at top left, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) bottom right / var(--corner-size) var(--corner-size) no-repeat,
        /* Four edges connecting the corners */
        linear-gradient(#fff, #fff) top center / var(--edge-length) var(--frame) no-repeat,
        linear-gradient(#fff, #fff) bottom center / var(--edge-length) var(--frame) no-repeat,
        linear-gradient(#fff, #fff) left center / var(--frame) var(--edge-length) no-repeat,
        linear-gradient(#fff, #fff) right center / var(--frame) var(--edge-length) no-repeat;
    mask:
        radial-gradient(circle at bottom right, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) top left / var(--corner-size) var(--corner-size) no-repeat,
        radial-gradient(circle at bottom left, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) top right / var(--corner-size) var(--corner-size) no-repeat,
        radial-gradient(circle at top right, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) bottom left / var(--corner-size) var(--corner-size) no-repeat,
        radial-gradient(circle at top left, transparent var(--radius), #fff calc(var(--radius) + 0.5px)) bottom right / var(--corner-size) var(--corner-size) no-repeat,
        linear-gradient(#fff, #fff) top center / var(--edge-length) var(--frame) no-repeat,
        linear-gradient(#fff, #fff) bottom center / var(--edge-length) var(--frame) no-repeat,
        linear-gradient(#fff, #fff) left center / var(--frame) var(--edge-length) no-repeat,
        linear-gradient(#fff, #fff) right center / var(--frame) var(--edge-length) no-repeat;
}

/* Outer corner rounding for the 4 corners of the board */
.cell-wrapper.corner-tl {
    border-top-left-radius: 8px;
}
.cell-wrapper.corner-tr {
    border-top-right-radius: 8px;
}
.cell-wrapper.corner-bl {
    border-bottom-left-radius: 8px;
}
.cell-wrapper.corner-br {
    border-bottom-right-radius: 8px;
}

.tile-slot {
    width: var(--tile-size);
    height: var(--tile-size);
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    position: relative;
}

.tile-slot.hole {
    background-color: transparent;
    box-shadow: none;
    border-radius: 8px; /* Same as tiles - looks like invisible tile slot */
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    background-color: var(--neutral-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: grab;
    box-shadow: var(--shadow-sm);
    position: absolute;
    /* top and left will be set by JS */
    transition: top 0.2s ease, left 0.2s ease, background-color 0.3s ease, transform 0.15s ease;
    z-index: 10;
    touch-action: none; /* Prevent browser scrolling/zooming while dragging */
}

.tile.dragging {
    opacity: 0.3;
    cursor: grabbing;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.tile.correct {
    background-color: var(--success-color);
    color: white;
}

.tile.present {
    background-color: var(--warning-color);
    color: white;
}

.tile.animal {
    background-color: transparent;
    font-size: 3.5rem;
    box-shadow: none; /* Remove shadow for cleaner look */
}

.tile.hedgehog {
    transform: translateY(-4px);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--modal-bg);
    padding: 30px;
    border-radius: 16px;
    max-width: 90%;
    width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.modal h2 {
    margin-bottom: 15px;
    color: var(--primary-color);
}

.modal p {
    margin-bottom: 15px;
    line-height: 1.5;
    color: var(--modal-text);
}

#modal-close {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

#modal-close:hover {
    background: #4f46e5;
}

/* Navigation */
.game-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    padding-bottom: 15px;
    width: 100%;
    margin-top: 10px;
}

.nav-group {
    display: flex;
    gap: 20px;
    align-items: center;
}

.nav-item {
    background: none;
    border: none;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--nav-inactive);
    cursor: pointer;
    padding: 5px 0;
    position: relative;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.nav-item.active {
    color: var(--nav-active);
}

.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: -17px; /* Align with border-bottom of nav */
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--nav-active);
    border-radius: 3px 3px 0 0;
}

.nav-icon-btn {
    background: none;
    border: none;
    color: var(--nav-inactive);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.nav-icon-btn:hover {
    color: var(--nav-active);
}

/* Moves Display */
.game-info-centered {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 10px 0 20px;
}

.moves-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.moves-label {
    font-size: 2rem;
    font-weight: 800;
    color: var(--nav-inactive);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.moves-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--moves-value-color);
    line-height: 1;
}

/* Results Section */
.results-section {
    background: var(--results-bg);
    padding: 30px 20px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    text-align: center;
    margin-top: 20px;
    color: var(--modal-text);
}

.results-section.hidden {
    display: none;
}

.results-section h2 {
    font-family: 'serif'; /* Or a specific font if available */
    font-size: 2rem;
    color: var(--results-heading);
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.result-stars {
    font-size: 3.5rem;
    color: #eef2ff; /* Empty star color */
    text-shadow: 0 0 2px #cbd5e1;
    margin: 5px 0;
}

.result-stars .filled {
    color: #fcd34d; /* Filled star color */
    text-shadow: 0 0 2px #f59e0b;
}

.result-animals {
    margin: 10px 0 20px;
}

.stats-divider {
    height: 2px;
    background: #e5e7eb;
    margin: 20px 0;
    width: 100%;
}

/* Moves Comparison */
.moves-comparison {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

.comp-label {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--comp-label-color);
}

.comparison-item {
    text-align: center;
}

.comp-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--stat-val-color);
    line-height: 1;
}

.comp-sub {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--stat-sub-color);
    margin-top: 5px;
    text-transform: uppercase;
}

/* Stats Row */
.stats-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
}

.stat-label-main {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--comp-label-color);
}

.stat-group {
    display: flex;
    gap: 30px;
}

.stat-item {
    text-align: center;
}

.stat-val {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--stat-val-color);
}

.stat-sub {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--stat-sub-color);
    text-transform: uppercase;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.action-btn {
    flex: 1;
    padding: 15px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s;
}

.action-btn:active {
    transform: scale(0.98);
}

.share-btn {
    background: var(--share-btn-bg);
    color: var(--share-btn-text);
}

.play-btn {
    background: var(--play-btn-bg);
    color: var(--play-btn-text);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive adjustments handled by board-width-driven layout */

/* Refactored Inline Styles */
.result-animal-icon {
    font-size: 4rem;
}

.modal-content-wrapper {
    text-align: left;
    margin-bottom: 20px;
}

.modal-list {
    list-style-type: none;
    padding: 0;
}

.modal-list-item {
    margin-bottom: 10px;
}

.loading-modal {
    width: auto;
    padding: 20px;
}

.spinner {
    margin: 20px auto;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Settings Modal */
.settings-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    gap: 20px;
}

.setting-info {
    flex: 1;
    text-align: left;
}

.setting-label {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 4px;
}

.setting-description {
    font-size: 0.85rem;
    color: #6b7280;
    line-height: 1.4;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--toggle-bg);
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

.reset-stats-btn {
    padding: 8px 20px;
    background-color: #ef4444;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.reset-stats-btn:hover {
    background-color: #dc2626;
}

.reset-stats-btn:active {
    transform: scale(0.98);
}

#settings-close {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 10px;
}

#settings-close:hover {
    background: #4f46e5;
}

