:root {
  color-scheme: light;
  --focus-vh: 100svh;
  --bg: #f6efe4;
  --panel: #fffaf2;
  --ink: #221b16;
  --muted: #74685e;
  --line: #a9784d;
  --line-soft: #dac4a5;
  --red: #b42322;
  --black: #24211e;
  --green: #2f6f5e;
  --gold: #c88724;
  --blue: #2d5f86;
  --shadow: 0 18px 42px rgba(54, 35, 20, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html.focus-board,
body.focus-board {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(122, 83, 51, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(122, 83, 51, 0.08) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(280px, 360px);
  gap: 16px;
}

.topbar,
.panel {
  background: rgba(255, 250, 242, 0.96);
  border: 1px solid rgba(122, 83, 51, 0.18);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 78px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.status-wrap {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: clamp(32px, 2cm, 76px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  display: none;
}

h2 {
  margin-bottom: 10px;
  font-size: 17px;
}

p,
span {
  line-height: 1.45;
}

#gameStatus {
  min-width: 0;
  width: min(520px, 100%);
  flex: 1 1 auto;
  position: relative;
  margin-top: 0;
  padding: 10px 16px;
  color: #4f463c;
  background: #fff7df;
  border: 2px solid #e0c08a;
  border-radius: 999px;
  text-align: center;
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 700;
}

#gameStatus::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  width: 14px;
  height: 14px;
  background: #fff7df;
  border-left: 2px solid #e0c08a;
  border-bottom: 2px solid #e0c08a;
  transform: translateY(-50%) rotate(45deg);
}

#gameStatus.check-status {
  color: #9f4f16;
}

.status-mascot {
  position: relative;
  width: clamp(54px, 8vw, 74px);
  height: clamp(54px, 8vw, 74px);
  flex: 0 0 auto;
  display: block;
  transform: translateY(3px);
}

.status-mascot::before {
  content: none;
}

.status-mascot::after {
  content: none;
}

.status-dino-img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 5px 8px rgba(54, 35, 20, 0.16));
}

.top-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 46px;
  height: 46px;
  color: var(--blue);
  background: #f9ecd7;
  border: 1px solid var(--line-soft);
  border-radius: 50%;
  cursor: pointer;
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
}

.hint-btn {
  min-width: 92px;
  min-height: 46px;
  padding: 0 14px;
  color: #fff;
  background: var(--green);
  border: 1px solid rgba(47, 111, 94, 0.35);
  border-radius: 999px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
  white-space: nowrap;
}

.hint-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.35);
  opacity: 0.58;
}

.pill {
  min-width: 76px;
  padding: 10px 12px;
  color: #fff;
  background: var(--red);
  border-radius: 999px;
  text-align: center;
  font-weight: 900;
}

.pill.black {
  background: var(--black);
}

.board-frame {
  position: relative;
  width: min(100%, 700px, calc((100dvh - 170px) * 0.9));
  aspect-ratio: 9 / 10;
  margin: 14px auto 0;
  padding: clamp(20px, 4vw, 34px);
  background: #e8bd78;
  border: 7px solid #7a5333;
  border-radius: 8px;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 255, 255, 0.34);
  touch-action: none;
  user-select: none;
}

.board-frame.thinking::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 3px solid rgba(47, 111, 94, 0.28);
  border-radius: 8px;
  pointer-events: none;
  animation: thinkingPulse 1.4s ease-in-out infinite;
}

@keyframes thinkingPulse {
  0%,
  100% {
    opacity: 0.35;
  }

  50% {
    opacity: 0.95;
  }
}

.board-lines {
  display: none;
}

.board-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.grid-line {
  position: absolute;
  display: block;
  background: var(--line);
}

.grid-line.vertical {
  width: 2px;
  transform: translateX(-1px);
}

.grid-line.horizontal {
  height: 2px;
  transform: translateY(-1px);
}

.river {
  position: absolute;
  z-index: 1;
  left: 6.25%;
  right: 6.25%;
  top: calc(45.061% + 2px);
  height: calc(9.877% - 4px);
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: rgba(91, 55, 29, 0.34);
  background: #e8bd78;
  font-size: clamp(26px, 5vw, 48px);
  font-weight: 900;
  pointer-events: none;
}

.palace {
  position: absolute;
  z-index: 2;
  left: 39.0625%;
  width: 21.875%;
  height: 19.753%;
  background:
    linear-gradient(to bottom right, transparent calc(50% - 1px), var(--line) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom left, transparent calc(50% - 1px), var(--line) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px));
  pointer-events: none;
}

.palace::before,
.palace::after {
  content: none;
}

.palace-top {
  top: 5.556%;
}

.palace-bottom {
  bottom: 5.556%;
}

