:root {
  --bg: #08090f;
  --panel: rgba(18, 20, 32, 0.86);
  --panel-2: rgba(30, 33, 52, 0.88);
  --text: #eef3ff;
  --muted: #95a0b8;
  --good: #7cf7b5;
  --bad: #ff5470;
  --warn: #ffd166;
  --glitch: #65e6ff;
  --purple: #b886ff;
  --cell: 46px;
  --gap: 5px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 20%, rgba(101, 230, 255, 0.13), transparent 28%),
    radial-gradient(circle at 80% 0%, rgba(184, 134, 255, 0.13), transparent 30%),
    linear-gradient(145deg, #05060a 0%, #111322 55%, #070811 100%);
  overflow: hidden;
}

body.shake { animation: shake 180ms linear 1; }
@keyframes shake {
  0%, 100% { transform: translate(0,0); }
  25% { transform: translate(3px,-2px); }
  50% { transform: translate(-3px,2px); }
  75% { transform: translate(2px,3px); }
}

.scanlines::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.032),
    rgba(255,255,255,0.032) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: overlay;
  z-index: 20;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr 300px;
  gap: 18px;
  padding: 18px;
  height: 100vh;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35), inset 0 0 24px rgba(101,230,255,0.03);
  backdrop-filter: blur(8px);
}

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 25px; letter-spacing: -0.04em; }
h2 { font-size: 16px; color: var(--glitch); text-transform: uppercase; letter-spacing: 0.08em; }
p { color: var(--muted); line-height: 1.35; }

.stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-variant-numeric: tabular-nums;
}
.stat strong { color: white; }
.bar {
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.fill { height: 100%; width: 50%; background: linear-gradient(90deg, var(--good), var(--glitch)); transition: width 160ms; }
.fill.bad { background: linear-gradient(90deg, var(--bad), var(--warn)); }

.prestigeBox {
  margin: 14px 0;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(184,134,255,.18), rgba(101,230,255,.10));
  border: 1px solid rgba(184,134,255,.34);
  box-shadow: inset 0 0 18px rgba(184,134,255,.08);
}
.prestigeBox.ready {
  border-color: rgba(124,247,181,.65);
  box-shadow: 0 0 26px rgba(124,247,181,.18), inset 0 0 18px rgba(124,247,181,.08);
}
.prestigeBox strong { display:block; font-size: 18px; }
.prestigeBox small { color: var(--muted); }

.center {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.window-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.dots span {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin-left: 6px;
  background: var(--bad);
  box-shadow: 0 0 12px currentColor;
}
.dots span:nth-child(2) { background: var(--warn); }
.dots span:nth-child(3) { background: var(--good); }

#grid-widget {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
  background: rgba(2, 4, 10, 0.58);
}
#grid-widget::before {
  content: "";
  position: absolute;
  inset: 16px;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(101,230,255,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(101,230,255,0.08) 1px, transparent 1px);
  background-size: calc(var(--cell) + var(--gap)) calc(var(--cell) + var(--gap));
  background-position: 0 0;
  pointer-events: none;
}

.grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--size), var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  padding: 16px;
  border-radius: 16px;
  background: rgba(4, 7, 16, 0.92);
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 18px 40px rgba(0,0,0,.25);
}

