:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #647074;
  --page: #f4f8f2;
  --panel: #ffffff;
  --panel-strong: #eaf2f1;
  --line: #d9e3de;
  --green-dark: #375f5f;
  --green-mid: #4f8580;
  --green-light: #dcefe7;
  --coral: #e95852;
  --gold: #f0bf3a;
  --blue: #2c6fd0;
  --shadow: 0 22px 60px rgba(30, 52, 50, 0.16);
  --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 14% 12%, rgba(240, 191, 58, 0.14), transparent 28%),
    linear-gradient(135deg, #f4f8f2 0%, #eef6f7 52%, #f8f4ea 100%);
  color: var(--ink);
}

button,
select {
  font: inherit;
}

button {
  border: 0;
}

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

.game-stage,
.side-panel {
  border: 1px solid rgba(55, 95, 95, 0.14);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

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

.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.9), rgba(255, 255, 255, 0.74));
}

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

.brand img {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(55, 95, 95, 0.2);
}

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

.brand h1 {
  font-size: clamp(1.45rem, 2.4vw, 2.2rem);
}

.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: var(--panel);
  border: 1px solid var(--line);
}

.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: 44px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--green-dark);
  color: #fff;
}

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

.board-frame {
  width: min(86vh, 100%, 720px);
  aspect-ratio: 1;
  position: relative;
  border-radius: var(--radius);
  padding: clamp(8px, 1vw, 12px);
  background: linear-gradient(145deg, #243f3f, #47706d);
  box-shadow: 0 26px 54px rgba(23, 32, 38, 0.22);
}

.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: calc(var(--radius) - 2px);
  overflow: hidden;
  background: var(--green-light);
}

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

.square.light {
  background: #dff0e1;
}

.square.dark {
  background: #4b7474;
}

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

.square.selected {
  box-shadow: inset 0 0 0 4px var(--gold);
}

.square.last-move {
  box-shadow: inset 0 0 0 4px rgba(44, 111, 208, 0.48);
}

.square.check {
  box-shadow: inset 0 0 0 4px var(--coral);
}

.square.legal::after {
  content: "";
  width: 26%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(23, 32, 38, 0.28);
  position: absolute;
}

.square.capture::after {
  content: "";
  width: 78%;
  aspect-ratio: 1;
  border: 4px solid rgba(233, 88, 82, 0.68);
  border-radius: 999px;
  position: absolute;
}

.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;
  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, 7.4vw, 5.5rem);
  line-height: 1;
  user-select: none;
  pointer-events: none;
  transform: translateY(-1px);
}

.piece.white {
  color: #fffaf0;
  text-shadow:
    0 2px 0 rgba(23, 32, 38, 0.64),
    0 8px 18px rgba(23, 32, 38, 0.24);
}

.piece.black {
  color: #151a1c;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.34),
    0 8px 18px rgba(23, 32, 38, 0.3);
}

.thinking-overlay {
  position: absolute;
  inset: 12px;
  border-radius: calc(var(--radius) - 2px);
  display: grid;
  place-items: center;
  gap: 12px;
  align-content: center;
  background: rgba(23, 32, 38, 0.42);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.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: #fff;
  animation: spin 800ms linear infinite;
}

.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 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.primary-button {
  min-height: 46px;
  border-radius: var(--radius);
  background: var(--coral);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 12px 22px rgba(233, 88, 82, 0.24);
}

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

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

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--panel-strong);
  color: var(--green-dark);
  border: 1px solid var(--line);
}

.icon-button svg {
  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: #fff;
  color: var(--ink);
}

.capture-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.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;
}

.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: #fff;
  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: #fff;
  border: 1px solid var(--line);
  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;
}

.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;
  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: 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);
  }
}

@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(2, 1fr);
  }

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