:root {
  --ink: #253044;
  --muted: #667085;
  --paper: #fffaf0;
  --panel: rgba(255, 255, 255, 0.86);
  --line: rgba(37, 48, 68, 0.16);
  --teal: #27b6a6;
  --blue: #4f8cff;
  --green: #57c65f;
  --yellow: #ffd84f;
  --orange: #ff9f43;
  --pink: #ff6aa2;
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --shadow: 0 18px 45px rgba(37, 48, 68, 0.16);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  background:
    linear-gradient(90deg, rgba(79, 140, 255, 0.1) 1px, transparent 1px),
    linear-gradient(rgba(39, 182, 166, 0.1) 1px, transparent 1px),
    linear-gradient(135deg, #fff7df 0%, #e8fbff 48%, #fff0f7 100%);
  background-size: 34px 34px, 34px 34px, auto;
  user-select: none;
  touch-action: manipulation;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 3px 16px rgba(37, 48, 68, 0.12);
  backdrop-filter: blur(8px);
}

.home-logo {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 900;
  white-space: nowrap;
}

.home-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 0.8rem;
}

.game-logo {
  min-width: 0;
  overflow: hidden;
  justify-self: center;
  color: var(--teal);
  font-size: clamp(1.1rem, 3vw, 1.55rem);
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-logo span {
  color: var(--yellow);
  text-shadow: 0 2px 0 var(--ink);
}

.top-actions,
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions {
  justify-self: end;
  border: 3px solid rgba(37, 48, 68, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  padding: 6px;
  box-shadow: 0 6px 18px rgba(37, 48, 68, 0.1);
}

.pill,
.btn,
.icon-btn,
.rule-card {
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(37, 48, 68, 0.15);
  transition: transform 90ms ease, box-shadow 90ms ease, background 140ms ease;
}

.pill {
  min-width: 116px;
  min-height: 50px;
  padding: 10px 20px;
  background: #fff;
  font-size: 1.12rem;
}

.pill.active {
  background: var(--yellow);
}

.icon-btn {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  background: #fff;
  font-size: 1.15rem;
}

.btn {
  min-height: 42px;
  padding: 8px 16px;
  color: #fff;
}

.btn.green {
  background: var(--green);
}

.btn.blue {
  background: var(--blue);
}

.btn.orange {
  background: var(--orange);
}

.pill:active,
.btn:active,
.icon-btn:active,
.rule-card:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(37, 48, 68, 0.15);
}

.app {
  height: 100%;
  min-height: 0;
}

.screen {
  display: none;
  height: 100%;
  min-height: 0;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
}

.screen.active {
  display: grid;
}

.mode-screen.active {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 22px;
  background: #f7fbff;
}

.mode-panel {
  width: min(920px, 100%);
  text-align: center;
}

.mode-panel h1 {
  margin-bottom: 26px;
  font-size: clamp(3rem, 9vw, 6rem);
  color: var(--ink);
  text-shadow: none;
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 20px;
}

.mode-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-height: 250px;
  border: 5px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 24px;
  color: var(--ink);
  box-shadow: var(--shadow), 8px 8px 0 rgba(37, 48, 68, 0.22);
  text-align: center;
}

.mode-card:first-child {
  border-color: var(--teal);
}

.mode-card:nth-child(2) {
  border-color: var(--blue);
}

.mode-card strong {
  font-size: 2rem;
  line-height: 1;
}

.mode-card span:last-child {
  color: var(--muted);
  font-size: 1.08rem;
  font-weight: 800;
}

.mode-icon {
  display: grid;
  width: 88px;
  height: 88px;
  place-items: center;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-size: 2.5rem;
  box-shadow: 5px 5px 0 rgba(37, 48, 68, 0.2);
}

.side-panel {
  position: relative;
  z-index: 2;
  overflow: auto;
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.back-btn {
  display: none;
  min-height: 40px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  padding: 6px 14px;
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 3px 0 rgba(37, 48, 68, 0.16);
}

#learnScreen .side-panel {
  background: #ffffff;
  border-right: 6px solid var(--teal);
}

#learnScreen .side-panel h1 {
  color: var(--ink);
  text-shadow: none;
}

#learnScreen .side-copy {
  border: 3px solid var(--teal);
  border-radius: 8px;
  background: #eafffc;
  padding: 10px 12px;
  box-shadow: none;
  color: var(--ink);
  font-weight: 900;
}