.board {
  --piece-size: clamp(34px, 6.2vmin, 54px);
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.cell {
  position: absolute;
  z-index: 3;
  width: 16%;
  height: 14.2%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
}

.cell.move::after,
.cell.check::before {
  content: "";
  position: absolute;
  border-radius: 50%;
}

.cell.move::after {
  z-index: 4;
  width: 32%;
  aspect-ratio: 1;
  background: rgba(47, 111, 94, 0.82);
  box-shadow: 0 0 0 4px rgba(255, 250, 242, 0.72), 0 4px 10px rgba(34, 27, 22, 0.22);
}

.cell.capture-move::after {
  width: 38%;
  background: rgba(47, 111, 94, 0.92);
}

.cell.capture-move {
  box-shadow: inset 0 0 0 5px rgba(47, 111, 94, 0.58);
}

.cell.check::before {
  width: 92%;
  aspect-ratio: 1;
  border: 4px solid rgba(200, 135, 36, 0.88);
  background: rgba(255, 244, 208, 0.42);
}

.cell.hint-from::before,
.cell.hint-to::before,
.cell.capture-target::before {
  content: "";
  position: absolute;
  border-radius: 50%;
}

.cell.hint-from::before {
  width: 92%;
  aspect-ratio: 1;
  border: 5px solid rgba(47, 111, 94, 0.9);
  background: rgba(232, 255, 241, 0.48);
  animation: hintPulse 1s ease-in-out infinite;
}

.cell.hint-to::before {
  width: 74%;
  aspect-ratio: 1;
  border: 5px solid rgba(200, 135, 36, 0.9);
  background: rgba(255, 244, 208, 0.58);
  animation: hintPulse 1s ease-in-out infinite 120ms;
}

.cell.hint-to::after {
  content: "";
  position: absolute;
  width: 34%;
  aspect-ratio: 1;
  border-right: 6px solid var(--green);
  border-bottom: 6px solid var(--green);
  transform: rotate(-45deg);
}

.cell.capture-target::before {
  width: 100%;
  aspect-ratio: 1;
  border: 5px solid rgba(180, 35, 34, 0.82);
  background: rgba(255, 235, 221, 0.58);
  animation: captureRing 780ms ease-out both;
}

.piece {
  position: relative;
  z-index: 2;
  width: var(--piece-size);
  height: var(--piece-size);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: currentColor;
  background: #f1d39b;
  border: 3px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 5px 0 rgba(94, 58, 31, 0.24), inset 0 0 0 2px rgba(130, 85, 42, 0.2);
  font-size: clamp(19px, 3.4vw, 31px);
  font-weight: 900;
  pointer-events: none;
}

.piece.red {
  color: var(--red);
}

.piece.black {
  color: var(--black);
}

.piece.last-piece::after {
  content: "";
  position: absolute;
  right: 6%;
  bottom: 6%;
  width: 22%;
  aspect-ratio: 1;
  background: var(--green);
  border: 2px solid #f1d39b;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(34, 27, 22, 0.2);
}

.piece.human-last::after {
  background: var(--gold);
}

.piece.just-moved {
  animation: pieceTravel 560ms cubic-bezier(0.16, 0.92, 0.34, 1);
}

.capture-fx {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  pointer-events: none;
  animation: captureFloat 1150ms ease-out both;
}

.capture-victim {
  width: var(--piece-size);
  height: var(--piece-size);
  display: grid;
  place-items: center;
  color: currentColor;
  background: #f1d39b;
  border: 3px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 5px 0 rgba(94, 58, 31, 0.18);
  font-size: clamp(19px, 3.4vw, 31px);
  font-weight: 900;
  animation: victimTaken 720ms ease-in both;
}

.capture-victim.red {
  color: var(--red);
}

.capture-victim.black {
  color: var(--black);
}

.capture-label {
  position: absolute;
  top: calc(100% + 8px);
  min-width: max-content;
  padding: 5px 9px;
  color: #fff;
  background: rgba(34, 27, 22, 0.88);
  border-radius: 999px;
  font-size: clamp(13px, 2.2vw, 18px);
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(34, 27, 22, 0.18);
}

@keyframes hintPulse {
  0%,
  100% {
    transform: scale(0.88);
    opacity: 0.74;
  }

  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}

@keyframes captureRing {
  0% {
    transform: scale(0.45);
    opacity: 0;
  }

  55% {
    transform: scale(1.08);
    opacity: 1;
  }

  100% {
    transform: scale(1.28);
    opacity: 0;
  }
}

@keyframes captureFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.82);
  }

  16%,
  70% {
    opacity: 1;
    transform: translate(-50%, -60%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -90%) scale(0.72);
  }
}

@keyframes victimTaken {
  0%,
  30% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: scale(0.2) rotate(18deg);
  }
}

@keyframes pieceTravel {
  0% {
    transform: translate(var(--move-from-x, 0), var(--move-from-y, 0)) scale(0.92);
    filter: brightness(1.03);
  }

  58% {
    transform: translate(0, -10px) scale(1.08);
    filter: brightness(1.1);
  }

  78% {
    transform: translate(0, 3px) scale(0.98);
  }

  100% {
    transform: translate(0, 0) scale(1);
    filter: brightness(1);
  }
}

.board.locked {
  cursor: wait;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  padding: 14px;
}

.segmented,
.select-row {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  background: #ecdec9;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.segment,
.actions button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.segment:active,
.actions button:active,
.button-feedback {
  transform: scale(0.97);
  filter: brightness(1.08);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.36), 0 3px 10px rgba(34, 27, 22, 0.14);
}

