:root {
  --bg: #040810;
  --surface: rgba(5, 14, 28, 0.95);
  --surface-2: rgba(8, 20, 38, 0.7);
  --green: #00e87a;
  --green-bright: #00ff88;
  --green-dim: rgba(0, 232, 122, 0.18);
  --purple: #a855f7;
  --purple-dim: rgba(168, 85, 247, 0.2);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.12);
  --text: #c8e4ff;
  --text-dim: #4a6a88;
  --border: rgba(0, 232, 122, 0.15);
  --border-bright: rgba(0, 232, 122, 0.55);
  --red: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Mono", monospace;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

/* ---- BACKGROUND ---- */
.bg-grid {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 232, 122, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 232, 122, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 0%, transparent 100%);
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.06) 3px,
    rgba(0, 0, 0, 0.06) 4px
  );
  z-index: 999;
}

/* ---- FRAME ---- */
.frame {
  width: min(1320px, 97vw);
  margin: 1.2rem auto;
  padding: 1.1rem;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, rgba(5, 14, 26, 0.97), rgba(3, 8, 16, 0.98));
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.8), 0 0 160px rgba(0, 232, 122, 0.03);
}

/* ---- TOPBAR ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.title-block { flex: 0 0 auto; }

.era-block {
  flex: 1;
  min-width: 180px;
}

.rate-block {
  flex: 0 0 auto;
  text-align: right;
}

h1, h2 {
  font-family: "Oxanium", sans-serif;
  letter-spacing: 0.08em;
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 2vw + 1rem, 2.6rem);
  color: var(--green-bright);
  text-shadow: 0 0 32px rgba(0, 255, 136, 0.4);
}

h2 {
  font-size: 0.82rem;
  color: var(--green);
  margin-bottom: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.label {
  color: var(--text-dim);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 0.2rem;
}

.era-name {
  font-family: "Oxanium", sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  margin: 0 0 0.35rem;
}

.era-bar-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  margin-bottom: 0.25rem;
}

.era-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--purple));
  width: 0%;
  transition: width 0.6s ease;
  box-shadow: 0 0 8px rgba(0, 232, 122, 0.4);
}

.era-next {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin: 0;
}

.rate-value {
  font-family: "Oxanium", sans-serif;
  font-size: 1.05rem;
  color: var(--amber);
}

/* ---- MAIN GRID ---- */
.grid {
  display: grid;
  grid-template-columns: 230px 250px 1fr;
  gap: 0.9rem;
  align-items: start;
}

.right-column {
  display: grid;
  gap: 0.9rem;
}

.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.9rem;
}

/* ---- AI TERMINAL ---- */
.ai-terminal {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 560px;
  position: relative;
  border-color: rgba(0, 255, 136, 0.22);
  background: #010601;
}

/* CRT scanlines overlay on terminal */
.ai-terminal::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.14) 2px,
    rgba(0, 0, 0, 0.14) 4px
  );
  pointer-events: none;
  z-index: 3;
}

.terminal-header {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid rgba(0, 255, 136, 0.18);
  background: rgba(0, 255, 136, 0.05);
  position: relative;
  z-index: 4;
}

.terminal-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.67rem;
  color: rgba(0, 255, 136, 0.7);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ai-status-badge {
  padding: 0.1rem 0.32rem;
  border: 1px solid rgba(0, 255, 136, 0.38);
  background: rgba(0, 255, 136, 0.08);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  color: #00ff88;
  animation: status-flicker 4s ease-in-out infinite;
}

.terminal-entity-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.ai-name {
  color: #00ff88;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.04em;
}

.consciousness-track { margin-top: 0.1rem; }

.consciousness-bar-wrap {
  height: 3px;
  background: rgba(0, 255, 136, 0.08);
  overflow: hidden;
  margin-top: 0.18rem;
}

.consciousness-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #00e870, #a855f7);
  width: 0%;
  transition: width 1.2s ease;
  box-shadow: 0 0 6px rgba(0, 255, 136, 0.4);
}

.terminal-body {
  flex: 1;
  padding: 0.65rem 0.7rem;
  overflow-y: auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  line-height: 1.75;
  background: #010801;
  position: relative;
  z-index: 4;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 255, 136, 0.18) transparent;
}

.terminal-line {
  word-break: break-word;
  min-height: 1.2em;
}

