@font-face {
    font-family: 'Minecraftia';
    /* Fallback to system monospace since TTF download failed, but keep pixel aesthetic */
    src: local('Courier New'), local('Monaco');
}

:root {
    --bg-color: #000;
    --text-color: #fff;
    --accent-color: #ffff55;
    /* Minecraft Yellow */
    --x-color: #ff5555;
    /* Light Red */
    --o-color: #55ffff;
    /* Aqua */
    --border-color: #000;
    --pixel-size: 4px;

    /* New Dirt Pattern */
    --dirt-bg: url('assets/dirt_real.png');

    /* Base64 Stone Pattern */
    --stone-bg: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16" fill="%237d7d7d"/><rect width="4" height="4" x="2" y="2" fill="%239a9a9a"/><rect width="4" height="4" x="10" y="10" fill="%235a5a5a"/><rect width="2" height="2" x="12" y="4" fill="%235a5a5a"/><rect width="2" height="2" x="4" y="12" fill="%239a9a9a"/></svg>');

    /* Base64 Alex Pattern */
    --alex-bg: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" width="100%" height="100%"><rect width="8" height="8" fill="%23f6b597"/><rect width="8" height="2" fill="%23e38c27"/><rect width="2" height="1" x="0" y="2" fill="%23e38c27"/><rect width="1" height="2" x="0" y="3" fill="%23e38c27"/><rect width="2" height="1" x="6" y="2" fill="%23e38c27"/><rect width="1" height="2" x="7" y="3" fill="%23e38c27"/><rect width="2" height="1" x="1" y="4" fill="%23ffffff"/><rect width="2" height="1" x="5" y="4" fill="%23ffffff"/><rect width="1" height="1" x="2" y="4" fill="%23476822"/><rect width="1" height="1" x="6" y="4" fill="%23476822"/><rect width="2" height="1" x="3" y="5" fill="%23ce8d6e"/><rect width="2" height="1" x="3" y="6" fill="%23bb5454"/></svg>');

    /* Base64 Enderman Pattern */
    --enderman-bg: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 8" width="100%" height="100%"><rect width="8" height="8" fill="%23141414"/><rect width="3" height="1" x="0" y="4" fill="%23d06fda"/><rect width="3" height="1" x="5" y="4" fill="%23d06fda"/><rect width="1" height="1" x="1" y="4" fill="%23f2b4f6"/><rect width="1" height="1" x="6" y="4" fill="%23f2b4f6"/></svg>');
}

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

body {
    font-family: 'Minecraftia', 'Press Start 2P', monospace;
    background-image: var(--dirt-bg);
    background-size: 64px 64px;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
    user-select: none;
}

/* Overlay removed for Minecraft theme but class kept for structure */
.crt-overlay {
    display: none;
}

.container {
    width: 100%;
    max-width: 500px;
    padding: 20px;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 30px;
    background: rgba(0, 0, 0, 0.6);
    border: var(--pixel-size) solid #000;
}

header {
    text-align: center;
}

h1 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--accent-color);
    text-shadow: 2px 2px 0 #000;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    text-align: center;
    color: #ffeb3b;
}

