:root {
  color-scheme: light;
  font-size: 18px;
  --cell: 33px;
  --grid: #8d6b42;
  --line: #5f4225;
  --paper: #f7e2b8;
  --paper-dark: #dfbd7e;
  --ink: #202020;
  --sente: #fff4d6;
  --gote: #dff2ff;
  --accent: #0b6b68;
  --danger: #b14135;
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #ece7dc;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid #cabd9f;
  background: #fffaf0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

#status {
  margin-top: 4px;
  color: #5e5648;
  font-size: 16px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.controls button,
.toggle,
.selectControl select {
  min-height: 34px;
  border: 1px solid #9d8b6e;
  border-radius: 6px;
  padding: 6px 12px;
  background: #fff;
  color: #242018;
  cursor: pointer;
}

.controls button:hover,
.toggle:hover,
.selectControl select:hover {
  border-color: var(--accent);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.selectControl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  white-space: nowrap;
}

.selectControl select {
  padding: 5px 28px 5px 10px;
  background: #fff;
  color: #242018;
  cursor: pointer;
}

.zoom {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
  font-size: 16px;
  white-space: nowrap;
}

.zoom input {
  width: 130px;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.boardShell {
  overflow: auto;
  padding: 18px;
  background: #d8ceb9;
}

.numberedBoard {
  display: grid;
  grid-template-columns: auto 32px;
  grid-template-areas: "files corner" "board ranks";
  grid-template-rows: 32px auto;
  width: max-content;
}

.columnNumbers, .rowNumbers {
  display: grid;
  color: #46321c;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: #d8ceb9;
}

.columnNumbers {
  grid-area: files;
  grid-template-columns: repeat(36, var(--cell));
  padding: 0 2px;
}

.rowNumbers {
  grid-area: ranks;
  grid-template-rows: repeat(36, var(--cell));
  padding: 2px 0;
  white-space: nowrap;
}

.matchDialog { width: min(520px, calc(100vw - 32px)); border: 2px solid #5f4225; border-radius: 12px; padding: 24px; background: #fffaf0; color: #20180f; }
.matchDialog::backdrop { background: #0008; }
.matchDialog h2 { margin: 0 0 24px; }
.matchPlayers { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: center; gap: 16px; }
.matchPlayers label { display: grid; gap: 10px; font-weight: 700; }
.matchPlayers select { width: 100%; min-height: 48px; padding: 8px; font: inherit; }
.matchDialog p { font-size: 14px; line-height: 1.6; margin-top: 18px; }
.matchActions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.matchActions button { min-height: 44px; padding: 10px 16px; }
.matchActions button[type="submit"], #matchButton { background: #5f4225; color: white; }
#matchSummary { font-size: 14px; margin-top: 6px; }
@media (max-width: 420px) { .matchPlayers { grid-template-columns: 1fr; gap: 12px; } .matchPlayers > span { display: none; } }

.columnNumbers span, .rowNumbers span {
  display: grid;
  place-items: center;
}

.rowNumbers span {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: clamp(8px, calc((var(--cell) - 4px) / 3), 12px);
  word-break: keep-all;
  line-height: 1;
}

.coordinateCorner {
  grid-area: corner;
  display: grid;
  place-items: center;
  min-width: 0;
  white-space: nowrap;
  font-size: 10px;
  line-height: 1;
  text-align: center;
  color: #46321c;
}

.board {
  grid-area: board;
  width: calc(var(--cell) * 36 + 4px);
  height: calc(var(--cell) * 36 + 4px);
  display: grid;
  grid-template-columns: repeat(36, var(--cell));
  grid-template-rows: repeat(36, var(--cell));
  border: 2px solid var(--line);
  background: #dec18f url("assets/shogi-board-wood-clean.png") center / 100% 100% no-repeat;
  box-shadow: 0 14px 36px rgb(55 42 23 / 24%);
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid rgb(95 66 37 / 44%);
  background: transparent;
  position: relative;
}

.cell:nth-child(2n) {
  background: transparent;
}

/* Go-board-style dots at the intersections of each 3-by-3 block. */
.cell.starPoint::before {
  content: "";
  position: absolute;
  left: -1px;
  top: -1px;
  width: clamp(4px, calc(var(--cell) * 0.13), 8px);
  height: clamp(4px, calc(var(--cell) * 0.13), 8px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #302317;
  z-index: 2;
  pointer-events: none;
}

.cell.campCross::after {
  content: "";
  position: absolute;
  left: -1px;
  top: -1px;
  width: calc(var(--cell) * 0.55);
  height: calc(var(--cell) * 0.55);
  transform: translate(-50%, -50%);
  background:
    linear-gradient(#000, #000) center / 100% 3px no-repeat,
    linear-gradient(#000, #000) center / 3px 100% no-repeat;
  z-index: 2;
  pointer-events: none;
}

.piece {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  background: url("assets/shogi-piece-22f3e43efd5d.png") center / contain no-repeat;
  color: #1d1710;
  clip-path: none;
  font-weight: 700;
  line-height: 0.95;
  font-size: min(calc(var(--cell) * 0.4), calc((var(--cell) - 8px) / var(--piece-characters, 2)));
  letter-spacing: 0;
  text-orientation: upright;
  writing-mode: vertical-rl;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
}

.piece.gote {
  transform: rotate(180deg);
}

.piece.promoted {
  color: var(--danger);
}

.piece.current {
  outline: 3px solid #1c6fca;
  outline-offset: -2px;
}

.piece.offturn {
  opacity: 1;
}

.target {
  box-shadow: inset 0 0 0 4px rgb(11 107 104 / 68%);
  cursor: pointer;
}

.target.capture {
  box-shadow: inset 0 0 0 4px rgb(177 65 53 / 75%);
}

.cell.target.capture.lastMoveTo {
  background: #ffb8ad !important;
  box-shadow: inset 0 0 0 5px #c92f22;
}

.cell.target.capture .piece {
  outline: 3px solid #c92f22;
  outline-offset: -2px;
}

.cell.target.capture .piece.lastMovedPiece {
  border-color: #7f160f;
  outline-color: #c92f22;
  filter: saturate(1.35) brightness(1.04);
}

.lastMoveFrom {
  background: #ffe08a !important;
  box-shadow: inset 0 0 0 3px #c78300;
}

.lastMoveTo {
  background: #9ee59f !important;
  box-shadow: inset 0 0 0 4px #198754;
}

.piece.lastMovedPiece {
  border-color: #075c36;
  outline: 3px solid #0b7a49;
  outline-offset: -2px;
  filter: saturate(1.2) brightness(1.04);
}

.panel {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  border-left: 1px solid #cabd9f;
  background: #fffaf0;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.selected,
.captured,
.logBlock {
  padding: 14px 0;
  border-bottom: 1px solid #dfd3b8;
}

#selection {
  min-height: 44px;
  line-height: 1.55;
}

.captureRow {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
}

#moveLog {
  margin: 0;
  padding-left: 0;
  list-style: none;
  max-height: 58vh;
  overflow: auto;
  font-variant-numeric: tabular-nums;
}

#moveLog li {
  margin: 0 0 8px;
  line-height: 1.35;
  white-space: nowrap;
}

#moveLog li span {
  display: inline-block;
}

.gameOverOverlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(20 17 12 / 58%);
}

.gameOverOverlay[hidden] {
  display: none;
}

.gameOverDialog {
  width: min(360px, 100%);
  border: 2px solid #6e4b25;
  border-radius: 8px;
  padding: 28px;
  background: #fffaf0;
  box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
  text-align: center;
}

.gameOverLabel {
  margin-bottom: 8px;
  color: #6b5b42;
  font-size: 16px;
}

.gameOverDialog h2 {
  margin-bottom: 22px;
  font-size: 30px;
}

.gameOverDialog button {
  min-height: 40px;
  border: 1px solid #78552d;
  border-radius: 6px;
  padding: 8px 18px;
  background: #fff;
  cursor: pointer;
}

.moveNotice {
  position: fixed;
  z-index: 90;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  border: 1px solid #6f5b3b;
  border-radius: 6px;
  padding: 10px 14px;
  background: #fffaf0;
  box-shadow: 0 8px 24px rgb(0 0 0 / 24%);
  font-size: 16px;
  line-height: 1.5;
}

.moveNotice[hidden] {
  display: none;
}

@media (max-width: 920px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .panel {
    border-left: 0;
    border-top: 1px solid #cabd9f;
  }
}
/* Keep compound-move choices scrollable even for crowded lion positions. */
.moveChoiceDialog { max-width: min(680px, 90vw); max-height: 80vh; overflow: auto; border-radius: 12px; padding: 20px; }
.moveChoiceDialog button { display: block; width: 100%; margin: 8px 0; padding: 12px; text-align: left; white-space: normal; }
.moveChoiceDialog::backdrop { background: #0008; }
.mateAuditDialog { width: min(680px, 90vw); max-height: 80vh; overflow: auto; padding: 24px; border: 2px solid #6e4b25; border-radius: 8px; background: #fffaf0; line-height: 1.7; }
.mateAuditDialog::backdrop { background: #0008; }
.mateAuditDialog button { padding: 8px 18px; }
.gameOverDialog button { margin: 4px; }

.matchActions { flex-wrap: wrap; }

#kifuSaveStatus { font-size: .875rem; }
.savedKifuDialog { width: min(680px, 90vw); max-height: 80vh; overflow: auto; }
#savedKifuList { padding-left: 1.25rem; }
#savedKifuList li { margin: .75rem 0; }
#savedKifuList button { margin-left: .75rem; }


/* Compact three-character names without vertical justification gaps. */
.piece.threeCharacterPiece { writing-mode: horizontal-tb; font-size: calc((var(--cell) - 4px) / 3); }
.threeCharacterLabel { display: flex; flex-direction: column; align-items: center; writing-mode: horizontal-tb; }
.threeCharacterLabel > span { display: block; line-height: .86; letter-spacing: 0; }
