:root {
    --bg-color: #f0f4f8;
    --text-color: #333;
    --secondary-text-color: #666;
    --card-front: #fff;
    --card-back: #1e90ff;
    --primary: #1e90ff;
    --secondary: #0d6efd;
    --primary-rgb: 30, 144, 255;
    --results-bg: #fff;
    --results-gold: #d4af37;
    --results-silver: #aaaaaa;
    --results-bronze: #9f7a34;
    --results-nth-rows: #f7f9fc;
    --results-line: #e0e0e0;
    --cursor-x: 0px;
    --cursor-y: 0px;
    --grid-cols: 4;
}

body.light-theme {
    --bg-color: #f0f4f8;
    --text-color: #333;
    --secondary-text-color: #666;
    --card-front: #fff;
    --card-back: #1e90ff;
    --primary: #1e90ff;
    --secondary: #0d6efd;
    --primary-rgb: 30, 144, 255;
    --results-bg: #fff;
    --results-gold: #d4af37;
    --results-silver: #aaaaaa;
    --results-bronze: #9f7a34;
    --results-nth-rows: #f7f9fc;
    --results-line: #e0e0e0;
}

body.dark-theme {
    --bg-color: #23272f;
    --text-color: #f5f5f5;
    --secondary-text-color: #d1d1d1;
    --card-front: #2d323c;
    --card-back: #3b82f6;
    --primary: #3b82f6;
    --secondary: #60a5fa;
    --primary-rgb: 59, 130, 246;
    --results-bg: #2d323c;
    --results-gold: #d6b152;
    --results-silver: #cfcfcf;
    --results-bronze: #b58e4e;
    --results-nth-rows: #373b49;
    --results-line: #272837;
}

body.blue-cards {
    --card-back: #1e90ff;
    --primary: #1e90ff;
    --secondary: #0d6efd;
    --primary-rgb: 30, 144, 255;
}

body.green-cards {
    --card-back: #22c55e;
    --primary: #22c55e;
    --secondary: #1b9a48;
    --primary-rgb: 34, 197, 94;
}

body.orange-cards {
    --card-back: #ff9800;
    --primary: #ff9800;
    --secondary: #d37e00;
    --primary-rgb: 255, 152, 0;
}

body.gray-cards {
    --card-back: #888;
    --primary: #888;
    --secondary: #686868;
    --primary-rgb: 136, 136, 136;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
}

body::before {
    content: '';
    position: fixed;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 70%);
    pointer-events: none;
    transform: translate(-50%, -50%);
    left: var(--cursor-x, 0);
    top: var(--cursor-y, 0);
    z-index: -1;
    transition: left 0.2s ease-out, top 0.2s ease-out;
}

body.light-theme::before {
    background: radial-gradient(circle, rgba(var(--primary-rgb), 0.1) 0%, rgba(var(--primary-rgb), 0) 70%);
}

/* ----- HEADER ----- */
header {
    display: flex;
    flex-direction: column;
    text-align: center;
    margin-bottom: 20px;
}

.corner-logos {
    position: absolute;
    top: 0;
    left: 0;
    width: 99vw;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 1000;
    padding: 12px 16px;
    box-sizing: border-box;
}

.corner-logos img {
    height: 64px;
    width: auto;
    max-width: 22vw;
    pointer-events: auto;
    border-radius: 10px;
}

.corner-logos .logo-left {
    align-self: flex-start;
}

.corner-logos .logo-right {
    align-self: flex-start;
}

@media (max-width: 600px) {
    .corner-logos img {
        height: 40px;
        max-width: 38vw;
    }
    .corner-logos {
        padding: 4px 6px;
    }
}

#header-canvas {
    width: 60vw;
    height: 4px;
    background: linear-gradient(90deg, #1e90ff, #22c55e, #ff9800);
    margin-bottom: 12px;
    align-self: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 5px;
}

header p {
    font-size: 1rem;
    color: var(--secondary-text-color);
}

#theme-toggle, #color-toggle {
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 1rem;
    cursor: pointer;
    margin: 12px 0 8px 10px;
    transition: background-color 0.3s;
    display: inline-block;
    box-shadow: 0 2px 6px rgba(30, 144, 255, 0.10);
}

#theme-toggle:hover, #color-toggle:hover {
    background-color: var(--secondary);
}

#toggle-button-container {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px;
}

/* ----- MAIN ----- */
main {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 20px;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    position: relative;
}

@media (min-width: 1200px) {
    #main-content {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 40px;
    }
    #game-board {
        margin-right: 40px;
    }
    #results, #button-container {
        margin-left: 100px;
    }
}

/* ----- NAME INPUT, DIFFICULTY SELECTION ----- */
#input-container {
    display: flex;
    flex-direction: row;
    gap: 20px;
    align-items: center;
}

#difficulty-container, #name-input-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    background-color: var(--results-bg);
    border-radius: 8px;
    padding: 8px 16px;
    box-shadow: 0 1px 4px rgba(var(--primary-rgb), 0.07);
    width: fit-content;
}

#difficulty-label, #player-name-label {
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--primary);
    font-size: 1rem;
}

#difficulty, #player-name {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: var(--card-front);
    color: var(--text-color);
    border: 1.5px solid var(--primary);
    border-radius: 6px;
    padding: 7px 34px 7px 12px;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s;
    box-shadow: 0 1px 2px rgba(var(--primary-rgb), 0.05);
    position: relative;
}
#player-name {
    cursor: text;
}
#difficulty:focus, #player-name:focus {
    outline: none;
    border-color: var(--secondary);
}

