:root {
  color-scheme: light;
  --board-width: 720px;
  --board-vertical-chrome: 372px;
  --poster-vertical-chrome: 52px;
  --side-panel-width: 280px;
  --page: #eef2ed;
  --ink: #19221f;
  --muted: #5a6863;
  --panel: #f8faf6;
  --line: #24312d;
  --square-light: #d8c7a5;
  --square-dark: #7f9b87;
  --square-hover: #f0d879;
  --piece-dark: #202825;
  --piece-light: #f2f5ee;
  --piece-ring: rgba(25, 34, 31, 0.22);
  --focus: #2f7f91;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background: var(--page);
}

button {
  font: inherit;
}

.app-shell {
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-layout {
  width: min(96vw, 1040px);
  display: grid;
  justify-items: center;
}

.game-header {
  width: min(100%, var(--board-width));
  aspect-ratio: 45 / 16;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background-color: #0d1110;
  background-image: url("../assets/images/Poster_regen.png");
  background-position: top center;
  background-repeat: no-repeat;
  background-size: 100% auto;
  box-shadow: 0 10px 28px rgba(25, 34, 31, 0.14);
}

.game-header h1 {
  margin: 0;
  position: absolute;
  top: 0;
  right: 0;
  width: 10%;
  height: 10%;
  min-width: 44px;
  min-height: 44px;
  font-size: 0;
  cursor: pointer;
  user-select: none;
}

.game-header.transition-hidden {
  opacity: 0;
}

.status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 1.4em;
  margin: 0;
  padding: 8px 12px;
  color: #f8faf6;
  background: rgba(13, 17, 16, 0.68);
  font-size: 1rem;
}

.controls {
  width: min(100%, var(--board-width));
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 0 0 16px;
}

.controls.advanced-collapsed .advanced-control {
  display: none;
}

.toggle-control,
.field-control {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 0.95rem;
}

.toggle-control {
  padding: 0 12px;
  border: 1px solid rgba(25, 34, 31, 0.24);
  border-radius: 8px;
  background: var(--panel);
}

.toggle-control input {
  width: 18px;
  height: 18px;
  accent-color: var(--focus);
}

.field-control {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.field-control span {
  color: var(--muted);
  font-size: 0.78rem;
}

.field-control select {
  min-width: 132px;
  height: 36px;
  border: 1px solid rgba(25, 34, 31, 0.24);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
}

.debug-output-control {
  flex-basis: 100%;
}

.debug-output-control textarea {
  width: min(100%, var(--board-width));
  min-height: 180px;
  padding: 10px;
  border: 1px solid rgba(25, 34, 31, 0.24);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  font: 0.82rem / 1.35 monospace;
  resize: vertical;
}

.icon-button {
  min-width: 72px;
  height: 44px;
  padding: 0 14px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(25, 34, 31, 0.24);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}

.icon-button:hover {
  border-color: rgba(25, 34, 31, 0.46);
}

.icon-button:focus-visible,
.square:focus-visible,
.piece:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.board {
  width: min(
    100%,
    var(--board-width),
    max(0px, calc((100dvh - var(--board-vertical-chrome)) * var(--board-fit-ratio, 1) - 8px))
  );
  justify-self: center;
  aspect-ratio: var(--board-aspect, 1);
  position: relative;
  border: 3px solid var(--line);
  overflow: hidden;
  background-color: var(--line);
  background-image: url("../assets/images/hotel.png");
  background-position: var(--hotel-bg-x, 50%) var(--hotel-bg-y, 50%);
  background-repeat: no-repeat;
  background-size: var(--hotel-bg-width, 100%) var(--hotel-bg-height, 100%);
  box-shadow: 0 18px 50px rgba(25, 34, 31, 0.18);
  touch-action: none;
  user-select: none;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: rgba(25, 18, 28, 0.4);
  pointer-events: none;
}

.board.start-screen {
  width: min(100%, var(--board-width));
  height: min(
    max(0px, calc(100dvh - var(--poster-vertical-chrome) - 8px)),
    calc(min(96vw, var(--board-width)) * 1.7778)
  );
  aspect-ratio: auto;
  border: 0;
  background: #0d1110;
}

.board.start-screen::before {
  display: none;
}

.start-button {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: clamp(20px, 5vw, 44px);
  border: 0;
  color: #f8faf6;
  background: #0d1110;
  cursor: pointer;
}

.start-button::before {
  content: "";
  position: absolute;
  inset: -18px;
  background-image: url("../assets/images/Poster_regen.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(18px) saturate(1.12);
  opacity: 0.52;
}

.start-button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 16, 0.34);
}