.segment {
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.segment.active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 5px 16px rgba(54, 35, 20, 0.12);
}

.select-row select {
  width: 100%;
  min-height: 48px;
  padding: 0 42px 0 14px;
  color: var(--ink);
  background: #f4e6d0;
  border: 2px solid var(--green);
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  appearance: auto;
}

.color-choice {
  margin-top: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions button {
  padding: 0 10px;
  color: #fff;
  background: var(--green);
  font-weight: 900;
}

.actions button:nth-child(3) {
  background: var(--green);
}

.actions button:nth-child(4) {
  background: var(--green);
}

.actions button:disabled {
  color: #80766b;
  background: #ded0bb;
}

.records {
  max-height: 260px;
  margin: 0;
  padding-left: 22px;
  overflow: auto;
  color: var(--muted);
}

.records li {
  margin: 8px 0;
}

.win-modal {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(34, 27, 22, 0.24);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.win-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.win-modal[hidden] {
  display: none;
}

.win-card {
  width: min(390px, 92vw);
  padding: 24px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(122, 83, 51, 0.18);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(34, 27, 22, 0.24);
  text-align: center;
}

.win-card h2 {
  margin: 12px 0 6px;
  font-size: 30px;
}

.win-card p {
  color: var(--muted);
  font-weight: 800;
}

.dino {
  position: relative;
  width: 150px;
  height: 112px;
  margin: 0 auto;
}

.dino-photo {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 36% 44%;
  border: 4px solid #2f6f5e;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(34, 27, 22, 0.18);
}

.dino-body {
  position: absolute;
  left: 30px;
  top: 20px;
  width: 92px;
  height: 70px;
  background: #69a986;
  border: 4px solid #2f6f5e;
  border-radius: 48px 48px 34px 34px;
}

.dino-tail {
  position: absolute;
  left: 10px;
  top: 58px;
  width: 44px;
  height: 24px;
  background: #69a986;
  border: 4px solid #2f6f5e;
  border-right: 0;
  border-radius: 28px 0 0 28px;
  transform: rotate(-18deg);
}

.dino-eye {
  position: absolute;
  right: 24px;
  top: 18px;
  width: 8px;
  height: 8px;
  background: var(--ink);
  border-radius: 50%;
}

.dino-smile {
  position: absolute;
  right: 16px;
  top: 38px;
  width: 20px;
  height: 10px;
  border-bottom: 3px solid var(--ink);
  border-radius: 0 0 20px 20px;
}

.dino-tear {
  display: none;
  position: absolute;
  right: 18px;
  top: 28px;
  width: 8px;
  height: 14px;
  background: #5aa7d8;
  border-radius: 8px 8px 10px 10px;
}

.win-card.lose .dino-body,
.win-card.lose .dino-tail,
.win-card.lose .dino-leg {
  display: none;
}

.win-card.lose .dino {
  width: 230px;
  height: 172px;
}

.win-card.lose .dino-photo {
  display: block;
}

.dino-leg {
  position: absolute;
  bottom: 12px;
  width: 18px;
  height: 24px;
  background: #69a986;
  border: 4px solid #2f6f5e;
  border-top: 0;
  border-radius: 0 0 12px 12px;
}

.leg-one {
  left: 54px;
}

.leg-two {
  left: 92px;
}

.win-actions {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.win-actions button {
  min-height: 46px;
  color: #fff;
  background: var(--green);
  border: 0;
  border-radius: 7px;
  font-weight: 900;
}

.win-actions button:last-child {
  color: var(--ink);
  background: #f4e6d0;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .side {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-wrap {
    width: 100%;
    margin-left: 0;
  }

  .status-mascot {
    width: 52px;
    height: 52px;
  }

  #gameStatus {
    min-width: 0;
    flex: 1;
  }

  .pill {
    flex: 1;
  }

  .top-actions {
    width: 100%;
  }

  .board-frame {
    border-width: 5px;
    padding: 16px;
  }

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

body.focus-board {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: var(--focus-vh);
}

body.focus-board .app {
  width: 100vw;
  max-width: 100vw;
  height: var(--focus-vh);
  min-height: var(--focus-vh);
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

body.focus-board .play-area {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  place-items: start center;
}

body.focus-board .side {
  display: none;
}

body.focus-board .topbar {
  min-height: 64px;
  padding: 10px 12px;
}

body.focus-board h1 {
  display: none;
}

body.focus-board .board-frame {
  width: min(calc((var(--focus-vh) - 128px) * 0.9), calc(100dvw - 28px));
  max-height: calc(var(--focus-vh) - 118px);
  margin-top: 0;
  padding: clamp(30px, 5.2vmin, 50px);
}

@media (orientation: landscape) {
  body.focus-board .board-frame {
    width: min(calc((var(--focus-vh) - 124px) * 0.9), calc(100dvw - 40px));
    max-height: calc(var(--focus-vh) - 116px);
  }
}

body.focus-board .board {
  --piece-size: clamp(40px, 8.9vmin, 68px);
}

body.focus-board .piece {
  font-size: clamp(23px, 4.7vw, 40px);
}
