:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #637067;
  --panel: #fbfaf5;
  --line: #ddd9cf;
  --accent: #286e56;
  --accent-strong: #174d3b;
  --light-square: #e7d7b0;
  --dark-square: #7c9a6c;
  --selected: #f4c24d;
  --target: #24382e;
  --wrong: #bb3d2d;
  --right: #2f7d55;
  --title-font: "Segoe Script", "Brush Script MT", "Lucida Handwriting", cursive;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(40, 110, 86, 0.12), transparent 36%),
    linear-gradient(210deg, rgba(124, 154, 108, 0.18), transparent 34%),
    #f1eee6;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

button:focus-visible,
.square:focus-visible {
  outline: 3px solid rgba(40, 110, 86, 0.35);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 360px) minmax(240px, 320px);
  gap: clamp(18px, 4vw, 48px);
  min-height: 100vh;
  padding: clamp(16px, 4vw, 48px);
  align-items: center;
}

.board-zone,
.control-panel,
.ad-rail {
  min-width: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow,
.label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: var(--title-font);
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.8rem);
  line-height: 1.02;
}

h2 {
  font-size: 1.75rem;
  line-height: 1.16;
}

.icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
}

.position-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.position-meta span,
.theme {
  display: inline-flex;
  width: fit-content;
  border: 1px solid rgba(23, 33, 27, 0.14);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.board-wrap {
  position: relative;
  width: min(76vh, 100%);
  max-width: 720px;
  aspect-ratio: 1;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 8px solid #2d352e;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(31, 41, 34, 0.26);
  overflow: hidden;
}

.piece-traveler {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition-property: transform;
  transition-timing-function: ease-in-out;
}

.piece-traveler .piece-image {
  width: 96%;
  height: 96%;
}

.turn-popup {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 7;
  pointer-events: none;
  transform: translate(-50%, -50%);
  border-radius: 8px;
  padding: 14px 24px;
  background: rgba(45, 53, 46, 0.94);
  color: #ffffff;
  font-size: 1.8rem;
  font-weight: 800;
  box-shadow: 0 16px 38px rgba(28, 35, 30, 0.32);
  animation: turn-popup 1000ms ease both;
}

.fireworks {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}

.firework-burst {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f4c24d;
  box-shadow: 0 0 18px rgba(244, 194, 77, 0.72);
  animation: burst-core 900ms ease-out both;
}

.firework-burst span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
  transform: translate(-50%, -50%) rotate(var(--angle)) translateX(0);
  animation: spark-fly 900ms ease-out both;
}

.firework-burst span:nth-child(3n) {
  background: #2f7d55;
}

.firework-burst span:nth-child(3n + 1) {
  background: #f4c24d;
}

.firework-burst span:nth-child(3n + 2) {
  background: #bb3d2d;
}

@keyframes turn-popup {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.94);
  }

  18%,
  76% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }

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

@keyframes burst-core {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }

  18% {
    opacity: 1;
  }

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

@keyframes spark-fly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateX(0) scale(0.5);
  }

  15% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--angle)) translateX(var(--distance)) scale(0.85);
  }
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  min-height: 0;
  padding: 0;
}

.square:hover {
  transform: none;
}

.light {
  background: var(--light-square);
}

.dark {
  background: var(--dark-square);
}

.square.selected {
  background: var(--selected);
}

.square.target::after {
  content: "";
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(36, 56, 46, 0.42);
  position: absolute;
}

.square.capture-target::after {
  content: "";
  position: absolute;
  inset: 10%;
  border: 5px solid rgba(36, 56, 46, 0.38);
  border-radius: 50%;
}

.piece-image {
  width: 96%;
  height: 96%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  position: relative;
  z-index: 1;
  user-select: none;
  filter: drop-shadow(0 4px 2px rgba(0, 0, 0, 0.26));
}

.coordinates {
  position: absolute;
  color: rgba(23, 33, 27, 0.64);
  font-size: 0.74rem;
  font-weight: 800;
  pointer-events: none;
}

.files {
  left: 8px;
  right: 8px;
  bottom: -22px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  text-align: center;
}

.ranks {
  top: 8px;
  bottom: 8px;
  left: -22px;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
}

.control-panel {
  border-left: 1px solid rgba(23, 33, 27, 0.14);
  padding-left: clamp(18px, 4vw, 40px);
}

.ad-rail {
  display: grid;
  align-content: center;
}

.puzzle-heading {
  margin-bottom: 20px;
}

.select-field {
  margin-bottom: 16px;
}

.select-field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-weight: 750;
}

.select-field select:focus-visible {
  outline: 3px solid rgba(40, 110, 86, 0.35);
  outline-offset: 2px;
}

.theme {
  margin: 12px 0 0;
}

.status {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  font-weight: 750;
  line-height: 1.35;
}

.status.correct {
  border-color: rgba(47, 125, 85, 0.45);
  color: var(--right);
}

.status.wrong {
  border-color: rgba(187, 61, 45, 0.45);
  color: var(--wrong);
}

.ad-slot {
  display: grid;
  place-items: center;
  width: 100%;
  border: 1px dashed rgba(23, 33, 27, 0.3);
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(255, 255, 255, 0.52) 0,
      rgba(255, 255, 255, 0.52) 10px,
      rgba(40, 110, 86, 0.06) 10px,
      rgba(40, 110, 86, 0.06) 20px
    ),
    rgba(251, 250, 245, 0.82);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ad-slot-large {
  height: min(600px, 72vh);
  min-height: 360px;
}

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

#previousButton,
#nextButton {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

#previousButton:hover,
#nextButton:hover {
  background: var(--accent-strong);
}

.puzzle-counter {
  margin-top: 22px;
}

.puzzle-counter p:last-child {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
}

.attribution {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.attribution a {
  color: var(--accent-strong);
  font-weight: 800;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(320px, 1fr) minmax(280px, 360px);
    align-items: start;
  }

  .ad-rail {
    grid-column: 1 / -1;
  }

  .ad-slot-large {
    height: 180px;
    min-height: 180px;
  }
}

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

  .board-wrap {
    width: 100%;
  }

  .control-panel {
    border-left: 0;
    padding-left: 0;
    padding-top: 18px;
  }

  h1 {
    font-size: clamp(2.2rem, 13vw, 4.2rem);
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 14px 14px 32px;
  }

  .board {
    border-width: 5px;
  }

  .coordinates {
    display: none;
  }

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

  .ad-slot-large {
    height: auto;
    min-height: 250px;
  }

}
