:root {
  --cc-bg: #08111a;
  --cc-panel: rgba(7, 13, 20, 0.7);
  --cc-border: rgba(255, 255, 255, 0.14);
  --cc-text: #f5efe3;
  --cc-muted: rgba(245, 239, 227, 0.72);
  --cc-accent: #f6b36c;
  --cc-accent-2: #89f1ff;
  --cc-danger: #ff8d74;
  --cc-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  --cc-radius-xl: 32px;
  --cc-radius-pill: 999px;
  --cc-font-sans: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  --cc-font-display: "Cormorant Garamond", Georgia, serif;
  --cc-font-pieces: "Noto Sans Symbols 2", "Apple Symbols", "Segoe UI Symbol", serif;

  --cc-light: #e9dfcc;
  --cc-dark: #5d7f89;
  --cc-piece-white: #fbf7ee;
  --cc-piece-black: #141b24;

  /* Space the board must leave for the scoreboard, controls and exit chip. */
  --cc-chrome: 200px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--cc-bg);
  color: var(--cc-text);
  font-family: var(--cc-font-sans);
}

body {
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  font: inherit;
  touch-action: manipulation;
}

.cc-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 18%, rgba(246, 179, 108, 0.24), transparent 24%),
    radial-gradient(circle at 84% 12%, rgba(137, 241, 255, 0.16), transparent 20%),
    linear-gradient(180deg, rgba(6, 10, 15, 0.6), rgba(6, 10, 15, 0.92));
}

.cc-bg-video,
.cc-bg-overlay,
.cc-bg-grid {
  position: absolute;
  inset: 0;
}

.cc-bg-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.2;
  filter: saturate(0.8) contrast(1.1);
}

.cc-bg-overlay {
  background:
    linear-gradient(180deg, rgba(6, 10, 16, 0.15) 0%, rgba(6, 10, 16, 0.48) 46%, rgba(6, 10, 16, 0.88) 100%),
    radial-gradient(circle at 40% 20%, rgba(255, 255, 255, 0.08), transparent 18%);
}

.cc-bg-grid {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 72px 72px;
  opacity: 0.22;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.95));
}

.cc-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(36px);
  opacity: 0.45;
}

.cc-orb-a {
  width: 16rem;
  height: 16rem;
  left: -5rem;
  top: 8rem;
  background: rgba(246, 179, 108, 0.22);
}

.cc-orb-b {
  width: 22rem;
  height: 22rem;
  right: -8rem;
  bottom: -4rem;
  background: rgba(137, 241, 255, 0.14);
}

.cc-shell {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100% - 2rem));
  height: 100dvh;
  margin: 0 auto;
  padding: 0.9rem 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0.7rem;
}

.glass {
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045) 0%, rgba(255, 255, 255, 0.015) 100%),
    var(--cc-panel);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  box-shadow: var(--cc-shadow);
}

.cc-stage-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 12px 14px;
  overflow: hidden;
}

/* Scoreboard */

.cc-scoreboard {
  display: flex;
  gap: 20px;
  background: rgba(6, 10, 16, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  padding: 8px 22px 8px 24px;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.cc-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
  padding: 4px 6px;
}

.cc-stat + .cc-stat {
  border-left: 1px solid rgba(255, 255, 255, 0.14);
  padding-left: 16px;
}

.cc-stat-label {
  margin: 0 0 4px;
  color: rgba(246, 179, 108, 0.85);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.62rem;
  font-weight: 700;
}

.cc-stat strong {
  font-size: 1rem;
  font-weight: 700;
}

/* Stage + board */

.cc-stage {
  position: relative;
  width: min(100%, calc(100dvh - var(--cc-chrome)));
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.1);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.cc-board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  container-type: size;
  touch-action: none;
}

.cc-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--cc-light);
  cursor: default;
  outline: none;
  touch-action: none;
}

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

.cc-square.cc-movable {
  cursor: grab;
}

.cc-square.cc-last::before,
.cc-square.cc-selected::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(246, 179, 108, 0.42);
  pointer-events: none;
}

.cc-square.cc-selected::before {
  background: rgba(246, 179, 108, 0.7);
}

.cc-square:focus-visible {
  box-shadow: inset 0 0 0 3px var(--cc-accent-2);
  z-index: 1;
}

/* Legal move markers */
.cc-square.cc-target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(8, 17, 26, 0.28);
  pointer-events: none;
  z-index: 2;
}

.cc-square.cc-target.cc-capture::after {
  width: 92%;
  height: 92%;
  background: transparent;
  border: 5px solid rgba(8, 17, 26, 0.3);
}

