:root {
    --red: #DC0A2D; --border: #89061C; --bg: #98CB98; 
    --text: #0F380F; --blue: #2980B9; --grey: #222;
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: 'Press Start 2P', cursive; 
    user-select: none; 
    -webkit-tap-highlight-color: transparent; 
}

body {
    background: #1a1a1a linear-gradient(45deg, #222 25%, transparent 25%, transparent 75%, #222 75%) 0 0/40px 40px;
    height: 100vh; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    overflow: hidden;
}

/* DEVICE */
.main-device {
    background: var(--red); 
    width: 100%; 
    max-width: 650px; 
    height: 95vh; 
    max-height: 850px;
    border-radius: 15px 15px 50px 15px; 
    padding: 20px; 
    border: 4px solid var(--border);
    box-shadow: inset 5px 5px 15px #ffffff50, inset -5px -5px 15px #00000050, 10px 10px 0 #000;
    display: flex; 
    flex-direction: column; 
    position: relative;
}

/* HEADER */
.device-header { 
    display: flex; 
    gap: 15px; 
    margin-bottom: 10px; 
    border-bottom: 4px solid var(--border); 
    padding-bottom: 5px; 
    flex-shrink: 0; 
}
.sensor-big { width: 50px; height: 50px; background: radial-gradient(at 30% 30%, #44E0FF, #0099CC); border: 4px solid #fff; border-radius: 50%; box-shadow: 0 0 15px #44E0FF; }
.sensor-group { display: flex; gap: 8px; margin-top: 5px; }
.sensor { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #00000050; }
.s-red { background: #F00; } .s-yel { background: #FF0; } .s-grn { background: #0F0; }

/* SCREEN CONTAINER - FIXED OVERFLOW */
.screen-container { 
    background: #dedede; 
    padding: 15px 20px 25px; 
    border-radius: 10px 10px 40px 10px; 
    border: 4px solid var(--grey); 
    flex: 1; 
    display: flex; 
    min-height: 0; 
    margin-bottom: 10px; 
    width: 100%; /* Force width constraint */
    overflow: hidden; /* Prevent spillover */
}

.screen-bezel { 
    background: var(--grey); 
    padding: 12px; 
    border-radius: 8px; 
    flex: 1; 
    display: flex; 
    overflow: hidden; 
    width: 100%; 
}

.lcd-screen { 
    background: var(--bg); 
    color: var(--text); 
    padding: 10px; 
    border-radius: 4px; 
    box-shadow: inset 3px 3px 8px #00000030; 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    width: 100%;
}

.content-wrapper { display: flex; flex-direction: column; height: 100%; width: 100%; }
.center-all { justify-content: center; align-items: center; text-align: center; }

/* UI ELEMENTS */
.header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; flex-shrink: 0; width: 100%; }
.title { font-size: 14px; }
.battery { font-size: 8px; border: 2px solid var(--text); padding: 2px; border-radius: 2px; }
.subtitle { font-size: 10px; text-align: center; margin-bottom: 8px; border-bottom: 2px solid var(--text); padding-bottom: 5px; flex-shrink: 0; font-weight: bold; width: 100%; }

/* SPRITES - FIXED LAYOUT */
.sprite-grid { 
    display: grid; 
    /* minmax(0, 1fr) prevents items from forcing the grid wider than the container */
    grid-template-columns: repeat(5, minmax(0, 1fr)); 
    gap: 5px; 
    flex: 1; 
    align-content: center; 
    min-height: 0;
    width: 100%;
}

.sprite-opt { 
    border: 2px solid transparent; 
    border-radius: 6px; 
    cursor: pointer; 
    background: #ffffff30; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    aspect-ratio: 1/1;
    overflow: hidden; /* Contains image scaling */
}

.sprite-opt:hover { background: #ffffff60; }
.sprite-opt.sel { 
    border-color: var(--text); 
    background: #fff; 
    /* Removed scaling that might cause overflow, used inset shadow instead */
    box-shadow: inset 0 0 0 2px var(--text), 2px 2px 5px #00000030; 
    z-index: 2; 
}
.sprite-opt img { 
    width: 100%; 
    height: auto; 
    image-rendering: pixelated; 
}

/* FORM */
.form-container { width: 100%; margin: 8px 0; flex-shrink: 0; display: flex; flex-direction: column; gap: 5px; }
input { 
    width: 100%; background: #ffffff50; border: 2px solid var(--text); padding: 8px; 
    font-size: 12px; color: var(--text); outline: none; text-transform: uppercase; 
}

.status-bar { font-size: 8px; text-align: center; padding: 4px; background: var(--text); color: var(--bg); flex-shrink: 0; width: 100%; }
.dashed { background: transparent; color: var(--text); border: 2px dashed var(--text); }
.hidden { display: none !important; }

/* CONTROLS */
.controls { display: flex; justify-content: space-between; align-items: center; padding: 0 10px; flex-shrink: 0; width: 100%; }
.d-pad { position: relative; width: 100px; height: 100px; }
.d-key { background: #222; position: absolute; box-shadow: 2px 2px 0 #00000050; }
.d-c { width: 34px; height: 34px; top: 33px; left: 33px; z-index: 2; box-shadow: none; }
.d-u { width: 34px; height: 34px; top: 0; left: 33px; border-radius: 5px 5px 0 0; }
.d-d { width: 34px; height: 34px; bottom: 0; left: 33px; border-radius: 0 0 5px 5px; }
.d-l { width: 34px; height: 34px; top: 33px; left: 0; border-radius: 5px 0 0 5px; }
.d-r { width: 34px; height: 34px; top: 33px; right: 0; border-radius: 0 5px 5px 0; }

.btns { display: flex; gap: 20px; align-items: flex-start; }
.btn-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.b-pos { margin-top: 35px; } 
.btn-col label { font-size: 8px; font-weight: bold; color: var(--border); }

.round-btn { width: 55px; height: 55px; border-radius: 50%; border: none; font-size: 16px; cursor: pointer; box-shadow: inset -3px -3px 5px #00000060, 4px 4px 0 #00000060; color: #fff; }
.round-btn:active { transform: translate(2px, 2px); box-shadow: inset -2px -2px 3px #00000060; }
.btn-b { background: #222; border: 3px solid #555; }

/* GOLD BUTTON */
.btn-a {
    background: linear-gradient(135deg, #FFD700, #FFC107, #FFD700);
    border: 3px solid #B8860B; color: #5c4000; position: relative; overflow: hidden;
    animation: pulse 2s infinite; text-shadow: 1px 1px 0 #ffffff80;
}
.btn-a::before {
    content: ''; position: absolute; top: 0; left: -150%; width: 100%; height: 100%;
    background: linear-gradient(120deg, transparent, #ffffffcc, transparent);
    transform: skewX(-20deg); animation: shine 3s infinite linear;
}

/* ANIMATIONS & MISC */
.progress-box { width: 80%; height: 15px; border: 2px solid var(--text); padding: 2px; }
#progressBar { height: 100%; width: 0%; background: var(--text); transition: width 7s linear; }
.vents { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; padding-right: 15px; }
.v { width: 50px; height: 6px; background: #00000030; border-radius: 3px; }

/* MODALS */
.modal { position: fixed; inset: 0; background: #000000e0; z-index: 99; display: flex; justify-content: center; align-items: center; }
.card, .dex-entry { background: #f8f8f8; width: 90%; max-width: 380px; border-radius: 10px; padding: 15px; }
.card { border: 6px solid var(--blue); box-shadow: 0 0 20px #000; }
.card-head { background: var(--blue); color: #fff; padding: 8px; display: flex; justify-content: space-between; margin: -15px -15px 15px; font-size: 12px; }
.ball { width: 20px; height: 20px; background: #fff; border-radius: 50%; }
.card-body { display: flex; gap: 15px; margin-bottom: 15px; }
.avatar { width: 70px; height: 70px; background: #ccc; border: 3px solid #000; object-fit: cover; }
.info { flex: 1; overflow: hidden; }
.lbl { font-size: 8px; color: #666; margin-bottom: 4px; }
.code { background: #fff; border: 2px solid #000; padding: 6px; font-size: 10px; word-break: break-all; font-family: monospace; font-weight: bold; margin-bottom: 8px; cursor: pointer; }
.blur { filter: blur(4px); user-select: none; } .blur:hover { filter: none; }
.warn { color: red; font-size: 9px; text-align: center; margin-bottom: 10px; }
.act-btn { width: 100%; padding: 12px; background: #F00; color: #fff; border: 4px solid var(--border); font-size: 14px; cursor: pointer; box-shadow: 4px 4px 0 #000; }
.act-btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 #000; }

.dex-entry { background: var(--bg); border: 8px solid var(--red); box-shadow: 0 0 0 100px #00000080; }
.dex-head { background: var(--text); color: var(--bg); padding: 8px; text-align: center; font-size: 12px; margin-bottom: 15px; }
.dex-body { display: flex; gap: 15px; margin-bottom: 15px; }
#succImg { width: 90px; height: 90px; border: 3px solid var(--text); background: #fff; }
.dex-info p { font-size: 10px; margin-bottom: 8px; color: var(--text); }
.blue { color: var(--blue); font-weight: bold; } .grn { color: #006400; font-weight: bold; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes blink-fast { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes shine { 0% { left: -150%; } 20% { left: 150%; } 100% { left: 150%; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #FFD700aa; } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.blink { animation: blink 1s infinite; } .blink-fast { animation: blink-fast 0.3s infinite; }

@media(max-height: 700px) {
    .main-device { padding: 10px; } .screen-container { padding: 10px; } .d-pad { width: 80px; height: 80px; } 
    .d-key { width: 26px; height: 26px; } .d-u { left: 27px; } .d-d { left: 27px; } .d-l { top: 27px; } .d-r { top: 27px; } .d-c { top: 27px; left: 27px; }
}