.start-button img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.start-text {
  position: relative;
  z-index: 2;
  width: min(88%, 560px);
  display: grid;
  justify-items: center;
  gap: 12px;
}

.start-help {
  padding: 14px 18px;
  border-radius: 8px;
  color: #f8faf6;
  background: rgba(13, 17, 16, 0.76);
  font-size: clamp(1.2rem, 3.4vw, 1.85rem);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}

.start-label {
  min-width: 148px;
  padding: 10px 18px;
  border: 1px solid rgba(248, 250, 246, 0.62);
  border-radius: 8px;
  background: rgba(13, 17, 16, 0.72);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.poster-transition {
  position: fixed;
  z-index: 20;
  overflow: hidden;
  border-radius: 0;
  background: #0d1110;
  box-shadow: 0 18px 50px rgba(25, 34, 31, 0.22);
  pointer-events: none;
  transition:
    left 680ms cubic-bezier(0.2, 0.8, 0.2, 1),
    top 680ms cubic-bezier(0.2, 0.8, 0.2, 1),
    width 680ms cubic-bezier(0.2, 0.8, 0.2, 1),
    height 680ms cubic-bezier(0.2, 0.8, 0.2, 1),
    border-radius 680ms cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 680ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.poster-transition-active {
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(25, 34, 31, 0.14);
}

.poster-transition::before {
  content: "";
  position: absolute;
  inset: -18px;
  background-image: url("../assets/images/Poster_regen.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(18px) saturate(1.12);
  opacity: 0.52;
}

.poster-transition::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(13, 17, 16, 0.34);
}

.poster-transition img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.poster-transition-active img {
  height: auto;
  object-fit: fill;
}

.level-complete-prompt {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: clamp(18px, 5vw, 40px);
  border: 0;
  color: #f8faf6;
  background: rgba(25, 34, 31, 0.62);
  font-size: clamp(1.35rem, 4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
}

.level-complete-prompt:hover,
.level-complete-prompt:focus-visible {
  background: rgba(25, 34, 31, 0.72);
}

.play-area {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, var(--board-width)) minmax(220px, var(--side-panel-width));
  justify-content: center;
  align-items: start;
  gap: 16px;
}

.play-area.single-column {
  width: min(100%, var(--board-width));
  grid-template-columns: 1fr;
}

.play-area.start-mode {
  width: min(100%, var(--board-width));
}

.move-list {
  max-height: min(94vw, 720px);
  overflow: auto;
}

.move-list.hidden {
  display: none;
}

.move-score-panel {
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid rgba(25, 34, 31, 0.24);
  border-radius: 8px;
  background: var(--panel);
}

.move-score-panel:last-child {
  margin-bottom: 0;
}

.move-score-panel h2 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(25, 34, 31, 0.14);
  color: var(--ink);
  background: var(--panel);
  font-size: 0.95rem;
}

.move-score-panel ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.move-score-panel li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(25, 34, 31, 0.1);
  color: var(--muted);
  font-size: 0.9rem;
}

.move-score-panel li.best {
  color: var(--ink);
  background: rgba(22, 132, 58, 0.13);
}

.move-list strong {
  color: inherit;
  font-weight: 700;
}

