formation-chess-web 0.2.0

Rules engine and text notation for Formation Chess (阵棋), a strategy board game where piece formations reshape nearby abilities
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-red: #c62828;
  --color-black: #1a1a1a;
  --color-white: #757575;
  --color-board-bg: #e8d5b0;
  --color-board-line: #444;
  --color-border: #ccc;
  --radius: 4px;
  --cell-size: 52px;
}

html, body { height: 100%; font-family: system-ui, sans-serif; background: #eee; color: #222; }

#app { display: flex; flex-direction: column; height: 100vh; max-width: 1200px; margin: 0 auto; background: #fff; box-shadow: 0 0 12px rgba(0,0,0,.08); }

/* ---- toolbar ---- */
#toolbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: #f5f5f5; border-bottom: 1px solid var(--color-border); font-size: 14px; flex-shrink: 0;
}
#toolbar button {
  padding: 4px 12px; border: 1px solid #bbb; border-radius: var(--radius);
  background: #fff; cursor: pointer; font-size: 13px;
}
#toolbar button:hover { background: #e8e8e8; }
#toolbar .btn-action { border-color: #ddd; font-size: 13px; }
.toolbar-spacer { flex: 1; }
.toolbar-sep { margin: 0 2px; color: #999; }
#player-indicator { font-weight: 600; }
#white-indicator { cursor: pointer; user-select: none; }
#white-indicator:hover { text-decoration: underline; }
#white-indicator.no-white { cursor: default; pointer-events: none; }

/* ---- main ---- */
#main { display: flex; flex: 1; overflow: hidden; }

/* ---- sidebar ---- */
#sidebar {
  display: flex; flex-direction: column; width: 120px; flex-shrink: 0;
  border-right: 1px solid var(--color-border); padding: 8px; gap: 0;
}
.pool { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.pool-label { font-size: 12px; font-weight: 600; padding: 4px 0; color: #666; text-align: center; }
.pool-items { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-content: flex-start; padding: 4px 0; overflow-y: auto; flex: 1; }
.pool-divider { height: 1px; background: var(--color-border); margin: 4px 0; flex-shrink: 0; }

/* ---- board ---- */
#board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
#board { position: relative; background: var(--color-board-bg); border-radius: 4px; user-select: none; }

.board-lines {
  position: absolute; top: 0; left: 0; pointer-events: none;
}
.board-lines line { stroke: var(--color-board-line); stroke-width: 1; }

/* ---- intersections ---- */
.intersection {
  position: absolute;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 2;
  transform: translate(-50%, -50%);
}

.intersection.hint-move::after,
.intersection.hint-capture::after,
.intersection.hint-push::after,
.intersection.hint-multi::after,
.intersection.hint-white::after {
  content: ''; position: absolute; inset: 6%;
  border-radius: 50%; pointer-events: none; z-index: 5;
  border: 3px solid;
}
.intersection.hint-move::after    { border-color: rgba(76,175,80,.7);  background: rgba(76,175,80,.15); }
.intersection.hint-capture::after { border-color: rgba(244,67,54,.7);  background: rgba(244,67,54,.15); }
.intersection.hint-push::after    { border-color: rgba(255,152,0,.7);  background: rgba(255,152,0,.15); }
.intersection.hint-multi::after   { border-color: rgba(156,39,176,.7); background: rgba(156,39,176,.15); }
.intersection.hint-white::after   { border-color: rgba(33,150,243,.7); background: rgba(33,150,243,.15); }

.intersection.selected::before {
  content: ''; position: absolute; inset: 12%;
  border: 3px solid #2196f3; border-radius: 6px; z-index: 2; pointer-events: none;
}

/* ---- pieces ---- */
.piece {
  width: 78%; height: 78%; position: relative; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid rgba(255,255,255,.25);
  cursor: pointer; transition: box-shadow .12s;
}
.piece:hover { filter: brightness(1.2); }
.pool .piece-wrap {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
}
.pool .piece-wrap .piece { width: 100%; height: 100%; }

.piece-text { font-size: 18px; line-height: 1; font-weight: 600; color: #fff; pointer-events: none; }
.pool .piece .piece-text { font-size: 14px; }

.piece-red    { background: var(--color-red); }
.piece-black  { background: var(--color-black); }
.piece-white  { background: var(--color-white); }
/* shapes */
.shape-square           { border-radius: 2px; }
.shape-circle           { border-radius: 50%; }
.shape-diamond          { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); border-radius: 0; }

.shape-triangle-up {
    clip-path: polygon(50% 0, 100% 100%, 0 100%);
    border-radius: 0;
}
.shape-triangle-down {
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    border-radius: 0;
}

/* board: shift centroid to intersection */
#board .shape-triangle-up   { transform: translateY(-16.67%); }
#board .shape-triangle-down { transform: translateY(16.67%); }
/* pool: no centroid shift */
.pool .shape-triangle-up,
.pool .shape-triangle-down  { transform: none; }

.shape-triangle-up .piece-text {
    position: absolute;
    top: 66.67%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.shape-triangle-down .piece-text {
    position: absolute;
    top: 33.33%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.pool-piece-selected { box-shadow: 0 0 0 3px #ffeb3b; }

/* ---- status ---- */
#status { padding: 6px 12px; background: #f5f5f5; border-top: 1px solid var(--color-border); font-size: 13px; min-height: 30px; flex-shrink: 0; }
#status.error { color: #c62828; }

/* ---- overlay & panels ---- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 100; display: flex; align-items: center; justify-content: center; }
.hidden { display: none !important; }

.panel { background: #fff; border-radius: 8px; padding: 24px; position: relative; max-width: 520px; width: 90%; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.panel h2 { margin-bottom: 16px; font-size: 18px; }
.panel-close { position: absolute; top: 8px; right: 12px; border: none; background: none; font-size: 22px; cursor: pointer; color: #888; }

.panel-tabs { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 2px solid #e0e0e0; }
.panel-tabs .tab { padding: 6px 14px; border: none; background: none; cursor: pointer; font-size: 14px; color: #666; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.panel-tabs .tab:hover { color: #333; }
.panel-tabs .tab.active { color: #1976d2; border-bottom-color: #1976d2; font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.form-row { display: flex; gap: 16px; margin-bottom: 12px; align-items: center; }
.form-row label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.form-row input[type=number] { width: 60px; padding: 4px 6px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; }

#load-text { width: 100%; font-family: monospace; font-size: 12px; padding: 8px; border: 1px solid #ccc; border-radius: 4px; resize: vertical; margin-bottom: 12px; }

.tab-content button, .form-row button {
  padding: 6px 20px; border: 1px solid #1976d2; border-radius: var(--radius);
  background: #1976d2; color: #fff; cursor: pointer; font-size: 14px;
}
.tab-content button:hover { background: #1565c0; }

.rules-content { font-size: 13px; line-height: 1.7; white-space: pre-line; max-height: 60vh; overflow-y: auto; }

/* ---- popup for capture/push choice ---- */
.popup { position: fixed; z-index: 200; background: #fff; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18); overflow: hidden; }
.popup button { display: block; width: 100%; padding: 8px 20px; border: none; background: none; cursor: pointer; font-size: 14px; text-align: left; white-space: nowrap; }
.popup button:hover { background: #f0f0f0; }
.popup button.capture-opt { color: #c62828; }
.popup button.push-opt { color: #e65100; }

/* ---- game-over ---- */
.game-over {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.game-over-content {
  background: #fff; border-radius: 16px; padding: 40px 60px;
  text-align: center; box-shadow: 0 8px 48px rgba(0,0,0,.25);
  animation: gameOverIn .35s ease-out;
}
@keyframes gameOverIn {
  from { transform: scale(.7); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.game-over-title {
  font-size: 48px; font-weight: 700; margin-bottom: 24px; letter-spacing: 8px;
}
.game-over-title.red  { color: #c62828; }
.game-over-title.black{ color: #1a1a1a; }
.game-over-title.draw { color: #666; }
.game-over-content button {
  padding: 10px 36px; font-size: 16px;
  border: none; border-radius: 8px;
  background: #1976d2; color: #fff; cursor: pointer;
}
.game-over-content button:hover { background: #1565c0; }
.game-over-content .btn-secondary { background: #e0e0e0; color: #333; margin-left: 12px; }
.game-over-content .btn-secondary:hover { background: #ccc; }

/* ======== mobile (≤ 600px) ======== */
@media (max-width: 600px) {
  :root { --cell-size: 38px; }

  #toolbar {
    gap: 3px; padding: 4px 6px; font-size: 11px; flex-wrap: wrap;
  }
  #toolbar button {
    padding: 3px 7px; font-size: 11px;
  }
  #player-indicator { font-size: 12px; }
  #white-indicator { font-size: 12px; }

  #main { flex-direction: column; }

  #sidebar {
    width: 100%; flex-direction: column; height: auto;
    border-right: none; border-top: 1px solid var(--color-border);
    padding: 4px 6px; gap: 0; overflow: hidden; flex-shrink: 0;
  }
  .pool { flex: none; }
  .pool-label { font-size: 10px; padding: 1px 0; }
  .pool-divider { width: auto; height: 1px; margin: 2px 6px; }
  .pool-items { flex-wrap: nowrap; gap: 3px; padding: 2px 0; overflow-x: auto; }
  .pool .piece-wrap { width: 28px; height: 28px; }
  .pool .piece .piece-text { font-size: 11px; }
  .pool .shape-triangle-up .piece-text,
  .pool .shape-triangle-down .piece-text { top: 50%; }  /* pool triangles: text at center */

  #board-wrap { padding: 8px; }
  #board { border-radius: 2px; }

  .piece-text { font-size: 14px; }
  .piece { border-width: 1px; }

  .intersection.selected::before { border-width: 2px; }

  .game-over-content { padding: 32px 40px; }
  .game-over-title { font-size: 36px; letter-spacing: 4px; }
  .game-over-content button { padding: 8px 28px; font-size: 14px; }

  .panel { padding: 16px; }
  .panel h2 { font-size: 16px; margin-bottom: 12px; }
  .panel-tabs .tab { font-size: 12px; padding: 4px 10px; }

  .popup button { font-size: 13px; padding: 6px 14px; }
}