/* Free play (Sandbox Lab, Control Training). The rest of the site uses base.css;
   the font and the colours below are kept in step with it by hand. */

@font-face {
    font-family: "Rajdhani";
    src: url("../assets/fonts/rajdhani-500.woff2") format("woff2");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Rajdhani";
    src: url("../assets/fonts/rajdhani-600.woff2") format("woff2");
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Rajdhani";
    src: url("../assets/fonts/rajdhani-700.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ===== Design Tokens ===== */
:root {
    color-scheme: dark;

    --bg: #060912;
    --bg-2: #0a101d;
    --ink: #f1f5f9;
    --ink-dim: #b4c0d6;
    --accent: #22d3ee;
    --accent-2: #f97316;
    --panel: rgba(10, 16, 30, 0.92);
    --stroke: rgba(148, 163, 184, 0.3);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: "Rajdhani", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 17px;
    font-weight: 500;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ===== Canvas ===== */
.canvas-wrap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    background: radial-gradient(circle at 20% 20%, rgba(30, 41, 59, 0.6), rgba(15, 23, 42, 0.9));
}

/* ===== Top Bar ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: linear-gradient(to bottom, rgba(15, 23, 42, 0.9), transparent);
    pointer-events: none;
    z-index: 100;
}

.top-bar > * {
    pointer-events: auto;
}

/* ===== Menu Button ===== */
.menu-btn {
    background: var(--panel);
    border: 1px solid var(--stroke);
    color: var(--ink);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.menu-btn:hover {
    background: rgba(34, 211, 238, 0.2);
    border-color: var(--accent);
}

.menu-icon {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.menu-icon span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--ink);
    border-radius: 1px;
}

/* ===== HUD ===== */
.hud {
    display: flex;
    gap: 1.2rem;
    font-size: 0.85rem;
    color: var(--ink-dim);
    background: var(--panel);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--stroke);
}

.hud-item {
    white-space: nowrap;
}

/* ===== Home Link ===== */
.home-link {
    color: var(--ink-dim);
    text-decoration: none;
    font-size: 0.85rem;
    background: var(--panel);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--stroke);
}

.home-link:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* ===== Menu Overlay ===== */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 60px;
    overflow-y: auto;
}

.menu-overlay.open {
    display: flex;
}

.menu-panel {
    background: var(--panel);
    border: 1px solid var(--stroke);
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    margin-bottom: 40px;
}

.menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--stroke);
}

.menu-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--ink-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: var(--ink);
}

/* ===== Menu Sections ===== */
.menu-section {
    border-bottom: 1px solid var(--stroke);
}

.menu-section:last-child {
    border-bottom: none;
}

.menu-section .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.2rem;
    cursor: pointer;
    user-select: none;
}

.menu-section .section-header:hover {
    background: rgba(34, 211, 238, 0.1);
}

.menu-section .section-header h3 {
    margin: 0;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink);
}

.section-arrow {
    color: var(--ink-dim);
    transition: transform 0.2s;
}

.menu-section.expanded .section-arrow {
    transform: rotate(180deg);
}

.section-content {
    display: none;
    padding: 0 1.2rem 1rem;
}

.menu-section.expanded .section-content {
    display: block;
}

/* ===== Controls ===== */
.control {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.8rem;
}

.control:last-child {
    margin-bottom: 0;
}

.control label {
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.7rem;
    color: var(--ink-dim);
}

.control input,
.control select {
    background: rgba(11, 12, 16, 0.8);
    border: 1px solid var(--stroke);
    color: var(--ink);
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    width: 100%;
}

.control-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
}

.control-row:last-child {
    margin-bottom: 0;
}

/* Side by side, the two fields must line up: the row carries the spacing. */
.control-row .control {
    margin-bottom: 0;
    align-content: start;
}

/* ===== Buttons ===== */
.menu-actions {
    display: grid;
    gap: 0.6rem;
    padding: 1rem 1.2rem;
    background: rgba(11, 12, 16, 0.5);
}

.btn {
    background: linear-gradient(120deg, var(--accent), #38bdf8);
    color: #0b0c10;
    border: none;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

.btn:hover {
    filter: brightness(1.1);
}

.btn.secondary {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--stroke);
    color: var(--ink);
}

.btn.secondary:hover {
    border-color: var(--accent);
}

.btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

/* ===== Help Box ===== */
.help {
    position: fixed;
    bottom: 16px;
    right: 16px;
    background: var(--panel);
    border: 1px solid var(--stroke);
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-size: 0.8rem;
    color: var(--ink-dim);
    max-width: 360px;
    z-index: 50;
}

/* ===== Status Box ===== */
.status {
    position: fixed;
    top: 60px;
    right: 16px;
    background: var(--panel);
    border: 1px solid var(--stroke);
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-size: 0.85rem;
    color: var(--ink-dim);
    min-width: 180px;
    text-align: right;
    white-space: pre-line;
    z-index: 50;
}

/* ===== Minimap ===== */
.minimap {
    position: fixed;
    left: 16px;
    bottom: 16px;
    width: 220px;
    height: 140px;
    background: rgba(11, 12, 16, 0.88);
    border: 1px solid var(--stroke);
    border-radius: 10px;
    overflow: hidden;
    z-index: 60;
    cursor: crosshair;
}

.minimap canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===== End Overlay ===== */
.end-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 400;
}

.end-overlay.open {
    display: flex;
}

.end-card {
    width: min(460px, 92vw);
    background: var(--panel);
    border: 1px solid var(--stroke);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.end-card h3 {
    margin: 0 0 0.5rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.end-stats {
    margin: 0.6rem 0 1rem;
    color: var(--ink-dim);
    line-height: 1.45;
    white-space: pre-line;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    background: var(--panel);
    border: 1px solid var(--stroke);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 320px;
    width: 90%;
}

.modal-content h3 {
    margin: 0 0 1rem;
    color: var(--accent);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .hud {
        display: none;
    }

    .help {
        max-width: 280px;
        font-size: 0.75rem;
    }

    .status {
        top: 50px;
        font-size: 0.8rem;
    }
}