.btn {
  width: var(--cell);
  height: var(--cell);
  border: 0;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  position: relative;
  font-weight: 800;
  font-size: 10px;
  background: linear-gradient(145deg, #2e3556, #14182a);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.16), 0 0 12px rgba(101,230,255,0.10);
  transition: transform 80ms, filter 80ms, box-shadow 120ms;
  user-select: none;
}
.btn:hover { transform: translateY(-1px) scale(1.05); filter: brightness(1.18); }
.btn:active { transform: scale(0.92); }
.btn.normal { background: linear-gradient(145deg, #3478ff, #17316e); }
.btn.splitter { background: linear-gradient(145deg, #7cf7b5, #136f4a); }
.btn.corrupt { background: linear-gradient(145deg, #ff5470, #560817); animation: pulseBad 800ms infinite alternate; }
.btn.explosive { background: linear-gradient(145deg, #ffd166, #9d3b00); }
.btn.chain { background: linear-gradient(145deg, #65e6ff, #075c78); }
.btn.glitch { background: linear-gradient(145deg, #b886ff, #441073); animation: glitchy 700ms infinite steps(2); }
.btn.firewall { background: linear-gradient(145deg, #ffffff, #5f6f91); color: #14182a; }
.btn.core { border-radius: 16px; background: linear-gradient(145deg, #ff2f92, #31001d); }
.btn.locked { opacity: 0.11; pointer-events: none; background: rgba(255,255,255,.04); box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }

@keyframes pulseBad { from { box-shadow: 0 0 4px rgba(255,84,112,.2); } to { box-shadow: 0 0 22px rgba(255,84,112,.75); } }
@keyframes glitchy { 0% { filter: hue-rotate(0deg); } 50% { filter: hue-rotate(80deg) saturate(1.5); } }

.upgrade, .dangerBtn {
  width: 100%;
  padding: 11px 12px;
  margin: 8px 0;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel-2);
  text-align: left;
  cursor: pointer;
  transition: transform 90ms, filter 90ms;
}
.upgrade:hover, .dangerBtn:hover { transform: translateY(-1px); filter: brightness(1.15); }
.upgrade small { display: block; color: var(--muted); margin-top: 3px; }
.dangerBtn { text-align: center; background: rgba(255,84,112,0.14); }
.dangerBtn.ready { background: rgba(124,247,181,0.16); border-color: rgba(124,247,181,.4); }
.dangerBtn:disabled, .upgrade:disabled { opacity: .45; cursor: not-allowed; transform: none; }

#log {
  height: 210px;
  overflow: auto;
  font-size: 12px;
  color: var(--muted);
  padding-right: 4px;
}
.logItem { margin-bottom: 7px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.glitch { color: var(--glitch); }

.float {
  position: fixed;
  pointer-events: none;
  font-weight: 900;
  text-shadow: 0 0 12px rgba(255,255,255,0.5);
  animation: floatUp 850ms ease-out forwards;
  z-index: 30;
}
@keyframes floatUp {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-60px) scale(1.35); }
}

.spark {
  position: fixed;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  pointer-events: none;
  background: white;
  box-shadow: 0 0 14px white;
  animation: spark 520ms ease-out forwards;
  z-index: 28;
}
@keyframes spark {
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

.toast {
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(0,0,0,0.72);
  border: 1px solid rgba(255,255,255,0.18);
  color: white;
  z-index: 40;
  animation: toast 1800ms ease forwards;
}
@keyframes toast { 0%,100% { opacity: 0; transform: translateX(-50%) translateY(-12px); } 12%,80% { opacity: 1; transform: translateX(-50%) translateY(0); } }

@media (max-width: 960px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  #grid-widget { min-height: 520px; }
}

/* Patch: readable compact buttons on dense grids */
.btn {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 2px;
  line-height: 1;
  font-size: clamp(7px, calc(var(--cell) * 0.24), 12px);
  min-width: 0;
}
.btn.explosive { font-size: clamp(6px, calc(var(--cell) * 0.20), 11px); }
.btn.core { font-size: clamp(6px, calc(var(--cell) * 0.18), 11px); }

/* Patch: stronger upgrade level readability */
.upgradeTop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.upgradeTop b { min-width: 0; }
.upgradeTop em {
  flex: 0 0 auto;
  font-style: normal;
  font-size: 11px;
  color: var(--good);
  border: 1px solid rgba(124,247,181,.25);
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(124,247,181,.08);
}
.upgradeCost {
  display: inline-block;
  margin-top: 7px;
  font-size: 11px;
  color: var(--warn);
}

/* Patch: automatic reboot and claim popup */
.rebootMeter {
  display: none;
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.rebootMeter.show { display: block; }
.rebootMeter span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--glitch), var(--good));
  transition: width 160ms linear;
}
.rebootPopup {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,.62);
  backdrop-filter: blur(7px);
  z-index: 65;
  padding: 18px;
  text-align: center;
}
.rebootPopup.show { display: grid; }
.rebootPopup p { color: var(--muted); margin: 0 0 14px; }
.winCard { box-shadow: 0 24px 90px rgba(0,0,0,.58), 0 0 70px rgba(124,247,181,.12), inset 0 0 30px rgba(124,247,181,.08); }
.winCard h2 { color: var(--good); font-size: 24px; letter-spacing: 0; text-transform: none; }
.wipeBtn {
  width: 100%;
  padding: 9px 12px;
  margin: 8px 0;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  cursor: pointer;
}
.wipeBtn:hover { color: var(--text); filter: brightness(1.15); }
@keyframes popupIn { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Chain lightning feedback */
.chainSvg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 32;
  filter: drop-shadow(0 0 8px rgba(101,230,255,.95));
}
.chainPath {
  fill: none;
  stroke: white;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .96;
  animation: chainZap 170ms ease-out forwards;
}
.btn.chainFlash {
  filter: brightness(3.2) saturate(.15);
  box-shadow: 0 0 26px white, inset 0 0 0 1px white;
}
@keyframes chainZap {
  0% { opacity: 0; stroke-dasharray: 0 1000; }
  35% { opacity: 1; }
  100% { opacity: 0; stroke-dasharray: 1000 0; }
}

/* Loss / retry modal */
.modalBackdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,.66);
  backdrop-filter: blur(6px);
  z-index: 60;
  padding: 18px;
}
.modalBackdrop.show { display: grid; }
.modalCard {
  width: min(430px, 100%);
  border-radius: 22px;
  padding: 22px;
  background: linear-gradient(145deg, rgba(28, 31, 50, .96), rgba(10, 12, 22, .98));
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 24px 80px rgba(0,0,0,.55), inset 0 0 30px rgba(255,84,112,.06);
  animation: popupIn 180ms ease-out;
}
.modalCard h2 { color: var(--bad); font-size: 22px; letter-spacing: 0; text-transform: none; }
.modalCard p { margin: 0 0 14px; }
.modalKicker {
  color: var(--warn);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .14em;
  margin-bottom: 8px;
}
.lossStats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 16px 0;
}
.lossStats div {
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 13px;
  background: rgba(255,255,255,.045);
  padding: 10px;
}
.lossStats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}
.lossStats strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

/* Faster reboot win-state visuals */
body.rebooting #grid-widget { box-shadow: inset 0 0 70px rgba(124,247,181,.28), 0 0 45px rgba(101,230,255,.18); }
body.rebooting .grid { animation: stabilizeGrid 480ms linear infinite alternate; }
body.rebooting .btn { filter: brightness(1.45) saturate(.8); box-shadow: 0 0 18px rgba(124,247,181,.35), inset 0 0 0 1px rgba(255,255,255,.4); }
@keyframes stabilizeGrid { from { transform: scale(.995); } to { transform: scale(1.01); } }

/* More readable feedback text */
.float { font-size: 16px; letter-spacing: .02em; }
.float-good { color: var(--good); text-shadow: 0 0 14px rgba(124,247,181,.75); }
.float-bad { color: var(--bad); text-shadow: 0 0 14px rgba(255,84,112,.75); }
.float-warn { color: var(--warn); text-shadow: 0 0 14px rgba(255,209,102,.75); }
.float-glitch { color: var(--purple); text-shadow: 0 0 14px rgba(184,134,255,.8); }

/* Bombs */
.btn.timedBomb { background: linear-gradient(145deg, #ff965c, #681b00); animation: bombPulse 500ms infinite alternate; }
.btn.explosive { font-size: clamp(14px, calc(var(--cell) * 0.48), 22px); }
.btn.timedBomb { font-size: clamp(11px, calc(var(--cell) * 0.32), 17px); }
.bombTimer {
  position: absolute;
  right: 2px;
  bottom: 1px;
  min-width: 13px;
  height: 13px;
  padding: 0 2px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 8px;
  background: rgba(0,0,0,.55);
  color: white;
}
@keyframes bombPulse { from { box-shadow: 0 0 7px rgba(255,150,92,.28); } to { box-shadow: 0 0 24px rgba(255,150,92,.85); } }
.explosionRing {
  position: fixed;
  width: 16px;
  height: 16px;
  border: 3px solid var(--warn);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 35;
  box-shadow: 0 0 25px var(--warn), inset 0 0 20px rgba(255,255,255,.45);
  animation: explosionRing 500ms ease-out forwards;
}
@keyframes explosionRing { to { width: 155px; height: 155px; opacity: 0; border-width: 1px; } }

/* Defuse modal */
.defuseCard h2 { color: var(--warn); text-transform: none; letter-spacing: 0; font-size: 22px; }
.defuseSequence { display: flex; justify-content: center; gap: 8px; margin: 14px 0; }
.defuseSequence span { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); font-weight: 900; }
.defuseSequence span.current { border-color: var(--warn); box-shadow: 0 0 16px rgba(255,209,102,.35); }
.defuseSequence span.done { color: var(--good); border-color: rgba(124,247,181,.45); background: rgba(124,247,181,.12); }
.defusePad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.defusePad .dangerBtn { font-size: 20px; text-align: center; margin: 0; }
.winStats { margin-top: 10px; }

.defuseRing {
  position: fixed;
  width: 18px;
  height: 18px;
  border: 3px solid var(--good);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 35;
  box-shadow: 0 0 25px var(--good), inset 0 0 20px rgba(124,247,181,.35);
  animation: defuseRing 560ms ease-out forwards;
}
@keyframes defuseRing { to { width: 120px; height: 120px; opacity: 0; border-width: 1px; } }

/* Patch: centered victory modal and green success title */
.winBackdrop {
  z-index: 75;
}
.modalCard.winCard {
  text-align: center;
  box-shadow: 0 24px 90px rgba(0,0,0,.58), 0 0 70px rgba(124,247,181,.18), inset 0 0 30px rgba(124,247,181,.10);
}
.modalCard.winCard h2 {
  color: var(--good);
}
.winKicker {
  color: var(--good);
}

/* Patch: make dense grid clicks feel precise and responsive */
.btn {
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  isolation: isolate;
  transform-origin: center;
}
.btn:hover {
  transform: translateY(-1px) scale(1.015);
  z-index: 2;
}
.btn:active {
  transform: scale(0.97);
}
.btn > * {
  pointer-events: none;
}
.bombTimer {
  pointer-events: none;
}
.grid {
  user-select: none;
}

/* Trojan buttons */
.btn.bugTrojan {
  background: linear-gradient(145deg, #ff8bd1, #681848);
  font-size: clamp(14px, calc(var(--cell) * 0.48), 22px);
  animation: trojanWiggle 900ms ease-in-out infinite alternate;
}
.btn.radTrojan {
  background: linear-gradient(145deg, #d9ff65, #486000);
  color: #182000;
  font-size: clamp(14px, calc(var(--cell) * 0.48), 22px);
  box-shadow: 0 0 16px rgba(217,255,101,.28), inset 0 0 0 1px rgba(255,255,255,.25);
}
@keyframes trojanWiggle {
  from { filter: hue-rotate(-10deg) brightness(1); }
  to { filter: hue-rotate(18deg) brightness(1.2); }
}

/* Bug Trojan maze */
.mazeCard h2 { color: var(--warn); text-transform: none; letter-spacing: 0; font-size: 22px; }
.mazeTimer {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.mazeTimer strong { color: var(--warn); }
.mazeBoard.tileMaze {
  --maze-size: 13;
  position: relative;
  width: min(390px, 92vw);
  aspect-ratio: 1 / 1;
  margin: 12px auto 14px;
  display: grid;
  grid-template-columns: repeat(var(--maze-size), 1fr);
  grid-template-rows: repeat(var(--maze-size), 1fr);
  gap: 1px;
  padding: 8px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(5, 8, 18, .96);
  touch-action: none;
  user-select: none;
  box-shadow: inset 0 0 24px rgba(101,230,255,.08);
}
.mazeTile {
  min-width: 0;
  min-height: 0;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: clamp(8px, 2vw, 13px);
  font-weight: 1000;
  line-height: 1;
  pointer-events: none;
}
.mazeTile.wall {
  background: linear-gradient(135deg, rgba(255,84,112,.55), rgba(184,134,255,.42));
  box-shadow: inset 0 0 8px rgba(255,255,255,.08);
}
.mazeTile.path {
  background: rgba(101,230,255,.08);
  border: 1px solid rgba(101,230,255,.08);
}
.mazeTile.start {
  color: var(--glitch);
  background: rgba(101,230,255,.20);
  border-color: rgba(101,230,255,.50);
}
.mazeTile.finish {
  color: var(--good);
  background: rgba(124,247,181,.22);
  border-color: rgba(124,247,181,.60);
  box-shadow: 0 0 14px rgba(124,247,181,.20);
}
.mazeTile.tracerTile {
  color: #06101c;
  background: #fff;
  border-color: var(--glitch);
  box-shadow: 0 0 18px rgba(101,230,255,.9), 0 0 4px #fff inset;
  transform: scale(1.08);
}

/* Patch: hostile timers and freeze button */
.btn.freeze {
  background: linear-gradient(145deg, #d8f7ff, #2d7cff);
  color: #071323;
  font-size: clamp(14px, calc(var(--cell) * 0.48), 22px);
  box-shadow: 0 0 14px rgba(101,230,255,.32), inset 0 0 0 1px rgba(255,255,255,.35);
}
.btn.frozen {
  filter: saturate(.55) brightness(1.35) hue-rotate(165deg);
  animation-play-state: paused !important;
  box-shadow: 0 0 18px rgba(216,247,255,.55), inset 0 0 0 2px rgba(216,247,255,.75);
}
.freezeBadge {
  position: absolute;
  left: 3px;
  bottom: 2px;
  font-size: 10px;
  line-height: 1;
  pointer-events: none;
}
.btn.bugTrojan .bombTimer,
.btn.radTrojan .bombTimer {
  background: rgba(0,0,0,.42);
}
.btn.radTrojan {
  animation: radCharge 900ms infinite alternate;
}
@keyframes radCharge {
  from { box-shadow: 0 0 8px rgba(217,255,101,.22), inset 0 0 0 1px rgba(255,255,255,.20); }
  to { box-shadow: 0 0 28px rgba(217,255,101,.85), inset 0 0 12px rgba(217,255,101,.45); }
}


/* Hidden Rootkit event */
.btn.rootkit {
  background: radial-gradient(circle at 50% 45%, #210014 0%, #6d0036 52%, #140008 100%);
  border-radius: 6px;
  color: #ffbad8;
  font-size: clamp(8px, calc(var(--cell) * 0.22), 13px);
  box-shadow: 0 0 22px rgba(255,47,146,.48), inset 0 0 14px rgba(0,0,0,.55), inset 0 0 0 1px rgba(255,186,216,.35);
  animation: rootkitPulse 620ms infinite alternate;
}
.btn.tether {
  background: conic-gradient(from 45deg, #fff 0 12%, #130017 12% 25%, #65e6ff 25% 38%, #130017 38% 50%, #fff 50% 62%, #130017 62% 75%, #65e6ff 75% 88%, #130017 88% 100%);
  color: #071323;
  border-radius: 50% 18% 50% 18%;
  font-size: clamp(14px, calc(var(--cell) * 0.50), 24px);
  box-shadow: 0 0 30px rgba(101,230,255,.9), 0 0 10px #fff inset;
  animation: tetherBeacon 430ms infinite alternate;
}
@keyframes rootkitPulse {
  from { filter: brightness(.9); transform: scale(.99); }
  to { filter: brightness(1.35); transform: scale(1.025); }
}
@keyframes tetherBeacon {
  from { filter: brightness(1) saturate(1.1); transform: rotate(-2deg) scale(.96); }
  to { filter: brightness(1.75) saturate(1.5); transform: rotate(2deg) scale(1.06); }
}


/* Upgrade cards with buy/sell controls */
.upgradeCard {
  padding: 11px 12px;
  margin: 8px 0;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 12px;
  background: var(--panel-2);
}
.upgradeCard small { display: block; color: var(--muted); margin-top: 3px; }
.upgradeActions {
  display: grid;
  grid-template-columns: 1fr .78fr;
  gap: 7px;
  margin-top: 8px;
}
.upgradeActions .upgrade {
  margin: 0;
  text-align: center;
  padding: 8px 9px;
}
.sellUpgrade {
  background: rgba(255, 209, 102, 0.10);
  color: var(--warn);
}

/* UI polish: currency clarity, responsive sidebars, future-proof upgrades/log */
.sidebar-left,
.sidebar-right {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#core-info-widget,
#prestige-widget,
#upgrades-widget,
#event-log-widget {
  min-height: 0;
}

#upgrades-widget {
  display: flex;
  flex-direction: column;
  flex: 1 1 58%;
  min-height: 260px;
}

#event-log-widget {
  display: flex;
  flex-direction: column;
  flex: 1 1 42%;
  min-height: 180px;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 10px;
}

.currencyCard {
  margin: 12px 0 10px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(124,247,181,.16), rgba(101,230,255,.10));
  border: 1px solid rgba(124,247,181,.35);
  box-shadow: inset 0 0 22px rgba(124,247,181,.06), 0 0 24px rgba(124,247,181,.08);
}
.currencyCard span,
.currencyCard small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.currencyCard strong {
  display: block;
  margin: 3px 0;
  font-size: 30px;
  line-height: 1;
  color: var(--good);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(124,247,181,.22);
}

.upgradeHeader,
.logHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.upgradeHeader h2,
.logHeader h2 { margin: 0; }
.upgradeHeader small {
  color: var(--warn);
  font-size: 11px;
  text-align: right;
}
.upgradeList {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}
.upgradeCard {
  display: grid;
  gap: 5px;
}
.upgradeActions {
  grid-template-columns: minmax(0, 1fr) minmax(74px, .72fr);
}
.upgradeActions .upgrade {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#log {
  flex: 1 1 auto;
  min-height: 120px;
  height: auto;
  max-height: none;
  overflow: auto;
  scrollbar-width: thin;
}
.logItem {
  overflow-wrap: anywhere;
}
.feedbackBtn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(101,230,255,.35);
  background: rgba(101,230,255,.10);
  color: var(--glitch);
  font-size: 11px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
.feedbackBtn:hover { filter: brightness(1.2); }
.float-agentFloat {
  color: var(--good);
  letter-spacing: .06em;
  word-spacing: .28em;
  text-shadow: 0 0 16px rgba(124,247,181,.9), 0 2px 8px rgba(0,0,0,.65);
}

@media (max-width: 1180px) {
  .app { grid-template-columns: 280px minmax(0, 1fr) 280px; gap: 12px; padding: 12px; }
  .panel { padding: 12px; }
}

@media (max-width: 960px) {
  .sidebar-left,
  .sidebar-right {
    overflow: visible;
  }
  #upgrades-widget,
  #event-log-widget {
    flex: none;
    min-height: 0;
  }
  .upgradeList,
  #log {
    max-height: 360px;
  }
}

/* Linear beginner progression + responsive dashboard pass */
.app {
  grid-template-columns: minmax(270px, 330px) minmax(360px, 1fr) minmax(260px, 320px);
  align-items: stretch;
}

.sidebar-left,
.sidebar-right,
.center {
  min-height: 0;
}

.sidebar-left {
  overflow: hidden;
}

#core-info-widget {
  flex: 0 0 auto;
}

#upgrades-widget {
  flex: 1 1 auto;
  min-height: 0;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 10px;
}

#event-log-widget {
  flex: 1 1 auto;
  min-height: 220px;
}

#prestige-widget,
#run-stats-widget {
  flex: 0 0 auto;
}

.levelCard {
  margin: 10px 0 12px;
  padding: 11px 12px;
  border-radius: 14px;
  background: rgba(101,230,255,.08);
  border: 1px solid rgba(101,230,255,.22);
}
.levelCard span,
.levelCard small { display:block; color: var(--muted); font-size: 11px; }
.levelCard strong { display:block; margin: 3px 0; color: var(--glitch); }
.feedbackWide { width: 100%; }

.systemHealthCard {
  display: grid;
  grid-template-columns: minmax(210px, .85fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  padding: 9px 10px;
  border-radius: 14px;
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(255,255,255,.09);
}
.healthBars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.healthBars > div {
  min-width: 0;
}
.healthBars span,
.healthBars strong {
  font-size: 11px;
  line-height: 1;
}
.healthBars span { color: var(--muted); }
.healthBars strong { float: right; font-variant-numeric: tabular-nums; }
.miniBar {
  clear: both;
  height: 6px;
  margin-top: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.miniBar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--good), var(--glitch));
}
.miniBar.bad i { background: linear-gradient(90deg, var(--bad), var(--warn)); }
.threatPills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}
.threatPills span {
  min-width: 45px;
  padding: 4px 6px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
}
.threatPills b { color: var(--warn); font-variant-numeric: tabular-nums; }

.bossBarShell {
  height: 0;
  overflow: hidden;
  opacity: 0;
  transition: height 160ms ease, opacity 160ms ease, margin 160ms ease;
  margin: 0;
}
.bossBarShell.show {
  height: 46px;
  opacity: 1;
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(255,84,112,.36);
  background: linear-gradient(135deg, rgba(255,84,112,.16), rgba(184,134,255,.10));
  box-shadow: 0 0 22px rgba(255,84,112,.10);
}
.bossMeta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 900;
  color: #ffbad8;
}
.bossMeta strong { color: white; font-variant-numeric: tabular-nums; }
.bossBar {
  height: 9px;
  margin-top: 6px;
  border-radius: 999px;
  background: rgba(0,0,0,.28);
  overflow: hidden;
}
.bossBar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--bad), var(--purple));
  box-shadow: 0 0 18px rgba(255,84,112,.45);
}

