/* Full-viewport background */
#bg {
  position: fixed;
  inset: 0;
  background: url("Background.jpg") center / cover no-repeat;
  z-index: -1;
  filter: brightness(0.55) contrast(1.1); /* darken slightly so HUD pops */
}

/* Stats bar – glass + neon */
#stats-bar {
  display: flex;
  flex-wrap: wrap;              /* allow wrapping instead of horizontal overflow */
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(90deg, rgba(0,20,30,0.9), rgba(0,40,50,0.8));
  border-bottom: 2px solid #00ff9f;
  box-shadow: 0 0 20px rgba(0,255,159,0.35);
  backdrop-filter: blur(6px);
  overflow-x: hidden;           /* safety net */
  max-width: 100%;
  box-sizing: border-box;
}

.title {
  font-size: 1.35rem;
  letter-spacing: 0.1em;
  text-shadow: 0 0 8px #00ff9f;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Individual stats */
.stat-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4.5rem;
}

.label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  opacity: 0.75;
  margin-bottom: 0.15rem;
}

.value {
  font-size: 1.6rem;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid #00ff9f;
  border-radius: 4px;
  padding: 0.15rem 0.6rem;
  min-width: 2.2rem;
  text-align: center;
  box-shadow: 0 0 10px rgba(0, 255, 159, 0.4);
  transition: color 0.2s, box-shadow 0.2s;
}

