* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(900px 480px at 0% 0%, #3c2b20 0%, transparent 55%),
    #16120f;
  color: #2b2218;
  font-family: "Segoe UI", sans-serif;
}

button,
img {
  font: inherit;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(520px, 46vw);
  align-items: stretch;
  gap: 16px;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 12px;
  overflow: hidden;
}

.board-section {
  min-width: 0;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}

.board-frame {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  display: grid;
  grid-template-columns: clamp(22px, 5cqmin, 36px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) clamp(22px, 5cqmin, 36px);
  padding: clamp(6px, 1.6cqmin, 12px);
  background: #5a3822;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 2px #3e2616,
    0 18px 50px rgba(0, 0, 0, 0.45);
}

body.recording .board-frame {
  box-shadow:
    inset 0 0 0 2px #3e2616,
    0 0 0 3px #9a3030,
    0 18px 50px rgba(0, 0, 0, 0.45);
}

.rank-labels {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
}

.file-labels {
  grid-column: 2;
  grid-row: 2;
  display: flex;
}

.rank-labels span,
.file-labels span {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f6e7c1;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: clamp(12px, 2.4cqmin, 20px);
  font-weight: 700;
}

.board {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
}

.square {
  position: relative;
  min-width: 0;
  min-height: 0;
  container-type: inline-size;
}

.board.show-fields .square::before {
  content: attr(data-coord);
  position: absolute;
  top: 4%;
  left: 5%;
  z-index: 3;
  color: rgba(0, 0, 0, 0.45);
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: max(11px, 24cqw);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.square.light {
  background: #f0d9b5;
}

.square.dark {
  background: #b58863;
}

.square.last {
  box-shadow: inset 0 0 0 4px rgba(246, 214, 92, 0.95);
}

.square.drag-over {
  outline: 3px solid #f6e27a;
  outline-offset: -3px;
  z-index: 1;
}

.square.reject {
  animation: reject 0.45s ease;
}

@keyframes reject {
  40% {
    box-shadow: inset 0 0 0 5px #a32020;
  }
}

.square.hint::after,
.square.capture::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 2;
  box-sizing: border-box;
}

.square.hint::after {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(20, 16, 12, 0.28);
}

.square.capture::after {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  background: transparent;
  border: 0.45em solid rgba(20, 16, 12, 0.38);
}

.board-piece {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.board-piece img,
.palette-piece img,
.promo-btn img {
  pointer-events: none;
  user-select: none;
}

.board-piece img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.side {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 14px;
  overflow: hidden;
}

.side-left {
  flex: 0 0 250px;
  width: 250px;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.panel,
.recorder,
.files {
  background: #f6f0e6;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

.panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px 14px 12px;
}

.files {
  flex: 0 0 auto;
  padding: 14px 14px 12px;
}

.recorder {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px;
}

h2 {
  margin: 0;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 26px;
  font-weight: 700;
}

.recorder.live h2::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 50%;
  background: #c0392b;
  box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.16);
  vertical-align: 2px;
}

.group-label {
  margin: 12px 0 6px;
  color: #7a6753;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.palette-piece {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fffaf2, #e7d8c0);
  border: 1px solid #e0d0b8;
  border-radius: 8px;
  cursor: grab;
}

.palette-piece img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

body.recording .palette-piece {
  cursor: not-allowed;
  opacity: 0.62;
}

.hint-text,
.count,
.status {
  margin: 8px 0 0;
  color: #6e5c49;
  font-size: 13px;
  line-height: 1.4;
}

.count {
  margin-bottom: 0;
  font-weight: 700;
}

.status {
  min-height: 1.4em;
  margin: 0 0 8px;
}

.status.bad {
  color: #8e2a2a;
  font-weight: 700;
}

.recorder-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

button.start,
button.stop,
button.clear,
.promo-btn {
  border: 0;
  cursor: pointer;
}

button.start,
button.stop {
  border-radius: 8px;
  padding: 8px 16px;
  color: #fff;
  font-weight: 700;
}

button.start {
  background: #2d6b40;
}

button.stop {
  background: #8d3030;
}

button.clear {
  border-radius: 8px;
  padding: 8px 12px;
  background: #efe2cc;
  color: #3a2c1e;
  font-weight: 700;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.fields-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: #3a2c1e;
  font-weight: 700;
  cursor: pointer;
}

.fields-toggle input {
  margin: 0;
  accent-color: #2d6b40;
}

.turn-choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin: 10px 0 6px;
  padding: 8px 12px;
  border: 1px solid #e0d0b8;
  border-radius: 10px;
  background: #efe2cc;
  color: #3a2c1e;
}

.turn-choice legend {
  padding: 0 4px;
  color: #6e5c49;
  font-size: 12px;
  font-weight: 700;
}

.turn-choice label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  cursor: pointer;
}

.turn-choice input {
  margin: 0;
  accent-color: #2d6b40;
}

