body.app {
  height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  background: #312e2b;
  color: #ebe8e4;
  font-family: "Segoe UI", system-ui, sans-serif;
}

body.app .top { padding: 8px 0 4px; }

body.app > main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.app .foot { display: none; }

body.app .mark,
body.app .nav a { color: #ebe8e4; }

body.app .foot { color: #b7b4b0; }

body.app .wrap { width: min(1460px, calc(100% - 20px)); }

.game {
  --board: min(calc(100vh - 188px), calc(100vw - 430px), 900px);
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: calc(var(--board) + 42px) 332px;
  justify-content: center;
  gap: 16px;
  align-items: start;
  padding: 4px 0 8px;
}

.stage { width: calc(var(--board) + 42px); }

.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  min-height: 52px;
  padding: 2px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-weight: 750;
  background: #4a4846;
}

.avatar.you { background: #6b8f3c; color: #fff; }

.who { display: grid; line-height: 1.2; }

.who strong { font-size: 16px; }

.sub { color: #b7b4b0; font-size: 13px; }

.clock {
  margin-left: auto;
  min-width: 92px;
  padding: 6px 10px;
  border-radius: 4px;
  background: #262421;
  color: #ebe8e4;
  text-align: center;
  font-weight: 750;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.clock.running { background: #f1f1f1; color: #262421; }

.clock.low.running,
.clock.low { background: #c23b32; color: #fff; }

.board-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  height: var(--board);
}

.eval {
  position: relative;
  width: 32px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-radius: 3px;
  overflow: hidden;
  background: #3c3b39;
}

.eval.flipped { flex-direction: column-reverse; }

.eval-rest,
.eval-white {
  flex: 1 1 0;
}

.eval-white { background: #f3f3f3; }

.eval-score {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.9);
  color: #1a1a1a;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
}

.board-wrap {
  position: relative;
  flex: none;
  width: var(--board);
  height: var(--board);
}

body.app .board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  background: #739552;
}

body.app .sq {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  background: #739552;
  cursor: pointer;
  touch-action: none;
}

body.app .sq.light { background: #ebecd0; }

body.app .sq.moved::before,
body.app .sq.selected::before,
body.app .sq.check::before,
body.app .sq.hot::before {
  content: "";
  position: absolute;
  inset: 0;
}

body.app .sq.moved::before { background: rgba(255, 255, 0, 0.35); }

body.app .sq.selected::before,
body.app .sq.hot::before { background: rgba(255, 255, 0, 0.5); }

body.app .sq.check::before {
  background: radial-gradient(circle, rgba(232, 56, 42, 0.85) 0%, rgba(232, 56, 42, 0.15) 68%, transparent 72%);
}

.coord {
  position: absolute;
  z-index: 2;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

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

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

.sq.light .coord { color: #739552; }

.sq.dark .coord { color: #ebecd0; }

body.app .piece,
.ghost,
.promo-piece {
  background-position: center;
  background-repeat: no-repeat;
  background-size: 92%;
}

body.app .piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  font-size: 0;
  pointer-events: none;
}

.sq.target::after {
  content: "";
  position: absolute;
  z-index: 2;
  left: 34%;
  top: 34%;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.17);
  pointer-events: none;
}

.sq.target.capture::after {
  left: 5%;
  top: 5%;
  width: 90%;
  height: 90%;
  background: transparent;
  box-shadow: inset 0 0 0 7px rgba(0, 0, 0, 0.17);
}

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}

.ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  pointer-events: none;
}

.promo {
  position: absolute;
  z-index: 8;
  width: 12.5%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.promo-piece {
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  background-color: #f4f4f4;
  cursor: pointer;
}

.promo-piece:hover { background-color: #d6d6d6; }

.result {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 7;
  min-width: 210px;
  padding: 16px 18px;
  border-radius: 8px;
  background: rgba(38, 36, 33, 0.95);
  color: #fff;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.result strong { display: block; font-size: 22px; }

.result p { margin: 6px 0 12px; color: #d9d6d1; }

.result button,
.row button,
.choice {
  border: 0;
  border-radius: 4px;
  background: #81b64c;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.result button { min-height: 40px; padding: 0 16px; }

.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(var(--board) + 104px);
  min-height: 0;
}

.moves-pane {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.controls {
  flex: none;
  display: grid;
  gap: 8px;
}

.field { display: grid; gap: 6px; font-size: 14px; color: #d9d6d1; }

.field select {
  width: 100%;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid #4a4846;
  border-radius: 4px;
  background: #262421;
  color: #fff;
  font: inherit;
}

.row { display: flex; gap: 8px; }

body.app .row button,
body.app button.choice {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: #4a4846;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.15;
  cursor: pointer;
}

body.app .controls .row:first-of-type button {
  flex-direction: column;
  gap: 3px;
  min-height: 58px;
  font-size: 13px;
}

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  display: block;
}

body.app .row button:hover,
body.app button.choice:hover { background: #5d5a57; }

body.app .row button:disabled {
  opacity: 0.4;
  cursor: default;
}

body.app #resign { background: #6e3430; }

body.app #resign:hover:not(:disabled) { background: #85423d; }

body.app button.choice.on { background: #81b64c; color: #fff; }

.moves-head {
  flex: none;
  margin: 0 0 6px;
  font-size: 14px;
  color: #b7b4b0;
  font-weight: 700;
}

.moves {
  flex: 1 1 auto;
  height: 0;
  min-height: 0;
  overflow: auto;
  border-radius: 6px;
  background: #262421;
  font-variant-numeric: tabular-nums;
}

.moves div {
  display: grid;
  grid-template-columns: 42px 1fr 1fr;
  gap: 6px;
  padding: 5px 10px;
}

.moves .on {
  background: #4a4846;
  border-radius: 3px;
}

.hint {
  margin: 0;
  color: #b7b4b0;
  font-size: 13px;
}

#status { margin: 0; min-height: 1.4em; }

html[data-theme="light"] body.app {
  background: var(--paper);
  color: var(--ink);
}

html[data-theme="light"] body.app .mark,
html[data-theme="light"] body.app .nav a { color: var(--ink); }

html[data-theme="light"] .sub,
html[data-theme="light"] .hint,
html[data-theme="light"] .moves-head,
html[data-theme="light"] .field { color: var(--muted); }

html[data-theme="light"] .avatar { background: #d9d4ca; color: var(--ink); }

html[data-theme="light"] .avatar.you { background: #6b8f3c; color: #fff; }

html[data-theme="light"] .clock { background: #f1f1f1; color: #262421; }

html[data-theme="light"] .moves { background: #fff; color: var(--ink); }

html[data-theme="light"] .moves .on { background: #e7f2df; }

html[data-theme="light"] body.app .row button,
html[data-theme="light"] body.app button.choice {
  background: #e6e2da;
  color: #17211c;
}

html[data-theme="light"] body.app .row button:hover,
html[data-theme="light"] body.app button.choice:hover { background: #d4cfc4; }

html[data-theme="light"] body.app #resign { background: #6e3430; color: #fff; }

html[data-theme="light"] body.app button.choice.on { background: #81b64c; color: #fff; }

html[data-theme="light"] .field select {
  background: #fff;
  color: #17211c;
  border-color: rgba(23, 33, 28, 0.14);
}

@media (max-width: 980px) {
  body.app { height: auto; overflow: auto; }
  body.app > main { display: block; }
  .game {
    --board: min(calc(100vw - 84px), 640px);
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
    height: auto;
  }
  .stage { width: min(100%, calc(var(--board) + 42px)); margin: 0 auto; }
  .side { height: auto; }
  .moves { height: 280px; flex: none; }
}
