:root {
  color-scheme: dark;
  --green: #2fd86a;
  --green-soft: rgba(47, 216, 106, 0.34);
  --text: #eaffee;
  --muted: #a7d6ad;
  --blue: #173cff;
  --blue-dark: #050b72;
  --red: #ef1d1d;
  --red-dark: #820000;
  --gold: #ffd75e;
  --cyan: #3ed7ff;
  --panel: rgba(4, 8, 12, 0.94);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  background: #030607;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  background: #030607 url("assets/pattern.jpg");
  overscroll-behavior: none;
}

button,
select {
  min-height: 44px;
  font: inherit;
  font-size: 16px;
  touch-action: manipulation;
}

button {
  color: var(--text);
  background: #06130b;
  border: 1px solid var(--green);
  border-radius: 4px;
  cursor: pointer;
}

.app {
  width: min(1180px, calc(100% - 14px));
  margin: 0 auto;
  padding: 14px 0 34px;
}

.mast {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 0 14px;
}

.title-art {
  width: min(299px, 100%);
  height: auto;
  image-rendering: pixelated;
  border: 1px solid var(--green);
  background: #081509;
}

.mast p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

h1, h2, h3, p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 4vw, 2.45rem);
  line-height: 1.08;
}

h2 {
  margin: 0 0 12px;
  color: #fff;
  font-size: 1.28rem;
}

h3 {
  margin: 20px 0 6px;
  color: var(--gold);
  font-size: 1rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 4px 0 14px;
  border-bottom: 1px solid var(--green-soft);
}

.tab {
  min-width: 0;
  padding: 8px 6px;
}

.tab.active {
  color: #001706;
  background: var(--green);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.combat-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.card,
.text-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--green-soft);
  border-radius: 6px;
  background: var(--panel);
}

.board {
  position: relative;
  display: grid;
  gap: 8px;
  overflow: hidden;
  padding: 7px;
  border: 2px solid #6f7d96;
  border-radius: 4px;
  background: #020613;
}

.classic-art {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: url("assets/back.gif") no-repeat center top / 100% auto;
  image-rendering: pixelated;
  opacity: 0.06;
  pointer-events: none;
}

.packet-grid,
.machine,
.overlay {
  position: relative;
  z-index: 1;
}

.packet-grid,
.machine-body {
  display: grid;
  grid-template-columns: minmax(52px, 0.82fr) repeat(5, minmax(25px, 1fr)) minmax(42px, 1.08fr);
  gap: 4px;
}

.label,
.blank,
.cell,
.packet-button,
.run-button {
  min-height: 40px;
  border: 1px solid #70a8ff;
  background: rgba(7, 20, 126, 0.92);
}

.label {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: "Courier New", monospace;
  font-size: 0.62rem;
  text-shadow: 1px 1px 0 #000;
}

.packet-button,
.run-button,
.packet-button:hover,
.packet-button:focus-visible,
.run-button:hover,
.run-button:focus-visible {
  min-width: 0;
  padding: 0;
  color: #fff;
  font-family: "Courier New", monospace;
  font-size: 0.86rem;
  background: #02026f;
  border-radius: 3px;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.cell::after {
  content: "";
  width: min(22px, 58%);
  aspect-ratio: 1;
  border: 1px solid #eafff0;
}

.pri-cell.on::after {
  border-color: #fff3b0;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(255, 215, 94, 0.95);
}

.compiler-cell.on::after {
  border-color: #dffbff;
  background: var(--cyan);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.78), 0 0 14px rgba(62, 215, 255, 0.95);
  transform: scale(1.16);
}

.blank {
  opacity: 0.28;
}

.machine h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  margin: 0;
  color: #fff;
  font-family: "Courier New", monospace;
  font-size: 0.92rem;
  background: var(--blue-dark);
}

.machine.enemy h2 {
  background: var(--red-dark);
}

.machine-body {
  margin-top: 5px;
}

.ram-label {
  display: flex;
  align-items: center;
  justify-content: center;
  grid-column: 1;
  color: #fff;
  border: 1px solid #70a8ff;
  background: var(--blue-dark);
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
}

.enemy .ram-label {
  border-color: #ff6c6c;
  background: var(--red-dark);
}

.ram-list {
  display: grid;
  grid-column: 2 / span 5;
  grid-template-rows: repeat(7, minmax(26px, 1fr));
  min-height: 182px;
  border: 1px solid #70a8ff;
  background: rgba(0, 12, 140, 0.72);
}