#difficulty option {
    background: var(--card-front);
    color: var(--text-color);
}

#difficulty {
    background-image: url("data:image/svg+xml;utf8,<svg fill='gray' height='16' viewBox='0 0 20 20' width='16' xmlns='http://www.w3.org/2000/svg'><path d='M5.516 7.548a.75.75 0 0 1 1.06 0L10 10.97l3.424-3.423a.75.75 0 1 1 1.06 1.06l-4 4a.75.75 0 0 1-1.06 0l-4-4a.75.75 0 0 1 0-1.06z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px 18px;
}

@media(max-width: 750px) {
    #input-container {
        display: flex;
        flex-direction: column;
        gap: 0;
    }
}

@media (max-width: 500px) {
    #difficulty-container, #name-input-container {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 8px 8px;
    }
    #difficulty, #player-name {
        width: 100%;
    }
}

/* ----- TIMER AND COUNTER ----- */
#stats-container {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 10px;
}

#timer, #flips {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary);
}

#flips {
    margin-bottom: 10px;
}

/* ----- PROGRESS BAR ----- */
#progress-container {
    width: 200px;
    height: 12px;
    background-color: var(--results-bg);
    border-radius: 6px;
    margin: 20px 0;
    z-index: 1;
}

#progress-bar {
    width: 0;
    height: 100%;
    background-color: var(--primary);
    border-radius: 6px;
    transition: width 0.3s ease;
}

/* ----- CANVAS BACKGROUND ----- */
#bg-canvas {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120%;
    height: 105%;
    z-index: 0;
    pointer-events: none;
    border-radius: 16px;
}

/* ----- GAME BOARD ----- */
#game-board {
    flex: 1 1 600px;
    display: grid;
    grid-template-columns: repeat(var(--grid-cols, 4), 1fr);
    gap: 10px;
    justify-items: start;
    margin: 0 auto 20px auto;
    width: 100%;
    max-width: 700px;
    min-width: 0;
    position: relative;
    z-index: 1;
    align-items: center;
    overflow: visible;
}

.card {
    width: calc((600px - (var(--grid-cols, 4) - 1) * 10px) / var(--grid-cols, 4));
    aspect-ratio: 1 / 1;
    max-width: 110px;
    min-width: 12px;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    perspective: 600px;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    will-change: transform, box-shadow;
    vertical-align: top;
}

@media (max-width: 600px) {
    #game-board {
        gap: 4px;
        max-width: 100vw;
    }
    .card {
        width: calc((100vw - (var(--grid-cols, 4) - 1) * 10px) / var(--grid-cols, 4));
        max-width: 48px;
        min-width: 28px;
        font-size: 1.1rem;
    }
}

.card:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 24px rgba(var(--primary-rgb), 0.25);
    z-index: 2;
}

.card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 10px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    background: linear-gradient(120deg, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0.02) 80%);
}
.card:hover::after {
    opacity: 1;
}

.card.flipped:hover,
.card.pair-found:hover {
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    z-index: 1;
    cursor: default;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    backface-visibility: hidden;
}

.card-back {
    background-color: var(--card-back);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    z-index: 1;
}

.card-front {
    background-color: var(--card-front);
    transform: rotateY(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    z-index: 2;
}

@keyframes pairFoundFlash {
    0% {
        background-color: var(--card-front);
    }
    30% {
        background-color: #4ade80;
    }
    100% {
        background-color: var(--card-front);
    }
}

.card.pair-found .card-front {
    animation: pairFoundFlash 0.7s ease;
}

/* ----- BUTTONS ----- */
#button-container {
    display: flex;
    justify-content: center;
    gap: 16px;
    width: 100%;
    max-width: 350px;
}

#results-buttons-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
}

#button-container button {
    flex: 1 1 0;
    min-width: 0;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    margin: 30px 10px;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: var(--secondary);
}

/* ----- FOOTER ----- */
footer {
    margin-top: auto;
    padding-top: 10px;
    text-align: center;
}

/* ----- RESULTS ----- */
#results {
    flex: 0 0 110px;
    max-width: 400px;
    min-width: 220px;
    width: 100%;
    margin-top: 30px;
    background: var(--results-bg);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(30, 144, 255, 0.10);
    padding: 18px 16px 0 16px;
    display: block;
}

#results h2 {
    font-size: 1.2rem;
    color: var(--primary);
    margin-bottom: 10px;
    text-align: center;
}

#results-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 224px;
    overflow-y: auto;
}

#results-list li {
    padding: 6px;
    border-bottom: 1px solid var(--results-line);
    font-size: 1rem;
    color: var(--secondary-text-color);
}

#results-list li:nth-child(1) {
    font-weight: bold;
    color: var(--results-gold);
}

#results-list li:nth-child(2) {
    font-weight: bold;
    color: var(--results-silver);
}

#results-list li:nth-child(3) {
    font-weight: bold;
    color: var(--results-bronze);
}

#results-list li:nth-child(even) {
    background-color: var(--results-nth-rows);
}

#results-list li:last-child {
    border-bottom: none;
}

#results-list li#no-results-text {
    font-weight: normal;
    color: var(--secondary-text-color);
    font-style: italic;
}