.move-list-empty {
  margin: 0;
  padding: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.square {
  position: absolute;
  left: var(--cell-x);
  top: var(--cell-y);
  z-index: 1;
  width: calc(9.2% * var(--cell-scale-x, 1));
  height: calc(10.5% * var(--cell-scale-y, 1));
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
}

.square.light {
  background: transparent;
}

.square.dark {
  background: transparent;
}

.square.drop-target {
  border-radius: 8px;
  background: rgba(240, 216, 121, 0.32);
  outline: 2px solid rgba(240, 216, 121, 0.88);
  outline-offset: -2px;
}

.square.selected-square {
  border-radius: 8px;
  outline: 2px solid rgba(248, 250, 246, 0.86);
  outline-offset: -2px;
}

.square.legal-target::before {
  content: "";
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(248, 250, 246, 0.62);
  box-shadow:
    0 0 0 2px rgba(47, 127, 145, 0.55),
    0 0 18px rgba(240, 216, 121, 0.82);
  pointer-events: none;
}

.piece {
  position: relative;
  width: 84%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 0;
  border: 0;
  appearance: none;
  background-color: transparent;
  box-shadow: none;
  line-height: 0;
  cursor: grab;
}

.piece::before {
  content: "";
  position: absolute;
  inset: 10%;
  z-index: -1;
  border-radius: 50%;
  opacity: 0.76;
  pointer-events: none;
}

.piece-image {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.piece:disabled {
  cursor: default;
}

.piece:active {
  cursor: grabbing;
}

.piece.light-piece::before {
  background: rgba(250, 238, 151, 0.64);
  box-shadow:
    0 0 12px rgba(250, 238, 151, 0.95),
    0 0 24px rgba(65, 190, 210, 0.46);
}

.piece.dark-piece::before {
  background: rgba(113, 232, 142, 0.46);
  box-shadow:
    0 0 12px rgba(113, 232, 142, 0.92),
    0 0 24px rgba(184, 82, 221, 0.5);
}

.piece.dragging {
  opacity: 0.42;
}

.piece.movable {
  filter: drop-shadow(0 0 8px rgba(240, 216, 121, 0.9));
}

.piece.capture-preview-piece {
  filter: drop-shadow(0 0 10px rgba(217, 75, 61, 0.9));
}

.piece.ai-source-piece {
  opacity: 0;
}

.piece.ai-moving-piece {
  position: absolute;
  z-index: 5;
  margin: 0;
  pointer-events: none;
  transition: transform 280ms ease-in-out;
}

.square.capture-square::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 4px solid #d94b3d;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  animation: capture-ring 420ms ease-out forwards;
}

.piece.captured-piece {
  animation: captured-piece 420ms ease-out forwards;
}

@keyframes captured-piece {
  0% {
    filter: none;
    transform: scale(1);
  }

  45% {
    filter: brightness(1.35) saturate(1.4);
    transform: scale(1.12);
  }

  100% {
    filter: brightness(0.9) saturate(0.7);
    opacity: 0.18;
    transform: scale(0.72);
  }
}

@keyframes capture-ring {
  0% {
    opacity: 0.95;
    transform: scale(0.65);
  }

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

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

.move-arrows line {
  stroke: #16843a;
  stroke-width: 1.8;
  stroke-linecap: round;
  opacity: 0.86;
  filter: drop-shadow(0 1px 2px rgba(248, 250, 246, 0.75));
}

.move-arrows marker path {
  fill: #16843a;
}

.hover-arrows {
  z-index: 4;
}

.hover-arrows line {
  stroke-width: 2.6;
  opacity: 0.34;
}

.hover-arrows marker path {
  opacity: 0.44;
}

@media (max-width: 900px) {
  .game-layout,
  .game-header,
  .controls,
  .play-area {
    width: min(100%, var(--board-width));
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .move-list {
    max-height: 260px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    height: 100dvh;
    padding: 16px;
    place-items: start center;
  }

  .board {
    width: min(
      100%,
      var(--board-width),
      max(0px, calc((100dvh - 158px) * var(--board-fit-ratio, 1) - 8px))
    );
  }

  .board.start-screen {
    width: min(100%, var(--board-width));
    height: min(
      max(0px, calc(100dvh - 40px - 8px)),
      calc((100vw - 32px) * 1.7778)
    );
  }
}
