:root {
  color-scheme: light;
  --ink: #101923;
  --muted: #5b6870;
  --page: #f4f8f2;
  --panel: #ffffff;
  --panel-strong: #e8f1ee;
  --line: #d2ded9;
  --green-dark: #254f50;
  --green-mid: #3f7773;
  --green-light: #dbefe3;
  --coral: #ff524a;
  --gold: #ffc84b;
  --blue: #286de0;
  --cyan: #46d7d0;
  --violet: #8468ff;
  --shadow: 0 26px 80px rgba(21, 45, 46, 0.18);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 9%, rgba(255, 200, 75, 0.28), transparent 24%),
    radial-gradient(circle at 86% 18%, rgba(70, 215, 208, 0.22), transparent 24%),
    radial-gradient(circle at 50% 94%, rgba(132, 104, 255, 0.16), transparent 30%),
    linear-gradient(135deg, #f7fbf3 0%, #edf7f9 48%, #fbf2e6 100%);
  color: var(--ink);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(37, 79, 80, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 79, 80, 0.045) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.88), rgba(0, 0, 0, 0.18));
}

body::after {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -1;
  pointer-events: none;
  background:
    conic-gradient(from 220deg at 52% 50%, transparent, rgba(255, 200, 75, 0.12), transparent 26%, rgba(70, 215, 208, 0.12), transparent 58%, rgba(255, 82, 74, 0.08), transparent);
  filter: blur(44px) saturate(1.3);
  opacity: 0.82;
  animation: ambientSweep 18s ease-in-out infinite alternate;
}

button,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(1920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(14px, 2.4vw, 48px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 430px);
  gap: clamp(16px, 2.4vw, 34px);
}

.game-stage,
.side-panel {
  border: 1px solid rgba(55, 95, 95, 0.14);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.88), rgba(244, 250, 249, 0.72)),
    rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.18);
}

.game-stage {
  min-width: 0;
  border-radius: var(--radius);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  position: relative;
}

.game-stage::before,
.side-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.72), transparent 32%, rgba(255, 255, 255, 0.34) 70%, transparent);
  mix-blend-mode: soft-light;
}

.side-panel {
  position: relative;
}

.topbar {
  min-height: 96px;
  padding: clamp(14px, 2vw, 22px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(234, 242, 241, 0.92), rgba(255, 255, 255, 0.74)),
    radial-gradient(circle at 12% 12%, rgba(255, 200, 75, 0.2), transparent 28%);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand img {
  width: clamp(52px, 4vw, 68px);
  height: clamp(52px, 4vw, 68px);
  flex: 0 0 auto;
  border-radius: 16px;
  box-shadow:
    0 16px 34px rgba(55, 95, 95, 0.24),
    0 0 0 1px rgba(255, 255, 255, 0.72) inset;
  animation: logoFloat 4.8s ease-in-out infinite;
}

.brand h1,
.moves-panel h2,
.promotion-dialog h2 {
  margin: 0;
  line-height: 1;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.6rem, 2.2vw, 3rem);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.score-strip {
  min-width: 270px;
  padding: 8px;
  border-radius: 999px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(244, 249, 247, 0.9));
  border: 1px solid var(--line);
  box-shadow:
    0 14px 34px rgba(37, 79, 80, 0.08),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.score-strip span,
.score-strip strong {
  min-width: 0;
  white-space: nowrap;
}

.score-strip span {
  padding: 7px 10px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.score-strip strong {
  width: 50px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.28), transparent 34%),
    linear-gradient(135deg, var(--green-dark), #1f6663);
  color: #fff;
  box-shadow: 0 12px 24px rgba(37, 79, 80, 0.24);
}

.board-zone {
  min-height: 0;
  padding: clamp(16px, 2.4vw, 28px);
  display: grid;
  place-items: center;
}

.board-frame {
  width: min(84vh, 100%, 1100px);
  aspect-ratio: 1;
  position: relative;
  border-radius: calc(var(--radius) + 8px);
  padding: clamp(9px, 1vw, 16px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.24), transparent 18%),
    linear-gradient(145deg, #183839, #477b76 52%, #173333);
  box-shadow:
    0 34px 90px rgba(23, 32, 38, 0.26),
    0 0 0 1px rgba(255, 255, 255, 0.38) inset,
    0 0 70px rgba(70, 215, 208, 0.16);
  isolation: isolate;
}

.board-frame::before {
  content: "";
  position: absolute;
  inset: -10px;
  z-index: -1;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255, 200, 75, 0.3), rgba(70, 215, 208, 0.18), rgba(255, 82, 74, 0.18));
  filter: blur(22px);
  opacity: 0.72;
  animation: boardAura 7s ease-in-out infinite alternate;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--green-light);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.25) inset,
    0 16px 36px rgba(0, 0, 0, 0.18) inset;
  transform: translateZ(0);
}

