@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap");

:root {
    --bg: #f0f0f0;
    --text: #111111;
    --tile-border: #999;
    --key-bg: #dddddd;
    --key-pressed: #bbbbbb;
    --popup-overlay: rgba(0, 0, 0, 0.35);
    --popup-bg: #ffffff;
}

body.dark {
    --bg: #111827;
    --text: #f3f4f6;
    --tile-border: #4b5563;
    --key-bg: #374151;
    --key-pressed: #4b5563;
    --popup-overlay: rgba(0, 0, 0, 0.6);
    --popup-bg: #1f2937;
}

body {
    font-family: "Press Start 2P", "Courier New", monospace;
    text-align: center;
    background-color: var(--bg);
    color: var(--text);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#game-wrap {
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 18px auto 0;
}

#theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1100;
    border: 0;
    width: 72px;
    height: 38px;
    border-radius: 0;
    padding: 0;
    cursor: pointer;
    background: #cbd5e1;
    transition: background-color 220ms ease;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    box-shadow: 0 0 0 2px var(--text), 3px 3px 0 rgba(0, 0, 0, 0.35);
}

body.dark #theme-toggle {
    background: #1d4ed8;
}

#theme-toggle .theme-icon {
    width: 50%;
    height: 100%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 78% 78%;
    user-select: none;
    opacity: 1;
    z-index: 1;
}

#theme-toggle .theme-icon.sun {
    background-image: url("sun.png");
}

#theme-toggle .theme-icon.moon {
    background-image: url("moon.png");
    background-size: 100% 100%;
}

#theme-toggle .theme-thumb {
    position: absolute;
    top: 50%;
    left: 3px;
    width: 32px;
    height: 32px;
    box-sizing: border-box;
    border-radius: 0;
    background: #00000079;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
    transition: transform 220ms cubic-bezier(0.22, 0.8, 0.34, 1);
    border: 2px solid #000;
    transform: translateY(-50%);
}

body.dark #theme-toggle .theme-thumb {
    transform: translate(34px, -50%);
}

#word-length-label {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
}

h1 {
    margin-top: 16px;
}

#game-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 5), 58px);
    gap: 6px;
    justify-content: center;
    margin: 20px auto;
}

.cell {
    width: 58px;
    height: 58px;
    border: 2px solid var(--tile-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 0;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08), 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.cell.flip-reveal {
    animation: tileFlip 420ms ease;
}

.green { background-color: #6aaa64; color: white; }
.yellow { background-color: #c9b458; color: white; }
.gray { background-color: #dc2626; color: white; }

#keyboard {
    margin-top: 20px;
}

.keyboard-row {
    margin-bottom: 4px;
}

.key {
    display: inline-block;
    margin: 3px;
    padding: 10px 12px;
    min-width: 38px;
    font-size: 12px;
    font-weight: 700;
    background-color: var(--key-bg);
    color: var(--text);
    cursor: pointer;
    user-select: none;
    border-radius: 0;
    border: 2px solid var(--text);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
}
.key.pressed {
    background-color: var(--key-pressed);
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.28);
}

.key.state-green {
    background-color: #6aaa64;
    color: white;
}

.key.state-yellow {
    background-color: #c9b458;
    color: white;
}

.key.state-gray {
    background-color: #dc2626;
    color: white;
}

#message {
    min-height: 24px;
    margin-top: 16px;
    white-space: pre-line;
    font-size: 11px;
    letter-spacing: 0.3px;
}

#character-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 900;
    overflow: hidden;
}

#character-layer canvas {
    position: absolute;
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.45));
}

#popup {
    position: fixed;
    inset: 0;
    background: var(--popup-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#popup.hidden {
    display: none;
}

#popup-card {
    width: fit-content;
    max-width: min(520px, calc(100% - 30px));
    background: var(--popup-bg);
    color: var(--text);
    border-radius: 0;
    padding: 10px 12px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
    border: 3px solid var(--text);
    box-shadow: 0 0 0 3px var(--bg), 8px 8px 0 rgba(0, 0, 0, 0.35);
}

#popup-text {
    margin: 0 0 8px;
    white-space: pre-line;
    font-size: 12px;
    line-height: 1.35;
    text-align: center;
    letter-spacing: 0.3px;
}

#popup-card.popup-flip {
    animation: popupTextFlip 320ms ease;
}

#popup-close {
    border: 0;
    border-radius: 0;
    background: #1f6feb;
    color: #fff;
    padding: 10px 16px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
    border: 2px solid #000;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
}

#popup-replay {
    border: 0;
    border-radius: 0;
    background: #2b8a3e;
    color: #fff;
    padding: 10px 16px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 8px;
    display: none;
    font-family: inherit;
    border: 2px solid #000;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
}

@keyframes tileFlip {
    0% {
        transform: rotateX(0deg);
    }
    50% {
        transform: rotateX(90deg);
    }
    100% {
        transform: rotateX(0deg);
    }
}

@keyframes popupTextFlip {
    0% {
        transform: rotateX(90deg);
        opacity: 0;
    }
    100% {
        transform: rotateX(0deg);
        opacity: 1;
    }
}
