:root {
  --bg: #000704;
  --panel: rgba(0, 20, 10, 0.88);
  --panel-strong: rgba(0, 12, 7, 0.94);
  --green: #39ff6a;
  --green-soft: #aaffbb;
  --green-dim: #0f8f38;
  --green-dark: #062a15;
  --yellow: #f8ff72;
  --red: #ff5f73;
  --white-piece: #f4fff5;
  --black-piece: #050805;
  --line: rgba(57, 255, 106, 0.55);
  --line-dim: rgba(57, 255, 106, 0.2);
  --shadow: 0 0 26px rgba(57, 255, 106, 0.22);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--green-soft);
  font-family: var(--mono);
}

body {
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  user-select: none;
}

#matrix-rain {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  opacity: 0.62;
  pointer-events: none;
}

.hidden { display: none !important; }

.neon-panel {
  border: 1px solid var(--green);
  background: linear-gradient(180deg, rgba(0, 21, 9, 0.92), rgba(0, 11, 6, 0.95));
  box-shadow: var(--shadow), inset 0 0 28px rgba(57, 255, 106, 0.08);
}

.landing {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.landing-card {
  width: min(980px, 100%);
  padding: clamp(18px, 4vw, 36px);
  border-radius: 18px;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--yellow);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(3rem, 9vw, 7.5rem);
  line-height: 0.88;
  color: var(--green);
  text-shadow: 0 0 18px rgba(57, 255, 106, 0.75);
}

h2 {
  color: var(--green);
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.intro {
  max-width: 720px;
  color: var(--green-soft);
  line-height: 1.5;
  margin: 18px 0 28px;
}

.infinity-mark {
  position: relative;
  width: 112px;
  height: 112px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--yellow);
  text-shadow: 0 0 20px rgba(248, 255, 114, 0.8);
  background: rgba(248, 255, 114, 0.04);
}

.infinity-mark span {
  position: absolute;
  font-size: 4.8rem;
  line-height: 1;
}

.infinity-mark span:not(.rotate) {
  animation: binary-spin 5.5s linear infinite;
}

.infinity-mark .rotate {
  transform: rotate(90deg);
  opacity: 0.82;
  animation: binary-spin-offset 5.5s linear infinite reverse;
}

.forms-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.form-card {
  border: 1px solid var(--line-dim);
  background: rgba(0, 0, 0, 0.26);
  padding: 18px;
  border-radius: 12px;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--green-soft);
  font-size: 0.88rem;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #001107;
  color: var(--green-soft);
  padding: 12px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(57, 255, 106, 0.18);
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 42px;
  border: 1px solid var(--green);
  color: var(--green-soft);
  background: rgba(57, 255, 106, 0.08);
  padding: 10px 14px;
  letter-spacing: 0.04em;
  transition: transform 100ms ease, background 120ms ease, box-shadow 120ms ease;
}

.primary {
  width: 100%;
  color: #001307;
  background: var(--green);
  font-weight: 800;
}

.secondary {
  background: transparent;
}

.ghost {
  background: rgba(57, 255, 106, 0.06);
}

.danger {
  border-color: var(--red);
  color: var(--red);
  background: rgba(255, 95, 115, 0.08);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 16px rgba(57, 255, 106, 0.24);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tiny-note {
  margin: 18px 0 0;
  color: rgba(170, 255, 187, 0.62);
  font-size: 0.78rem;
}

.game {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 420px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  padding: 12px 16px;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  line-height: 1;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.board-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 14px;
  overflow: hidden;
}

.board {
  width: min(calc(100vw - 28px), calc(100svh - 130px), 760px);
  aspect-ratio: 1 / 1;
  display: grid;
  border: 2px solid var(--green);
  box-shadow: 0 0 22px rgba(57, 255, 106, 0.24), inset 0 0 36px rgba(57, 255, 106, 0.08);
  background: rgba(0, 13, 6, 0.96);
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line-dim);
  border-bottom: 1px solid var(--line-dim);
  min-width: 0;
  min-height: 0;
  background: rgba(0, 12, 6, 0.86);
}

.cell.outer {
  background: rgba(0, 24, 10, 0.9);
}