/* Warning states (optional JS-driven classes) */
.value.danger  { color: #ff3355; border-color: #ff3355; box-shadow: 0 0 12px #ff3355; }
.value.warning { color: #ffcc00; border-color: #ffcc00; box-shadow: 0 0 12px #ffcc00; }

/* Memory slots */
.memory {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.memory .slot {
  width: 70px;
  height: 70px;
  border: 1px solid #00ff9f;
  border-radius: 4px;
  background: rgba(0,0,0,0.45);
  overflow: hidden;
}

.memory .slot.empty {
  opacity: 0.4;
}

/* Make the rest of the page sit cleanly under the bar */
body {
  margin: 0;
  min-height: 100vh;
  color: #e0ffe0;
  overflow-x: hidden;
}
#game {
  padding: 1rem;
  /* board grid, side panels, etc. */
}

/* ──────────────────────────────────────────────
   Stat-change animations
   ────────────────────────────────────────────── */

/* Base transition so every value change is smooth */
.value {
  transition:
    transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
    color 0.3s ease,
    box-shadow 0.3s ease,
    border-color 0.3s ease,
    background 0.3s ease;
}

/* Quick “pop” when the number actually changes */
@keyframes stat-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.value.pop {
  animation: stat-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Green flash – beneficial change (Credit↑, Tbps↑, Brain↑, Noise↓, Timer↑) */
@keyframes flash-good {
  0%   { box-shadow: 0 0 10px rgba(0, 255, 159, 0.4); background: rgba(0,0,0,0.45); }
  30%  { box-shadow: 0 0 28px #00ff9f, 0 0 12px #00ff9f; background: rgba(0, 255, 159, 0.25); }
  100% { box-shadow: 0 0 10px rgba(0, 255, 159, 0.4); background: rgba(0,0,0,0.45); }
}

.value.flash-good {
  animation: flash-good 0.6s ease-out;
}

/* Red flash – harmful change (Noise↑, Brain↓, Timer↓) */
@keyframes flash-bad {
  0%   { box-shadow: 0 0 10px rgba(0, 255, 159, 0.4); background: rgba(0,0,0,0.45); }
  30%  { box-shadow: 0 0 28px #ff3355, 0 0 12px #ff3355; background: rgba(255, 51, 85, 0.3); color: #ff3355; border-color: #ff3355; }
  100% { box-shadow: 0 0 10px rgba(0, 255, 159, 0.4); background: rgba(0,0,0,0.45); }
}

.value.flash-bad {
  animation: flash-bad 0.65s ease-out;
}

/* Continuous subtle pulse when a value is in the danger zone */
@keyframes danger-pulse {
  0%, 100% { box-shadow: 0 0 8px #ff3355; }
  50%      { box-shadow: 0 0 22px #ff3355, 0 0 10px #ff3355; }
}

.value.danger {
  color: #ff3355;
  border-color: #ff3355;
  animation: danger-pulse 1.4s ease-in-out infinite;
}

/* Slightly softer warning (orange) */
@keyframes warning-pulse {
  0%, 100% { box-shadow: 0 0 8px #ffcc00; }
  50%      { box-shadow: 0 0 18px #ffcc00; }
}

.value.warning {
  color: #ffcc00;
  border-color: #ffcc00;
  animation: warning-pulse 1.6s ease-in-out infinite;
}

/* ──────────────────────────────────────────────
   5 × 6 Playing Grid
   ────────────────────────────────────────────── */
#board-container {
  display: flex;
  justify-content: center;
  margin: 1.5rem auto;
  padding: 1rem;
}

#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 96px);
  grid-template-rows: repeat(6, 96px);
  gap: 4px;
  background: rgba(0, 10, 20, 0.7);
  border: 2px solid #00ff9f;
  box-shadow: 0 0 25px rgba(0, 255, 159, 0.3);
  padding: 6px;
  border-radius: 6px;
}

.cell {
  position: relative;
  width: 96px;
  height: 96px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(0, 255, 159, 0.25);
  border-radius: 4px;
  overflow: hidden;
}

.cell img.tile {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Face-down server tiles */
.cell.face-down {
  background: linear-gradient(135deg, #001a1a, #003333);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #00ff9f;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-shadow: 0 0 6px #00ff9f;
  border: 1px solid #00ff9f;
}
.cell.face-down::after {
  content: "SERVER";
}

/* Hacker token */
#hacker-token {
  position: absolute;
  width: 38px;
  height: 38px;
  background: radial-gradient(circle, #00ff9f 20%, #00cc77 70%, transparent 80%);
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow:
    0 0 12px #00ff9f,
    0 0 24px #00ff9f,
    inset 0 0 8px rgba(255,255,255,0.6);
  z-index: 20;
  pointer-events: none;
  transition: left 0.35s ease, top 0.35s ease;
  transform: translate(-50%, -50%);
}

/* Optional: small “Hacker” label inside the token */
#hacker-token::after {
  content: "Hacker";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: bold;
  color: #003322;
}

/* ──────────────────────────────────────────────
   3D Tile Flip
   ────────────────────────────────────────────── */
.cell {
  perspective: 600px;          /* enables 3D space */
}

.tile-card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.tile-card.flipped {
  transform: rotateY(180deg);
}

/* Both faces share the same size and sit on top of each other */
.tile-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Front = real artwork */
.tile-face.front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Back = face-down “SERVER” side */
.tile-face.back {
  background: linear-gradient(135deg, #001a1a, #003333);
  color: #00ff9f;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-shadow: 0 0 6px #00ff9f;
  border: 1px solid #00ff9f;
  transform: rotateY(180deg);   /* pre-rotated so it shows correctly when flipped */
}

.tile-face.back::after {
  content: "SERVER";
}

/* Legal placement / move highlights */
.cell.legal {
  outline: 2px solid #00ff9f;
  box-shadow: 0 0 12px #00ff9f;
  cursor: pointer;
}

/* Effect tiles (noise, credit, logic-gate, ice) */
.cell.has-effect {
  box-shadow: 0 0 14px #ff3355;
  outline: 1px solid #ff3355;
}

/* Efreet permanent EXIT – orange square, 2px smaller than the cell */
.cell.has-exit {
  /* optional outer glow on the cell itself */
  box-shadow: 0 0 12px rgba(255, 136, 0, 0.45);
}

.cell.has-exit::before {
  content: "";
  position: absolute;
  /* cell is 96×96; inset 1px each side → 94×94 (2px smaller) */
  inset: 1px;
  border: 3px solid #ff8800;
  border-radius: 0;                 /* square, not circle */
  box-shadow:
    0 0 10px #ff8800,
    inset 0 0 6px rgba(255, 136, 0, 0.35);
  pointer-events: none;
  z-index: 5;
  box-sizing: border-box;
}

/* Visual ICE token overlay */
.ice-token {
  position: absolute;
  inset: 8px;
  border-radius: 4px;
  background: rgba(0, 30, 40, 0.85);
  border: 2px solid #00e5ff;
  color: #00e5ff;
  font-size: 0.65rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 0 6px #00e5ff;
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.5);
}
.cell {
  position: relative; /* needed for absolute ICE token */
}

/* Visual ICE token overlay */
.ice-token {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 60px;
  height: 60px;
  z-index: 6;
  pointer-events: none;
  filter: drop-shadow(0 0 4px #ff3355);
}
.ice-token img {
  width: 98%;
  height: 98%;
  object-fit: contain;
  border-radius: 3px;
}
.cell { position: relative; } /* needed for absolute token */

#hacker-token.on-server {
  opacity: 0.45;
  filter: brightness(1.2);
}

/* Side panel column */
#side-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.5rem;
  width: 300px;                 /* ≈ 3 tiles */
  flex-shrink: 0;
}

/* ── Message Field: 3 tiles wide × 2 tiles high ── */
#message-field {
  width: 300px;
  height: 200px;                /* ≈ 2 tiles */
  background: #000;
  border: 2px solid #00ff9f;
  border-radius: 6px;
  box-shadow: 0 0 14px rgba(0,255,159,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0.5rem;
  box-sizing: border-box;
  overflow: auto;
  color: #00ff9f;
  font-family: "Courier New", monospace;
}

#message-field .mf-label {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-bottom: 0.25rem;
  text-align: center;
}

#next-tile-img {
  width: 72px;
  height: 72px;
  border: 2px solid #00ff9f;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,255,159,0.4);
  display: none;
  object-fit: contain;
}

#rotation-controls {
  margin-top: 0.3rem;
  display: none;
  gap: 0.4rem;
}

#rotation-controls button {
  background: rgba(0,0,0,0.6);
  border: 1px solid #00ff9f;
  color: #00ff9f;
  font-family: inherit;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}
#rotation-controls button:hover {
  background: rgba(0,255,159,0.2);
}

#next-tile-name {
  margin-top: 0.2rem;
  font-size: 0.8rem;
  text-align: center;
}

#phase-ui {
  width: 100%;
  text-align: center;
  margin-top: 0.4rem;
}