.cc-square.cc-target {
  cursor: pointer;
}

.cc-square.cc-check {
  background:
    radial-gradient(circle, rgba(255, 92, 70, 0.95) 0%, rgba(255, 92, 70, 0.55) 45%, transparent 75%),
    var(--cc-light);
}

.cc-square.cc-dark.cc-check {
  background:
    radial-gradient(circle, rgba(255, 92, 70, 0.95) 0%, rgba(255, 92, 70, 0.55) 45%, transparent 75%),
    var(--cc-dark);
}

.cc-coord {
  position: absolute;
  font-size: max(9px, 1.7cqmin);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  color: var(--cc-dark);
}

.cc-dark .cc-coord {
  color: var(--cc-light);
}

.cc-coord-rank {
  top: 4px;
  left: 4px;
}

.cc-coord-file {
  bottom: 3px;
  right: 4px;
}

/* Pieces */

.cc-piece {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-family: var(--cc-font-pieces);
  font-size: 9.6cqmin;
  line-height: 1;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.cc-piece.cc-w {
  color: var(--cc-piece-white);
  -webkit-text-stroke: 0.9px #1d2731;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
}

.cc-piece.cc-b {
  color: var(--cc-piece-black);
  -webkit-text-stroke: 0.6px rgba(255, 255, 255, 0.35);
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
}

.cc-dragging .cc-piece {
  opacity: 0.25;
}

/* The kings are Colin. */
.cc-king {
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 6%;
}

.cc-king-face {
  width: 76%;
  height: 76%;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

.cc-king.cc-b .cc-king-face {
  transform: scaleX(-1);
  filter: grayscale(1) contrast(1.15) brightness(0.78) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

.cc-king-crown {
  position: absolute;
  top: 1%;
  left: 50%;
  width: 46%;
  transform: translateX(-50%) rotate(-8deg);
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.5));
}

.cc-king.cc-w .cc-king-crown {
  fill: #f6c35c;
  stroke: #8a5a14;
}

.cc-king.cc-b .cc-king-crown {
  fill: #d5dde6;
  stroke: #27303a;
  transform: translateX(-50%) rotate(8deg);
}

.cc-king-crown path {
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.cc-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  container-type: size;
  transform: scale(1.12);
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.45));
}

.cc-ghost .cc-piece {
  font-size: 78cqmin;
}

.cc-stage.cc-thinking .cc-king.cc-engine .cc-king-face {
  animation: cc-ponder 1.2s ease-in-out infinite;
}

@keyframes cc-ponder {
  0%,
  100% {
    transform: scaleX(-1) rotate(0deg);
  }
  50% {
    transform: scaleX(-1) rotate(-9deg);
  }
}

.cc-stage.cc-thinking .cc-king.cc-w.cc-engine .cc-king-face {
  animation-name: cc-ponder-w;
}

@keyframes cc-ponder-w {
  0%,
  100% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(9deg);
  }
}

/* Controls row */

.cc-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(100%, calc(100dvh - var(--cc-chrome)));
}

.cc-status {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--cc-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-status.cc-alert {
  color: var(--cc-danger);
}

.cc-icon-button {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(6, 10, 16, 0.65);
  color: var(--cc-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.cc-icon-button:hover,
.cc-icon-button:focus-visible {
  outline: none;
  background: rgba(246, 179, 108, 0.12);
  border-color: rgba(246, 179, 108, 0.4);
}

.cc-audio-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.cc-audio-icon-off {
  display: none;
}

.cc-icon-button[aria-pressed="true"] .cc-audio-icon-on {
  display: none;
}

.cc-icon-button[aria-pressed="true"] .cc-audio-icon-off {
  display: block;
}

/* Overlays */

.cc-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 20;
  background: linear-gradient(180deg, rgba(4, 8, 13, 0.35), rgba(4, 8, 13, 0.72));
  transition: opacity 180ms ease;
}

.cc-overlay.cc-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.cc-overlay-card {
  width: min(100%, 25rem);
  max-height: 100%;
  overflow-y: auto;
  padding: 1.15rem 1.1rem 1.2rem;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03)),
    rgba(9, 15, 24, 0.94);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cc-overlay-kicker {
  margin: 0 0 0.45rem;
  color: rgba(246, 179, 108, 0.88);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
}

.cc-overlay-card h2 {
  margin: 0.1rem 0 0.9rem;
  max-width: 18ch;
  font-family: var(--cc-font-display);
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  line-height: 0.95;
  font-weight: 600;
}

.cc-option {
  width: 100%;
  margin-bottom: 0.8rem;
}

.cc-option-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cc-muted);
}

.cc-segmented {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(4, 8, 13, 0.6);
}

