/* ========================================
   The Universe of Room 209 — Styles
   ======================================== */

:root {
    --bg: #05050f;
    --surface: #0d1117;
    --surface-hover: #151b27;
    --accent: #7c4dff;
    --accent-glow: rgba(124, 77, 255, 0.35);
    --accent-secondary: #00e5ff;
    --text: #e0e6f0;
    --text-muted: #7a8599;
    --border: #1c2333;
    --radius: 12px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --star-color: rgba(255, 255, 255, 0.6);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    background-image: url('bg-deepfield.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

/* --- Deep space background overlay --- */
body::before,
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

body::before {
    background: rgba(5, 5, 15, 0.4);
}

/* Nebula glow */
body::after {
    background:
        radial-gradient(ellipse at 20% 50%, rgba(124, 77, 255, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 30%, rgba(0, 229, 255, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(124, 77, 255, 0.04) 0%, transparent 40%);
}

header, main, footer, .modal-overlay {
    position: relative;
    z-index: 1;
}

/* --- Header --- */
header {
    text-align: center;
    padding: 2.5rem 1rem 1.5rem;
}

header h1 {
    font-size: 2.5rem;
    letter-spacing: 0.02em;
    margin-bottom: 0.4rem;
    background: linear-gradient(135deg, #7c4dff, #00e5ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.05rem;
    max-width: 600px;
    margin: 0 auto;
}

/* --- Game Grid --- */
main {
    flex: 1;
    padding: 1rem 2rem 3rem;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}

/* --- Game Card --- */
.game-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.6rem;
    backdrop-filter: blur(4px);
    background: rgba(13, 17, 23, 0.85);
}

.game-card:hover,
.game-card:focus-visible {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 24px var(--accent-glow);
    outline: none;
}

.game-card .emoji {
    font-size: 2.8rem;
    line-height: 1;
}

.game-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.game-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.game-card .badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.2em 0.6em;
    border-radius: 4px;
    margin-top: 0.3rem;
}

.badge-playable {
    background: rgba(0, 229, 255, 0.12);
    color: var(--accent-secondary);
    border: 1px solid rgba(0, 229, 255, 0.3);
}

.badge-source {
    background: rgba(124, 77, 255, 0.12);
    color: var(--accent);
    border: 1px solid rgba(124, 77, 255, 0.25);
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow: auto;
    position: relative;
    padding: 2rem;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--accent);
}

.modal-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    padding-right: 2rem;
}

.modal-body canvas {
    display: block;
    margin: 0 auto;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: #080810;
}

.modal-body .game-controls {
    margin-top: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.modal-body .game-controls kbd {
    display: inline-block;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.15em 0.5em;
    font-family: inherit;
    font-size: 0.85em;
    color: var(--text);
}

.modal-body .source-link {
    display: inline-block;
    margin-top: 1rem;
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}

.modal-body .source-link:hover {
    text-decoration: underline;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--accent-secondary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    header h1 { font-size: 1.8rem; }
    main { padding: 1rem; }
    .game-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.8rem; }
    .game-card { padding: 1rem; }
    .game-card .emoji { font-size: 2rem; }
    .modal { padding: 1.25rem; max-height: 95vh; }
    .modal-body canvas {
        max-width: 100%;
        height: auto;
    }
}

/* --- Touch-friendly --- */
@media (pointer: coarse) {
    .game-card { padding: 1.2rem; min-height: 120px; }
    .modal-close { font-size: 2.2rem; padding: 8px; }
    .dpad button:active { background: #1c2333; transform: scale(0.95); }
}

/* --- Prevent pull-to-refresh and overscroll in game modal --- */
.modal-overlay.active {
    overscroll-behavior: contain;
    touch-action: none;
}

.modal-body {
    touch-action: pan-y;
}

.modal-body canvas {
    touch-action: none;
}
