*{margin:0;padding:0;box-sizing:border-box}
html,body{width:100%;height:100%;overflow-x:hidden;background:#0d0d1a;font-family:'Press Start 2P',monospace;color:#c2c3c7}
body{
  background:#0d0d1a;
  background-image:
    radial-gradient(ellipse at 50% 0%,#1d2b5322 0%,transparent 60%),
    url("data:image/svg+xml,%3Csvg width='4' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='1' height='1' fill='%23ffffff08'/%3E%3C/svg%3E");
}
#app{display:flex;justify-content:center;align-items:flex-start;gap:0;min-height:100vh;padding:20px 10px}
#console-wrapper{display:flex;flex-direction:column;align-items:center}
#bezel{
  background:linear-gradient(180deg,#2a2a3a 0%,#1e1e2e 100%);
  border-radius:18px;
  padding:16px 20px 12px;
  box-shadow:
    0 0 0 3px #111122,
    0 8px 32px #00000088,
    inset 0 1px 0 #3a3a4a;
  position:relative;
}
#bezel-top{display:flex;align-items:center;gap:10px;margin-bottom:10px;justify-content:center;position:relative}
.bezel-label{font-size:14px;color:#ff77a8;text-shadow:0 0 8px #ff77a866;letter-spacing:2px}
.bezel-sub{font-size:6px;color:#5f574f;letter-spacing:1px}
#led-indicator{width:8px;height:8px;border-radius:50%;position:absolute;right:0;top:50%;transform:translateY(-50%);transition:all .3s}
.led-off{background:#5f574f;box-shadow:none}
.led-on{background:#00e436;box-shadow:0 0 8px #00e436,0 0 16px #00e43666}

#screen-wrapper{
  position:relative;
  width:512px;height:512px;
  border-radius:6px;
  overflow:hidden;
  background:#000;
  box-shadow:inset 0 0 20px #00000088,0 0 1px #000;
}
#canvas{
  width:512px;height:512px;
  image-rendering:pixelated;
  image-rendering:crisp-edges;
  display:block;
}
#scanlines{
  position:absolute;top:0;left:0;right:0;bottom:0;
  background:repeating-linear-gradient(
    0deg,
    transparent,transparent 3px,
    rgba(0,0,0,0.12) 3px,rgba(0,0,0,0.12) 4px
  );
  pointer-events:none;
  z-index:2;
}
#vignette{
  position:absolute;top:0;left:0;right:0;bottom:0;
  background:radial-gradient(ellipse at center,transparent 60%,rgba(0,0,0,0.5) 100%);
  pointer-events:none;
  z-index:3;
}

#cart-slot{
  margin-top:10px;
  text-align:center;
}
#cart-label{
  display:inline-block;
  background:linear-gradient(180deg,#1a1a28,#12121e);
  border:2px solid #333348;
  border-radius:6px;
  padding:8px 24px;
  cursor:pointer;
  transition:all .15s;
}
#cart-label:hover{background:linear-gradient(180deg,#222238,#1a1a2e);border-color:#ff77a8}
#cart-text{font-size:7px;color:#83769c;letter-spacing:1px}
#cart-label.inserting{animation:cartInsert .6s ease}
@keyframes cartInsert{
  0%{transform:translateY(0)}
  30%{transform:translateY(6px)}
  60%{transform:translateY(-2px)}
  100%{transform:translateY(0)}
}

#controls-area{
  display:flex;
  justify-content:space-between;
  align-items:center;
  width:400px;
  margin-top:16px;
}
#dpad{
  display:grid;
  grid-template-columns:44px 44px 44px;
  grid-template-rows:44px 44px 44px;
  gap:2px;
}
.dpad-btn{
  width:44px;height:44px;
  background:linear-gradient(180deg,#3a3a4e,#2a2a3e);
  border:2px solid #444460;
  border-radius:8px;
  color:#c2c3c7;
  font-size:14px;
  cursor:pointer;
  font-family:'Press Start 2P',monospace;
  transition:all .08s;
  -webkit-tap-highlight-color:transparent;
  touch-action:manipulation;
}
.dpad-btn:active,.dpad-btn.pressed{
  background:linear-gradient(180deg,#29adff44,#29adff22);
  border-color:#29adff;
  color:#fff1e8;
  transform:scale(0.93);
  box-shadow:0 0 8px #29adff44;
}
.dpad-up{grid-column:2;grid-row:1}
.dpad-left{grid-column:1;grid-row:2}
.dpad-center{grid-column:2;grid-row:2;background:#1a1a28;border-radius:4px}
.dpad-right{grid-column:3;grid-row:2}
.dpad-down{grid-column:2;grid-row:3}

#action-btns{display:flex;gap:16px;align-items:center}
.action-btn{
  width:52px;height:52px;
  border-radius:50%;
  font-family:'Press Start 2P',monospace;
  font-size:14px;
  cursor:pointer;
  border:3px solid;
  transition:all .08s;
  -webkit-tap-highlight-color:transparent;
  touch-action:manipulation;
}
#btn-o{
  background:linear-gradient(180deg,#3a3a4e,#2a2a3e);
  border-color:#ff004d;
  color:#ff004d;
}
#btn-o:active,#btn-o.pressed{
  background:#ff004d33;
  color:#fff1e8;
  box-shadow:0 0 12px #ff004d66;
  transform:scale(0.92);
}
#btn-x{
  background:linear-gradient(180deg,#3a3a4e,#2a2a3e);
  border-color:#29adff;
  color:#29adff;
}
#btn-x:active,#btn-x.pressed{
  background:#29adff33;
  color:#fff1e8;
  box-shadow:0 0 12px #29adff66;
  transform:scale(0.92);
}

#demo-bar{
  display:flex;gap:6px;margin-top:14px;flex-wrap:wrap;justify-content:center;
}
.demo-btn{
  font-family:'Press Start 2P',monospace;
  font-size:7px;
  padding:6px 12px;
  background:#1a1a2e;
  border:1px solid #333348;
  border-radius:4px;
  color:#83769c;
  cursor:pointer;
  transition:all .15s;
  -webkit-tap-highlight-color:transparent;
}
.demo-btn:hover,.demo-btn.active{border-color:#ffec27;color:#ffec27}
#cart-info{
  margin-top:8px;
  font-size:6px;
  color:#5f574f;
  text-align:center;
}
#cart-info span{margin:0 8px}