.board.board-3d {
  display: block;
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
  background:
    radial-gradient(circle at 35% 20%, rgba(255, 255, 255, 0.22), transparent 30%),
    linear-gradient(135deg, #193d3f, #2d6664);
}

.board.board-3d canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  border-radius: var(--radius);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  color: inherit;
  cursor: pointer;
  isolation: isolate;
  transition: transform 170ms ease, filter 170ms ease, box-shadow 170ms ease;
}

.square.light {
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.45), transparent 38%),
    linear-gradient(135deg, #e7f6e8, #cfe6d6);
}

.square.dark {
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.13), transparent 38%),
    linear-gradient(135deg, #5d8580, #345f60);
}

.square:hover {
  filter: brightness(1.08) saturate(1.08);
}

.square.selected {
  box-shadow:
    inset 0 0 0 4px var(--gold),
    inset 0 0 38px rgba(255, 200, 75, 0.34);
  animation: selectedPulse 1.35s ease-in-out infinite;
}

.square.last-move {
  box-shadow:
    inset 0 0 0 4px rgba(40, 109, 224, 0.58),
    inset 0 0 42px rgba(70, 215, 208, 0.32);
}

.square.check {
  box-shadow:
    inset 0 0 0 4px var(--coral),
    inset 0 0 46px rgba(255, 82, 74, 0.48);
  animation: checkPulse 800ms ease-in-out infinite alternate;
}

.square.legal::after {
  content: "";
  width: 26%;
  aspect-ratio: 1;
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.92) 0 18%, rgba(255, 200, 75, 0.78) 19% 55%, rgba(255, 200, 75, 0.16) 56% 100%);
  position: absolute;
  z-index: 2;
  box-shadow: 0 0 24px rgba(255, 200, 75, 0.45);
  animation: targetBreathe 1.25s ease-in-out infinite;
}

.square.capture::after {
  content: "";
  width: 78%;
  aspect-ratio: 1;
  border: 4px solid rgba(255, 82, 74, 0.82);
  border-radius: 999px;
  position: absolute;
  z-index: 2;
  box-shadow: 0 0 28px rgba(255, 82, 74, 0.42);
  animation: captureRing 1.05s ease-in-out infinite;
}

.coord {
  position: absolute;
  font-size: clamp(0.62rem, 1.1vw, 0.78rem);
  font-weight: 800;
  opacity: 0.62;
  pointer-events: none;
}

.coord.file {
  right: 6px;
  bottom: 4px;
}

.coord.rank {
  left: 6px;
  top: 4px;
}

.dark .coord {
  color: #eaf2f1;
}

.light .coord {
  color: #375f5f;
}

.piece {
  z-index: 1;
  --move-x: 0%;
  --move-y: 0%;
  width: 82%;
  height: 82%;
  display: grid;
  place-items: center;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", serif;
  font-size: clamp(2.15rem, 6.2vw, 8rem);
  line-height: 1;
  user-select: none;
  pointer-events: none;
  transform: translateY(-1px);
  filter: saturate(1.08) contrast(1.06);
  will-change: transform, filter;
  transition: transform 180ms ease, filter 180ms ease;
}

.piece.moved-piece {
  animation: pieceGlideLand 560ms cubic-bezier(0.16, 0.92, 0.24, 1) both;
}

.piece.white {
  color: #fffdf4;
  text-shadow:
    0 2px 0 rgba(23, 32, 38, 0.7),
    0 10px 24px rgba(23, 32, 38, 0.26),
    0 0 20px rgba(255, 255, 255, 0.36);
}

.piece.black {
  color: #081014;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.42),
    0 10px 24px rgba(23, 32, 38, 0.34),
    0 0 18px rgba(255, 255, 255, 0.16);
}

