:root{
  --chrome-a:#2a4d9e; --chrome-b:#1a2f6e;
  --bg:#0d0d1a; --panel:#16162a; --border:#3a3a5c;
  --term-bg:#050508; --term-green:#33ff66; --term-amber:#ffb648; --term-red:#ff3c78;
  --accent:#3a86ff;
}
*{ box-sizing:border-box; margin:0; padding:0; }
body{
  background:
    radial-gradient(circle at 50% 0%, #1a1a3e 0%, #0a0a16 60%, #050508 100%);
  font-family:'VT323', monospace;
  color:#c7c7e0;
  min-height:100vh;
  display:flex; align-items:center; justify-content:center;
  padding:12px;
  overflow-x:hidden;
}

/* CRT overlay */
#crt-overlay{
  position:fixed; inset:0; pointer-events:none; z-index:999;
  background:repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,0.18) 3px, rgba(0,0,0,0) 4px);
  animation:flicker 4s infinite steps(60);
}
@keyframes flicker{ 0%,100%{opacity:.9;} 50%{opacity:1;} 96%{opacity:.7;} }

#window{
  width:100%; max-width:1040px;
  background:var(--panel);
  border:2px solid var(--border);
  border-radius:6px;
  box-shadow:0 0 40px rgba(58,134,255,0.25), 0 0 0 4px rgba(0,0,0,0.4);
  position:relative;
}
#window.shake{ animation:shake .4s; }
@keyframes shake{ 0%,100%{transform:translate(0);} 20%{transform:translate(-6px,2px);} 40%{transform:translate(6px,-2px);} 60%{transform:translate(-4px,-2px);} 80%{transform:translate(4px,2px);} }

#titlebar{
  display:flex; align-items:center; justify-content:space-between;
  background:linear-gradient(180deg, var(--chrome-a), var(--chrome-b));
  padding:6px 10px;
  border-bottom:2px solid #0a0a20;
  border-radius:4px 4px 0 0;
}
#title-text{ font-family:'Press Start 2P', monospace; font-size:11px; color:#e8f0ff; text-shadow:1px 1px 0 #000; }
#win-buttons{ display:flex; gap:4px; }
.win-btn{
  width:22px; height:20px; font-family:monospace; font-size:12px; cursor:pointer;
  background:#c0c0d0; border:2px outset #e8e8f0; color:#111;
}
.win-btn.close{ background:#e05a6a; }
.win-btn:active{ border-style:inset; }

#subtitle{
  text-align:center; padding:6px; font-size:18px; color:var(--term-amber);
  background:#0a0a16; border-bottom:1px solid var(--border);
  min-height:30px;
}

#stats-bar{
  display:flex; flex-wrap:wrap; gap:10px; align-items:center; justify-content:space-between;
  padding:6px 12px; font-size:16px; color:#8fa;
  background:#0c0c1c; border-bottom:1px solid var(--border);
}
#stats-bar span{ text-shadow:0 0 6px currentColor; }
#fail-count{ color:var(--term-red); }
#mute-toggle{
  font-family:'VT323',monospace; font-size:14px; cursor:pointer;
  background:#1c1c34; color:#9cf; border:1px solid var(--accent); padding:3px 8px; border-radius:3px;
}

#main{ display:flex; gap:14px; padding:14px; flex-wrap:wrap; }

#stage-wrap{
  flex:1 1 480px; min-width:280px; position:relative;
  border:3px solid #000; border-radius:4px; overflow:hidden;
  box-shadow:inset 0 0 60px rgba(0,0,0,0.8);
}
#canvas{
  width:100%; height:auto; display:block; cursor:crosshair;
  image-rendering:pixelated;
  filter:saturate(1.1);
}
#stage-wrap::after{ /* vignette */
  content:''; position:absolute; inset:0; pointer-events:none;
  box-shadow:inset 0 0 90px rgba(0,0,0,0.9);
  border-radius:4px;
}
#error-flash{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-family:'Press Start 2P', monospace; font-size:16px; color:#fff; text-align:center;
  background:rgba(255,20,80,0.5); opacity:0; pointer-events:none; transition:opacity .1s;
  text-shadow:2px 2px 0 #000; padding:20px;
}
#error-flash.show{ opacity:1; animation:eflick .1s infinite; }
@keyframes eflick{ 50%{ transform:translateX(4px); } }

#side{ flex:1 1 300px; min-width:260px; display:flex; flex-direction:column; gap:10px; }