.score-board {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.score-card {
    text-align: center;
    padding: 15px;
    min-width: 120px;
    line-height: 1.5;
}

.pixel-box {
    border: calc(var(--pixel-size) / 2) solid var(--border-color);
    background-image: var(--stone-bg);
    background-size: 64px 64px;
    image-rendering: pixelated;
    color: #fff;
    box-shadow:
        inset -4px -4px 0px 0px rgba(0, 0, 0, 0.5),
        inset 4px 4px 0px 0px rgba(255, 255, 255, 0.5);
    text-shadow: 2px 2px 0 #3f3f3f;
}

.btn {
    font-family: 'Minecraftia', monospace;
    background-image: var(--stone-bg);
    background-size: 32px 32px;
    image-rendering: pixelated;
    color: #fff;
    text-shadow: 2px 2px 0 #3f3f3f;
    border: 3px solid #000;
    box-shadow:
        inset -4px -4px 0px 0px rgba(0, 0, 0, 0.5),
        inset 4px 4px 0px 0px rgba(255, 255, 255, 0.5);
    padding: 15px 20px;
    cursor: pointer;
    font-size: 1rem;
    text-transform: uppercase;
}

.btn:hover {
    filter: brightness(1.2);
    color: #ffffa0;
}

.btn:active {
    transform: translateY(2px);
}

/* Setup Screen */
#setup-screen {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

label {
    font-size: 0.8rem;
    color: #ccc;
}

input[type="text"] {
    font-family: 'Minecraftia', monospace;
    background: #000;
    color: var(--text-color);
    border: 2px solid #555;
    padding: 10px;
    font-size: 1rem;
    outline: none;
}

input[type="text"]:focus {
    border-color: #fff;
}

.difficulty-options {
    display: flex;
    gap: 15px;
}

.diff-btn {
    flex: 1;
    font-family: 'Minecraftia', monospace;
    background-image: var(--stone-bg);
    background-size: 32px 32px;
    image-rendering: pixelated;
    color: #ffffff;
    text-shadow: 2px 2px 0 #000;
    border: 3px solid #000;
    box-shadow:
        inset -4px -4px 0px 0px rgba(0, 0, 0, 0.5),
        inset 4px 4px 0px 0px rgba(255, 255, 255, 0.5);
    padding: 15px;
    cursor: pointer;
    font-size: 0.8rem;
}

.diff-btn:hover {
    filter: brightness(1.2);
    color: #fff;
}

.diff-btn.active {
    filter: brightness(1.2);
    box-shadow:
        inset -4px -4px 0px 0px rgba(255, 255, 255, 0.5),
        inset 4px 4px 0px 0px rgba(0, 0, 0, 0.5);
    color: #5555ff;
    /* Minecraft Blue/Active color */
}

#start-btn {
    margin-top: 10px;
}

.btn-green {
    color: #55ff55 !important;
    /* Minecraft Green text to indicate action */
}

/* Game Screen */
.hidden {
    display: none !important;
}

.status {
    text-align: center;
    font-size: 1rem;
    margin-bottom: 20px;
    min-height: 1rem;
    line-height: 1.5;
    color: #ffeb3b;
    transition: all 0.3s;
}

.status.game-over {
    font-size: 2rem;
    color: #55ff55;
    /* Minecraft green */
    text-shadow: 3px 3px 0 #000;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: var(--pixel-size);
    background: #000;
    border: var(--pixel-size) solid #000;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 400px;
    margin: 0 auto;
}

.cell {
    background-image: var(--stone-bg);
    background-size: 64px 64px;
    image-rendering: pixelated;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
    cursor: pointer;
    box-shadow:
        inset -4px -4px 0px 0px rgba(0, 0, 0, 0.3),
        inset 4px 4px 0px 0px rgba(255, 255, 255, 0.3);
}

.cell:hover {
    filter: brightness(1.2);
}

.cell.x {
    background-image: var(--alex-bg), var(--stone-bg);
    background-size: 80% 80%, 64px 64px;
    background-position: center;
    background-repeat: no-repeat, repeat;
    color: transparent;
    /* hide X text */
}

.cell.o {
    background-image: var(--enderman-bg), var(--stone-bg);
    background-size: 80% 80%, 64px 64px;
    background-position: center;
    background-repeat: no-repeat, repeat;
    color: transparent;
    /* hide O text */
}

.cell.win {
    /* Apply a brightness/contrast filter or a semi-transparent inset shadow to indicate a win without removing the background image. */
    background-color: rgba(0, 255, 0, 0.4) !important;
    background-blend-mode: multiply;
    animation: blink 0.5s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 30px;
}

.controls .btn {
    font-size: 0.8rem;
    padding: 12px 15px;
    width: auto;
}

#menu-btn {
    font-size: 0.6rem;
    padding: 8px 12px;
    opacity: 0.8;
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }

    .cell {
        font-size: 2.5rem;
    }

    .score-card {
        padding: 10px;
        min-width: 90px;
        font-size: 0.8rem;
    }
}