#playScreen {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
}

#playScreen .play-side {
  border-right: 0;
  border-left: 1px solid var(--line);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 0.95;
  letter-spacing: 0;
}

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

.side-copy,
.turn-card p {
  color: var(--muted);
  font-weight: 700;
}

.lesson-list,
.mini-lessons {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.lesson-btn {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
}

.lesson-btn.active {
  border-color: var(--teal);
  background: #eafffc;
}

.lesson-piece {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 2rem;
  box-shadow: none;
}

.lesson-btn strong,
.lesson-btn span {
  display: block;
}

.lesson-btn span {
  color: var(--muted);
  font-weight: 700;
}

.lesson-stars {
  color: var(--orange);
  font-size: 1.2rem;
}

.rule-card {
  width: 100%;
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  text-align: left;
}

.learn-stage,
.play-stage {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: 16px;
}

.learn-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(860px, 100%);
  margin: 0 auto 10px;
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.learn-hud strong,
.turn-card strong {
  font-size: 1.35rem;
}

.progress-wrap {
  width: min(860px, 100%);
  height: 12px;
  margin: 0 auto 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--pink));
  transition: width 220ms ease;
}

.board-wrap {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  place-items: center;
}

.learn-board-row {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(190px, 270px);
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-width: 0;
}

.learn-info {
  align-self: center;
  border: 3px solid var(--teal);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: var(--shadow);
}

.chess-board {
  display: grid;
  width: min(64vh, 72vw, 650px);
  aspect-ratio: 1;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border: 7px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow), 8px 8px 0 rgba(37, 48, 68, 0.18);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: var(--light-square);
}

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

.square.selected::after,
.square.move::after,
.square.capture::after,
.square.star-target::after,
.square.last-move::after,
.square.check::after {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.square.selected::after {
  border: 5px solid rgba(255, 216, 79, 0.95);
}

.square.move::after {
  background: rgba(105, 105, 105, 0.42);
}

.square.capture::after {
  border: 7px solid rgba(255, 106, 162, 0.72);
}

.square.star-target::after {
  border: 5px dashed rgba(255, 159, 67, 0.9);
}

.square.last-move::after {
  background: rgba(255, 216, 79, 0.36);
  border-radius: 8px;
}

.square.check::after {
  background: rgba(255, 93, 93, 0.45);
  border-radius: 8px;
}

.piece {
  position: relative;
  z-index: 2;
  display: grid;
  width: 92%;
  height: 92%;
  place-items: center;
  border-radius: 0;
  background: transparent;
  font-size: clamp(1.9rem, 7vmin, 5rem);
  font-family: "DejaVu Sans", "Segoe UI Symbol", "Arial Unicode MS", serif;
  font-weight: 400;
  line-height: 1;
  filter: none;
}

.piece.white {
  color: #fafafa;
  text-shadow:
    0 1px 0 #4b5568,
    1px 0 0 #4b5568,
    -1px 0 0 #4b5568,
    0 -1px 0 #4b5568;
}

.piece.black {
  color: #3f4a5f;
  text-shadow: none;
}

.star {
  z-index: 1;
  font-size: clamp(1.7rem, 6vmin, 4.4rem);
  line-height: 1;
  filter: drop-shadow(0 4px 0 rgba(37, 48, 68, 0.18));
  animation: star-bounce 850ms ease-in-out infinite alternate;
}

#learnBoard .star {
  font-size: clamp(1.25rem, 4.5vmin, 3.2rem);
}

@keyframes star-bounce {
  to {
    transform: scale(1.1) rotate(8deg);
  }
}

.message {
  width: 100%;
  min-height: 0;
  margin: 8px 0 0;
  border-radius: 8px;
  background: transparent;
  padding: 0;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  text-align: left;
  box-shadow: none;
}

.play-side label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-weight: 800;
}

select {
  min-height: 42px;
  border: 3px solid rgba(37, 48, 68, 0.16);
  border-radius: 999px;
  background: #fff;
  padding: 6px 12px;
  color: var(--ink);
  font-weight: 800;
}

.turn-card,
.captured {
  margin-top: 16px;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: var(--shadow);
}

.captured div {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 8px;
  min-height: 32px;
  align-items: center;
  font-size: 1.2rem;
}