.enemy-list {
  border-color: #ff6c6c;
  background: rgba(150, 0, 0, 0.8);
}

.ram-slot {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 6px;
  color: #fff;
  border-top: 1px solid rgba(255, 255, 255, 0.72);
  font-family: "Courier New", monospace;
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ram-slot:first-child {
  border-top: 0;
}

.ram-slot.virus {
  color: #ffd5d5;
}

.ram-slot.lock {
  color: #ffe66d;
}

.cpu {
  display: grid;
  grid-template-columns: minmax(52px, 0.82fr) minmax(0, 6.1fr);
  gap: 4px;
  min-height: 40px;
  margin-top: 5px;
  padding: 3px;
  border: 2px solid #5f8bff;
  background: #020514;
}

.enemy-cpu {
  border-color: #ff4646;
}

.cpu span {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid #fff;
  background: var(--blue-dark);
  font-family: "Courier New", monospace;
}

.enemy-cpu span {
  background: var(--red-dark);
}

.cpu div {
  background: #eff3ff;
  border: 1px solid #dce6ff;
  overflow: hidden;
}

.cpu b {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--blue);
  transition: width 180ms ease;
}

.enemy-cpu b {
  background: var(--red);
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.84);
}

.overlay.active {
  display: flex;
}

.overlay-box {
  width: min(90%, 340px);
  padding: 18px;
  text-align: center;
  border: 1px solid #fff;
  border-radius: 6px;
  background: #020202;
}

.overlay-title {
  margin: 0 0 4px;
  color: #fff;
  font-size: 1.55rem;
  font-weight: 700;
}

.overlay-body {
  margin: 0 0 14px;
  color: var(--muted);
}

#startButton {
  min-width: 120px;
  min-height: 52px;
  font-size: 18px;
  font-weight: 700;
}

.status {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.status > div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(47, 216, 106, 0.24);
  border-radius: 4px;
  background: #071015;
}

.status span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.status strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.side-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

#enemyToggle.is-on {
  color: #1c0707;
  background: #ff5757;
  border-color: #ffb0b0;
}

.microcopy {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.program-list {
  display: grid;
  gap: 7px;
}

.program-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 4px;
  background: #101b22;
}

.program-card strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe {
  display: inline-flex;
  gap: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  color: #041507;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--green);
}

.text-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--green-soft);
  border-radius: 6px;
  background: var(--panel);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  background: #05090d;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(47, 216, 106, 0.16);
  text-align: left;
}

th {
  color: #06120a;
  background: var(--green);
}

select {
  min-height: 44px;
  margin-bottom: 14px;
  padding: 6px 10px;
  color: var(--text);
  border: 1px solid var(--green);
  border-radius: 4px;
  background: #06110b;
}

.net-map {
  display: grid;
  grid-template-columns: repeat(48, minmax(4px, 1fr));
  gap: 1px;
  max-width: 780px;
  padding: 8px;
  border: 1px solid #245aff;
  background: #01030d;
}

.map-cell {
  aspect-ratio: 1;
  background: #05112a;
}

.map-cell.has-owner {
  background: #17317e;
}

.map-cell.selected {
  background: #fff;
}

.ranking-list {
  display: grid;
  gap: 8px;
  max-width: 520px;
  margin: 0;
  padding-left: 26px;
}

.ranking-list li {
  padding: 8px 10px;
  border: 1px solid rgba(47, 216, 106, 0.22);
  border-radius: 4px;
  background: #101b22;
}

.ranking-list span {
  float: right;
  color: var(--gold);
  font-weight: 700;
}

@media (min-width: 760px) {
  .app {
    width: min(1180px, calc(100% - 36px));
  }

  .mast {
    flex-direction: row;
    align-items: center;
    gap: 18px;
  }

  .tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .tab {
    padding: 8px 12px;
  }

  .status {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .side-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .program-list {
    max-height: 520px;
    overflow: auto;
    padding-right: 4px;
  }
}

@media (min-width: 900px) {
  .combat-layout {
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  }

  .board {
    max-width: 690px;
  }

  .packet-grid,
  .machine-body {
    grid-template-columns: minmax(64px, 0.95fr) repeat(5, minmax(34px, 1fr)) minmax(54px, 1.25fr);
    gap: 5px;
  }

  .label,
  .blank,
  .cell,
  .packet-button,
  .run-button {
    min-height: 42px;
  }
}
