:root {
  --green-900: #0f3526;
  --green-800: #16442f;
  --green-700: #1f5a3c;
  --green-100: #e6f1e9;
  --line: #cbd8ce;
  --light-square: #eef3e9;
  --dark-square: #7a9b70;
  --text: #17231c;
  --muted: #5e6d62;
  --white: #ffffff;
  --danger: #9b2f2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background: var(--white);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 12px;
}

.score {
  width: min(100%, 650px);
  margin: 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green-900);
  background: var(--green-100);
  font-weight: 700;
  white-space: nowrap;
}

.trainer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 18px 0 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  align-items: center;
  width: 100%;
}

label {
  color: var(--green-900);
  font-weight: 700;
}

select,
button {
  min-height: 44px;
  border: 1px solid var(--green-700);
  border-radius: 8px;
}

select {
  width: auto;
  min-width: min(260px, 100%);
  max-width: 100%;
  flex: 1 1 260px;
  padding: 0 12px;
  color: var(--text);
  background: var(--white);
}

button {
  flex: 0 1 auto;
  padding: 0 14px;
  color: var(--white);
  background: var(--green-800);
  font-weight: 700;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  background: var(--green-700);
}

button.secondary {
  color: var(--green-900);
  background: var(--white);
}

.button-row,
.mobile-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.button-row {
  display: contents;
}

.puzzle-card {
  width: min(100%, 650px);
  min-height: 170px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
}

.meta {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.message {
  margin: 0 0 12px;
  color: var(--green-900);
  font-size: 1.15rem;
  font-weight: 800;
}

.message.error {
  color: var(--danger);
}

.hint,
.explanation {
  margin: 10px 0 0;
  color: var(--text);
  line-height: 1.45;
}

.board-panel {
  display: grid;
  gap: 12px;
  justify-items: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(80vw, 650px);
  height: min(80vw, 650px);
  border: 6px solid var(--green-900);
  border-radius: 8px;
  overflow: hidden;
  background: var(--green-900);
  box-shadow: 0 14px 32px rgba(15, 53, 38, 0.16);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  color: #111;
  background: var(--light-square);
  line-height: 1;
}

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

.square.selected {
  outline: 4px solid #f2c94c;
  outline-offset: -4px;
}

.square.legal::after {
  content: "";
  position: absolute;
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(15, 53, 38, 0.35);
}

.piece {
  position: absolute;
  inset: 4%;
  z-index: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.piece-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.coord {
  position: absolute;
  z-index: 2;
  font-family: system-ui, sans-serif;
  font-size: clamp(0.56rem, 1.8vw, 0.78rem);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.coord-rank {
  left: 5px;
  top: 5px;
}

.coord-file {
  right: 5px;
  bottom: 5px;
}

.coord-light {
  color: rgba(15, 53, 38, 0.72);
}

.coord-dark {
  color: rgba(250, 255, 247, 0.86);
}

.mobile-actions {
  display: none;
  width: min(80vw, 650px);
}

@media (max-width: 760px) {
  .score {
    white-space: normal;
  }

  select,
  button {
    flex: 1 1 150px;
  }

  .board {
    width: min(90vw, 650px);
    height: min(90vw, 650px);
    border-width: 4px;
  }

  .mobile-actions {
    display: none;
    width: min(90vw, 650px);
  }
}