.cell.center {
  background: radial-gradient(circle at center, rgba(248, 255, 114, 0.32), rgba(57, 255, 106, 0.08) 55%, rgba(0, 12, 6, 0.95) 76%);
  box-shadow: inset 0 0 18px rgba(248, 255, 114, 0.26);
}

.cell.clickable,
.cell.selectable {
  cursor: pointer;
}

.cell.selectable::after,
.cell.legal::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(248, 255, 114, 0.72);
  pointer-events: none;
}

.cell.spawn-target::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(248, 255, 114, 0.7);
  box-shadow: inset 0 0 12px rgba(248, 255, 114, 0.16);
  pointer-events: none;
}

.cell.remove-target::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px dotted var(--red);
  box-shadow: inset 0 0 14px rgba(255, 95, 115, 0.22);
  pointer-events: none;
}

.cell.selected::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid var(--yellow);
  box-shadow: inset 0 0 18px rgba(248, 255, 114, 0.32), 0 0 14px rgba(248, 255, 114, 0.28);
  pointer-events: none;
}

.cell.move-source::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px solid var(--green);
  box-shadow: inset 0 0 16px rgba(57, 255, 106, 0.28), 0 0 12px rgba(57, 255, 106, 0.22);
  pointer-events: none;
}

.center-symbol {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: var(--black-piece);
  text-shadow: 0 0 14px rgba(248, 255, 114, 0.7);
}

.center-symbol span {
  position: absolute;
  font-size: clamp(20px, 5vw, 44px);
  font-weight: 900;
  color: var(--yellow);
}

.center-symbol span:not(.rotate) {
  animation: binary-spin 6.5s linear infinite;
}

.center-symbol .rotate {
  transform: rotate(90deg);
  opacity: 0.78;
  animation: binary-spin-offset 6.5s linear infinite reverse;
}

.piece {
  position: relative;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.12);
}

.piece::after {
  content: "";
  width: 42%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: rgba(57, 255, 106, 0.28);
  box-shadow: 0 0 10px rgba(57, 255, 106, 0.36);
}

.piece.white {
  background: var(--white-piece);
  border: 2px solid #ffffff;
  box-shadow: 0 0 16px rgba(244, 255, 245, 0.5);
}

.piece.black {
  background: var(--black-piece);
  border: 2px solid var(--green);
  box-shadow: 0 0 16px rgba(57, 255, 106, 0.4);
}

.side-panel {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.side-panel section + section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-dim);
}

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

.player-card {
  border: 1px solid var(--line-dim);
  padding: 10px;
  background: rgba(0, 0, 0, 0.24);
}

.player-card.me {
  border-color: var(--yellow);
}

.player-name {
  color: var(--green);
  font-weight: 900;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 5px;
  font-size: 0.84rem;
}

.connected { color: var(--green); }
.disconnected { color: var(--red); }
.yellow { color: var(--yellow); }
.red { color: var(--red); }
.dim { color: rgba(170, 255, 187, 0.62); }

.phase-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--green);
}

.phase-title h2 {
  margin-bottom: 6px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.button-stack {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.choice-btn {
  font-size: 1.05rem;
  min-height: 52px;
}

.mode-active {
  background: rgba(248, 255, 114, 0.18);
  border-color: var(--yellow);
  color: var(--yellow);
}

.result-table {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
}

.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border-bottom: 1px dotted rgba(57, 255, 106, 0.2);
  padding-bottom: 5px;
}

.chat-messages,
.log-list {
  max-height: 170px;
  overflow: auto;
  border: 1px solid var(--line-dim);
  padding: 8px;
  background: rgba(0, 0, 0, 0.24);
}

.chat-line,
.log-line {
  margin-bottom: 6px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.game-over-banner {
  position: absolute;
  z-index: 5;
  inset: 35% 8% auto 8%;
  min-height: 160px;
  display: grid;
  place-items: center;
  text-align: center;
  background: rgba(0, 0, 0, 0.84);
  border: 1px solid var(--yellow);
  color: var(--yellow);
  font-size: clamp(1.4rem, 4vw, 3rem);
  font-weight: 900;
  text-shadow: 0 0 22px rgba(248, 255, 114, 0.66);
  padding: 18px;
}



.howto-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 28px);
  background: rgba(0, 0, 0, 0.96);
}