#phase-message {
  min-height: 1.3em;
  font-size: 0.85rem;
  color: #00ff9f;
}

#phase-buttons {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

#phase-buttons button {
  background: rgba(0,0,0,0.6);
  border: 1px solid #00ff9f;
  color: #00ff9f;
  font-family: inherit;
  cursor: pointer;
  padding: 0.3rem 0.7rem;
  border-radius: 3px;
}
#phase-buttons button:hover {
  background: rgba(0,255,159,0.2);
  box-shadow: 0 0 8px #00ff9f;
}

/* ── Software Market: black, 4 × 3 grid ── */
#message-field {
  width: 300px;
  min-height: 200px;
  background: #000;
  border: 2px solid #00ff9f;
  border-radius: 6px;
  padding: 0.5rem;
  box-sizing: border-box;
  color: #00ff9f;
}

#software-shop h3 {
  margin: 0 0 0.5rem;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
}

#software-shop {
  background: #000;
  border: 2px solid #00ff9f;
  border-radius: 6px;
  padding: 0.6rem;
  color: #00ff9f;
}

#software-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);   /* 4 tiles wide */
  grid-template-rows: repeat(4, auto);    /* 3 rows high */
  gap: 0.4rem;
  justify-items: center;
}

.soft-card {
  width: 64px;
  cursor: pointer;
  text-align: center;
  border: 1px solid #00ff9f;
  border-radius: 4px;
  padding: 3px;
  background: rgba(0, 15, 25, 0.9);
}

.soft-card:hover {
  box-shadow: 0 0 10px #00ff9f;
  background: rgba(0,40,50,0.95);
}

.soft-card img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.soft-card .soft-name {
  font-size: 0.8rem;
  margin-top: 2px;
}

.soft-card .soft-cost {
  font-size: 0.8rem;
  opacity: 0.8;
}

.slot {
  position: relative;
  width: 42px;
  height: 42px;
  border: 1px dashed #00ff9f;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.slot.exhausted {
  opacity: 0.7;
  cursor: default;
}
.slot.exhausted::after {
  content: "⏳";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  font-size: 1.2rem;
  pointer-events: none;
}

.slot.filled {
  border-style: solid;
  background: rgba(0, 255, 159, 0.15);
  box-shadow: 0 0 8px #00ff9f;
}