.thinking-overlay {
  position: absolute;
  inset: 12px;
  border-radius: calc(var(--radius) - 2px);
  display: grid;
  place-items: center;
  gap: 12px;
  align-content: center;
  background:
    radial-gradient(circle at 50% 44%, rgba(70, 215, 208, 0.24), transparent 28%),
    rgba(15, 26, 30, 0.56);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
  backdrop-filter: blur(8px) saturate(1.2);
  display: none !important;
}

.thinking-overlay[hidden] {
  display: none;
}

.thinking-overlay span {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 4px solid rgba(255, 255, 255, 0.42);
  border-top-color: var(--gold);
  border-right-color: var(--cyan);
  animation: spin 800ms linear infinite;
  box-shadow: 0 0 30px rgba(70, 215, 208, 0.45);
}

.side-panel {
  min-width: 0;
  border-radius: var(--radius);
  padding: clamp(14px, 2vw, 20px);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 16px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.primary-button,
.text-button,
.icon-button,
.promotion-grid button {
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, filter 160ms ease;
}

.primary-button {
  min-height: 46px;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.32), transparent 28%),
    linear-gradient(135deg, #ff524a, #eb3d58);
  color: #fff;
  font-weight: 800;
  box-shadow:
    0 14px 30px rgba(233, 88, 82, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.28) inset;
}

.primary-button:hover,
.text-button:hover,
.icon-button:hover,
.promotion-grid button:hover {
  transform: translateY(-1px);
  filter: saturate(1.08);
}

.icon-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(232, 241, 238, 0.92));
  color: var(--green-dark);
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(37, 79, 80, 0.08);
}

.music-button {
  position: relative;
  overflow: hidden;
}

.music-button::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 200, 75, 0.42), transparent 62%);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 180ms ease, transform 180ms ease;
}

.music-button.active {
  color: #fff;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.28), transparent 30%),
    linear-gradient(135deg, var(--green-dark), var(--blue) 52%, var(--violet));
  box-shadow:
    0 14px 34px rgba(40, 109, 224, 0.24),
    0 0 28px rgba(255, 200, 75, 0.26);
}

.music-button.active::after {
  opacity: 1;
  transform: scale(1.25);
  animation: musicPulse 920ms ease-in-out infinite;
}

.icon-button svg {
  position: relative;
  z-index: 1;
  width: 24px;
  height: 24px;
  fill: currentColor;
}

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

.option-grid label {
  display: grid;
  gap: 6px;
}

.option-grid span,
.panel-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 250, 249, 0.95));
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(37, 79, 80, 0.06);
}

.capture-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(235, 245, 242, 0.96), rgba(226, 239, 235, 0.92));
  border: 1px solid var(--line);
  box-shadow: 0 12px 26px rgba(37, 79, 80, 0.08) inset;
}

.capture-row {
  min-height: 34px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 1.55rem;
  line-height: 1;
  text-shadow: 0 5px 14px rgba(23, 32, 38, 0.18);
}

.capture-row:empty::before {
  content: "Belum ada";
  color: var(--muted);
  font-size: 0.95rem;
}

.moves-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.moves-panel h2,
.promotion-dialog h2 {
  font-size: 1.05rem;
}

.text-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff, #f5f9fb);
  color: var(--blue);
  border: 1px solid var(--line);
  font-weight: 800;
}

.move-list {
  min-height: 260px;
  max-height: 100%;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(250, 252, 251, 0.96));
  border: 1px solid var(--line);
  box-shadow: 0 12px 28px rgba(37, 79, 80, 0.06) inset;
  list-style: none;
  counter-reset: move;
}

.move-list li {
  display: grid;
  grid-template-columns: 38px 1fr 1fr;
  gap: 8px;
  min-height: 32px;
  align-items: center;
  border-bottom: 1px solid #eef2f0;
  animation: moveRowIn 260ms ease both;
}

.move-list li:last-child {
  border-bottom: 0;
}

.move-number {
  color: var(--muted);
  font-weight: 800;
}

.move-san {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.promotion-dialog {
  border: 0;
  border-radius: var(--radius);
  width: min(360px, calc(100vw - 32px));
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(237, 247, 245, 0.96));
  box-shadow: var(--shadow);
}

