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

:root {
    --minerafa-icon-pickaxe: none;
    --minerafa-icon-lantern: none;
    --minerafa-icon-scanner: none;
}

body {
    overflow: hidden;
    background: #1a1a2e;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

canvas {
    display: block;
}

/* Lobby */
#lobby-screen {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.24), transparent 45%),
        radial-gradient(circle at 80% 80%, rgba(16, 185, 129, 0.22), transparent 40%),
        rgba(3, 7, 18, 0.92);
}

#lobby-screen.hidden {
    display: none;
}

.lobby-card {
    width: min(440px, calc(100% - 24px));
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.36);
    background: rgba(15, 23, 42, 0.9);
    padding: 18px;
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.45);
}

.lobby-card h1 {
    font-family: 'Courier New', monospace;
    color: #e2e8f0;
    font-size: 20px;
    margin-bottom: 8px;
}

.lobby-subtitle {
    color: #94a3b8;
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.35;
}

.lobby-avatar-wrap {
    margin: 2px 0 12px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#lobby-rover-avatar {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    border-radius: 7px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(2, 6, 23, 0.8);
}

#lobby-rover-avatar[hidden] {
    display: none;
}

.lobby-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    color: #cbd5e1;
    font-size: 12px;
    font-family: 'Courier New', monospace;
}

#lobby-name {
    width: 100%;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(2, 6, 23, 0.9);
    color: #e2e8f0;
    padding: 8px 10px;
    font-family: 'Courier New', monospace;
}

#lobby-join {
    width: 100%;
    border-radius: 8px;
    border: 1px solid rgba(74, 222, 128, 0.55);
    background: rgba(20, 83, 45, 0.88);
    color: #dcfce7;
    padding: 10px 12px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

#lobby-join:disabled {
    opacity: 0.55;
    cursor: progress;
}

#lobby-status {
    margin-top: 10px;
    min-height: 1.25em;
    color: #93c5fd;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

#lobby-status.error {
    color: #fca5a5;
}

#lobby-status.ok {
    color: #86efac;
}

/* Blocker / Start Screen */
#blocker {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    cursor: pointer;
}

#instructions {
    text-align: center;
    color: #fff;
    padding: 40px 60px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#instructions h1 {
    font-size: 4rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #4ade80 0%, #22d3ee 50%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    letter-spacing: 4px;
}

#instructions .subtitle {
    font-size: 1.2rem;
    color: #94a3b8;
    margin-bottom: 30px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin: 30px 0;
}

.control-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.control-item .key {
    font-weight: bold;
    color: #4ade80;
    font-size: 0.9rem;
    padding: 4px 10px;
    background: rgba(74, 222, 128, 0.1);
    border-radius: 5px;
    font-family: 'Courier New', monospace;
}

.control-item .action {
    color: #e2e8f0;
    font-size: 0.9rem;
}

.click-to-play {
    margin-top: 30px;
    font-size: 1.1rem;
    color: #4ade80;
    animation: pulse 2s infinite;
}

.discovery-note {
    margin-top: 10px;
    color: #a5b4fc;
    font-size: 0.9rem;
    font-family: 'Courier New', monospace;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Crosshair */
#crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.92);
    font-size: 30px;
    font-weight: 100;
    z-index: 50;
    pointer-events: none;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.55);
    opacity: 0;
    transition: opacity 0.2s ease, color 0.15s ease, transform 0.12s ease;
}

#crosshair.visible {
    opacity: 1;
}

#crosshair.targeting {
    transform: translate(-50%, -50%) scale(1.08);
}

#crosshair.mineable {
    color: #d1fae5;
    text-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

#crosshair.blocked {
    color: #fecaca;
    text-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

/* Hotbar */
#hotbar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 5px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s;
}

#hotbar.visible {
    opacity: 1;
}

.hotbar-slot {
    width: 50px;
    height: 50px;
    background: rgba(139, 139, 139, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.15s ease;
}

.hotbar-slot.selected {
    border-color: #4ade80;
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.5);
    transform: scale(1.1);
}