.turn-choice:disabled {
  opacity: 0.55;
}

.turn-choice:disabled label {
  cursor: default;
}

button:disabled {
  opacity: 0.42;
  cursor: default;
}

button:focus-visible,
.promo-btn:focus-visible {
  outline: 2px solid #b5893f;
  outline-offset: 2px;
}

.notation-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notation-panel {
  flex: 1 1 50%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.notation-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.notation-panel h3 {
  margin: 0;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 16px;
}

.notation-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px;
  background: #fbf7ef;
  border: 1px solid #e3d5bf;
  border-radius: 10px;
  box-shadow: inset 0 1px 3px rgba(80, 50, 20, 0.06);
}

.moves-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recorded-moves:empty {
  display: none;
}

.loaded-moves {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
}

.loaded-moves .notation-empty,
.notation-body > .notation-empty {
  width: 100%;
}

.move-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 4px 4px 0;
  padding: 2px 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
}

.move-num {
  min-width: 1.4em;
  color: #7a6753;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

button.move-ply {
  border: 1px solid #d7c7b0;
  border-radius: 8px;
  padding: 6px 10px;
  background: #efe2cc;
  color: #3a2c1e;
  font-weight: 700;
  cursor: pointer;
}

button.move-ply.move-white {
  background: #fff8ee;
  border-color: #dcc9a8;
}

button.move-ply.move-black {
  background: #d8cbb8;
  border-color: #b9a790;
  color: #241a12;
}

button.move-ply:hover {
  filter: brightness(0.97);
}

button.move-ply.active {
  outline: 2px solid #2d6b40;
  outline-offset: 1px;
  box-shadow: inset 0 0 0 2px rgba(45, 107, 64, 0.35);
}

button.move-ply.move-white.active {
  background: #dff0e4;
  border-color: #2d6b40;
}

button.move-ply.move-black.active {
  background: #3f5f48;
  border-color: #2d6b40;
  color: #f4f0e8;
}

button.move-start {
  background: #f7f1e6;
}

button.move-start.active {
  background: #2d6b40;
  border-color: #2d6b40;
  color: #fff;
  outline: none;
  box-shadow: none;
}

.notation-empty,
.quiet {
  margin: 0;
  color: #8a7662;
  font-size: 14px;
}

.session + .session {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #e4d6c2;
}

.session h3 {
  margin: 0 0 6px;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 16px;
}

.meta,
.live-label,
.stopped,
.result {
  margin: 0 0 8px;
  font-size: 13px;
}

.meta,
.stopped {
  color: #7b6854;
}

.live-label {
  color: #8d3030;
  font-weight: 700;
}

.result {
  margin-top: 8px;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 18px;
  font-weight: 700;
}

.position-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.score {
  width: 100%;
  border-collapse: collapse;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 18px;
}

.score th {
  padding: 0 8px 4px 0;
  color: #8a7662;
  font-family: "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.score td {
  padding: 2px 8px 2px 0;
  vertical-align: baseline;
}

.score .num {
  width: 2em;
  color: #8a7662;
  font-size: 14px;
}

.promo {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 12, 8, 0.46);
}

.promo[hidden] {
  display: none;
}

.promo-card {
  padding: 16px;
  background: #f7f1e6;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.promo-card p {
  margin: 0 0 10px;
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 18px;
}

.promo-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.save-card {
  width: min(420px, calc(100vw - 32px));
}

.save-label {
  display: block;
  margin: 0 0 6px;
  color: #6e5c49;
  font-size: 13px;
  font-weight: 700;
}

.save-filename {
  width: 100%;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid #d7c7b0;
  border-radius: 8px;
  background: #fffaf2;
  color: #2b2218;
  font: inherit;
}

.save-hint {
  margin: 0 0 14px !important;
  color: #6e5c49;
  font-family: "Segoe UI", sans-serif !important;
  font-size: 13px !important;
  line-height: 1.4;
}

.save-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 800px) {
  body {
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .board-section {
    width: 100%;
    container-type: normal;
  }

  .board-frame {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    padding: 8px;
    grid-template-columns: clamp(20px, 7vw, 32px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) clamp(20px, 7vw, 32px);
  }

  .rank-labels span,
  .file-labels span {
    font-size: clamp(12px, 3.4vw, 18px);
  }

  .side {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .side-left {
    flex: none;
    width: auto;
    overflow: visible;
  }

  .panel {
    flex: none;
    overflow: visible;
  }

  .files {
    flex: none;
  }

  .recorder {
    flex: none;
  }

  .recorder-head {
    flex-wrap: wrap;
  }

  .notation-panels {
    flex: none;
  }

  .notation-panel {
    flex: none;
    min-height: 140px;
  }

  .notation-body {
    min-height: 120px;
  }
}

.promo-btn {
  width: 74px;
  height: 74px;
  padding: 6px;
  border-radius: 8px;
  background: #e7dcc6;
}

.promo-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