#dropzone{
  border:3px dashed var(--accent); border-radius:6px; padding:20px;
  text-align:center; cursor:pointer; background:rgba(58,134,255,0.05);
  transition:.15s;
}
#dropzone:hover, #dropzone.drag{ background:rgba(58,134,255,0.18); border-color:#7ab8ff; transform:scale(1.01); }
.dz-big{ font-size:20px; color:#cfe3ff; }
.dz-small{ font-size:15px; color:#889; margin-top:4px; }

#fileinfo{
  display:none; font-size:16px; padding:8px; background:#0c0c1c;
  border:1px solid var(--border); border-radius:4px; color:#bcd; word-break:break-word;
}
#fileinfo .corr{ color:var(--term-red); }

#repair-btn{
  font-family:'Press Start 2P', monospace; font-size:12px; line-height:1.5;
  padding:14px; cursor:pointer; border:none; border-radius:6px;
  background:linear-gradient(180deg, #ff5a8a, #c8305c); color:#fff;
  text-shadow:1px 1px 0 #000;
  box-shadow:0 0 20px rgba(255,90,138,0.5), 0 4px 0 #7a1a38;
  transition:.1s;
}
#repair-btn:hover:not(:disabled){ box-shadow:0 0 30px rgba(255,90,138,0.8), 0 4px 0 #7a1a38; }
#repair-btn:active:not(:disabled){ transform:translateY(3px); box-shadow:0 0 20px rgba(255,90,138,0.5); }
#repair-btn:disabled{ opacity:.6; cursor:wait; animation:pulseglow 1s infinite; }
@keyframes pulseglow{ 50%{ box-shadow:0 0 40px rgba(255,90,138,1); } }

#progress-wrap{ display:flex; align-items:center; gap:8px; }
#progress-bar{ flex:1; height:20px; background:#0a0a16; border:1px solid var(--border); border-radius:3px; overflow:hidden; }
#progress-fill{ height:100%; width:0; background:linear-gradient(90deg,#3a86ff,#7ab8ff); transition:width .3s; }
#progress-pct{ font-size:16px; width:44px; text-align:right; color:#9cf; }

#log{
  flex:1; min-height:160px; max-height:240px; overflow-y:auto;
  background:var(--term-bg); border:1px solid var(--border); border-radius:4px;
  padding:8px; font-size:16px; line-height:1.35;
}
.log-line{ color:var(--term-green); text-shadow:0 0 4px currentColor; }
.log-line.err{ color:var(--term-red); }
.log-line.ok{ color:var(--term-green); }

footer{
  display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px;
  padding:8px 14px; font-size:15px; color:#778;
  border-top:1px solid var(--border); background:#0a0a16;
  border-radius:0 0 4px 4px;
}
footer a{ color:var(--accent); text-decoration:none; border-bottom:1px dotted var(--accent); }
footer a:hover{ color:#7ab8ff; }

/* Modal */
#modal-overlay{
  position:fixed; inset:0; background:rgba(0,0,0,0.75); z-index:1000;
  display:flex; align-items:center; justify-content:center; padding:16px;
  backdrop-filter:blur(2px);
}
#modal{
  background:var(--panel); border:3px solid var(--term-red); border-radius:8px;
  max-width:460px; width:100%; padding:22px; text-align:center;
  box-shadow:0 0 50px rgba(255,60,120,0.4);
  animation:pop .3s;
}
@keyframes pop{ from{ transform:scale(.7); opacity:0; } to{ transform:scale(1); opacity:1; } }
#modal-title{ font-family:'Press Start 2P', monospace; font-size:14px; color:var(--term-red); line-height:1.6; margin-bottom:14px; text-shadow:2px 2px 0 #000; }
#modal-body{ font-size:18px; color:#cbd; line-height:1.4; margin-bottom:16px; }
.gauge{ margin:8px 0; text-align:left; }
.gauge-label{ font-size:15px; color:#9ab; margin-bottom:2px; }
.gauge-bar{ height:20px; background:#0a0a16; border:1px solid var(--border); border-radius:3px; overflow:hidden; }
.gauge-fill{ height:100%; display:flex; align-items:center; justify-content:center; font-size:13px; color:#fff; }
.gauge-fill.red{ background:linear-gradient(90deg,#c8305c,#ff5a8a); }
.gauge-fill.blue{ background:linear-gradient(90deg,#3a86ff,#7ab8ff); }
#modal-actions{ display:flex; flex-wrap:wrap; gap:8px; justify-content:center; margin-top:18px; }
.modal-btn{
  font-family:'VT323',monospace; font-size:16px; cursor:pointer;
  padding:8px 12px; border:2px outset #556; background:#1c1c34; color:#cfe3ff; border-radius:3px;
}
.modal-btn:hover{ background:#2a2a48; }
.modal-btn:active{ border-style:inset; }

#visitor-counter{
  text-align:center; padding:6px; font-size:16px; color:#0f0; background:#000;
  border-top:2px dashed #0f0; animation:blink 1s steps(2) infinite;
}
@keyframes blink{ 50%{ opacity:.3; } }

/* 1999 mode */
body.mode1999{ background:#008080; }
body.mode1999 #window{ font-family:'Comic Sans MS','VT323',cursive; }
body.mode1999 #subtitle{ color:#ff0; animation:blink 1s steps(2) infinite; }
body.mode1999 #title-text{ color:#ff0; }

@media (max-width:640px){
  #title-text{ font-size:8px; }
  #subtitle{ font-size:15px; }
  #modal-title{ font-size:11px; }
  #repair-btn{ font-size:10px; }
}