.chess-panel {
  --chess-width: 360px;

  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 36;
  width: var(--chess-width);
  max-width: calc(100vw - 20px);
  padding: 0 10px;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  background: #2c2c2c;
  box-shadow: 0 18px 44px rgb(0 0 0 / 48%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  touch-action: none;
  transition: opacity 220ms ease;
}

.chess-panel:not(.is-open),
.chess-panel:not(.is-open) * {
  pointer-events: none;
}

.chess-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.chess-panel.is-dragging,
.chess-panel.is-resizing {
  transition: none;
}

.chess-panel__sheet {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chess-clock {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  flex: 0 0 32px;
  height: 32px;
  margin: 0;
  padding: 0 2px;
  color: #c5c5c5;
  background: transparent;
  font-family: "Courier New", Courier, monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: grab;
}

.chess-panel.is-dragging .chess-clock {
  cursor: grabbing;
}

.chess-clock.is-active .chess-clock__time {
  color: #39ff14;
}

.chess-clock.is-low .chess-clock__time {
  color: #f87171;
}

.chess-clock__name,
.chess-clock__time {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
}

.chess-clock__name {
  min-width: 0;
  margin-left: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chess-clock__time {
  position: absolute;
  left: 50%;
  top: 50%;
  flex: none;
  font-variant-numeric: tabular-nums;
  transform: translate(-50%, -50%);
}

.chess-board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  width: 100%;
}

.chess-board-stage {
  position: relative;
  width: calc(var(--sq, 40px) * 8);
  height: calc(var(--sq, 40px) * 8);
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq, 40px));
  grid-template-rows: repeat(8, var(--sq, 40px));
  width: calc(var(--sq, 40px) * 8);
  height: calc(var(--sq, 40px) * 8);
  overflow: hidden;
  border-radius: 2px;
  touch-action: none;
  user-select: none;
}

.chess-sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--sq, 100%);
  height: var(--sq, 100%);
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #f0d9b5;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  cursor: pointer;
}

.chess-sq--dark {
  background: #b58863;
}

.chess-sq.is-last {
  box-shadow: inset 0 0 0 100px rgb(255 255 0 / 22%);
}

.chess-sq.is-selected {
  box-shadow: inset 0 0 0 100px rgb(20 85 30 / 42%);
}

.chess-sq.is-legal::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgb(20 20 20 / 22%);
  pointer-events: none;
}

.chess-sq.is-legal.is-capture::after {
  width: 72%;
  height: 72%;
  background: transparent;
  box-shadow: inset 0 0 0 4px rgb(20 20 20 / 22%);
}

.chess-piece {
  display: block;
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.chess-piece--fly {
  position: absolute;
  z-index: 4;
  margin: 0;
  transition: transform 250ms ease-out;
  will-change: transform;
}

.chess-start-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  border-radius: 2px;
  color: #f0f0f0;
  text-align: center;
  background: rgb(18 18 18 / 62%);
  pointer-events: auto;
}

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

.chess-start-overlay__copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(16em, 100%);
  transition: opacity 600ms ease;
}

.chess-start-overlay__copy.is-fading {
  opacity: 0;
}

.chess-status-slot {
  position: relative;
  width: 100%;
  min-height: 2.75em;
}

.chess-status-slot .chess-status {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  margin: 0;
  opacity: 0;
  transform: translateY(-50%);
  pointer-events: none;
  transition: opacity 600ms ease;
}

.chess-status-slot .chess-status.is-shown {
  opacity: 1;
}

.chess-status-slot .chess-status.is-fading,
.chess-status--count.is-fading {
  opacity: 0;
}

.chess-start-lower {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6em;
  width: 100%;
}

.chess-status--count {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}

.chess-status--count.is-shown {
  opacity: 1;
}

.chess-start.is-away {
  visibility: hidden;
  pointer-events: none;
}

.chess-status {
  min-height: 0;
  max-width: 100%;
  margin: 0;
  color: #e8e8e8;
  font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  font-size: calc(22px - 4pt);
  font-weight: 500;
  line-height: 1.25;
  text-align: center;
  text-shadow: 0 1px 8px rgb(0 0 0 / 55%);
}

.chess-start {
  margin: 0;
  padding: 2px 18px 4px;
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 8px;
  color: #fff;
  background: rgb(40 40 40 / 85%);
  font-family: "Caveat", "Segoe Script", cursive;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgb(0 0 0 / 35%);
}

.chess-start:hover,
.chess-start:focus-visible {
  border-color: #777;
  background: #454545;
}

.chess-start:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.chess-start:disabled {
  opacity: 0.45;
  cursor: default;
}

.chess-clock--top {
  padding-right: 26px;
}

.chess-clock--bottom {
  padding-right: 72px;
}

.chess-panel__close {
  position: absolute;
  right: 0;
  top: 50%;
  z-index: 2;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: #9ca3af;
  font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  transform: translateY(-50%);
  cursor: pointer;
}

.chess-panel__close:hover {
  color: #f3f4f6;
}

.chess-resize {
  position: absolute;
  right: -8px;
  bottom: 0;
  z-index: 3;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  appearance: none;
  cursor: nwse-resize;
  touch-action: none;
}

.chess-resize::before {
  content: "";
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 11px;
  height: 11px;
  border-right: 2px solid #8a8a8a;
  border-bottom: 2px solid #8a8a8a;
  border-radius: 0 0 2px 0;
}

.chess-resign {
  position: absolute;
  right: 15px;
  top: 50%;
  z-index: 2;
  margin: 0;
  padding: 3px 8px 4px;
  border: 1px solid #555;
  border-radius: 6px;
  background: rgb(44 44 44 / 88%);
  color: #e5e5e5;
  font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.2;
  transform: translateY(-50%);
  cursor: pointer;
}

.chess-resign:hover,
.chess-resign:focus-visible {
  color: #fff;
  border-color: #777;
  background: rgb(36 36 36 / 94%);
}

.chess-resign:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.chess-resign[hidden] {
  display: none;
}

.chess-board-stage .chess-promo {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(20 20 20 / 55%);
}

.chess-promo[hidden] {
  display: none;
}

.chess-promo__row {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-radius: 10px;
  background: #2c2c2c;
}

.chess-promo__btn {
  width: 52px;
  height: 52px;
  padding: 4px;
  border: 1px solid #555;
  border-radius: 8px;
  background: #f0d9b5;
  cursor: pointer;
}

.chess-promo__btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

@media (max-width: 520px) {
  .chess-panel {
    --chess-width: min(360px, calc(100vw - 16px));
    padding: 0 8px;
  }

  .chess-panel__sheet {
    gap: 0;
  }

  .chess-clock {
    flex-basis: 28px;
    height: 28px;
    padding: 0 2px;
  }

  .chess-clock__name,
  .chess-clock__time {
    font-family: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
  }

  .chess-status {
    font-size: calc(20px - 4pt);
  }

  .chess-start {
    padding: 1px 16px 3px;
    font-size: 22px;
  }
}
