:root {
  --green: #86ff7a;
  --cyan: #5ce1ff;
  --bg: #070a10;
  --panel: #0f1624;
  --line: #1e2b42;
  --text: #e9eff8;
  --muted: #93a3b8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  padding: 14px;
  background:
    radial-gradient(700px 400px at 80% -10%, rgba(92, 225, 255, 0.07), transparent 60%),
    radial-gradient(600px 400px at 0% 0%, rgba(134, 255, 122, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

.ch {
  max-width: 1000px;
  margin: 0 auto;
}

.ch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.ch-brand {
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
}

.ch-brand span {
  color: var(--green);
}

.ch-turn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-family: "Courier New", monospace;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #000;
}

.turn-dot.w {
  background: #f7f3e8;
}

.turn-dot.b {
  background: #161616;
  border-color: #93a3b8;
}

.ch-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  background: var(--panel);
}

.mode-switch button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 7px 10px;
  font-family: "Courier New", monospace;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.mode-switch button.active {
  background: var(--green);
  color: #06110a;
  font-weight: 700;
}

@media (max-width: 640px) {
  .mode-switch {
    order: 4;
    width: 100%;
  }

  .mode-switch button {
    flex: 1;
  }
}

.ch-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 12px;
  font-family: "Courier New", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.ch-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.ch-btn:disabled {
  opacity: 0.4;
  cursor: default;
  border-color: var(--line);
  color: var(--text);
}

.ch-btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #06110a;
  font-weight: 700;
}

.ch-btn-primary:hover {
  background: #a4ff9b;
  color: #06110a;
}

.ch-layout {
  display: grid;
  grid-template-columns: auto 280px;
  gap: 24px;
  align-items: start;
  justify-content: center;
}

.ch-board-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.ch-board {
  --sq: clamp(34px, 8vw, 72px);
  display: grid;
  grid-template-columns: repeat(8, var(--sq));
  grid-template-rows: repeat(8, var(--sq));
  padding: 10px;
  background: #241a12;
  border: 1px solid #3a2a1c;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.35);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--sq);
  height: var(--sq);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.square.light {
  background: #e8d7b9;
}

.square.dark {
  background: #a87b57;
}

.square.last {
  background-image: linear-gradient(rgba(92, 225, 255, 0.18), rgba(92, 225, 255, 0.18));
}

.square.selected {
  box-shadow: inset 0 0 0 3px var(--green);
}

.square.check {
  box-shadow: inset 0 0 0 4px rgba(255, 70, 70, 0.85);
}

.piece {
  position: relative;
  z-index: 2;
  font-family: "Segoe UI Symbol", "Arial Unicode MS", "Noto Sans Symbols", serif;
  font-size: calc(var(--sq) * 0.78);
  line-height: 1;
  pointer-events: none;
}

.piece.w {
  color: #fffdf6;
  text-shadow:
    0 1px 0 #1a120b,
    1px 0 0 #1a120b,
    -1px 0 0 #1a120b,
    0 -1px 0 #1a120b,
    0 0 2px rgba(0, 0, 0, 0.8);
}

.piece.b {
  color: #151515;
  text-shadow:
    0 1px 0 rgba(255, 250, 240, 0.55),
    1px 0 0 rgba(255, 250, 240, 0.55),
    -1px 0 0 rgba(255, 250, 240, 0.55),
    0 -1px 0 rgba(255, 250, 240, 0.55);
}

.move-dot {
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(28, 72, 30, 0.55);
  z-index: 1;
}

.move-ring {
  position: absolute;
  inset: 6%;
  border: 3px solid rgba(28, 72, 30, 0.55);
  border-radius: 50%;
  z-index: 1;
}

.coord {
  position: absolute;
  z-index: 1;
  color: rgba(30, 20, 12, 0.55);
  font-family: "Courier New", monospace;
  font-size: calc(var(--sq) * 0.16);
  line-height: 1;
  pointer-events: none;
}

.coord.file {
  right: 3px;
  bottom: 2px;
}

.coord.rank {
  left: 3px;
  top: 2px;
}

.ch-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ch-status {
  margin: 0;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 0.86rem;
  min-height: 2.8em;
}

.ch-status.alert {
  border-color: #ff5c5c;
  color: #ffb3b3;
}

.ch-status.win {
  border-color: var(--green);
  color: var(--green);
}

.ch-history {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 12px 14px;
}

.ch-history h2 {
  margin: 0 0 8px;
  font-family: "Courier New", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.ch-history ol {
  margin: 0;
  padding: 0 0 0 26px;
  max-height: 230px;
  overflow-y: auto;
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #c9d4e2;
}

.ch-history li {
  padding-left: 2px;
}

.ch-history .empty {
  color: #5f7088;
  list-style: none;
  margin-left: -26px;
}

.ch-rules {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.ch-rules summary {
  cursor: pointer;
  color: var(--cyan);
  font-family: "Courier New", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ch-rules ul {
  padding-left: 16px;
}

.ch-promo {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 7, 12, 0.82);
}

.ch-promo[hidden] {
  display: none;
}

.ch-promo-card {
  width: 100%;
  max-width: 340px;
  padding: 24px;
  background: var(--panel);
  border: 2px solid var(--green);
  box-shadow: 10px 10px 0 #000;
  text-align: center;
}

.ch-promo-card h2 {
  margin: 0 0 14px;
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
  text-transform: uppercase;
}

.ch-promo-options {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}

.ch-promo-options button {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  background: #e8d7b9;
  border: 1px solid #3a2a1c;
  color: #151515;
  font-family: "Segoe UI Symbol", serif;
  font-size: 2rem;
  cursor: pointer;
}

.ch-promo-options button:hover {
  background: var(--green);
}

@media (max-width: 900px) {
  .ch-layout {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .ch-side {
    width: min(100%, 600px);
  }
}

@media (max-width: 560px) {
  body {
    padding: 8px;
  }

  .ch-head {
    gap: 8px;
  }

  .ch-turn {
    order: 3;
  }

  .ch-board {
    padding: 6px;
  }

  .ch-rules {
    font-size: 0.74rem;
  }
}