:root {
  color-scheme: dark;
  --stone-dark: #21150f;
  --wood: #694126;
  --sand: #d09350;
  --sand-light: #f1c17b;
  --text: #351d0d;
  --panel-width: 31%;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-width: 320px; min-height: 100%; margin: 0; }

body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  overflow: hidden;
  color: #f6e5c7;
  background:
    radial-gradient(ellipse at 9% 52%, rgba(196, 93, 24, .45), transparent 28%),
    radial-gradient(ellipse at 93% 63%, rgba(81, 103, 91, .42), transparent 27%),
    radial-gradient(ellipse at 50% 110%, #b77b42 0, #52331f 34%, transparent 65%),
    linear-gradient(110deg, #28170e, #694126 45%, #29190f);
  font-family: Tahoma, "Noto Sans Thai", sans-serif;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid #fff0c8; outline-offset: 3px; }

.game-scene {
  position: relative;
  isolation: isolate;
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  overflow: hidden;
  background:
    linear-gradient(rgba(32, 16, 6, .12), rgba(22, 12, 6, .23)),
    url("../assets/images/background-cave.png") center / cover no-repeat;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .6), inset 0 0 0 5px rgba(42, 24, 13, .8), inset 0 0 0 8px rgba(205, 143, 79, .28);
}

.game-scene::before, .game-scene::after {
  position: absolute;
  z-index: -1;
  content: "";
  pointer-events: none;
}
.game-scene::before {
  inset: 0;
  opacity: .8;
  background:
    radial-gradient(ellipse at 0 0, rgba(16, 11, 8, .65), transparent 25%),
    radial-gradient(ellipse at 100% 0, rgba(18, 12, 8, .48), transparent 24%),
    radial-gradient(ellipse at 0 100%, rgba(22, 14, 8, .6), transparent 26%),
    radial-gradient(ellipse at 100% 100%, rgba(22, 14, 8, .5), transparent 25%);
}
.game-scene::after {
  inset: 8px;
  border: 1px solid rgba(255, 210, 145, .19);
  box-shadow: inset 0 0 30px rgba(18, 10, 5, .25);
}

.game-scene.is-loading { height: 100dvh; min-height: 0; overflow: hidden; }
.game-scene.is-loading .stage { visibility: hidden; }
.loading-screen { position: absolute; z-index: 2; inset: 0; display: none; overflow: hidden; background: #28170e; }
.game-scene.is-loading .loading-screen { display: grid; }
.loading-screen-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cave-mark {
  position: absolute;
  z-index: 0;
  color: rgba(54, 27, 13, .52);
  font-size: 58px;
  pointer-events: none;
  text-shadow: 0 2px 3px rgba(240, 173, 100, .13);
}
.cave-mark-left { top: 41%; left: 1.4%; transform: rotate(-24deg); }
.cave-mark-right { right: 1.7%; bottom: 11%; transform: rotate(12deg); }

.stage {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: minmax(0, 1.65fr) minmax(255px, .94fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: center;
  gap: 3.2%;
  padding: 3.2% 5.2%;
}

.board-frame {
  position: relative;
  width: auto;
  height: 95%;
  max-width: 100%;
  aspect-ratio: 1;
  justify-self: center;
  transform: translateX(63px) scale(1.1);
  padding: 0;
  border: 0;
}

.board-art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .82)) drop-shadow(0 2px 4px rgba(0, 0, 0, .58)) drop-shadow(0 3px 4px rgba(0, 0, 0, .30));
}

.board-frame::before, .board-frame::after {
  display: none;
}

.board-rim {
  position: absolute;
  top: 10.8%;
  left: 11%;
  width: 78.7%;
  height: 79.2%;
}

.board-grid {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
}

