:root {
    --bg: #111318;
    --panel: #161a22;
    --muted: #8b93a7;
    --text: #e9eefc;
    --accent: #6ea8ff;
    --accent-2: #78f5cf;
    --danger: #ff6b6b;
    --ring: 0 0 0 3px rgba(110, 168, 255, .25);
    --radius: 16px;
    --border: #20273a;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    background:
        radial-gradient(1200px 800px at 20% -10%, #1c2333 0%, rgba(28, 35, 51, 0) 60%),
        radial-gradient(1000px 700px at 120% 20%, #0e3b2f40 0%, rgba(14, 59, 47, 0) 55%),
        var(--bg);
    color: var(--text);
    font: 500 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial, sans-serif;
    overflow-x: hidden;
}

/* ===== Header ===== */
.site-header {
    position: sticky;
    top: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: linear-gradient(180deg, #141923f5, #0f141bf5);
    border-bottom: 1px solid var(--border);
    backdrop-filter: saturate(130%) blur(10px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, .35);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    font-weight: 800;
    letter-spacing: .02em;
}

.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-2);
    box-shadow: 0 0 18px rgba(120, 245, 207, .75), 0 0 2px rgba(120, 245, 207, 1);
}

.brand:hover { filter: brightness(1.06); }

.site-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid #2b3142;
    background: #0d1117;
    transition: .15s filter, .15s transform, .15s background, .15s border-color;
    font-weight: 600;
    letter-spacing: .02em;
}

.nav-link:hover { filter: brightness(1.05); }

.nav-primary {
    border-color: #345fb3;
    background: linear-gradient(180deg, #2a69d0, #214ea6);
}

/* ===== Accessibility ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ===== Page layout ===== */
.page {
    padding: 40px 16px 48px;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

/* ===== Game card: canvas + controls fused together ===== */
.game-card {
    margin-bottom: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 20px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .04);
    overflow: hidden;
    /* Canvas connects directly to controls bar with no gap */
}

#game-mount {
    position: relative;
    width: 100%;
    display: block;
    background: #0a0c12;
    /* Height is driven by the canvas inside; no forced height needed */
    line-height: 0;
}

#fullscreen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(10, 13, 20, .6);
    color: rgba(255, 255, 255, .6);
    cursor: pointer;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity .15s, background .15s;
}

#game-mount:hover #fullscreen-btn { opacity: 1; }
#fullscreen-btn:hover {
    background: rgba(30, 40, 60, .85);
    color: #fff;
}

/* Fullscreen: center canvas in the full-screen viewport */
#game-mount:fullscreen,
#game-mount:-webkit-full-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0c12;
}

#game-mount:fullscreen canvas,
#game-mount:-webkit-full-screen canvas {
    width: auto !important;
    height: 100vh !important;
    max-width: 100vw;
}

/* p5 canvas fills the mount */
#defaultCanvas0 {
    display: block;
    width: 100% !important;
    height: auto !important;
}

/* ===== Controls bar ===== */
.game-controls {
    display: grid;
    grid-template-columns: 340px 1fr;
    border-top: 1px solid var(--border);
    background: rgba(10, 13, 20, 0.92);
    backdrop-filter: saturate(130%) blur(8px);
}

/* Lobby section */
#lobby-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    border-right: 1px solid var(--border);
}

.ctrl-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
}

.ctrl-section {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.ctrl-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px;
}

.ctrl-divider {
    border-top: 1px solid var(--border);
}

/* Event log section */
.event-log-wrap {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}

.event-log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 7px;
}

.event-log-header button {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 8px;
}

#event-log {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    flex: 1;
    max-height: 120px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
    scrollbar-width: thin;
    scrollbar-color: #2b3450 transparent;
}

.log-entry {
    display: grid;
    grid-template-columns: 54px auto 1fr;
    gap: 8px;
    align-items: baseline;
    padding: 3px 0;
    border-bottom: 1px solid #141a28;
    animation: log-in .15s ease;
}

.log-entry:last-child { border-bottom: none; }

@keyframes log-in {
    from { opacity: 0; transform: translateY(-3px); }
    to   { opacity: 1; transform: none; }
}