.block-preview {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    image-rendering: pixelated;
}

/* Block colors */
.block-preview.grass {
    background: linear-gradient(to bottom, #4ade80 0%, #4ade80 30%, #8b5a2b 30%, #8b5a2b 100%);
}

.block-preview.dirt {
    background: #8b5a2b;
}

.block-preview.stone {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 50%, #6b7280 100%);
}

.block-preview.wood {
    background: linear-gradient(0deg, #5d3a1a 0%, #7d5a3a 50%, #5d3a1a 100%);
}

.block-preview.leaves {
    background: #22c55e;
    opacity: 0.9;
}

.block-preview.sand {
    background: #fcd34d;
}

.block-preview.cobblestone {
    background: linear-gradient(45deg, #4b5563 25%, #6b7280 25%, #6b7280 50%, #4b5563 50%, #4b5563 75%, #6b7280 75%);
    background-size: 10px 10px;
}

.block-preview.furnace {
    background: linear-gradient(135deg, #1f2937 0%, #334155 50%, #0f172a 100%);
}

.block-preview.lantern {
    background: radial-gradient(circle at 35% 35%, #fef08a 0%, #f59e0b 45%, #78350f 100%);
}

/* Debug Info */
#fps-overlay {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 70;
    color: #f8fafc;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.2;
    letter-spacing: 0.02em;
    background: rgba(2, 6, 23, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.38);
    border-radius: 6px;
    padding: 6px 8px;
    pointer-events: none;
    user-select: none;
}

#debug-info {
    position: fixed;
    top: 10px;
    left: 10px;
    color: white;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 5px;
}

#debug-info.visible {
    opacity: 1;
}

#biome {
    color: #93c5fd;
}

#health {
    color: #fca5a5;
}

#stamina {
    color: #86efac;
}

#time-of-day {
    color: #fdba74;
}

#inventory {
    color: #fcd34d;
}

#sim-stats {
    color: #7dd3fc;
}

#gravity-ops {
    color: #bfdbfe;
}

#fluid-ops {
    color: #93c5fd;
}

#fluid-queue {
    color: #67e8f9;
}

#journal {
    color: #a7f3d0;
}

#weather {
    color: #bfdbfe;
}

#risk {
    color: #fca5a5;
}

#heal-status {
    color: #86efac;
}

#smelt-status {
    color: #93c5fd;
}

#benchmark-status {
    color: #fcd34d;
}

#benchmark-result {
    color: #fca5a5;
    font-weight: 600;
}

#tool {
    color: #c4b5fd;
}

#mining-status {
    color: #f9a8d4;
}

#interaction {
    color: #d1d5db;
}

#interaction.ready {
    color: #86efac;
}

#interaction.done {
    color: #67e8f9;
}

#scan {
    color: #a5f3fc;
}

#objective {
    color: #67e8f9;
    font-weight: 600;
}

#tool,
#lantern-status,
#scan {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#tool::before,
#lantern-status::before,
#scan::before {
    content: '';
    width: 13px;
    height: 13px;
    image-rendering: pixelated;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    flex: 0 0 13px;
    opacity: 0.95;
}

#tool::before {
    background-image: var(--minerafa-icon-pickaxe);
}

#lantern-status::before {
    background-image: var(--minerafa-icon-lantern);
}

#scan::before {
    background-image: var(--minerafa-icon-scanner);
}

#toast-container {
    position: fixed;
    right: 20px;
    top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 90;
    pointer-events: none;
}

.toast {
    min-width: 220px;
    max-width: 360px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(10, 15, 25, 0.84);
    color: #e5e7eb;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    letter-spacing: 0.2px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    animation: toastIn 0.24s ease-out;
}

.toast.info {
    border-color: rgba(125, 211, 252, 0.45);
}

.toast.success {
    border-color: rgba(134, 239, 172, 0.5);
}

.toast.warn {
    border-color: rgba(252, 165, 165, 0.5);
}

.toast.exit {
    animation: toastOut 0.4s ease-in forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(18px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(16px);
    }
}