.runStatsCompact {
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.compactStats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.compactStats span {
  padding: 7px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,.045);
  color: var(--muted);
  font-size: 11px;
}
.compactStats b {
  float: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Condensed future-proof upgrades */
.upgradeList {
  display: grid;
  gap: 8px;
  align-content: start;
}
.upgradeCard.compactUpgrade {
  margin: 0;
  padding: 9px;
  gap: 6px;
}
.upgradeName {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.upgradeName i {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255,255,255,.08);
  font-style: normal;
  flex: 0 0 auto;
}
.upgradeName b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compactUpgrade small {
  font-size: 11px;
  line-height: 1.25;
  margin: 0;
}
.upgradeMiniActions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.upgradeMiniActions .upgrade {
  min-width: 0;
  margin: 0;
  padding: 6px 4px;
  text-align: center;
  font-size: 11px;
  border-radius: 9px;
}
.upgradeMiniActions .upgrade span {
  display: block;
  margin-top: 1px;
  color: var(--warn);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.sellRow .upgrade span { color: var(--good); }

/* Custom application scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(101,230,255,.55) rgba(255,255,255,.05);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track {
  background: rgba(255,255,255,.045);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(101,230,255,.75), rgba(184,134,255,.65));
  border: 2px solid rgba(8,9,15,.95);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(124,247,181,.85), rgba(101,230,255,.75));
}

@media (max-width: 1180px) {
  .app { grid-template-columns: 280px minmax(0, 1fr) 280px; }
  .systemHealthCard { grid-template-columns: 1fr; }
  .threatPills { justify-content: center; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; overflow: visible; }
  body { overflow: auto; }
  .panel { min-height: auto; }
  .systemHealthCard { position: sticky; top: 8px; z-index: 12; backdrop-filter: blur(8px); }
  #grid-widget { min-height: 520px; }
  .upgradeList, #log { max-height: 420px; }
}
.rebootCondition {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
  padding: 3px 6px 0;
  text-align: center;
}

/* Tutorial reliability + dashboard cleanup */
.systemHealthCard {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 8px;
}
.healthFooter {
  display: grid;
  grid-template-columns: minmax(170px, .9fr) minmax(220px, 1.1fr);
  gap: 8px;
  align-items: center;
}
.rebootCondition {
  grid-column: auto;
  text-align: left;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.07);
}
.healthFooter .threatPills {
  justify-content: flex-end;
}
.upgradeCard.tutorialFocus {
  border-color: rgba(124,247,181,.85);
  box-shadow: 0 0 0 1px rgba(124,247,181,.22), 0 0 28px rgba(124,247,181,.22), inset 0 0 18px rgba(124,247,181,.08);
  animation: helperFocus 850ms ease-in-out infinite alternate;
}
@keyframes helperFocus {
  from { filter: brightness(1); transform: translateY(0); }
  to { filter: brightness(1.18); transform: translateY(-1px); }
}
@media (max-width: 1180px) {
  .healthFooter { grid-template-columns: 1fr; }
  .healthFooter .threatPills { justify-content: flex-start; }
}

/* Tutorial objective targeting */
.btn.objective {
  outline: 2px solid var(--good);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px rgba(124,247,181,.18), 0 0 24px rgba(124,247,181,.55), inset 0 0 0 1px rgba(255,255,255,.35);
  animation: objectivePulse 850ms ease-in-out infinite alternate;
}
.btn.objective::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 14px;
  border: 1px solid rgba(124,247,181,.55);
  pointer-events: none;
}
@keyframes objectivePulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.25); }
}