.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  cursor: default;
}
.square.light, .square.dark { background: transparent; }
.square.playable { cursor: pointer; }
.square.playable:hover { filter: brightness(1.14); }
.square.is-selected::after, .square.is-target::after {
  position: absolute;
  inset: 4%;
  border: 3px solid rgba(255, 236, 171, .94);
  border-radius: 8%;
  content: "";
  box-shadow: 0 0 12px rgba(255, 226, 140, .64), inset 0 0 10px rgba(255, 224, 140, .3);
  pointer-events: none;
}
.square.is-target::after {
  inset: 34%;
  border: 0;
  border-radius: 50%;
  background: rgba(68, 109, 46, .72);
  box-shadow: 0 0 0 2px rgba(245, 220, 147, .8), 0 0 8px rgba(39, 49, 23, .6);
}
.square.is-target:hover::after { background: rgba(73, 139, 47, .9); }

.checker {
  position: relative;
  display: block;
  width: 94%;
  height: 94%;
  border-radius: 50%;
  transition: transform .16s ease;
}
.checker-art {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 2px rgba(25, 14, 8, .48));
}
.checker.king::before {
  position: absolute;
  z-index: 0;
  inset: -24%;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 242, 179, .8) 0 44%, rgba(255, 174, 40, .72) 58%, rgba(255, 112, 10, .34) 74%, transparent 90%),
    repeating-conic-gradient(from 8deg, rgba(255, 224, 132, .35) 0deg 3deg, transparent 3deg 17deg);
  filter: blur(3px);
  content: "";
  pointer-events: none;
}
.square.playable:hover .checker { transform: translateY(-2px); }
.square.is-selected .checker { transform: translateY(-3px) scale(1.06); filter: drop-shadow(0 0 6px rgba(255, 230, 159, .85)); }
.square:disabled { opacity: 1; }