/* Error display */
#error-display {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 30px;
    background: rgba(127, 29, 29, 0.9);
    color: #fecaca;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    border-radius: 10px;
    border: 1px solid rgba(239, 68, 68, 0.5);
    z-index: 200;
    max-width: 500px;
    text-align: center;
    pointer-events: none;
}

#settings-toggle {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 95;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(15, 23, 42, 0.78);
    color: #e2e8f0;
    padding: 8px 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
}

#benchmark-export {
    position: fixed;
    right: 20px;
    bottom: 56px;
    z-index: 95;
    border: 1px solid rgba(245, 158, 11, 0.55);
    background: rgba(41, 25, 4, 0.86);
    color: #fef3c7;
    padding: 8px 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
}

#benchmark-export:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#benchmark-export.hidden {
    display: none;
}

#settings-panel {
    position: fixed;
    right: 20px;
    top: 70px;
    width: 300px;
    z-index: 96;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.9);
    color: #e2e8f0;
    border-radius: 10px;
    padding: 12px;
    display: none;
}

#settings-panel.visible {
    display: block;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.settings-header h2 {
    font-size: 14px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
}

#setting-close {
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(30, 41, 59, 0.8);
    color: #e2e8f0;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
}

.setting-row {
    display: grid;
    grid-template-columns: 90px 1fr 52px;
    align-items: center;
    gap: 8px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    margin-bottom: 8px;
}

.setting-row input[type='range'] {
    width: 100%;
}

.checkbox-row {
    grid-template-columns: 90px 1fr;
}

.checkbox-row input[type='checkbox'] {
    justify-self: start;
}

/* HUD text overflow protection */
#debug-info span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    display: block;
}

#debug-info span.hud-optional {
    display: none;
}

/* Responsive breakpoints */
@media (max-width: 768px) {
    #instructions {
        padding: 20px 24px;
    }

    #instructions h1 {
        font-size: 2.4rem;
        letter-spacing: 2px;
    }

    #instructions .subtitle {
        font-size: 0.95rem;
        margin-bottom: 18px;
    }

    .controls-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        margin: 16px 0;
    }

    .control-item {
        padding: 8px 14px;
    }

    .control-item .key,
    .control-item .action {
        font-size: 0.8rem;
    }

    .click-to-play {
        font-size: 0.95rem;
        margin-top: 18px;
    }

    .hotbar-slot {
        width: 48px;
        height: 48px;
    }

    .block-preview {
        width: 32px;
        height: 32px;
    }

    #debug-info {
        font-size: 10px;
        padding: 6px;
        gap: 3px;
    }

    #debug-info span {
        max-width: 220px;
    }

    .toast {
        min-width: 160px;
        max-width: 260px;
        font-size: 11px;
        padding: 8px 10px;
    }

    #toast-container {
        right: 10px;
        top: 10px;
    }

    #settings-toggle {
        right: 10px;
        bottom: 10px;
    }

    #benchmark-export {
        right: 10px;
        bottom: 46px;
    }

    #settings-panel {
        right: 10px;
        top: 54px;
        width: min(300px, calc(100% - 20px));
    }
}

@media (max-width: 480px) {
    #instructions h1 {
        font-size: 1.6rem;
    }

    .hotbar-slot {
        width: 44px;
        height: 44px;
    }

    .block-preview {
        width: 28px;
        height: 28px;
    }

    #debug-info {
        font-size: 9px;
    }

    #debug-info span {
        max-width: 180px;
    }
}

@media (min-width: 1600px) {
    .hotbar-slot {
        width: 58px;
        height: 58px;
    }

    .block-preview {
        width: 42px;
        height: 42px;
    }

    #debug-info {
        font-size: 13px;
    }
}

/* Loading progress bar */
#loading-progress {
    width: 80%;
    max-width: 320px;
    margin: 12px auto;
}

#loading-bar-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

#loading-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #4ade80, #67e8f9);
    border-radius: 2px;
    transition: width 0.3s ease-out;
}

#loading-tip {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 6px;
    text-align: center;
    font-style: italic;
}