.captured span {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.play-wrap .chess-board {
  width: min(86vh, calc(100vw - 500px), 760px);
}

.play-board-row {
  display: grid;
  grid-template-columns: 150px minmax(0, auto) 150px;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.play-board-row::after {
  display: block;
  width: 150px;
  content: "";
}

.capture-strip {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  width: 100%;
  min-height: 86px;
  border-radius: 8px;
  background: transparent;
  padding: 10px;
  box-shadow: none;
}

.capture-column {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  width: 150px;
  height: min(86vh, calc(100vw - 500px), 760px);
}

.capture-strip span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.05;
}

.capture-strip b {
  min-height: 58px;
  overflow-wrap: anywhere;
  font-size: 1.3rem;
  line-height: 1.1;
}

.top-captures {
  margin: 0;
}

.bottom-captures {
  grid-row: 3;
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  max-width: min(92vw, 520px);
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 180%);
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 14px 18px;
  box-shadow: 8px 8px 0 rgba(37, 48, 68, 0.22);
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  transition:
    transform 180ms ease,
    opacity 180ms ease,
    visibility 0s linear 180ms;
}

.toast.show {
  visibility: visible;
  opacity: 1;
  transform: translate(-50%, 0);
  transition:
    transform 180ms ease,
    opacity 180ms ease;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(37, 48, 68, 0.34);
  backdrop-filter: blur(5px);
}

.overlay.show {
  display: grid;
}

.modal {
  width: min(92vw, 430px);
  border: 5px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 22px;
  text-align: center;
  box-shadow: 10px 10px 0 rgba(37, 48, 68, 0.22);
}

.modal-trophy {
  font-size: 4rem;
  line-height: 1;
}

.modal h2 {
  margin: 8px 0 6px;
  font-size: 2.2rem;
}

