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

:root {
    --orange-main: #ff8c42;
    --orange-light: #ffb347;
    --orange-dark: #e05a00;
    --green-screen: #9acd32;
    --screen-bg: #f5f5dc;
    --neon-cyan: #00f5ff;
    --neon-pink: #ff00aa;
}

body {
    font-family: 'Nunito', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Custom pixel art background */
    background: url('bg.png') center center;
    background-size: cover;
    background-attachment: fixed;
    padding: 10px;
    overflow-x: hidden;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Dark overlay on background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 20, 0.3);
    pointer-events: none;
    z-index: 0;
}

/* Floating sparkles */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(2px 2px at 10% 20%, rgba(255, 255, 255, 0.8) 50%, transparent 50%),
        radial-gradient(2px 2px at 30% 60%, rgba(255, 255, 255, 0.6) 50%, transparent 50%),
        radial-gradient(2px 2px at 50% 30%, rgba(255, 255, 255, 0.7) 50%, transparent 50%),
        radial-gradient(2px 2px at 70% 80%, rgba(255, 255, 255, 0.5) 50%, transparent 50%),
        radial-gradient(2px 2px at 90% 40%, rgba(255, 255, 255, 0.6) 50%, transparent 50%);
    animation: twinkle 3s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {
    0% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* Main Title - Big centered at top */
.main-title {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(28px, 6vw, 55px);
    color: var(--orange-main);
    text-align: center;
    z-index: 100;
    text-shadow: 
        4px 4px 0 #c24600,
        -2px -2px 0 #000;
    letter-spacing: 8px;
    animation: title-float 3s ease-in-out infinite;
}

@keyframes title-float {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-5px); }
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    min-height: 100vh;
    padding-top: 90px;
    padding-bottom: 20px;
    width: 100%;
}

/* Main content: 3 column layout */
.main-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 1400px;
    padding: 0 20px;
}

/* Center with tamagotchi and controls */
.center-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    order: 1;
}

/* Terminal Panel - Left */
.terminal-panel {
    background: rgba(0, 10, 20, 0.9);
    border: 3px solid #00ff88;
    border-radius: 15px;
    overflow: hidden;
    width: 100%;
    max-width: 320px;
    box-shadow: 
        0 0 20px rgba(0, 255, 136, 0.3),
        inset 0 0 30px rgba(0, 255, 136, 0.05);
    order: 2;
}

.terminal-header {
    background: linear-gradient(90deg, #1a1a2e, #2a2a40);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 2px solid #00ff88;
}

.terminal-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.terminal-dot.red { background: #ff5f56; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #27ca3f; }

.terminal-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #00ff88;
    margin-left: 10px;
}

.terminal-body {
    padding: 15px;
    height: 420px;
    overflow: hidden;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    line-height: 2.2;
    color: #00ff88;
}

.terminal-body p {
    margin: 5px 0;
    opacity: 0.9;
    animation: terminal-flicker 0.1s ease-in-out;
}

@keyframes terminal-flicker {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 1; }
}

/* Blinking cursor effect */
.terminal-body::after {
    content: '_';
    animation: blink-cursor 1s infinite;
}

@keyframes blink-cursor {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Desktop: 3 columns (1/4 - 2/4 - 1/4) */
@media (min-width: 1200px) {
    .main-content {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 40px;
    }
    
    .terminal-panel {
        flex: 1;
        max-width: 300px;
        order: 1;
        margin-top: 60px;
    }
    
    .center-side {
        flex: 2;
        order: 2;
    }
    
    .info-panel {
        flex: 1;
        max-width: 300px;
        order: 3;
        margin-top: 60px;
    }
}

/* Device Wrapper */
.device-wrapper {
    position: relative;
    width: min(85vw, 420px);
    height: min(65vh, 500px);
    animation: float 4s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-12px) rotate(1deg); }
}