.terminal-line.tier-0 { color: #00e070; font-size: 1.05rem; }
.terminal-line.tier-1 { color: rgba(0, 200, 100, 0.72); }
.terminal-line.tier-2 { color: #00cc66; }
.terminal-line.tier-3 { color: #00e878; }
.terminal-line.tier-4 { color: #a0ffd4; letter-spacing: 0.01em; }
.terminal-line.tier-5 {
  color: #ffffff;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.55);
  letter-spacing: 0.01em;
}

.terminal-cursor-line {
  padding-top: 0.1rem;
}

.terminal-cursor {
  display: inline-block;
  width: 7px;
  height: 0.9em;
  background: #00ff88;
  vertical-align: text-bottom;
  animation: cursor-blink 1.1s step-end infinite;
  box-shadow: 0 0 6px rgba(0, 255, 136, 0.6);
}

/* ---- CORE (click panel) ---- */
.core {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.value {
  font-family: "Oxanium", sans-serif;
  font-size: clamp(2rem, 3.5vw + 0.5rem, 3.4rem);
  color: var(--green-bright);
  margin: 0.2rem 0 0;
  text-shadow: 0 0 28px rgba(0, 255, 136, 0.45);
  line-height: 1;
}

.unit-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin: 0.1rem 0 0.6rem;
}

/* ---- GPU BUTTON ---- */
.gpu-btn {
  width: 190px;
  height: 190px;
  margin: 0.5rem auto 0;
  display: block;
  position: relative;
  background: #040e04;
  border: 2px solid rgba(0, 232, 122, 0.38);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  box-shadow:
    0 0 22px rgba(0, 232, 122, 0.1),
    inset 0 0 22px rgba(0, 232, 122, 0.04);
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.08s ease;
  animation: gpu-idle-pulse 3.5s ease-in-out infinite;
}

.gpu-circuit-bg {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 232, 122, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 232, 122, 0.07) 1px, transparent 1px);
  background-size: 15px 15px;
  pointer-events: none;
}

.gpu-rings {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gpu-ring-outer {
  position: absolute;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 1px solid transparent;
  border-top-color: rgba(0, 232, 122, 0.75);
  border-right-color: rgba(0, 232, 122, 0.2);
  animation: ring-cw 5s linear infinite;
}

.gpu-ring-inner {
  position: absolute;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 1px solid transparent;
  border-bottom-color: rgba(168, 85, 247, 0.65);
  border-left-color: rgba(168, 85, 247, 0.2);
  animation: ring-ccw 3.5s linear infinite;
}

.gpu-die {
  position: relative;
  z-index: 2;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, rgba(0, 232, 122, 0.18), rgba(168, 85, 247, 0.14));
  border: 1px solid rgba(0, 232, 122, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 22px rgba(0, 232, 122, 0.28),
    inset 0 0 14px rgba(0, 232, 122, 0.1);
}

.gpu-die-label {
  font-family: "Oxanium", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #00ff88;
  letter-spacing: 0.18em;
  text-shadow: 0 0 14px rgba(0, 255, 136, 0.9);
}

.gpu-btn:hover {
  border-color: rgba(0, 232, 122, 0.75);
  box-shadow:
    0 0 44px rgba(0, 232, 122, 0.22),
    inset 0 0 28px rgba(0, 232, 122, 0.07);
  filter: none;
}

.gpu-btn:active {
  border-color: #00ff88;
  box-shadow:
    0 0 70px rgba(0, 255, 136, 0.48),
    inset 0 0 44px rgba(0, 255, 136, 0.14);
  transform: scale(0.95);
  animation: none;
}

.btn-hint {
  font-size: 0.62rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-align: center;
  margin: 0.5rem 0 0.8rem;
  text-transform: uppercase;
}

/* ---- STATS ---- */
.stats {
  width: 100%;
  display: grid;
  gap: 0.38rem;
  margin-top: 0.3rem;
}

.stats div {
  display: flex;
  justify-content: space-between;
  background: var(--surface-2);
  padding: 0.38rem 0.5rem;
  border-left: 2px solid var(--green);
  font-size: 0.76rem;
}

.stats div span { color: var(--text-dim); }
.stats div strong { color: var(--green); font-weight: 600; }

/* ---- CARDS ---- */
.list { display: grid; gap: 0.45rem; }

.upgrades-grid {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.projects-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.card {
  padding: 0.6rem 0.65rem;
  border: 1px solid rgba(0, 232, 122, 0.16);
  background: linear-gradient(150deg, rgba(6, 18, 10, 0.9), rgba(4, 10, 18, 0.9));
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card h3 {
  font-family: "Oxanium", sans-serif;
  margin: 0 0 0.25rem;
  font-size: 0.84rem;
  color: var(--text);
  letter-spacing: 0.03em;
}

.card p {
  margin: 0.12rem 0;
  color: var(--text-dim);
  font-size: 0.74rem;
}

.upgrade-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.upgrade-head h3 { margin: 0; }

.owned-badge {
  margin: 0;
  padding: 0.1rem 0.35rem;
  border: 1px solid rgba(0, 232, 122, 0.35);
  background: rgba(0, 232, 122, 0.1);
  color: var(--green);
  font-family: "Oxanium", sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.cost-line { color: rgba(200, 228, 255, 0.5) !important; }

.card button {
  margin-top: 0.38rem;
  width: 100%;
  font-size: 0.72rem;
  padding: 0.36rem 0.5rem;
}

.completed-label {
  color: var(--green) !important;
  font-size: 0.7rem !important;
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* Affordable highlight */
.card.affordable {
  border-color: rgba(0, 232, 122, 0.58);
  box-shadow: 0 0 12px rgba(0, 232, 122, 0.1);
}

.card.affordable .owned-badge {
  border-color: rgba(0, 232, 122, 0.7);
  background: rgba(0, 232, 122, 0.18);
}

.card.affordable button { animation: acquire-pulse 1.5s ease-in-out infinite; }

/* ---- BUTTONS ---- */
button {
  border: 1px solid var(--border);
  color: var(--text);
  background: linear-gradient(130deg, rgba(0, 232, 122, 0.18), rgba(0, 100, 50, 0.18));
  font-family: "Oxanium", sans-serif;
  letter-spacing: 0.07em;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.08s ease;
  text-transform: uppercase;
}

button:hover { filter: brightness(1.18); }
button:active { transform: translateY(1px) scale(0.997); }

button.muted {
  opacity: 0.38;
  cursor: default;
}

/* ---- LOGS ---- */
#logList {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow: auto;
  display: grid;
  gap: 0.3rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(245, 158, 11, 0.2) transparent;
}

#logList li {
  font-size: 0.72rem;
  border-left: 2px solid var(--amber);
  background: var(--amber-dim);
  padding: 0.3rem 0.45rem;
  color: #fde68a;
}

/* ---- FOOTER ---- */
.footer {
  margin-top: 0.9rem;
  display: flex;
  gap: 0.55rem;
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}

.danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: linear-gradient(145deg, rgba(90, 12, 12, 0.75), rgba(40, 5, 5, 0.88));
}

/* ---- CLICK FLOAT ---- */
.click-float {
  position: fixed;
  pointer-events: none;
  font-family: "Oxanium", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green-bright);
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.7);
  animation: float-up 0.85s ease-out forwards;
  z-index: 9999;
  white-space: nowrap;
}

/* ---- ANIMATIONS ---- */
@keyframes gpu-idle-pulse {
  0%, 100% {
    box-shadow: 0 0 22px rgba(0, 232, 122, 0.1), inset 0 0 22px rgba(0, 232, 122, 0.04);
  }
  50% {
    box-shadow: 0 0 38px rgba(0, 232, 122, 0.2), inset 0 0 28px rgba(0, 232, 122, 0.08);
  }
}

@keyframes ring-cw {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes ring-ccw {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}

@keyframes float-up {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  60%  { opacity: 0.9; }
  100% { opacity: 0; transform: translateY(-55px) scale(0.82); }
}

@keyframes acquire-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(0, 232, 122, 0); }
  50%       { box-shadow: 0 0 14px rgba(0, 232, 122, 0.38); }
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

@keyframes status-flicker {
  0%, 88%, 100% { opacity: 1; }
  90%            { opacity: 0.35; }
  92%            { opacity: 1; }
  94%            { opacity: 0.35; }
  96%            { opacity: 1; }
}

/* ---- RESPONSIVE ---- */
@media (max-width: 1060px) {
  .grid {
    grid-template-columns: 220px 1fr;
    grid-template-rows: auto auto;
  }

  .ai-terminal {
    grid-column: 1 / -1;
    min-height: 220px;
    flex-direction: row;
    align-items: stretch;
  }

  .terminal-header {
    width: 200px;
    flex-shrink: 0;
    border-bottom: none;
    border-right: 1px solid rgba(0, 255, 136, 0.18);
  }

  .terminal-body {
    min-height: 160px;
  }

  .core {
    grid-column: 1;
  }

  .right-column {
    grid-column: 2;
    grid-row: 2;
  }
}

@media (max-width: 700px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .ai-terminal {
    flex-direction: column;
  }

  .terminal-header {
    width: auto;
    border-right: none;
    border-bottom: 1px solid rgba(0, 255, 136, 0.18);
  }

  .topbar {
    flex-direction: column;
    gap: 0.7rem;
  }

  .rate-block { text-align: left; }

  .upgrades-grid,
  .projects-grid {
    grid-template-columns: 1fr;
  }
}
