/* ============================================================
   Shared game UI — boards, cells, status, keypads
   Each game can override with its own id-specific rules in its file
   ============================================================ */

/* Game status banner */
.status {
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    text-align: center;
    font-weight: 500;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status.win {
    border-color: var(--success);
    color: var(--success);
    background: rgba(22, 163, 74, 0.08);
}

.status.lose {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(220, 38, 38, 0.08);
}

.status.info {
    border-color: var(--info);
    color: var(--info);
}

/* Score row */
.scoreboard {
    display: flex;
    justify-content: space-around;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
}

.score-cell {
    text-align: center;
}

.score-cell .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.score-cell .val {
    font-size: 1.4rem;
    font-family: var(--font-heading);
}

/* Generic board grid */
.board {
    display: grid;
    gap: 6px;
    justify-content: center;
    margin: 0 auto;
}

.cell {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    font-family: var(--font-heading);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    aspect-ratio: 1;
}

.cell:hover:not(.disabled):not(.locked) {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.cell:active:not(.disabled):not(.locked) {
    transform: scale(0.94);
}

.cell.disabled, .cell.locked {
    cursor: default;
}

.cell.x {
    color: var(--accent);
}

.cell.o {
    color: var(--accent-2);
}

.cell.filled {
    background: var(--accent-soft);
}

/* Keyboard-style keys */
.key {
    display: inline-grid;
    place-items: center;
    min-width: 36px;
    height: 44px;
    padding: 0 8px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s;
}

.key:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.key:active {
    transform: scale(0.92);
}

.key.used-correct {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.key.used-present {
    background: var(--warning);
    color: #fff;
    border-color: var(--warning);
}

.key.used-absent {
    background: var(--bg-soft);
    color: var(--text-muted);
    border-color: var(--border);
    opacity: 0.6;
}

/* Difficulty selector */
.difficulty {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.diff-btn {
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.diff-btn.active {
    background: var(--accent);
    color: #fff;
}

[data-theme="arcade"] .diff-btn.active {
    color: #0a0a16;
}

/* Tile/letter square for wordle-like */
.letter {
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    font-weight: 700;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    transition: transform 0.2s, background 0.3s, border-color 0.3s, color 0.3s;
}

.letter.filled {
    border-color: var(--accent);
    transform: scale(1.05);
}

.letter.correct {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.letter.present {
    background: var(--warning);
    color: #fff;
    border-color: var(--warning);
}

.letter.absent {
    background: var(--bg-soft);
    color: var(--text-muted);
    border-color: var(--border);
}

.letter.flip {
    animation: flip 0.4s ease;
}

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

@media (max-width: 480px) {
    .letter {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }
}

/* Wordle row */
.word-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

/* Hangman stage */
.hangman-svg {
    width: 200px;
    height: 220px;
    margin: 0 auto;
}

.hangman-svg path, .hangman-svg circle, .hangman-svg line {
    stroke: var(--text);
    stroke-width: 3;
    fill: none;
    stroke-linecap: round;
}

/* 2048 tiles */
.t-2048 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 320px;
    height: 320px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    margin: 0 auto;
    position: relative;
}

.tile-2048 {
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.4rem;
    transition: transform 0.1s;
}

.tile-2048[data-v="2"] {
    background: #eee4da;
    color: #776e65;
}

.tile-2048[data-v="4"] {
    background: #ede0c8;
    color: #776e65;
}

.tile-2048[data-v="8"] {
    background: #f2b179;
    color: #fff;
}

.tile-2048[data-v="16"] {
    background: #f59563;
    color: #fff;
}

.tile-2048[data-v="32"] {
    background: #f67c5f;
    color: #fff;
}

.tile-2048[data-v="64"] {
    background: #f65e3b;
    color: #fff;
}

.tile-2048[data-v="128"] {
    background: #edcf72;
    color: #fff;
    font-size: 1.2rem;
}

.tile-2048[data-v="256"] {
    background: #edcc61;
    color: #fff;
    font-size: 1.2rem;
}

.tile-2048[data-v="512"] {
    background: #edc850;
    color: #fff;
    font-size: 1.2rem;
}

.tile-2048[data-v="1024"] {
    background: #edc53f;
    color: #fff;
    font-size: 1rem;
}

.tile-2048[data-v="2048"] {
    background: #edc22e;
    color: #fff;
    font-size: 1rem;
}

.tile-2048[data-v="4096"] {
    background: #3c3a32;
    color: #fff;
    font-size: 1rem;
}

@media (max-width: 400px) {
    .t-2048 {
        width: 280px;
        height: 280px;
    }

    .tile-2048 {
        font-size: 1.1rem;
    }
}

/* Memory cards */
.mem-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 320px;
    max-width: 100%;
    margin: 0 auto;
}

.mem-card {
    aspect-ratio: 1;
    perspective: 600px;
    cursor: pointer;
}

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

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

.mem-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    font-size: 2rem;
    border: 2px solid var(--border);
}

.mem-front {
    background: var(--accent);
    color: #fff;
}

.mem-back {
    background: var(--bg-elev);
    transform: rotateY(180deg);
}

.mem-card.matched .mem-back {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.mem-card.matched {
    animation: pulse 0.4s ease;
}

@keyframes pulse {
    50% {
        transform: scale(1.08);
    }
}

/* Connect 4 */
.c4-wrap {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    display: inline-block;
    margin: 0 auto;
    max-width: 100%;
}

.c4-board {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 5px;
    width: 320px;
    max-width: 100%;
}

.c4-cell {
    aspect-ratio: 1;
    background: var(--bg-soft);
    border-radius: 999px;
    display: grid;
    place-items: center;
    cursor: pointer;
    position: relative;
    min-width: 0;
}

.c4-disc {
    width: 86%;
    height: 86%;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: inset 0 -4px 6px rgba(0, 0, 0, 0.2);
}

.c4-disc.p2 {
    background: var(--accent-2);
}

/* Only the just-dropped disc animates a drop from above the board. Existing
   discs are rendered WITHOUT animation so they don't re-fall on every move. */
.c4-disc.c4-drop-new {
    animation: c4-drop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.c4-disc.c4-no-anim {
    animation: none;
}

@keyframes c4-drop {
    0% {
        transform: translateY(-160px);
        opacity: 0;
    }
    60% {
        transform: translateY(8px);
        opacity: 1;
    }
    80% {
        transform: translateY(-4px);
    }
    100% {
        transform: translateY(0);
    }
}

/* Mastermind pegs */
.mm-peg {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 2px solid var(--border);
    background: var(--bg-soft);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.mm-feedback {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.mm-fb {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
}

.mm-fb.black {
    background: var(--text);
}

.mm-fb.white {
    background: #fff;
    border-color: var(--text);
}

.mm-palette {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.mm-color {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}

.mm-color:hover {
    transform: scale(1.15);
}

.mm-color.selected {
    border-color: var(--text);
}

/* Minesweeper */
.mw-board {
    display: inline-grid;
    gap: 1px;
    background: var(--border);
    padding: 1px;
    border-radius: var(--radius-sm);
}

.mw-cell {
    width: 28px;
    height: 28px;
    background: var(--bg-elev);
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
}

.mw-cell.revealed {
    background: var(--bg-soft);
    cursor: default;
}

.mw-cell.flagged {
    background: var(--warning);
    color: #fff;
}

.mw-cell.mine {
    background: var(--danger);
    color: #fff;
}

.mw-cell[data-n="1"] {
    color: var(--info);
}

.mw-cell[data-n="2"] {
    color: var(--success);
}

.mw-cell[data-n="3"] {
    color: var(--danger);
}

.mw-cell[data-n="4"] {
    color: var(--accent-2);
}

.mw-cell[data-n="5"] {
    color: #b91c1c;
}

.mw-cell[data-n="6"] {
    color: #06b6d4;
}

.mw-cell[data-n="7"] {
    color: #7c3aed;
}

.mw-cell[data-n="8"] {
    color: var(--text);
}

/* Snake */
.snake-wrap {
    position: relative;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    display: inline-block;
}

canvas.game-canvas {
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    display: block;
    max-width: 100%;
    height: auto;
    touch-action: none;
}

/* Battleship */
.bs-board {
    display: inline-grid;
    gap: 2px;
    background: var(--border);
    padding: 2px;
    border-radius: var(--radius-sm);
}

.bs-cell {
    width: 26px;
    height: 26px;
    background: var(--bg-elev);
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    cursor: pointer;
}

.bs-cell.hit {
    background: var(--danger);
    color: #fff;
}

.bs-cell.miss {
    background: var(--bg-soft);
    color: var(--text-muted);
}

.bs-cell.sunk {
    background: var(--text);
    color: #fff;
}

/* Sudoku */
.su-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background: var(--border-strong);
    padding: 1px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    width: 360px;
    max-width: 100%;
    aspect-ratio: 1;
}

.su-cell {
    background: var(--bg-elev);
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    border: 1px solid var(--border);
}

.su-cell.given {
    color: var(--text);
    font-weight: 700;
}

.su-cell.user {
    color: var(--accent);
}

.su-cell.selected {
    background: var(--accent-soft);
}

.su-cell.peer {
    background: rgba(99, 102, 241, 0.06);
}

.su-cell.wrong {
    color: var(--danger);
}

.su-cell[data-row="2"], .su-cell[data-row="5"] {
    border-bottom: 2px solid var(--border-strong);
}

.su-cell[data-col="2"], .su-cell[data-col="5"] {
    border-right: 2px solid var(--border-strong);
}

/* Trivia / Quiz options */
.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quiz-opt {
    padding: 12px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.quiz-opt:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.quiz-opt.correct {
    background: rgba(22, 163, 74, 0.12);
    border-color: var(--success);
    color: var(--success);
}

.quiz-opt.wrong {
    background: rgba(220, 38, 38, 0.12);
    border-color: var(--danger);
    color: var(--danger);
}

.quiz-opt.disabled {
    pointer-events: none;
    opacity: 0.7;
}

/* Progress bar */
.progress {
    height: 8px;
    background: var(--bg-soft);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* On-screen D-pad for mobile */
.dpad {
    display: grid;
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(3, 56px);
    gap: 6px;
    margin: 12px auto 0;
    justify-content: center;
}

.dpad button {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1.4rem;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.dpad button:active {
    background: var(--accent-soft);
}

.dpad .up {
    grid-area: 1 / 2;
}

.dpad .left {
    grid-area: 2 / 1;
}

.dpad .right {
    grid-area: 2 / 3;
}

.dpad .down {
    grid-area: 3 / 2;
}

/* Inline hint text */
.hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0 8px;
}
