:root {
  color-scheme: dark;
  font-family: Tahoma, system-ui, sans-serif;
  background: #100b08;
  color: #f7dfb3;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, #342013, #100b08 78%);
}

button { font: inherit; }

.game,
.game-splash {
  width: min(100vw, 167.46575svh, 978px);
  aspect-ratio: 978 / 584;
  position: relative;
}

.game-splash {
  overflow: hidden;
  background: #24170e;
}

.game-splash-poster {
  display: block;
  width: 100%;
  height: 100%;
}

.game-splash .game-loading-status {
  bottom: clamp(48px, 14%, 82px);
  width: min(42%, 420px);
  padding: 5px 8px;
  border-radius: 8px;
  background: #170e09d9;
}

.game-splash .loading-progress-fill {
  background: linear-gradient(90deg, #a66836, #ffda87);
}

.game-splash .game-loading-start {
  bottom: clamp(6px, 4%, 24px);
  width: min(160px, 40%);
  height: clamp(30px, 8%, 42px);
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent url("../assets/images/wooden-start-button.webp") center / contain no-repeat;
  text-shadow: 0 1px 3px #1b0d04;
  color: #fff1cf;
  cursor: pointer;
  font-weight: 700;
}

.game-splash .game-loading-start:focus-visible {
  outline: 2px solid #fff1cf;
  outline-offset: 3px;
}

.game {
  isolation: isolate;
  --side-panel-inset: 8.9cqw;
  --side-panel-width: 10.6cqw;
  --panel-border: .12cqw solid #8c623b;
  --panel-surface: linear-gradient(145deg, #2a1c13, #130d09);
  --panel-shadow: 0 .3cqw .8cqw #0009;
  container-type: inline-size;
  overflow: hidden;
  --scene-side-shading: linear-gradient(90deg, #0b0704a8, #130b0670 19%, transparent 36% 64%, #080c0e76 83%, #080c0eb8);
  --scene-vertical-shading: linear-gradient(0deg, #09060488, transparent 22% 78%, #09060455);
  background:
    var(--scene-side-shading),
    var(--scene-vertical-shading),
    #24170e var(--scene-image, none) center / cover no-repeat;
  box-shadow: 0 1.2cqw 4cqw #0009;
}

/* Isolate the original wooden board from the interchangeable room scenes. */
.game::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    var(--scene-side-shading),
    var(--scene-vertical-shading),
    url('../assets/images/makruk-background.png') center / 100% 100% no-repeat;
  clip-path: inset(0 22.06% 4.85% 22.06% round 2cqw);
  pointer-events: none;
}

.game[data-scene="original"] { background-size: 100% 100%; }
.game[data-scene="original"]::before { display: none; }

.board {
  position: absolute;
  z-index: 1;
  /* Grid edges measured against the 1287 × 768 background artwork. */
  left: 23.62%;
  top: 3.65%;
  width: 52.68%;
  height: 87.76%;
  display: grid;
  grid-template-columns: 88fr 84fr 84fr 84fr 83fr 84fr 84fr 87fr;
  grid-template-rows: 88fr 88fr 83fr 84fr 82fr 81fr 82fr 86fr;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  background: transparent;
  color: #f8e1b8;
}

.square:disabled { opacity: 1; cursor: default; }

.square[aria-pressed="true"] {
  box-shadow: inset 0 0 0 .16cqw #ffe19a75;
}

.square:focus-visible {
  z-index: 3;
  outline: .3cqw solid #fff0a9;
  outline-offset: -.35cqw;
}

.coordinate {
  display: none;
  position: absolute;
  z-index: 1;
  top: .18cqw;
  left: .28cqw;
  color: #f8cf78;
  font-size: 1.35cqw;
  line-height: 1;
  text-shadow: 0 1px 3px #241006;
  pointer-events: none;
}

.file-letter-patch {
  position: absolute;
  left: calc(var(--letter-x) - 1.25cqw);
  top: 86.65%;
  width: 2.5cqw;
  height: 2.65cqw;
  background-image:
    var(--scene-side-shading),
    var(--scene-vertical-shading),
    url('../assets/images/makruk-background.png');
  background-repeat: no-repeat;
  background-size: 100cqw calc(100cqw * 584 / 978);
  background-position:
    calc(1.25cqw - var(--letter-x)) calc(-86.65cqw * 584 / 978),
    calc(1.25cqw - var(--letter-x)) calc(-86.65cqw * 584 / 978),
    calc(1.25cqw - var(--letter-x)) -48.95cqw;
  mask-image: radial-gradient(ellipse closest-side, #000 62%, transparent 100%);
  pointer-events: none;
}

.coordinate.file {
  display: block;
  top: auto;
  right: .34cqw;
  bottom: .25cqw;
  left: auto;
  color: rgb(212 175 111 / 63%);
  text-shadow: 0 1px 1px #24100670;
}

.piece-art {
  display: block;
  position: relative;
  pointer-events: none;
}

.piece-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.piece {
  position: absolute;
  left: 14%;
  bottom: 0;
  width: 72%;
  height: 84%;
}

.piece img {
  object-position: center bottom;
  filter: drop-shadow(0 .18cqw .15cqw #160c06c9);
}

.piece.met-art { left: 6.8%; width: 86.4%; height: 66%; }
.piece.met-art img { transform: scaleX(.8); }
.piece.khon-art { left: 8.6%; width: 82.8%; height: 85.1%; }
.piece.king-art { height: 100%; }
.piece.horse-art { height: 92%; }
.piece.rook-art { left: 7%; width: 86%; height: 59%; }
.piece.pawn-art {
  top: 21%;
  left: 21%;
  bottom: auto;
  width: 58%;
  height: 58%;
}

.piece.pawn-art img { object-position: center; }

.piece.dark-art:not(.pawn-art) img {
  /* Trim the fringe at the base and keep the trimmed edge on the square line. */
  clip-path: inset(0 0 2% 0);
  translate: 0 2%;
  filter: none;
}

.square[aria-pressed="true"] .piece {
  filter: drop-shadow(0 0 .19cqw #fff0ba) drop-shadow(0 0 .4cqw #ffad38);
}

.toolbar {
  position: absolute;
  z-index: 3;
  top: 1.7cqw;
  display: grid;
  gap: .55cqw;
  padding: 1.1cqw .8cqw .8cqw;
  border: var(--panel-border);
  border-radius: .65cqw;
  background: var(--panel-surface);
  box-shadow: var(--panel-shadow);
}

.toolbar-left { left: 1.15cqw; }


.tool-button {
  width: 4.1cqw;
  height: 4.1cqw;
  padding: 0;
  border: 0;
  background: transparent;
  color: #f5e1c4;
  font-family: Arial, sans-serif;
  font-size: 3.2cqw;
  line-height: 1;
  text-shadow: 0 2px 6px #000;
  cursor: pointer;
}

.tool-button:hover { color: #ffc574; background: #fff1d314; border-radius: .4cqw; }
.tool-button:focus-visible { outline: 1px solid #ffd78f; border-radius: .4cqw; }

.capture {
  position: absolute;
  z-index: 2;
  top: 16.1%;
  width: var(--side-panel-width);
  padding: .75cqw .8cqw;
  border: var(--panel-border);
  border-radius: .65cqw;
  background: var(--panel-surface);
  box-shadow: var(--panel-shadow);
  text-shadow: 0 1px 3px #000;
}

.capture-dark { left: var(--side-panel-inset); }
.capture-light { right: var(--side-panel-inset); }

.capture h2 {
  margin: 0 0 .35cqw;
  padding-bottom: .48cqw;
  border-bottom: 1px solid #98663d;
  color: #ffe4bb;
  font-size: 1.37cqw;
  font-weight: 400;
  line-height: 1.35;
  text-align: center;
}

.capture ul {
  display: grid;
  gap: .12cqw;
  margin: 0;
  padding: 0;
  list-style: none;
}

.capture li {
  min-height: 2.35cqw;
  display: grid;
  grid-template-columns: 2.66cqw auto;
  justify-content: space-between;
  align-items: center;
  column-gap: .35cqw;
  padding: 0 .32cqw;
  font-size: 1.38cqw;
  font-variant-numeric: tabular-nums;
}

.capture li:nth-child(odd) {
  border-radius: .28cqw;
  background: #f6cb890b;
}

.mini-piece {
  width: 2.25cqw;
  height: 1.95cqw;
}

.capture-dark .mini-piece img {
  filter: brightness(1.3) drop-shadow(0 0 .13cqw #e9ba7960);
}

.selection-status {
  position: absolute;
  right: 1.6cqw;
  bottom: 1.2cqw;
  z-index: 3;
  max-width: 30cqw;
  padding: .45cqw .8cqw;
  border: 1px solid #a87a4d75;
  border-radius: .45cqw;
  background: #100b08c7;
  color: #f5dfbd;
  font-size: 1.3cqw;
  text-align: center;
  text-shadow: 0 1px 3px #000;
}

@media (max-width: 560px) {
  .game { min-width: 320px; }
  .capture { top: 16.1%; }
  .tool-button { width: 5cqw; height: 5cqw; font-size: 4cqw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}

.square.destination { cursor: pointer; }

.square.destination::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0;
  background:
    radial-gradient(circle closest-side, #fff 28%, transparent 30%),
    url("../assets/images/move-corners.svg") center / 100% 100% no-repeat;
  filter: drop-shadow(0 0 .12cqw #30190c);
  pointer-events: none;
}

.square.capture-destination::after {
  background-image:
    radial-gradient(circle closest-side, #fff 18%, transparent 20%),
    url("../assets/images/move-corners.svg");
}

.ai-settings {
  position: absolute;
  z-index: 4;
  left: var(--side-panel-inset);
  top: 1.7cqw;
  width: var(--side-panel-width);
  display: grid;
  gap: .35cqw;
  padding: .55cqw .65cqw .65cqw;
  border: var(--panel-border);
  border-radius: .65cqw;
  background: var(--panel-surface);
  box-shadow: var(--panel-shadow);
  color: #f8d9a8;
  font-size: max(10px, 1.35cqw);
  line-height: 1.2;
}

.ai-settings[hidden] { display: none; }

.ai-settings select {
  width: 100%;
  min-width: 0;
  min-height: max(24px, 2.65cqw);
  padding: 0 .45cqw;
  border: 1px solid #75512f;
  border-radius: .35cqw;
  background: #160f0b;
  color: #fff0d4;
  font: inherit;
  cursor: pointer;
}

.ai-settings select:focus-visible { outline: 1px solid #ffd78f; }

@media (max-width: 560px) {
  .ai-settings { top: auto; bottom: 17%; width: max(48px, var(--side-panel-width)); }
}

.square.checked-king::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  border: .34cqw solid #ff816c;
  box-shadow: inset 0 0 1.2cqw .2cqw #a8110d;
  pointer-events: none;
  animation: check-pulse 650ms ease-in-out 2;
}

.selection-status.threat-alert {
  border-color: #ff816c;
  background: #4a1714;
  color: #fff0dd;
}

@keyframes check-pulse {
  50% { opacity: .36; }
}

@media (prefers-reduced-motion: reduce) {
  .square.checked-king::before { animation: none; }
}

@font-face {
  font-family: "Noto Serif Thai Title";
  src: url("../assets/fonts/noto-serif-thai-title.ttf") format("truetype");
  font-display: swap;
}

.game-title {
  position: absolute;
  z-index: 2;
  left: 1.65%;
  bottom: 3.2%;
  width: 19.5%;
  margin: 0;
  color: #e6bb79;
  font: 400 3.05cqw / 1.35 "Noto Serif Thai Title", "Noto Serif Thai", serif;
  text-align: center;
  text-shadow: 0 .15cqw .35cqw #190e08;
  white-space: nowrap;
}

.last-ai-corners {
  --move-mark-color: #a2dbef;
  opacity: .6;
  position: absolute;
  z-index: 1;
  inset: 0;
  filter: drop-shadow(0 0 .11cqw #141b25) drop-shadow(0 0 .1cqw #141b25);
  pointer-events: none;
}

.last-ai-corners::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--move-mark-color);
  mask: url("../assets/images/move-corners.svg") center / 100% 100% no-repeat;
}

.last-ai-corners-target {
  --move-mark-color: #e0f8ff;
  filter: drop-shadow(0 0 .12cqw #122232) drop-shadow(0 0 .16cqw #27688b);
}

.last-ai-note {
  display: block;
  margin-top: .2cqw;
  color: #f1d39a;
}

.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .25cqw;
}

#sound-toggle {
  padding: 0 .28cqw;
  border: 1px solid #75512f;
  border-radius: .25cqw;
  background: #160f0b;
  color: #ffe3a8;
  font: inherit;
  line-height: 1.1;
  cursor: pointer;
}

#sound-toggle[aria-pressed="true"] { color: #c2ae98; }
#sound-toggle:focus-visible { outline: 1px solid #ffd78f; }

.endgame-count {
  position: absolute;
  z-index: 4;
  top: 52%;
  right: 2.05%;
  width: 17%;
  padding: 1cqw .65cqw;
  border: .16cqw solid #b99056;
  border-radius: .7cqw;
  background: var(--panel-surface);
  box-shadow: 0 .4cqw 1.2cqw #000a;
  text-align: center;
  pointer-events: none;
  animation: count-panel-in 180ms ease-out;
}

.endgame-count h2,
.endgame-count p { margin: 0; }
.endgame-count h2 { font-size: 1.7cqw; }
#endgame-value {
  color: #ffe09f;
  font-size: 3.25cqw;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#endgame-detail { color: #ddb983; font-size: 1.24cqw; }

@keyframes count-panel-in {
  from { opacity: 0; translate: 0 .5cqw; }
}

@media (prefers-reduced-motion: reduce) {
  .endgame-count { animation: none; }
}

.scene-icon-cover { display: none; }
.game[data-scene="original"] .scene-icon-cover { display: block; }

.scene-icon-cover {
  position: absolute;
  left: 94.8%;
  top: var(--scene-cover-y);
  width: 4.65cqw;
  height: 3.7cqw;
  background-image:
    var(--scene-side-shading),
    var(--scene-vertical-shading),
    url('../assets/images/makruk-background.png');
  background-repeat: no-repeat;
  background-size: 100cqw calc(100cqw * 584 / 978);
  background-position:
    -94.8cqw var(--scene-cover-offset),
    -94.8cqw var(--scene-cover-offset),
    -94.8cqw var(--scene-sample-offset);
  mask-image: radial-gradient(ellipse closest-side, #000 82%, transparent 100%);
  pointer-events: none;
}

.scene-icon-cover-fullscreen {
  --scene-cover-y: 2.23%;
  --scene-cover-offset: -1.33cqw;
  --scene-sample-offset: -10.5cqw;
}

.scene-icon-cover-flip {
  --scene-cover-y: 9.95%;
  --scene-cover-offset: -5.94cqw;
  --scene-sample-offset: -15.1cqw;
}