.promotion-dialog::backdrop {
  background: rgba(23, 32, 38, 0.46);
}

.promotion-dialog form {
  display: grid;
  gap: 16px;
}

.promotion-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promotion-grid button {
  aspect-ratio: 1;
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.62), transparent 30%),
    var(--panel-strong);
  color: var(--ink);
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols", serif;
  font-size: 2.3rem;
}

button:focus-visible,
select:focus-visible,
.square:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

button:disabled,
select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes ambientSweep {
  from {
    transform: rotate(-4deg) scale(1);
  }

  to {
    transform: rotate(5deg) scale(1.04);
  }
}

@keyframes boardAura {
  from {
    opacity: 0.48;
    transform: scale(0.985);
  }

  to {
    opacity: 0.82;
    transform: scale(1.015);
  }
}

@keyframes logoFloat {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}

@keyframes selectedPulse {
  0%,
  100% {
    filter: saturate(1);
  }

  50% {
    filter: saturate(1.2) brightness(1.04);
  }
}

@keyframes checkPulse {
  from {
    filter: brightness(1);
  }

  to {
    filter: brightness(1.14) saturate(1.18);
  }
}

@keyframes targetBreathe {
  0%,
  100% {
    transform: scale(0.86);
    opacity: 0.82;
  }

  50% {
    transform: scale(1.06);
    opacity: 1;
  }
}

@keyframes captureRing {
  0%,
  100% {
    transform: scale(0.94);
  }

  50% {
    transform: scale(1.03);
  }
}

@keyframes pieceRise {
  from {
    opacity: 1;
    transform: translateY(8px) scale(0.92);
  }

  to {
    opacity: 1;
    transform: translateY(-1px) scale(1);
  }
}

@keyframes pieceLand {
  0% {
    transform: translateY(-12px) scale(1.12);
    filter: drop-shadow(0 22px 18px rgba(23, 32, 38, 0.24)) saturate(1.2);
  }

  64% {
    transform: translateY(2px) scale(0.98);
  }

  100% {
    transform: translateY(-1px) scale(1);
  }
}

@keyframes pieceGlideLand {
  0% {
    transform: translate3d(var(--move-x), var(--move-y), 0) scale(1.02);
    filter:
      drop-shadow(0 34px 22px rgba(23, 32, 38, 0.3))
      saturate(1.2)
      contrast(1.08);
  }

  42% {
    transform: translate3d(calc(var(--move-x) * 0.42), calc(var(--move-y) * 0.42 - 12px), 0) scale(1.1);
    filter:
      drop-shadow(0 42px 28px rgba(23, 32, 38, 0.26))
      saturate(1.24)
      contrast(1.1);
  }

  76% {
    transform: translate3d(0, 4px, 0) scale(0.985);
    filter:
      drop-shadow(0 10px 10px rgba(23, 32, 38, 0.2))
      saturate(1.12)
      contrast(1.08);
  }

  100% {
    transform: translate3d(0, -1px, 0) scale(1);
    filter:
      drop-shadow(0 0 0 rgba(23, 32, 38, 0))
      saturate(1.08)
      contrast(1.06);
  }
}

@keyframes moveRowIn {
  from {
    opacity: 0;
    transform: translateX(8px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes musicPulse {
  0%,
  100% {
    transform: scale(0.82);
    opacity: 0.42;
  }

  50% {
    transform: scale(1.36);
    opacity: 0.82;
  }
}

@media (min-width: 1800px) {
  .topbar {
    min-height: 118px;
  }

  .side-panel {
    gap: 20px;
  }

  .primary-button,
  .icon-button,
  select {
    min-height: 54px;
  }

  .icon-button {
    width: 54px;
    height: 54px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

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

  .side-panel {
    grid-template-rows: auto;
  }

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

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
    gap: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .score-strip {
    width: 100%;
    min-width: 0;
  }

  .score-strip span {
    padding-inline: 4px;
    font-size: 0.78rem;
  }

  .board-zone {
    padding: 10px;
  }

  .board-frame {
    width: min(100%, 94vw);
    padding: 6px;
  }

  .piece {
    font-size: clamp(1.86rem, 10vw, 3.25rem);
  }

  .controls,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .icon-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .icon-button {
    width: 100%;
  }
}