.modal p {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 800;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stats-row > div {
  border-radius: 8px;
  background: #f7fbf8;
  padding: 12px;
}

.stats-row strong {
  display: block;
  font-size: 1.45rem;
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 15;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

body.theme-classic {
  --light-square: #f0d9b5;
  --dark-square: #b58863;
}

body.theme-classic .piece.black {
  color: #3f4a5f;
}

body.theme-classic .piece.white {
  color: #ffffff;
}

body.theme-kids {
  --light-square: #f0d9b5;
  --dark-square: #b58863;
}

body.theme-dino {
  --light-square: #dff4e9;
  --dark-square: #0b5f43;
}

body.theme-space {
  --light-square: #e4f1eb;
  --dark-square: #126846;
}

body.theme-candy {
  --light-square: #f2fbf6;
  --dark-square: #15835d;
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .topbar {
    height: auto;
    min-height: 48px;
    justify-content: center;
    gap: 8px;
    padding: 6px 8px;
  }

  .home-logo {
    justify-self: start;
    gap: 7px;
    font-size: 0.9rem;
  }

  .home-mark {
    width: 34px;
    height: 34px;
    border-width: 2px;
    font-size: 0.68rem;
  }

  .game-logo {
    justify-self: center;
    width: auto;
    order: initial;
    font-size: 1rem;
  }

  .top-actions {
    justify-self: end;
    order: initial;
    padding: 4px;
    gap: 4px;
    flex-wrap: nowrap;
  }

  .app {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .screen.active {
    display: flex;
    flex-direction: column;
  }

  .mode-screen.active {
    min-height: 0;
    padding: 14px;
  }

  .mode-panel h1 {
    margin-bottom: 16px;
    font-size: clamp(2.4rem, 14vw, 4rem);
  }

  .mode-options {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    width: min(100%, 360px);
    margin: 0 auto;
  }

  .mode-card {
    min-height: 160px;
    padding: 18px;
  }

  .mode-icon {
    width: 64px;
    height: 64px;
    font-size: 2rem;
  }

  .side-panel {
    border: 0;
    padding: 10px;
  }

  .back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
  }

  #learnScreen.active,
  #playScreen.active {
    height: 100%;
    overflow: hidden;
  }

  #learnScreen .side-panel {
    flex: 0 0 auto;
    max-height: 162px;
    overflow: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #learnScreen .side-panel h1 {
    display: inline-block;
    margin: 0 0 0 10px;
    font-size: 1.45rem;
    vertical-align: middle;
  }

  #learnScreen .side-copy,
  #learnScreen .mini-lessons {
    display: none;
  }

  .lesson-list {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .lesson-list::-webkit-scrollbar {
    display: none;
  }

  .lesson-btn {
    min-width: 132px;
    grid-template-columns: 34px 1fr auto;
    padding: 7px;
  }

  .lesson-piece {
    width: 34px;
    height: 34px;
    font-size: 1.4rem;
  }

  .lesson-btn span {
    display: none;
  }

  .learn-stage,
  .play-stage {
    min-height: 0;
    flex: 1 1 auto;
    padding: 8px;
    overflow: hidden;
  }

  .learn-hud {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    width: 100%;
    margin-bottom: 7px;
    padding: 7px 9px;
  }

  .chess-board,
  .play-wrap .chess-board {
    width: min(calc(100vw - 108px), 76vh, 620px);
  }

  .learn-board-row {
    grid-template-columns: minmax(0, 1fr) minmax(130px, 180px);
    flex: 1 1 auto;
    align-items: center;
    gap: 8px;
    min-height: 0;
  }

  .learn-info {
    width: auto;
    margin: 0;
    padding: 10px;
  }

  #playScreen {
    flex-direction: row;
  }

  #playScreen .play-stage {
    flex: 1 1 auto;
  }

  #playScreen .play-side {
    flex: 0 0 185px;
    order: 2;
    border-left: 1px solid var(--line);
    overflow: hidden;
  }

  #playScreen .play-side h1 {
    margin-bottom: 8px;
    font-size: 1.45rem;
  }

  .controls {
    gap: 6px;
  }

  .controls label {
    width: 100%;
  }

  select,
  .btn {
    min-height: 36px;
    padding: 5px 10px;
    font-size: 0.85rem;
  }

  .play-board-row {
    grid-template-columns: 76px minmax(0, auto) 76px;
    gap: 8px;
  }

  .play-board-row::after {
    width: 76px;
  }

  .capture-column {
    width: 76px;
    gap: 8px;
  }

  .capture-strip {
    min-height: 96px;
    padding: 8px;
  }

  .capture-strip span {
    font-size: 0.72rem;
  }

  .capture-strip b {
    min-height: 46px;
    font-size: 0.95rem;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 4px 8px;
    min-height: 44px;
  }

  .home-logo span:last-child {
    display: none;
  }

  .home-mark {
    width: 32px;
    height: 32px;
  }

  .game-logo {
    display: block;
    font-size: 0.9rem;
    text-align: left;
    justify-self: start;
  }

  .pill {
    min-width: 56px;
    min-height: 34px;
    padding: 5px 8px;
    font-size: 0.82rem;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  .lesson-btn {
    min-width: 118px;
  }

  .learn-stage,
  .play-stage {
    min-height: auto;
  }

  #playScreen {
    flex-direction: column;
    overflow: auto;
  }

  #playScreen .play-stage {
    flex: 0 0 auto;
    min-height: 0;
    order: 1;
    width: 100%;
  }

  #playScreen .play-side {
    flex: 0 0 auto;
    order: 2;
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  #playScreen .play-side h1 {
    display: none;
  }

  .learn-hud {
    gap: 8px;
    padding: 8px;
  }

  .learn-hud > div:nth-child(2) {
    display: none;
  }

  .learn-hud strong,
  .turn-card strong {
    font-size: 1.1rem;
  }

  .progress-wrap {
    margin-bottom: 8px;
  }

  .chess-board,
  .play-wrap .chess-board {
    width: min(calc(100vw - 22px), calc(100dvh - 250px), 520px);
    border-width: 5px;
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .learn-board-row {
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
  }

  .play-board-row {
    grid-template-columns: 54px minmax(0, auto) 10px;
    gap: 6px;
  }

  .play-board-row::after {
    width: 10px;
  }

  .capture-column {
    width: 54px;
    gap: 6px;
  }

  .capture-strip {
    min-height: 72px;
    padding: 4px;
  }

  .capture-strip span {
    font-size: 0.58rem;
  }

  .capture-strip b {
    min-height: 36px;
    font-size: 0.78rem;
  }

  .learn-info {
    width: min(100%, 520px);
    max-height: 82px;
    overflow: hidden;
    padding: 10px;
  }

  .message {
    font-size: 0.9rem;
  }
}