.log-time { color: #3d4a63; white-space: nowrap; }

.log-tag {
    font-size: 10px;
    letter-spacing: .04em;
    padding: 1px 5px;
    border-radius: 4px;
    text-transform: uppercase;
    white-space: nowrap;
}

.log-tag.conn  { background: #0d2b1a; color: #5df098; border: 1px solid #1a4f2e; }
.log-tag.lobby { background: #0c1e38; color: #6ea8ff; border: 1px solid #1a3a6e; }
.log-tag.game  { background: #1a1c2e; color: #a8b4d0; border: 1px solid #282e48; }
.log-tag.error { background: #2e0f0f; color: #ff6b6b; border: 1px solid #5e1f1f; }

.log-msg { color: #cfd7ea; }

.key-hints {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #1a2035;
}

.key-hint {
    font-size: 11px;
    color: #6b7a9a;
    display: flex;
    align-items: center;
    gap: 4px;
}

kbd {
    font-family: ui-monospace, monospace;
    font-size: 10px;
    color: #a0aec0;
    background: #141b2d;
    border: 1px solid #2a3452;
    border-radius: 4px;
    padding: 1px 5px;
    line-height: 1.6;
}

/* ===== Lobby info (active lobby badge) ===== */
#lobby-info {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #0d1117;
    border: 1px solid #2b3142;
}

#lobby-code-badge {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    letter-spacing: .18em;
    padding: 6px 9px;
    border-radius: 8px;
    background: #121826;
    border: 1px dashed #2b3550;
    color: #cfe0ff;
}

/* ===== Inputs ===== */
input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #29324a;
    background: #0d1117;
    color: var(--text);
    outline: none;
    font-size: 14px;
    transition: .15s border-color, .15s box-shadow, .15s background;
}

input::placeholder { color: #657091; }

input:focus {
    border-color: #36507e;
    box-shadow: var(--ring);
    background: #0b0f14;
}

input[disabled] { opacity: .6; cursor: not-allowed; }

/* ===== Buttons ===== */
button {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #2a3752;
    background: linear-gradient(180deg, #1c2740, #162035);
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: .02em;
    cursor: pointer;
    transition: .15s transform, .15s filter, .15s background, .15s border-color;
    white-space: nowrap;
}

button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button[disabled] { opacity: .5; cursor: not-allowed; }

.btn-accent {
    border-color: #345fb3;
    background: linear-gradient(180deg, #2a69d0, #214ea6);
}

.btn-ghost {
    background: #0d1117;
    border-color: #2b3142;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
}

/* ===== Hints ===== */
.hint {
    font-size: 12px;
    color: #7c86a3;
}

/* ===== Toast ===== */
#toast {
    position: fixed;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%) translateY(20px);
    background: #0b0f14;
    color: #e6f0ff;
    border: 1px solid #25314a;
    padding: 10px 16px;
    border-radius: 12px;
    opacity: 0;
    pointer-events: none;
    transition: .25s opacity, .25s transform;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
    z-index: 999;
    font-size: 14px;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== Below-fold info ===== */
.page-info {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.tips, .notes {
    background: rgba(11, 14, 22, 0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.tips h2, .notes h2 {
    margin: 0 0 10px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .02em;
    color: #cfe0ff;
}

.tips ul {
    margin: 0;
    padding-left: 20px;
    color: #cfd7ea;
}

.tips li {
    margin: 5px 0;
    font-size: 14px;
    line-height: 1.5;
}

.notes p {
    margin: 0 0 8px;
    font-size: 14px;
    color: #cfd7ea;
    line-height: 1.5;
}

.notes p:last-child { margin-bottom: 0; }

.ad-block {
    padding: 6px 0;
    border-top: 1px solid #232a3b;
}

/* ===== Footer ===== */
.site-footer {
    border-top: 1px solid var(--border);
    background: #0f141b;
    padding: 16px 0;
}

.footer-grid {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.footer-nav a {
    color: #9fb6ff;
    text-decoration: none;
    margin-left: 12px;
    font-size: 14px;
}

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

/* ===== Mobile ===== */
@media (max-width: 900px) {
    .site-header {
        padding: 0 16px;
    }

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

    #lobby-controls {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .info-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .site-nav .nav-link:not(.nav-primary) {
        display: none;
    }
}
