/* Shared game-page layout. Individual game styles supply accent colors and small overrides. */

/* Layout and base typography */
* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    color: white;
    /* Fixed to the window, so a page that scrolls to an ad below the board shows no seam. */
    background: linear-gradient(135deg, #050713, #17102c) fixed;
    font-family: Arial, sans-serif;
}

/* Split leftover height 2:3 above and below the game, so it sits a little above center
   when there is room (about 20-35px on laptop screens). The spacers only use spare
   space: on short screens they vanish, the header stays on the page, and no empty
   scrolling is added below the board. */
body::before,
body::after {
    content: '';
    flex: 2 1 0;
}

body::after {
    flex-grow: 3;
}

.game-container {
    width: min(100%, 950px);
}

/* Header and typography */
.game-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}

.home-link {
    color: var(--accent-soft, #d8b4fe);
    text-decoration: none;
    font-weight: bold;
}

.home-link:hover {
    color: white;
}

.game-title {
    text-align: center;
}

.game-title small {
    display: block;
    color: #9ca3af;
    font-family: monospace;
    letter-spacing: 0.15em;
}

.game-title h1 {
    margin: 2px 0 0;
    color: var(--accent, #a855f7);
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.2rem, 4vw, 2rem);
}

/* Time, the current score, and the best score. Each keeps its label and value together; on a
   narrow board they wrap onto a second line instead of splitting. */
.scores {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px 18px;
    font-family: monospace;
    font-size: 1rem;
}

.scores > span {
    white-space: nowrap;
}

/* Account save problems (see gameRuntime.js), across the header's full width. */
.save-status {
    grid-column: 1 / -1;
    margin: 0;
    color: #fde68a;
    font-size: 0.85rem;
    text-align: center;
}

.save-status[hidden] {
    display: none;
}

/* Board and message overlay */
.game-screen {
    position: relative;
    overflow: hidden;
    border: 3px solid var(--accent, #8f4fc0);
    border-radius: 12px;
    box-shadow: 0 0 30px var(--glow, rgba(143, 79, 192, 0.45));
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    background: #090d1c;
    image-rendering: pixelated;
    touch-action: none;
}

.message {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    padding: 24px;
    text-align: center;
    background: rgba(5, 7, 19, 0.7);
    pointer-events: none;
}

.message[hidden] {
    display: none;
}

/* Start screens show only the title; the paragraph appears for game-over results. */
.message p:empty {
    display: none;
}

.message h2 {
    margin: 0 0 10px;
    color: var(--accent-soft, #d8b4fe);
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.8rem, 6vw, 3.5rem);
}

/* The score and time sit straight on the dimmed board, with no box behind them. */
.message p {
    margin: 0;
    line-height: 1.55;
}

/* Board variants: portrait and square boards take the height the header leaves, up to
   640px wide. */
.layout-portrait,
.layout-square {
    --board-ratio: 0.75;
    width: min(100%, 640px, max(240px, calc((100dvh - 160px) * var(--board-ratio))));
}

.layout-square {
    --board-ratio: 1;
}

/* Home takes only its own width, leaving the rest of the row to the scores. */
.layout-portrait .game-header,
.layout-square .game-header {
    grid-template-columns: auto 1fr;
}

.layout-portrait .game-title,
.layout-square .game-title {
    grid-column: 1 / -1;
    grid-row: 1;
}

.layout-portrait .home-link,
.layout-portrait .scores,
.layout-square .home-link,
.layout-square .scores {
    grid-row: 2;
}

.layout-portrait .game-title h1,
.layout-square .game-title h1 {
    font-size: clamp(1.1rem, 4vw, 1.6rem);
}

.layout-portrait .scores,
.layout-square .scores {
    gap: 4px 12px;
    font-size: 0.85rem;
}

/* Ability controls */
.powerup-button {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
    width: 50px;
    height: 50px;
    overflow: hidden;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--accent-soft);
    background: rgba(9, 13, 28, 0.9);
    border: 2px solid var(--accent);
    border-radius: 6px;
    font-family: monospace;
    cursor: pointer;
}

.powerup-button:disabled {
    cursor: not-allowed;
}

.powerup-button:not(:disabled) {
    color: #090d1c;
    box-shadow: 0 0 14px var(--glow);
}

.powerup-fill {
    position: absolute;
    inset: 0;
    background: var(--accent);
    transform: scaleY(0);
    transform-origin: bottom;
}

.powerup-key,
.powerup-label {
    position: relative;
    z-index: 1;
    font-weight: bold;
}

.powerup-key {
    font-size: 1.1rem;
}

.powerup-label {
    margin-top: -8px;
    font-size: 0.4rem;
    letter-spacing: 0.06em;
}

/* Hints and focus */
.press-hint {
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--accent-soft);
}

