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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #0a0a0f;
    color: #ffffff;
    overflow: hidden;
    user-select: none;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* HUD Overlay */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* Crosshair */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
}

#crosshair::before {
    width: 2px;
    height: 20px;
    left: 9px;
    top: 0;
}

#crosshair::after {
    width: 20px;
    height: 2px;
    left: 0;
    top: 9px;
}

/* Debug Info */
#debug-info {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    overflow: hidden;
}

.debug-header {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    user-select: none;
}

.debug-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.debug-header span:first-child {
    color: #888;
    font-weight: bold;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.toggle-icon {
    color: #666;
    font-size: 16px;
}

.debug-content {
    padding: 12px 16px;
}

#debug-info.collapsed .debug-content {
    display: none;
}

#debug-info.collapsed .toggle-icon {
    transform: rotate(0deg);
}

#debug-info.collapsed .toggle-icon::before {
    content: '+';
}

#debug-info:not(.collapsed) .toggle-icon::before {
    content: '-';
}

.toggle-icon::before {
    content: '-';
}

.debug-content div {
    margin-bottom: 6px;
    color: #e0e0e0;
}

.debug-content div:last-child {
    margin-bottom: 0;
}

.debug-content span {
    color: #00ff88;
    font-weight: bold;
}

/* Loading Screen */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-content h1 {
    font-size: 72px;
    font-weight: 900;
    background: linear-gradient(135deg, #00ff88 0%, #00ccff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 40px;
    letter-spacing: -2px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 30px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #00ff88;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading Progress Bar */
.loading-bar-container {
    width: 300px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin: 20px auto;
    overflow: hidden;
}

#loading-bar-fill {
    width: 0%;
    height: 100%;
    background: #00ff88;
    transition: width 0.2s ease-out;
    box-shadow: 0 0 10px #00ff88;
}

.loading-content p {
    font-size: 18px;
    color: #a0a0a0;
    margin-bottom: 12px;
}

.loading-subtext {
    font-size: 14px;
    color: #606060;
    font-style: italic;
}

/* Pointer Lock Message */
#pointer-lock-message {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    cursor: pointer;
    /* Allow clicks to pass through to the canvas underneath */
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#pointer-lock-message.hidden {
    opacity: 0;
    pointer-events: none;
}

.message-content {
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 60px 80px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.message-content h2 {
    font-size: 48px;
    margin-bottom: 20px;
    color: #00ff88;
    font-weight: 800;
}

.message-content p {
    font-size: 18px;
    color: #c0c0c0;
}

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

#debug-info {
    animation: fadeIn 0.5s ease;
}

/* Performance Stats Panel */
/* Sun Direction Panel */
#sun-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    border: 1px solid rgba(255, 200, 0, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    min-width: 200px;
    animation: fadeIn 0.3s ease;
}

.sun-header {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 200, 0, 0.2);
    color: #ffc800;
    font-weight: bold;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sun-content {
    padding: 12px 16px;
}

.sun-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 10px;
}

.sun-btn {
    padding: 8px 4px;
    font-size: 10px;
    cursor: pointer;
    background: rgba(255, 200, 0, 0.2);
    color: #ffc800;
    border: 1px solid rgba(255, 200, 0, 0.3);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.sun-btn:hover {
    background: rgba(255, 200, 0, 0.4);
    border-color: rgba(255, 200, 0, 0.6);
}

.sun-btn:active {
    background: rgba(255, 200, 0, 0.6);
}

#perf-info {
    position: absolute;
    top: 20px;
    left: 240px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    min-width: 180px;
    animation: fadeIn 0.3s ease;
}

.perf-header {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: #888;
    font-weight: bold;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.perf-content {
    padding: 8px 16px 12px;
}

.perf-section {
    margin-bottom: 10px;
}

.perf-section:last-child {
    margin-bottom: 0;
}

.perf-section-title {
    color: #666;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    padding-bottom: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.perf-content div {
    color: #e0e0e0;
    margin-bottom: 3px;
}

.perf-content span {
    color: #00ff88;
    font-weight: bold;
}

/* Mode & Stamina HUD */
#mode-stamina-hud {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

#mode-indicator {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    padding: 6px 16px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

#mode-indicator.adventure {
    border-color: rgba(0, 255, 136, 0.5);
}

#mode-indicator.fight {
    border-color: rgba(255, 68, 68, 0.7);
    background: rgba(80, 0, 0, 0.7);
}

#mode-indicator.fight-action {
    border-color: rgba(255, 170, 0, 0.9);
    background: rgba(100, 50, 0, 0.8);
    box-shadow: 0 0 15px rgba(255, 170, 0, 0.4);
}

#mode-indicator.build {
    border-color: rgba(0, 170, 255, 0.7);
    background: rgba(0, 40, 80, 0.7);
}

#mode-label {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #ffffff;
}

#mode-indicator.adventure #mode-label {
    color: #00ff88;
}

#mode-indicator.fight #mode-label {
    color: #ff4444;
}

#mode-indicator.fight-action #mode-label {
    color: #ffaa00;
}

#mode-indicator.build #mode-label {
    color: #00aaff;
}

#stamina-bar-container {
    width: 200px;
    height: 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#stamina-bar-container.visible {
    opacity: 1;
}