.howto-card {
  width: min(960px, 100%);
  max-height: min(90svh, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--green);
  background: #000;
  box-shadow: 0 0 42px rgba(57, 255, 106, 0.30), inset 0 0 30px rgba(57, 255, 106, 0.08);
}

.howto-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: clamp(14px, 3vw, 22px);
  border-bottom: 1px solid var(--line-dim);
  background: rgba(0, 10, 5, 0.96);
}

.howto-header h2 {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 3rem);
  line-height: 1;
  color: var(--green);
  text-shadow: 0 0 18px rgba(57, 255, 106, 0.55);
}

.howto-content {
  overflow: auto;
  padding: clamp(14px, 3vw, 24px);
  display: grid;
  gap: 16px;
  line-height: 1.5;
}

.howto-content section {
  border: 1px solid var(--line-dim);
  background: rgba(0, 17, 7, 0.48);
  padding: clamp(12px, 2.5vw, 18px);
}

.howto-content h3 {
  margin: 0 0 8px;
  color: var(--yellow);
  letter-spacing: 0.08em;
  font-size: 1rem;
}

.howto-content p,
.howto-content ol,
.howto-content ul {
  margin-bottom: 0;
}

.howto-content ol,
.howto-content ul {
  padding-left: 22px;
}

.howto-content li + li {
  margin-top: 7px;
}

.howto-table {
  display: grid;
  grid-template-columns: minmax(90px, 0.7fr) minmax(0, 1.3fr);
  border: 1px solid var(--line-dim);
  margin: 10px 0;
}

.howto-table > div {
  padding: 9px 10px;
  border-right: 1px solid var(--line-dim);
  border-bottom: 1px solid var(--line-dim);
  background: rgba(0, 0, 0, 0.22);
}

.howto-table > div:nth-child(2n) {
  border-right: 0;
}

.howto-bottom-close {
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  border-radius: 0;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(160%);
  max-width: min(720px, calc(100vw - 28px));
  padding: 12px 16px;
  border: 1px solid var(--red);
  background: rgba(18, 0, 4, 0.94);
  color: #ffd8dd;
  box-shadow: 0 0 20px rgba(255, 95, 115, 0.24);
  transition: transform 180ms ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.selection-card {
  border: 1px solid var(--line-dim);
  background: rgba(0, 0, 0, 0.22);
  padding: 10px;
  margin: 12px 0;
  display: grid;
  gap: 5px;
}

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

@keyframes binary-spin-offset {
  from { transform: rotate(90deg); }
  to { transform: rotate(450deg); }
}

@media (max-width: 980px) {
  .game {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .board {
    width: min(calc(100vw - 56px), 720px);
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .landing { padding: 12px; }
  .landing-card { border-radius: 12px; }
  .brand-row { align-items: flex-start; }
  .infinity-mark { width: 78px; height: 78px; }
  .infinity-mark span { font-size: 3.2rem; }
  .forms-grid { grid-template-columns: 1fr; }

  .game {
    padding: 8px;
    gap: 8px;
  }

  .topbar {
    align-items: flex-start;
    padding: 10px;
  }

  .top-actions {
    flex-direction: column;
    width: 142px;
  }

  .top-actions button {
    min-height: 36px;
    padding: 7px;
    font-size: 0.75rem;
  }

  .board-shell { padding: 8px; }
  .board { width: min(calc(100vw - 32px), 620px); }
  .side-panel { padding: 12px; }
  .status-grid { grid-template-columns: 1fr; }
  .button-grid { grid-template-columns: 1fr; }

  .howto-header {
    flex-direction: column;
  }

  .howto-close {
    width: 100%;
  }

  .howto-content {
    font-size: 0.88rem;
  }

  .howto-table {
    grid-template-columns: 1fr;
  }

  .howto-table > div {
    border-right: 0;
  }
}

.player-card.cpu {
  border-color: rgba(248, 255, 114, 0.46);
  background: linear-gradient(135deg, rgba(248, 255, 114, 0.08), rgba(57, 255, 106, 0.05), rgba(0, 0, 0, 0.22));
}