.cc-segmented button {
  flex: 1;
  min-height: 36px;
  padding: 0.4rem 0.5rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cc-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.cc-segmented button:hover,
.cc-segmented button:focus-visible {
  outline: none;
  color: var(--cc-text);
}

.cc-segmented [data-level] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  border-radius: 16px;
}

.cc-elo {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  opacity: 0.75;
}

.cc-segmented:has([data-level]) {
  border-radius: 20px;
}

.cc-segmented button[aria-checked="true"] {
  background: rgba(246, 179, 108, 0.9);
  color: #1b130a;
}

.cc-overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 0.3rem;
}

.cc-overlay-link {
  display: inline-flex;
  margin-top: 0.85rem;
  padding: 0;
  border: 0;
  border-bottom: 1px solid rgba(245, 239, 227, 0.22);
  background: none;
  color: rgba(245, 239, 227, 0.82);
  text-decoration: none;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease;
}

.cc-overlay-link:hover,
.cc-overlay-link:focus-visible {
  color: var(--cc-accent);
  border-color: rgba(246, 179, 108, 0.5);
  outline: none;
}

.cc-promo-card {
  width: auto;
}

.cc-promo-options {
  display: flex;
  gap: 0.5rem;
}

.cc-promo-options button {
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--cc-light);
  container-type: size;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}

.cc-promo-options button:nth-child(even) {
  background: var(--cc-dark);
}

.cc-promo-options button:hover,
.cc-promo-options button:focus-visible {
  outline: none;
  transform: translateY(-2px);
  border-color: var(--cc-accent);
}

.cc-promo-options .cc-piece {
  font-size: 78cqmin;
}

/* Buttons */

.cc-chip,
.cc-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.85rem 1.2rem;
  border-radius: var(--cc-radius-pill);
  border: 1px solid var(--cc-border);
  background: rgba(9, 15, 22, 0.72);
  color: var(--cc-text);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.cc-chip:hover,
.cc-chip:focus-visible,
.cc-button:hover,
.cc-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  border-color: rgba(246, 179, 108, 0.58);
  background: rgba(246, 179, 108, 0.15);
}

.cc-button:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.cc-button-small {
  flex-shrink: 0;
  min-height: 38px;
  padding: 0.5rem 0.9rem;
  font-size: 0.64rem;
}

.cc-button-launch {
  background: rgba(36, 126, 66, 0.9);
  border-color: rgba(122, 234, 160, 0.34);
  color: #f2fff5;
}

.cc-button-launch:hover,
.cc-button-launch:focus-visible {
  background: rgba(45, 151, 79, 0.96);
  border-color: rgba(163, 255, 193, 0.54);
}

.cc-chip-exit {
  justify-self: center;
  width: fit-content;
  margin: 0 auto;
  font-size: 0.68rem;
  padding: 0.55rem 1rem;
  min-height: 36px;
  background: rgba(255, 141, 116, 0.18);
  border-color: rgba(255, 141, 116, 0.4);
  color: #ff9a8a;
}

.cc-chip-exit:hover {
  background: rgba(255, 141, 116, 0.3);
  border-color: rgba(255, 141, 116, 0.65);
  color: #ffcfc5;
}

@media (max-width: 700px) {
  :root {
    --cc-chrome: 190px;
  }

  .cc-shell {
    width: calc(100% - 0.75rem);
    padding: 0.4rem 0 max(0.6rem, env(safe-area-inset-bottom));
    gap: 0.5rem;
  }

  .cc-stage-wrap {
    padding: 10px 8px 12px;
    border-radius: 26px;
  }

  .cc-stage {
    border-radius: 12px;
  }

  .cc-scoreboard {
    gap: 10px;
    padding: 6px 14px;
  }

  .cc-stat + .cc-stat {
    padding-left: 10px;
  }

  .cc-stat-label {
    font-size: 0.54rem;
    letter-spacing: 0.1em;
  }

  .cc-status {
    font-size: 0.7rem;
  }

  .cc-button-small {
    padding: 0.45rem 0.7rem;
    font-size: 0.58rem;
  }

  .cc-square.cc-target.cc-capture::after {
    border-width: 3px;
  }

  .cc-segmented button {
    padding: 0.4rem 0.25rem;
    font-size: 0.6rem;
    letter-spacing: 0.03em;
  }

  .cc-elo {
    font-size: 0.52rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cc-bg-video {
    display: none;
  }

  .cc-orb {
    opacity: 0.2;
    filter: none;
  }

  .cc-stage.cc-thinking .cc-king.cc-engine .cc-king-face {
    animation: none;
  }
}