#stamina-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #ffaa00 0%, #ffcc00 100%);
    border-radius: 3px;
    transition: width 0.1s ease-out;
    box-shadow: 0 0 8px rgba(255, 170, 0, 0.5);
}

#stamina-bar-fill.low {
    background: linear-gradient(90deg, #ff4444 0%, #ff6644 100%);
    box-shadow: 0 0 8px rgba(255, 68, 68, 0.5);
}

#stamina-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 8px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Hotbar */
#hotbar {
    position: absolute !important;
    top: 50% !important;
    left: 20px !important;
    transform: translateY(-50%) !important;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.hotbar-slot {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.15s ease;
}

.hotbar-slot.selected {
    border-color: #00ff88;
    background: rgba(0, 255, 136, 0.15);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.hotbar-slot .slot-name {
    font-size: 10px;
    color: #e0e0e0;
    text-align: center;
}

.hotbar-slot .slot-key {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 9px;
    color: #808080;
    font-weight: bold;
}

/* Character Menu */
#character-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    pointer-events: auto;
}

#character-menu.hidden {
    display: none;
}

#character-menu .menu-content {
    background: rgba(30, 30, 40, 0.95);
    padding: 30px 40px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    min-width: 400px;
}

#character-menu h2 {
    font-size: 24px;
    color: #00ff88;
    margin-bottom: 20px;
    text-align: center;
}

#character-menu h3 {
    font-size: 14px;
    color: #888;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.equipment-grid {
    display: flex;
    gap: 30px;
}

.equipment-section, .ammo-section {
    flex: 1;
}

.equipment-slots {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.equip-slot {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 12px 8px;
    text-align: center;
}

.equip-slot:hover {
    border-color: rgba(0, 255, 136, 0.3);
}

.equip-label {
    font-size: 11px;
    color: #808080;
}

.ammo-slots {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ammo-slot {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ammo-label {
    font-size: 12px;
    color: #e0e0e0;
}

.ammo-count {
    font-size: 14px;
    color: #00ff88;
    font-weight: bold;
}

.menu-hint {
    text-align: center;
    margin-top: 20px;
    font-size: 12px;
    color: #606060;
}

/* Controls Section in Character Menu */
.controls-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 12px;
}

.control-group h4 {
    font-size: 11px;
    color: #00ff88;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.control-item {
    font-size: 11px;
    color: #a0a0a0;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-item .key {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 10px;
    color: #ffffff;
    font-family: 'Monaco', 'Courier New', monospace;
    min-width: 50px;
    text-align: center;
}

/* Error Screen */
#error-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

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

.error-content {
    max-width: 700px;
    padding: 40px;
    background: rgba(40, 0, 0, 0.9);
    border: 2px solid #ff4444;
    border-radius: 10px;
    text-align: center;
}

.error-content h1 {
    color: #ff4444;
    margin-bottom: 20px;
    font-size: 28px;
}

.error-message {
    color: #ffaaaa;
    font-size: 16px;
    margin-bottom: 20px;
    word-break: break-word;
}

.error-stack {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #662222;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: left;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    color: #ff8888;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

#error-reload {
    padding: 12px 30px;
    font-size: 16px;
    cursor: pointer;
    background: #cc3333;
    color: white;
    border: none;
    border-radius: 5px;
    transition: background 0.2s;
}

#error-reload:hover {
    background: #ff4444;
}
/* Tape Deck (F5) */
#tape-deck {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(20, 20, 25, 0.95);
    border: 2px solid #444;
    border-radius: 12px;
    padding: 20px;
    width: 300px;
    z-index: 2000;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    color: white;
    font-family: 'Monaco', monospace;
    pointer-events: auto;
}

#tape-deck.hidden { display: none; }

.tape-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    font-weight: bold;
    font-size: 14px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
}

.tape-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tape-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s;
    font-family: inherit;
}

.tape-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.record-btn { 
    background: #522; 
    color: #f55; 
    border: 1px solid #833; 
}
.record-btn:hover:not(:disabled) { background: #722; }

.stop-btn { 
    background: #333; 
    color: #aaa; 
    border: 1px solid #555; 
}
.stop-btn:hover:not(:disabled) { background: #444; }

.play-btn { 
    background: #252; 
    color: #5f5; 
    border: 1px solid #383; 
}
.play-btn:hover:not(:disabled) { background: #373; }

.tape-file-io {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 12px;
    color: #888;
    margin-bottom: 10px;
}

.io-btn {
    background: #334;
    border: 1px solid #557;
    color: #aad;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
    transition: background 0.1s;
}

.io-btn:hover {
    background: #445;
}

#current-tape-name {
    text-align: center;
    font-style: italic;
}

.tape-options {
    padding: 10px 0;
    border-top: 1px solid #333;
    margin-bottom: 10px;
}

.tape-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #aaa;
    cursor: pointer;
    user-select: none;
}

.tape-checkbox input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.tape-checkbox:hover span {
    color: #ccc;
}

.tape-hint {
    font-size: 11px;
    color: #666;
    text-align: center;
    margin-top: 4px;
}

.status-recording { 
    color: #f55; 
    animation: blink 1s infinite; 
}

.status-playing { 
    color: #5f5; 
}

.status-idle { 
    color: #888; 
}

@keyframes blink {
    50% { opacity: 0.5; }
}
