:root {
  --bg0: #1a1510;
  --bg1: #2a2118;
  --ink: #f4efe6;
  --muted: #b5a894;
  --line: rgba(255,255,255,0.12);
  --board: #e8c88a;
  --board-line: #2a1810;
  --hint: rgba(20, 85, 30, 0.55);
  --auto: #2ecc71;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Nunito", "Outfit", sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(700px 420px at 10% -10%, #3a2a18 0%, transparent 55%),
    radial-gradient(600px 380px at 100% 0%, #1e3a2a 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
}
.hidden { display: none !important; }
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 10px 14px;
  max-width: 920px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.topbar-spacer { flex: 1; min-width: 4px; }
.title-block { display: grid; min-width: 0; flex: 0 1 auto; }
.title-block strong { font-family: var(--display); font-size: 1.1rem; }
.status { color: var(--muted); font-size: 0.82rem; font-weight: 600; }

.side-player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.side-player .clock {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 0.95rem;
  min-width: 3.2em;
  text-align: right;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 8px;
  background: rgba(0,0,0,0.25);
}
.side-player .clock.active { color: #f6c453; background: rgba(246, 196, 83, 0.12); }
.side-player .clock.low { color: #ff6b6b; }

.player-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 200px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0,0,0,0.28);
}
.player-chip .ava {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; background: #3a3228; flex-shrink: 0;
}
.player-chip .pinfo { display: grid; min-width: 0; line-height: 1.15; }
.player-chip .pname {
  font-weight: 700; font-size: 0.88rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-chip .pchips { font-size: 0.72rem; font-weight: 700; color: #f6c453; white-space: nowrap; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(200px, 280px);
  gap: 2px;
  align-items: start;
}
.board-col { display: grid; gap: 8px; align-content: start; min-width: 0; }
.board-top-row {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 10px; width: 100%; max-width: 520px; min-height: 40px;
}
.board-wrap {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 8 / 9;
  position: relative;
  background: linear-gradient(145deg, #f0d090, #d4a860);
  border-radius: 6px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  padding: 3% 4%;
}
.board-lines {
  position: absolute;
  inset: 3% 4%;
  width: calc(100% - 8%);
  height: calc(100% - 6%);
  pointer-events: none;
  z-index: 1;
}
.board {
  position: absolute;
  inset: 3% 4%;
  z-index: 2;
  user-select: none;
  touch-action: manipulation;
}
.board.blurred { filter: blur(5px); pointer-events: none; }

.pause-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--display); font-weight: 900; font-size: 1.6rem;
  color: #fff; background: rgba(20, 16, 12, 0.35); z-index: 5; border-radius: 6px;
}
.hint-label {
  position: absolute; left: 8px; bottom: 8px; z-index: 4;
  font-size: 0.78rem; font-weight: 800; padding: 4px 8px; border-radius: 8px;
  background: rgba(46, 204, 113, 0.92); color: #0b1a10; pointer-events: none;
}

.pt {
  position: absolute;
  width: 11.5%;
  height: 11.5%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.pt .coord {
  position: absolute;
  font-size: 0.55rem;
  font-weight: 800;
  color: rgba(42, 24, 16, 0.55);
  pointer-events: none;
}
.pt .coord.file { bottom: -2px; right: 2px; }
.pt .coord.rank { top: -2px; left: 2px; }
.pt.last::after {
  content: "";
  position: absolute;
  width: 78%; height: 78%;
  border-radius: 50%;
  background: rgba(186, 202, 68, 0.55);
  z-index: 0;
}
.pt.selected::after {
  content: "";
  position: absolute;
  width: 78%; height: 78%;
  border-radius: 50%;
  background: rgba(20, 85, 30, 0.35);
  z-index: 0;
}
.pt.hint-from::after {
  content: "";
  position: absolute;
  width: 78%; height: 78%;
  border-radius: 50%;
  background: rgba(46, 204, 113, 0.45);
  z-index: 0;
}
.pt.hint-to::after {
  content: "";
  position: absolute;
  width: 78%; height: 78%;
  border-radius: 50%;
  background: rgba(46, 204, 113, 0.7);
  z-index: 0;
}
.pt.legal::before {
  content: "";
  width: 22%; height: 22%;
  border-radius: 50%;
  background: var(--hint);
  position: absolute;
  z-index: 0;
}
.pt.legal.capture::before {
  width: 82%; height: 82%;
  background: transparent;
  border: 4px solid var(--hint);
  border-radius: 50%;
}

.piece {
  width: 100%;
  height: 100%;
  max-width: 54px;
  max-height: 54px;
  z-index: 1;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.28));
}
.piece svg { width: 100%; height: 100%; display: block; }

.bottom-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; width: 100%; max-width: 520px;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }

.log-col {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0,0,0,0.28);
  padding: 8px 8px 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  align-self: start;
}
.move-log {
  list-style: none; margin: 0; padding: 0;
  overflow: auto; flex: 1;
  font-variant-numeric: tabular-nums;
  line-height: 1.5; font-size: 0.92rem; min-height: 0;
}
.move-log li { padding: 1px 0; }
.result { margin: 8px 0 0; font-weight: 800; color: #f6c453; font-size: 0.88rem; }

.btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 9px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: linear-gradient(135deg, #3d8b5a, #1f5a38); border-color: transparent; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.icon-btn { min-width: 42px; padding: 8px 10px; font-size: 1rem; line-height: 1; }
.btn.auto-on { background: var(--auto); border-color: transparent; color: #0b1a10; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: grid; place-items: center; z-index: 60; padding: 16px;
}
.modal-card {
  width: min(360px, 100%);
  background: #2a2118;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 16px;
}
.modal-card h3 { margin: 0 0 8px; font-family: var(--display); }
.modal-card p { margin: 0 0 14px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.field { display: grid; gap: 6px; margin: 12px 0 8px; font-weight: 700; font-size: 0.9rem; }
.field input {
  font: inherit; font-weight: 700; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(0,0,0,0.35); color: var(--ink);
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(20,16,12,0.92); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 12px; z-index: 50; font-weight: 700;
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; gap: 10px; }
  .board-wrap, .board-top-row, .bottom-row { max-width: none; }
  .log-col { height: auto !important; max-height: 34dvh; }
  .topbar { flex-wrap: wrap; }
  .player-chip { max-width: 42vw; }
}
