:root {
  color-scheme: dark;
  --bg: #02070d;
  --panel: rgba(7, 18, 29, 0.86);
  --panel-strong: rgba(9, 30, 43, 0.96);
  --line: rgba(84, 255, 216, 0.24);
  --line-strong: rgba(84, 255, 216, 0.58);
  --text: #f4f8fb;
  --muted: #9fb0bd;
  --accent: #24e7c2;
  --accent-2: #75a7ff;
  --danger: #ff5d8c;
  --dark-square: #081520;
  --light-square: #123141;
  --selected: #31f0c7;
  --move: #47a6ff;
  --capture: #ff4f8a;
  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;
  background:
    radial-gradient(circle at 15% 10%, rgba(35, 231, 194, 0.16), transparent 28%),
    radial-gradient(circle at 86% 20%, rgba(117, 167, 255, 0.14), transparent 30%),
    linear-gradient(135deg, #01040a 0%, #07111b 48%, #03070d 100%);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(84, 255, 216, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(117, 167, 255, 0.055) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent 82%);
}

.topbar {
  width: min(1180px, calc(100% - 32px));
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(2, 8, 15, 0.76);
  backdrop-filter: blur(18px);
  border-radius: 10px;
  position: sticky;
  top: 12px;
  z-index: 10;
  box-shadow: 0 0 35px rgba(36, 231, 194, 0.08);
}

.brand,
.navlinks a {
  color: var(--text);
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #060a12;
}

.brand span {
  display: grid;
  gap: 2px;
}

.brand small,
.intro,
.status-label,
.panel p,
.panel li,
.move-log li,
.level-card label {
  color: var(--muted);
}

.navlinks {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.navlinks a,
button,
select {
  border: 1px solid var(--line);
  background: rgba(8, 20, 31, 0.78);
  color: var(--text);
  border-radius: 8px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 800;
}

.navlinks a:hover,
button:hover,
select:hover {
  border-color: var(--line-strong);
  box-shadow: 0 0 22px rgba(36, 231, 194, 0.14);
}

button {
  cursor: pointer;
}

button.primary,
#newGameBtn {
  background: linear-gradient(135deg, #20d8ba, #54a7ff);
  color: #031018;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 48px auto;
}

.hero {
  display: grid;
  grid-template-columns: 1fr minmax(240px, 320px);
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.82rem;
  letter-spacing: 0;
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 7vw, 5.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.06rem;
}

.intro {
  max-width: 640px;
  font-size: 1.06rem;
  line-height: 1.6;
}

.level-card,
.panel-block,
.board-wrap {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
}

.level-card {
  padding: 16px;
  display: grid;
  gap: 9px;
}

.level-card select {
  width: 100%;
}

.arena {
  display: grid;
  grid-template-columns: minmax(320px, 720px) minmax(280px, 1fr);
  gap: 20px;
  align-items: start;
}

.board-wrap {
  padding: 16px;
  box-shadow: 0 0 45px rgba(36, 231, 194, 0.08);
}

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.board-head div:first-child {
  display: grid;
  gap: 4px;
}

.turn-pill {
  padding: 8px 11px;
  border-radius: 999px;
  color: #061018;
  background: var(--accent);
  font-weight: 900;
  white-space: nowrap;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(100%, 680px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.55), 0 0 50px rgba(84, 255, 216, 0.09);
  overflow: hidden;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.035);
  font-size: clamp(1.7rem, 7vw, 4.1rem);
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.square.light {
  background: linear-gradient(135deg, var(--light-square), #0d2532);
}

.square.dark {
  background: linear-gradient(135deg, #06101b, var(--dark-square));
}

.square:hover {
  filter: brightness(1.12);
}

.square.selected {
  outline: 3px solid var(--selected);
  outline-offset: -4px;
  box-shadow: inset 0 0 24px rgba(49, 240, 199, 0.45);
}

.square.move-target::after,
.square.capture-target::after {
  content: "";
  position: absolute;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  border: 2px solid currentColor;
  box-shadow: 0 0 18px currentColor;
}

.square.move-target {
  color: var(--move);
}

.square.capture-target {
  color: var(--capture);
}

.piece-white {
  color: #f2fbff;
  text-shadow: 0 0 16px rgba(117, 167, 255, 0.7);
}

.piece-black {
  color: #20e0c0;
  text-shadow: 0 0 16px rgba(36, 231, 194, 0.7);
}

.panel {
  display: grid;
  gap: 14px;
}

.panel-block {
  padding: 16px;
}

.panel button {
  width: 100%;
  margin-top: 8px;
}

.panel ul,
.move-log ol {
  margin: 0;
  padding-left: 20px;
}

.move-log ol {
  max-height: 180px;
  overflow: auto;
}

.win-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  z-index: 30;
}

.win-card {
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel-strong);
  text-align: center;
  box-shadow: 0 0 70px rgba(36, 231, 194, 0.25);
}

.victory-gif {
  height: 150px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.victory-gif span {
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  animation: victoryPulse 1.15s infinite ease-in-out;
}

.victory-gif span:nth-child(2) { animation-delay: 0.12s; }
.victory-gif span:nth-child(3) { animation-delay: 0.24s; }
.victory-gif span:nth-child(4) { animation-delay: 0.36s; }

@keyframes victoryPulse {
  0%, 100% { transform: scaleY(0.36); opacity: 0.55; }
  50% { transform: scaleY(1); opacity: 1; }
}

@media (max-width: 860px) {
  .topbar,
  .hero,
  .arena {
    grid-template-columns: 1fr;
  }

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

  .navlinks {
    justify-content: flex-start;
  }

  .shell {
    margin-top: 34px;
  }
}

@media (max-width: 520px) {
  .topbar,
  .shell {
    width: min(100% - 20px, 1180px);
  }

  .board-wrap {
    padding: 10px;
  }

  .brand small {
    display: none;
  }

  .navlinks a {
    padding: 9px 10px;
  }
}