.bone, .board-label {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  color: #f1c984;
  text-shadow: 0 2px 2px #4c2b16;
  pointer-events: none;
}
.bone, .board-label { display: none; }
.bone { left: 50%; width: 18%; height: 8%; border: 2px solid #9a6032; border-radius: 50%; background: linear-gradient(#e9bd7d, #9e6637); font-size: clamp(16px, 3vh, 25px); transform: translateX(-50%); }
.bone-top { top: -4%; }
.bone-bottom { bottom: -4%; }
.board-label { top: -5%; left: 50%; width: 10%; height: 10%; border: 2px solid #553018; border-radius: 50%; color: #633b1d; background: #eac286; font-size: clamp(13px, 2.5vh, 20px); transform: translateX(-50%); }

.control-panel {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  padding: 10px 12px 8px;
  border: 5px solid #57351f;
  border-radius: 30px 24px 28px 20px;
  background:
    repeating-linear-gradient(8deg, transparent 0 20px, rgba(255, 219, 160, .045) 21px, transparent 24px),
    linear-gradient(105deg, rgba(81, 48, 27, .96), rgba(151, 94, 46, .94) 47%, rgba(78, 45, 25, .97));
  box-shadow: inset 0 0 0 2px rgba(231, 173, 101, .47), inset 0 0 22px rgba(31, 17, 9, .55), 0 9px 18px rgba(19, 11, 6, .48);
}
.control-panel::before, .control-panel::after {
  position: absolute;
  top: 43%;
  width: 19px;
  height: 19px;
  border: 3px solid #dfb276;
  border-radius: 50%;
  background: #724422;
  content: "";
  box-shadow: 0 2px 3px #24150c;
}
.control-panel::before { left: -12px; }
.control-panel::after { right: -12px; }

.game-title {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 0 7px;
  padding: 1px 0 6px;
  border-bottom: 2px solid rgba(46, 26, 13, .53);
  text-align: center;
  text-shadow: 0 2px 1px #e1ae6e, 0 4px 3px rgba(24, 13, 6, .72);
}
.title-mark { height: 23px; color: #512e17; font-size: 24px; line-height: 1; }
.game-title h1 { margin: -2px 0 0; color: #40230f; font-size: clamp(26px, 5vh, 38px); font-weight: 900; line-height: 1.15; letter-spacing: .03em; }
.title-era { margin-top: 3px; padding: 0 19px; border: 2px solid #794822; border-radius: 20px; color: #3a210f; background: linear-gradient(#efc487, #c8894a); font-size: clamp(12px, 2.1vh, 17px); font-weight: 700; line-height: 1.55; box-shadow: 0 2px 3px rgba(27, 16, 8, .47); }

.player-list { display: grid; width: 100%; gap: 6px; }
.player-card {
  display: grid;
  min-height: 54px;
  grid-template-columns: 43px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border: 2px solid #80522e;
  border-radius: 28px 17px 22px 18px;
  color: #351f11;
  background: linear-gradient(110deg, #e5b778, #b8783e 83%);
  box-shadow: 0 3px 5px rgba(24, 14, 7, .44), inset 0 2px 2px rgba(255, 230, 180, .55);
  transition: transform .18s ease, filter .18s ease;
}
.player-card.is-active { border-color: #f2d293; filter: brightness(1.13); transform: translateX(-3px); }
.player-computer { background: linear-gradient(110deg, #d6ad7e, #987151 83%); }
.avatar { display: grid; width: 39px; height: 39px; place-items: center; border: 2px solid rgba(68, 39, 19, .8); border-radius: 50%; background: radial-gradient(circle at 35% 30%, #e8c38b, #8b5a31); font-size: 25px; box-shadow: 0 2px 3px rgba(37, 22, 11, .44); }
.player-details { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
.player-details strong { overflow: hidden; font-size: clamp(12px, 2.25vh, 17px); font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.mini-stone { width: 17px; height: 17px; border: 2px solid #4f321d; border-radius: 50%; box-shadow: inset 0 1px 2px rgba(255,255,255,.35), 0 1px 2px rgba(0,0,0,.4); }
.red-stone { background: radial-gradient(circle at 35% 25%, #e4b575, #885027); }
.black-stone { background: radial-gradient(circle at 35% 25%, #82705f, #29211b); }
.score-badge { display: grid; width: 31px; height: 31px; place-items: center; border: 2px solid #704323; border-radius: 9px; color: #f1d4a0; background: linear-gradient(#654126, #392315); font-size: 15px; font-weight: 800; box-shadow: inset 0 1px 2px rgba(255,255,255,.15); }

.turn-message {
  min-height: 24px;
  margin: 4px 0 3px;
  color: #f0d7ae;
  font-size: clamp(10px, 1.8vh, 13px);
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}

.menu-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 2px solid #754723;
  color: #3c230f;
  background: linear-gradient(180deg, #e5b778, #bd8043);
  cursor: pointer;
  font-weight: 900;
  text-shadow: 0 1px rgba(255, 223, 170, .42);
  box-shadow: 0 4px 5px rgba(27, 15, 7, .5), inset 0 2px 2px rgba(255, 228, 185, .54), inset 0 -2px 2px rgba(99, 55, 24, .34);
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.menu-button:hover { filter: brightness(1.12); }
.menu-button:active { transform: translateY(2px); box-shadow: 0 1px 2px rgba(27, 15, 7, .5), inset 0 2px 3px rgba(70, 38, 17, .3); }
.primary-button {
  width: 91%;
  min-height: 54px;
  border-width: 3px;
  border-radius: 30px;
  background: linear-gradient(180deg, #e9bd7f, #c18548 54%, #a66c37);
  font-size: clamp(20px, 3.8vh, 29px);
  box-shadow: 0 6px 8px rgba(25, 14, 7, .53), inset 0 3px 3px rgba(255, 228, 185, .57), inset 0 -3px 3px rgba(78, 42, 17, .46);
}
.menu-button.loading-start-button {
  position: relative;
  top: auto;
  left: auto;
  z-index: 1;
  width: min(211.2px, 60.72%);
  height: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 0;
  line-height: 0;
  opacity: 1;
}
.loading-start-art { display: block; width: 100%; height: auto; }
.loading-start-button:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-2px); }
.loading-start-button:disabled { cursor: wait; opacity: .58; }
.button-icon { display: inline-grid; min-width: 25px; place-items: center; color: #583318; font-size: 1.1em; }
.secondary-actions { display: grid; width: 75%; gap: 6px; margin-top: 6px; }
.secondary-button { min-height: 35px; border-radius: 24px; font-size: clamp(14px, 2.5vh, 18px); }
.secondary-button .button-icon { min-width: 22px; font-size: 1.05em; }
.panel-footer { display: flex; align-items: center; justify-content: center; gap: 7px; margin: auto 0 0; padding-top: 7px; color: rgba(255, 228, 187, .85); font-size: clamp(8px, 1.5vh, 10px); text-shadow: 0 1px 2px #351e10; }
.panel-footer span { color: #f2cf91; }

.dialog-backdrop[hidden] { display: none; }
.dialog-backdrop { position: absolute; z-index: 10; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(25, 15, 9, .76); backdrop-filter: blur(4px); }
.dialog-card { position: relative; display: flex; flex-direction: column; width: min(680px, 92%); height: min(544px, calc(min(584px, 100vh, 59.17vw) - 40px)); max-height: calc(min(584px, 100vh, 59.17vw) - 40px); padding: 28px 25px 22px; border: 4px solid #694021; border-radius: 25px; color: #3e2715; background: linear-gradient(145deg, #e7bd83, #b87d45); box-shadow: inset 0 0 0 2px #f0d09e, 0 10px 35px rgba(0,0,0,.5); text-align: center; }
.dialog-close { position: absolute; top: 7px; right: 12px; width: 32px; height: 32px; border: 0; color: #57351e; background: transparent; cursor: pointer; font-size: 27px; }
.dialog-kicker { margin: 0 0 4px; color: #704725; font-size: 11px; letter-spacing: .12em; }
.dialog-card h2 { margin: 0 0 12px; color: #382110; font-size: 24px; }
.dialog-content { min-height: 0; flex: 1 1 auto; overflow-y: auto; font-size: 14px; line-height: 1.8; text-align: left; }
.dialog-content p { margin: 7px 0; }
.dialog-content ul { margin: 5px 0 10px; padding-left: 22px; }
.dialog-content h3 { margin: 12px 0 4px; color: #382110; font-size: 16px; }
.dialog-content .about-game-title { margin-top: 0; text-align: center; }
.dialog-content .about-game-title strong { font-size: 18px; }
.dialog-content .about-game-title span { font-style: italic; }
.dialog-content .menu-button { width: 100%; }
.dialog-confirm { flex: 0 0 auto; width: 65%; margin: 18px auto 0; }
.mode-choice { display: grid; gap: 8px; }
.mode-choice button { width: 100%; min-height: 42px; }
.mode-choice button[aria-pressed="true"] { border-color: #f5dfa4; filter: brightness(1.16); }

@media (max-width: 700px) {
  body { overflow: auto; }
  .game-scene { width: 100vw; height: auto; min-height: 100vh; aspect-ratio: auto; overflow: visible; }
  .dialog-backdrop { position: fixed; }
  .dialog-card { width: min(680px, calc(100vw - 40px), calc(125vh - 50px)); height: auto; aspect-ratio: 5 / 4; max-height: calc(100vh - 40px); }
  .stage { min-height: 100vh; grid-template-columns: 1fr; grid-template-rows: auto auto; gap: 18px; padding: 24px 14px; }
  .board-frame { width: min(88vw, 57vh); height: auto; }
  .control-panel { width: min(88vw, 420px); min-height: 440px; justify-self: center; padding: 16px 18px 12px; }
  .game-title h1 { font-size: 34px; }
  .player-details strong { font-size: 16px; }
  .turn-message { font-size: 13px; }
  .primary-button { min-height: 58px; font-size: 25px; }
  .secondary-button { min-height: 41px; font-size: 16px; }
  .panel-footer { font-size: 10px; }
}

@media (max-height: 500px) and (min-width: 701px) {
  .stage { padding-top: 2%; padding-bottom: 2%; }
  .board-frame { width: auto; height: 95%; }
  .control-panel { padding-top: 7px; padding-bottom: 5px; }
  .game-title { margin-bottom: 4px; padding-bottom: 4px; }
  .title-mark { height: 17px; font-size: 18px; }
  .player-list { gap: 4px; }
  .player-card { min-height: 46px; }
  .avatar { width: 33px; height: 33px; font-size: 21px; }
  .turn-message { min-height: 20px; margin: 3px 0; }
  .primary-button { min-height: 45px; }
  .secondary-actions { gap: 4px; margin-top: 5px; }
  .secondary-button { min-height: 31px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.control-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  transform: translateX(26px) scale(1.1);
}
.control-panel::before, .control-panel::after { display: none; }
.panel-art { position: absolute; z-index: 0; inset: 0; display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.game-title, .panel-footer {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.player-list { position: absolute; z-index: 1; top: 28.5%; left: 16%; display: block; width: 68%; height: 19.5%; gap: 0; }
.player-card {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 46%;
  min-height: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 22px;
  background: transparent;
  box-shadow: none;
  transform: none;
  filter: none;
}
.player-computer { top: 53%; background: transparent; }
.player-card.is-active { border-color: rgba(255, 232, 177, .9); box-shadow: 0 0 10px rgba(255, 219, 148, .48); }
.avatar { display: none; }
.player-details { position: absolute; inset: 0; display: block; min-width: 0; }
.player-details strong {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.mini-stone { display: none; }
.score-badge {
  position: absolute;
  top: 29%;
  right: 7%;
  display: grid;
  width: 15%;
  height: 42%;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(46, 31, 20, .9);
  border-radius: 22%;
  color: #f1d9ad;
  background: rgba(76, 48, 30, .96);
  font-size: clamp(12px, 2.1vh, 17px);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .16);
}
.turn-message {
  position: absolute;
  z-index: 1;
  top: 49%;
  left: 18%;
  width: 64%;
  height: 2.5%;
  min-height: 0;
  margin: 0;
  color: #f5dfbd;
  font-size: clamp(9px, 1.35vh, 11px);
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 2px #321b0d;
}
.primary-button {
  position: absolute;
  z-index: 1;
  top: 51%;
  left: 17.5%;
  width: 65%;
  height: 10%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  opacity: 0;
  box-shadow: none;
}
.secondary-actions {
  position: absolute;
  z-index: 1;
  top: 61.5%;
  left: 22%;
  display: grid;
  width: 56%;
  height: 22.8%;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 5%;
  margin: 0;
}
.secondary-button { width: 100%; min-height: 0; height: 100%; padding: 0; border: 0; border-radius: 0; opacity: 0; box-shadow: none; }

@media (max-width: 700px) {
  .board-frame { transform: scale(1.1); }
  .control-panel { width: min(88vw, 420px); height: auto; min-height: 0; aspect-ratio: 768 / 1382; }
  .control-panel { transform: scale(1.1); }
  .score-badge { font-size: clamp(12px, 4vw, 16px); }
  .turn-message { font-size: clamp(9px, 2.8vw, 11px); }
}

.turn-message {
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.dialog-card .secondary-button {
  height: auto;
  min-height: 42px;
  padding: 8px 12px;
  border: 2px solid #754723;
  border-radius: 24px;
  opacity: 1;
  box-shadow: 0 4px 5px rgba(27, 15, 7, .5), inset 0 2px 2px rgba(255, 228, 185, .54), inset 0 -2px 2px rgba(99, 55, 24, .34);
}
.dialog-card .dialog-confirm { width: 65%; }