:focus-visible {
    outline: 3px solid var(--accent-soft);
    outline-offset: 3px;
}

/* Locked-game state */
/* A locked game opens to a big lock over the dimmed board, with the same words as its card on
   Home: what unlocks it. */
.game-locked-message {
    background: rgba(80, 80, 80, 0.65);
}

.game-locked-message::before {
    content: '';
    justify-self: center;
    width: clamp(96px, 30vmin, 220px);
    aspect-ratio: 1;
    margin-bottom: 14px;
    background: url('../../assets/images/game-lock.svg') center / contain no-repeat;
}

.game-locked-message h2 {
    color: #b0b0b0;
    font-size: 1.5rem;
}

.game-locked-message p {
    color: #f3e8ff;
    font-size: clamp(1rem, 2.6vw, 1.4rem);
    font-weight: bold;
}

/* A locked game has nothing to use, so its ability buttons stay out of sight. */
.game-screen:has(> .game-locked-message) .powerup-button {
    display: none;
}

/* Ads beside or below the board on the website (ads.js), at least 150px from it. */
.ad-slot {
    position: absolute;
    display: grid;
    justify-items: center;
    gap: 4px;
    /* Room under a banner below the board before the page ends. */
    padding-bottom: 16px;
}

.ad-slot[hidden],
.ad-slot:has(ins.adsbygoogle[data-ad-status='unfilled']) {
    display: none;
}

.ad-label {
    color: #6b7280;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Responsive layout and motion preferences */
@media (max-width: 620px) {
    body {
        padding: 10px;
    }

    .game-header {
        grid-template-columns: auto 1fr;
    }

    .game-title {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .home-link {
        grid-row: 2;
    }

    .scores {
        grid-row: 2;
        font-size: 0.8rem;
        gap: 4px 9px;
    }
}

/* Lucky revive banner, animated by ArcadeRuntime.tryRevive. */
/* Milestone pop-up: a see-through medal anywhere on the board, with the coins it earns. */
.milestone-popup {
    position: absolute;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    opacity: 0;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.milestone-medal {
    width: clamp(44px, 9vw, 72px);
    aspect-ratio: 1;
    opacity: 0.55;
}

.milestone-medal svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Read by screen readers only; the medal's color shows the tier. */
.milestone-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.milestone-coins {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #fde68a;
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1rem, 3vw, 1.4rem);
    font-weight: 700;
    /* A dark outline keeps the gold readable on light and dark boards. */
    text-shadow:
        -1px -1px 0 #1f1300,
        1px -1px 0 #1f1300,
        -1px 1px 0 #1f1300,
        1px 1px 0 #1f1300;
}

.milestone-coins img {
    width: 1.1em;
    height: 1.1em;
    image-rendering: pixelated;
}

.revive-banner {
    position: absolute;
    top: 12%;
    left: 50%;
    z-index: 3;
    transform: translateX(-50%);
    opacity: 0;
    color: #8b0000;
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.8rem, 6vw, 3.4rem);
    font-weight: 700;
    letter-spacing: 0.08em;
    white-space: nowrap;
    /* A pale outline keeps the dark red readable on the dark game boards. */
    text-shadow:
        -2px -2px 0 #fecaca,
        2px -2px 0 #fecaca,
        -2px 2px 0 #fecaca,
        2px 2px 0 #fecaca,
        0 0 18px rgba(254, 202, 202, 0.7);
    pointer-events: none;
}