/* Shell Image */
.device-shell {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.5))
            drop-shadow(0 0 30px rgba(255, 140, 66, 0.4));
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Screen positioned over the shell's screen area */
/* Adjust these values to fit your content.png perfectly */
.screen {
    position: absolute;
    top: 36%;      /* Distance from top - adjust to move up/down */
    left: 35%;   /* Distance from left - adjust to move left/right */
    width: 30%;    /* Width of screen area */
    height: 22%;   /* Height of screen area */
    background: linear-gradient(180deg, #f8f8e8 0%, #e8e8d0 100%);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Pixel grid overlay on screen */
.screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
    background-size: 8px 8px;
    pointer-events: none;
    z-index: 5;
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-around;
    padding: 4px 2px;
    background: rgba(0, 0, 0, 0.08);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.stat {
    display: flex;
    align-items: center;
    gap: 2px;
}

.stat-icon {
    font-size: 8px;
}

.stat-bar {
    width: 28px;
    height: 6px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
    overflow: hidden;
}

.stat-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.health-fill {
    background: linear-gradient(90deg, #ff6b6b, #ee5a5a);
    width: 100%;
}

.hunger-fill {
    background: linear-gradient(90deg, #ffd93d, #f5c800);
    width: 80%;
}

.energy-fill {
    background: linear-gradient(90deg, #6dd5ed, #2193b0);
    width: 90%;
}

.happiness-fill {
    background: linear-gradient(90deg, #c471ed, #9b59b6);
    width: 85%;
}

/* Pet Area */
.pet-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Pet Video */
#pet-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    position: relative;
    z-index: 2;
}

/* Action Items (food, bed, toy) */
.action-item {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s ease;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    z-index: 3;
}

.food-item {
    width: 40px;
    height: 40px;
    top: 50%;
    left: -50px;
    transform: translateY(-50%);
}

.food-item.show {
    opacity: 1;
    left: 10px;
    animation: food-bounce 0.5s ease-in-out 3;
}

@keyframes food-bounce {
    0%, 100% { transform: translateY(-50%) rotate(-5deg); }
    50% { transform: translateY(-60%) rotate(5deg); }
}

.bed-item {
    width: 60px;
    height: 60px;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
}

.bed-item.show {
    opacity: 0.8;
    bottom: 5px;
}

.toy-item {
    width: 50px;
    height: 50px;
    top: 50%;
    right: -50px;
    transform: translateY(-50%);
}

.toy-item.show {
    opacity: 1;
    right: 5px;
    animation: toy-spin 0.8s ease-in-out 2;
}

@keyframes toy-spin {
    0% { transform: translateY(-50%) rotate(0deg) scale(1); }
    50% { transform: translateY(-50%) rotate(180deg) scale(1.2); }
    100% { transform: translateY(-50%) rotate(360deg) scale(1); }
}

/* Speech Bubble */
.speech-bubble {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 10px;
    border-radius: 10px;
    max-width: 90%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 2px solid #333;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 10;
}

.speech-bubble.show {
    opacity: 1;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #333;
    border-bottom: none;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #fff;
    border-bottom: none;
}

#speech-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    color: #333;
    text-align: center;
    line-height: 1.4;
}

/* Webcam Preview */
.webcam-preview {
    position: absolute;
    bottom: 5px;
    left: 5px;
    width: 35px;
    height: 26px;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid #333;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.webcam-preview.active {
    opacity: 1;
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

/* Controls - All 5 Buttons */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 25px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 140, 66, 0.3);
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    background: linear-gradient(145deg, #3a3a5a, #2a2a40);
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.15);
    transition: all 0.2s ease;
}

.control-btn:hover {
    transform: scale(1.15) translateY(-3px);
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(255, 140, 66, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.2);
    border-color: var(--orange-main);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.primary {
    background: linear-gradient(145deg, var(--orange-main), var(--orange-dark));
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 
        0 6px 20px rgba(255, 140, 66, 0.4),
        inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.control-btn.primary:hover {
    box-shadow: 
        0 10px 35px rgba(255, 140, 66, 0.6),
        0 0 25px rgba(255, 140, 66, 0.5),
        inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.control-btn span {
    font-size: 22px;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}

.control-btn small {
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    opacity: 0.9;
}

.control-btn.listening {
    animation: pulse-listen 1s infinite;
    background: linear-gradient(145deg, #ff3366, #cc0033);
}

@keyframes pulse-listen {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 51, 102, 0.7), 0 6px 20px rgba(255, 51, 102, 0.4); }
    50% { box-shadow: 0 0 0 20px rgba(255, 51, 102, 0), 0 6px 30px rgba(255, 51, 102, 0.6); }
}

/* Info Panel - Right side */
.info-panel {
    text-align: left;
    color: white;
    max-width: 350px;
    background: rgba(0, 0, 30, 0.85);
    padding: 25px 30px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 3px solid rgba(255, 140, 66, 0.4);
}

.tagline {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    opacity: 0.9;
    margin-bottom: 20px;
    color: var(--neon-cyan);
    line-height: 1.8;
    text-align: center;
}

.instructions {
    text-align: left;
}

.instructions p {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    margin: 10px 0;
    opacity: 0.95;
    line-height: 1.8;
}

.instructions strong {
    color: var(--orange-main);
}

/* On mobile/tablet: stack with tamagotchi first */
@media (max-width: 1199px) {
    .main-content {
        flex-direction: column;
    }
    
    .center-side {
        order: 1;
    }
    
    .terminal-panel {
        order: 2;
        max-width: 350px;
    }
    
    .info-panel {
        order: 3;
        max-width: 350px;
        text-align: center;
    }
    
    .instructions {
        text-align: center;
    }
    
    .terminal-body {
        height: 150px;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 30, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

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

.loading-spinner {
    width: 70px;
    height: 70px;
    border: 5px solid rgba(255, 140, 66, 0.2);
    border-top-color: var(--orange-main);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
    box-shadow: 0 0 30px rgba(255, 140, 66, 0.3);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: var(--orange-main);
    text-shadow: 0 0 15px rgba(255, 140, 66, 0.5);
    animation: blink-text 1s ease-in-out infinite;
}

@keyframes blink-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Responsive */
@media (max-width: 500px) {
    .device-wrapper {
        width: 320px;
        height: 380px;
    }
    
    .control-btn {
        width: 52px;
        height: 52px;
    }
    
    .control-btn span {
        font-size: 18px;
    }
    
    .info-panel h2 {
        font-size: 22px;
    }
    
    .controls {
        gap: 8px;
    }
}

@media (min-width: 768px) {
    .main-title {
        top: 20px;
        font-size: 50px;
    }
    
    .container {
        padding-top: 90px;
        gap: 15px;
    }
    
    .device-wrapper {
        width: min(70vw, 500px);
        height: min(60vh, 600px);
    }
    
    .control-btn {
        width: 70px;
        height: 70px;
    }
    
    .control-btn span {
        font-size: 26px;
    }
    
    .control-btn small {
        font-size: 7px;
    }
}

/* Extra large screens */
@media (min-width: 1200px) {
    .main-title {
        margin-top: 105px;
        font-size: 60px;
    }
    
    .device-wrapper {
        width: min(50vw, 550px);
        height: min(65vh, 660px);
    }
    
    .container {
        padding-top: 100px;
    }
}

/* Glow effect on device */
.device-wrapper::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120%;
    height: 120%;
    background: radial-gradient(ellipse, rgba(255, 140, 66, 0.2) 0%, transparent 60%);
    pointer-events: none;
    z-index: -1;
    animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
}