/* INSPECTOR */
#inspector{
  position:relative;
  margin-left:0;
  width:0;
  overflow:hidden;
  transition:width .3s ease;
}
#inspector.open{width:280px;margin-left:16px}
#inspector-toggle{
  position:absolute;
  left:-28px;top:40px;
  writing-mode:vertical-rl;
  text-orientation:mixed;
  font-size:7px;
  color:#83769c;
  cursor:pointer;
  background:#1e1e2e;
  padding:10px 4px;
  border-radius:4px 0 0 4px;
  border:1px solid #333348;
  border-right:none;
  z-index:10;
  transition:color .15s;
}
#inspector-toggle:hover{color:#ffec27}
#inspector.open #inspector-toggle{left:-28px}
#inspector-content{
  background:#14141f;
  border:1px solid #333348;
  border-radius:8px;
  padding:12px;
  width:280px;
  max-height:560px;
  overflow-y:auto;
  overflow-x:hidden;
}
#inspector-content::-webkit-scrollbar{width:4px}
#inspector-content::-webkit-scrollbar-thumb{background:#333348;border-radius:2px}
.inspector-section{margin-bottom:14px}
.inspector-section h3{font-size:7px;color:#ffa300;margin-bottom:6px;letter-spacing:1px}
#cpu-bar-wrap{
  width:100%;height:10px;
  background:#0d0d1a;
  border-radius:3px;
  overflow:hidden;
  margin-bottom:4px;
}
#cpu-bar{height:100%;width:0%;background:linear-gradient(90deg,#00e436,#ffec27,#ff004d);border-radius:3px;transition:width .3s}
#cpu-pct,#fps-counter{font-size:6px;color:#5f574f}
#fps-counter{float:right}

#palette-grid{
  display:grid;
  grid-template-columns:repeat(8,1fr);
  gap:2px;
}
.pal-swatch{
  width:100%;
  aspect-ratio:1;
  border-radius:2px;
  position:relative;
  cursor:default;
}
.pal-swatch:hover::after{
  content:attr(data-hex);
  position:absolute;
  bottom:110%;left:50%;transform:translateX(-50%);
  font-size:5px;color:#fff1e8;background:#000000cc;
  padding:2px 4px;border-radius:2px;white-space:nowrap;z-index:99;
}
#mem-view{
  font-size:5px;
  line-height:1.6;
  color:#5f574f;
  max-height:120px;
  overflow-y:auto;
  word-break:break-all;
  font-family:'Press Start 2P',monospace;
}
#code-view{
  font-size:5.5px;
  line-height:1.8;
  color:#c2c3c7;
  max-height:160px;
  overflow:auto;
  white-space:pre-wrap;
  word-break:break-all;
}
#sprite-canvas{
  width:128px;height:128px;
  image-rendering:pixelated;
  background:#000;
  border:1px solid #333348;
}

#footer{
  position:fixed;bottom:0;left:0;right:0;
  text-align:center;
  padding:8px;
  font-size:5px;
  color:#5f574f;
  background:#0d0d1a;
  z-index:100;
}
#footer a{color:#ff77a8;text-decoration:none;margin-left:12px}
#footer a:hover{text-decoration:underline}

/* Responsive */
@media(max-width:900px){
  #app{flex-direction:column;align-items:center}
  #inspector{margin-left:0;margin-top:12px}
  #inspector.open{width:100%;max-width:520px}
  #inspector-toggle{
    writing-mode:horizontal-tb;
    position:relative;
    left:0;top:0;
    text-align:center;
    border-radius:4px 4px 0 0;
    border:1px solid #333348;
    border-bottom:none;
    width:100%;
  }
  #inspector-content{width:100%;max-width:520px}
}
@media(max-width:560px){
  #screen-wrapper,#canvas{width:calc(100vw - 60px);height:calc(100vw - 60px);max-width:512px;max-height:512px}
  #bezel{padding:10px 10px 8px}
  .bezel-label{font-size:10px}
  #controls-area{width:calc(100vw - 40px);max-width:400px}
}