:root {
  color-scheme: light;
  --bg: #fff;
  --panel: #fff;
  --line: #e5e7e6;
  --text: #1a1a1a;
  --muted: #747a76;
  --accent: #1a8f5c;
  --light: #eff1e9;
  --dark: #8ca78b;
  font:
    16px/1.5 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: #2ab87a;
}
header {
  max-width: 1080px;
  margin: 48px auto 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
}
.brand {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}
.author {
  font-size: 14px;
}
.tag {
  font:
    12px ui-monospace,
    monospace;
  letter-spacing: 0.5px;
  color: var(--muted);
}
main {
  max-width: 1080px;
  margin: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 42px;
  padding: 0 24px;
  align-items: start;
}
.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 12px;
}
.player > div {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.player strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 500;
}
.player time {
  font:
    500 28px ui-monospace,
    monospace;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 3px;
  white-space: nowrap;
}
.player time.running {
  background: #e8f3ec;
  color: #176c47;
}
.player time.low {
  color: #ba3d2e;
}
.side-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  background: #4e5b50;
  border: 1px solid #879486;
  border-radius: 50%;
}
.side-dot.white {
  background: #fff;
}
#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 3px;
  border: 1px solid #91a48a;
  touch-action: none;
  user-select: none;
  margin-bottom: 14px;
}
.square {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-width: 0;
  aspect-ratio: 1;
  background: var(--light);
  cursor: default;
}
.square.dark {
  background: var(--dark);
}
.square.last {
  box-shadow: inset 0 0 0 100px #c6ce5870;
}
.square.selected {
  box-shadow: inset 0 0 0 100px #c7d85799;
}
.square.legal:after {
  content: "";
  position: absolute;
  width: 25%;
  height: 25%;
  border-radius: 50%;
  background: #17291f45;
  pointer-events: none;
}
.square.legal:has(img):after {
  width: 90%;
  height: 90%;
  border: 5px solid #22392566;
  background: none;
}
.square img {
  width: 87%;
  height: 87%;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px #0002);
}
.square .coordinate {
  position: absolute;
  font: 500 11px system-ui;
  color: #56634c;
  left: 4px;
  top: 1px;
  pointer-events: none;
}
.square.dark .coordinate {
  color: #f6f8ee;
}
.square .file {
  top: auto;
  bottom: 1px;
  left: auto;
  right: 4px;
}
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 99;
  width: 76px;
  height: 76px;
  filter: drop-shadow(0 5px 3px #0004);
}
.square.dragging img {
  opacity: 0.25;
}
.game-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  color: var(--accent);
  padding: 4px 0;
  font-size: 14px;
}
#result {
  font-weight: 600;
}
.board-actions {
  display: flex;
  gap: 8px;
}
.board-actions #resign {
  margin-left: auto;
}
.panel {
  background: var(--panel);
  padding: 0 0 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 20px;
}
h1,
h2 {
  font-size: 16px;
  line-height: 1.3;
  margin: 0;
  font-weight: 500;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
label {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin: 14px 0 6px;
}
input,
select {
  width: 100%;
  min-width: 0;
  background: #fff;
  border: 1px solid #d7ddd8;
  border-radius: 3px;
  font: inherit;
  color: var(--text);
  padding: 8px 10px;
}
button {
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  border-radius: 3px;
  padding: 10px 16px;
}
.primary:hover:not(:disabled) {
  background: #16794e;
}
#start {
  width: 100%;
  margin-top: 20px;
}
.quiet,
.presets button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 14px;
}
.quiet:hover:not(:disabled),
.presets button:hover {
  background: #f3f6f3;
}
.danger {
  color: #a7463c;
}
.presets {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.presets button {
  flex: 1;
  padding: 5px;
}
.presets button.active {
  color: var(--accent);
  border-color: #9ac6ae;
  background: #f2f8f4;
}
.hint {
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 0;
}
#error {
  font-size: 14px;
  color: #b64032;
  overflow-wrap: anywhere;
}
.moves-panel {
  padding-bottom: 10px;
  border-bottom: 0;
}
.moves-head,
.move-row {
  display: grid;
  grid-template-columns: 32px 1fr 1fr;
  align-items: center;
  gap: 4px;
}
.moves-head {
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
#moves {
  height: 200px;
  overflow-y: auto;
  padding-top: 5px;
}
.move-row > span {
  color: var(--muted);
  font: 13px monospace;
}
.move-row button {
  text-align: left;
  font:
    15px ui-monospace,
    monospace;
  border: 0;
  background: transparent;
  padding: 7px;
  border-radius: 3px;
}
.move-row button:hover,
.move-row button.current {
  background: #e8f3ec;
  color: #176c47;
}
.review {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  margin-top: 8px;
}
.review button {
  border: 0;
}
.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 10px 0;
}
footer {
  max-width: 1080px;
  margin: 42px auto 0;
  padding: 20px 24px 40px;
  color: var(--muted);
  font-size: 13px;
}
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  max-width: calc(100vw - 32px);
  padding: 24px;
  box-shadow: 0 12px 50px #0002;
}
dialog::backdrop {
  background: #18231b66;
}
dialog h2 {
  margin-bottom: 18px;
}
#promotion-options {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
#promotion-options button {
  background: var(--light);
  border: 0;
  border-radius: 3px;
  padding: 5px;
}
#promotion-options img {
  width: 58px;
  height: 58px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
dialog p {
  color: var(--muted);
}
[hidden] {
  display: none !important;
}
@media (max-width: 850px) {
  main {
    grid-template-columns: minmax(0, 1fr) 250px;
    gap: 24px;
    padding: 0 20px;
  }
  header {
    padding: 0 20px;
    margin-top: 30px;
  }
  .player strong {
    font-size: 14px;
  }
  .player time {
    font-size: 23px;
  }
}
@media (max-width: 680px) {
  main {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
  main > section,
  aside {
    width: 100%;
  }
  header {
    margin: 24px auto;
  }
  .brand {
    font-size: 16px;
  }
  .author {
    font-size: 13px;
  }
  .game-panel {
    order: 1;
  }
  aside {
    display: contents;
  }
  aside > .panel:first-child {
    order: 0;
    width: 100%;
  }
  .moves-panel {
    order: 2;
    width: 100%;
  }
  .panel {
    margin-bottom: 0;
  }
  .player time {
    font-size: 27px;
  }
  .square .coordinate {
    font-size: 10px;
  }
  footer {
    margin-top: 20px;
  }
}

/* The game is the page: setup sits over the board, history follows underneath. */
header,
main,
footer {
  max-width: 760px;
}
header {
  margin-top: 32px;
  margin-bottom: 24px;
}
main {
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.game-panel,
.moves-panel {
  width: 100%;
}
.game-panel {
  order: 0;
}
.moves-panel {
  order: 1;
  margin: 0;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.board-stage {
  position: relative;
  margin-bottom: 14px;
  border-radius: 3px;
  overflow: hidden;
}
#board {
  margin-bottom: 0;
  transition: filter 0.2s;
}
.board-stage.is-covered #board {
  filter: blur(5px);
  pointer-events: none;
}
.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff42;
  padding: 16px;
}
.start-controls {
  width: 290px;
  max-width: 100%;
  padding: 24px;
  background: #fffffff2;
  border: 1px solid #e0e6e0;
  border-radius: 5px;
  box-shadow: 0 8px 28px #21372614;
}
.start-controls .section-heading {
  margin: 0 0 14px;
}
.time-control {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 12px;
}
.start-controls .hint {
  font-size: 13px;
}
.initializing {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: #fffffff2;
  border-radius: 5px;
  font-size: 14px;
  color: var(--muted);
}
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #dce7df;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.clock-decimal {
  font-size: 0.58em;
  color: var(--muted);
  margin-left: 1px;
}
.moves-panel #moves {
  height: 210px;
}
.moves-head,
.move-row {
  grid-template-columns: 44px 1fr 1fr;
}
footer {
  margin-top: 24px;
}
@media (prefers-reduced-motion: reduce) {
  #board {
    transition: none;
  }
  .spinner {
    animation-duration: 1.8s;
  }
}
@media (max-width: 680px) {
  main {
    gap: 20px;
  }
  .game-panel {
    order: 0;
  }
  .moves-panel {
    order: 1;
  }
  .start-controls {
    padding: 18px;
    width: 260px;
  }
  .start-controls .hint {
    margin-top: 10px;
  }
  .start-controls #start {
    margin-top: 14px;
  }
  .player time {
    font-size: 28px;
  }
}

/* Compact play surface. Only contextual controls stay visible. */
main,
footer {
  max-width: 660px;
}
main {
  margin: 28px auto 0;
  gap: 12px;
}
.player {
  padding-bottom: 8px;
}
.player strong {
  font-size: 14px;
}
.player time {
  font-size: 27px;
  padding: 0 3px;
}
.board-stage {
  margin-bottom: 8px;
}
.start-controls {
  width: auto;
  min-width: 230px;
  padding: 18px;
  border: 0;
  box-shadow: 0 3px 20px #21372614;
}
.time-control {
  text-align: center;
  font-size: 14px;
  margin: 0 0 12px;
}
.start-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.start-row select {
  width: 120px;
  font-size: 14px;
  padding: 8px;
}
.start-controls #start {
  width: auto;
  min-width: 76px;
  margin: 0;
  padding: 8px 16px;
  font-size: 14px;
}
.initializing {
  padding: 12px 16px;
  gap: 9px;
}
.spinner {
  width: 17px;
  height: 17px;
}
.game-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  font-size: 13px;
  color: var(--muted);
}
.game-toolbar #result {
  color: var(--text);
}
.board-actions {
  margin-left: auto;
}
.board-actions .quiet {
  border: 0;
  padding: 4px 0 4px 10px;
  font-size: 13px;
}
.moves-panel {
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
}
.moves-panel #moves {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 1px 12px;
  height: auto;
  max-height: 130px;
  padding: 0;
}
.move-row {
  display: inline-flex;
  gap: 1px;
  align-items: center;
}
.move-row > span {
  font-size: 12px;
  margin-right: 3px;
}
.move-row > span:after {
  content: ".";
}
.move-row button {
  font-size: 13px;
  padding: 3px 5px;
}
.moves-panel #live {
  font-size: 13px;
  margin-top: 8px;
  padding: 3px 0;
  border: 0;
  color: var(--accent);
}
footer {
  margin: 16px auto 0;
  padding-top: 0;
  font-size: 12px;
}
@media (max-width: 680px) {
  main {
    margin-top: 18px;
    gap: 10px;
    padding: 0 14px;
  }
  .player time {
    font-size: 25px;
  }
  .start-controls {
    width: auto;
    min-width: 220px;
    padding: 16px;
  }
  .start-controls #start {
    margin: 0;
  }
  footer {
    padding: 0 14px 20px;
  }
}

.start-controls .intro {
  max-width: 250px;
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}
.start-controls .intro a {
  color: var(--accent);
}

.start-controls {
  width: 340px;
  min-width: 0;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 24px;
}
.intro-title {
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 14px;
}
.start-controls .intro {
  max-width: none;
  font-size: 14px;
  line-height: 1.55;
  margin: 0 0 10px;
}
.intro-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 14px 0 20px;
}
.intro-links a {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: #9cc6af;
  text-underline-offset: 4px;
  border-radius: 3px;
  transition:
    color 0.15s,
    background 0.15s,
    text-decoration-color 0.15s;
}
.intro-links a:hover {
  color: #11653f;
  background: #e6f3eb;
  text-decoration-color: #11653f;
}
.intro-links a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
.intro-links a span {
  display: inline-block;
  transition: transform 0.15s;
}
.intro-links a:hover span {
  transform: translate(1px, -1px);
}
.start-controls .time-control {
  display: none;
}
.start-row {
  justify-content: space-between;
  gap: 12px;
}
.color-picker {
  position: relative;
  flex: 1;
  font-size: 14px;
}
.color-picker summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
  padding: 8px 11px;
  border: 1px solid #d7ddd8;
  border-radius: 3px;
  background: #fff;
  user-select: none;
}
.color-picker summary::-webkit-details-marker {
  display: none;
}
.color-picker summary:hover {
  border-color: #8eb59d;
  background: #f7faf8;
}
.color-picker summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chevron {
  color: var(--muted);
  line-height: 1;
}
.color-picker[open] .chevron {
  transform: rotate(180deg);
}
.color-options {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  padding: 4px;
  border: 1px solid #d7ddd8;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 5px 20px #12261a15;
  z-index: 2;
}
.color-options button {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  padding: 8px;
  border-radius: 2px;
  font-size: 14px;
}
.color-options button:hover,
.color-options button:focus-visible {
  background: #eef6f0;
  color: #176c47;
}
.color-options button[aria-pressed="true"] {
  background: #e8f3ec;
  color: #176c47;
  font-weight: 500;
}
.start-controls #start {
  min-width: 92px;
}
@media (max-width: 420px) {
  .start-controls {
    width: 300px;
    padding: 16px;
  }
  .intro-title {
    font-size: 16px;
    margin-bottom: 10px;
  }
  .start-controls .intro {
    font-size: 13px;
    line-height: 1.45;
  }
  .intro-links {
    margin: 10px 0 14px;
    gap: 12px;
  }
  .intro-links a {
    font-size: 13px;
  }
}

.start-controls {
  overflow: visible;
}
.color-options {
  top: calc(100% + 6px);
  bottom: auto;
}
.start-controls .intro a {
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: #9cc6af;
  text-underline-offset: 3px;
  border-radius: 2px;
  transition:
    color 0.15s,
    background 0.15s,
    text-decoration-color 0.15s;
}
.start-controls .intro a:hover {
  color: #11653f;
  background: #e6f3eb;
  text-decoration-color: #11653f;
}
.start-controls .intro a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.initializing {
  max-width: 290px;
  align-items: flex-start;
}
.initializing .spinner {
  flex-shrink: 0;
  margin-top: 3px;
}
.initializing p {
  font-size: 13px;
  line-height: 1.5;
  margin: 6px 0 0;
  color: var(--muted);
}

#lichess-analysis {
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  align-self: center;
  padding: 4px 0;
}
#lichess-analysis:hover {
  color: #11653f;
  background: #e6f3eb;
}
.game-toolbar {
  flex-wrap: wrap;
}
.board-actions {
  flex-wrap: wrap;
  align-items: center;
}

.result-card {
  width: 300px;
  max-width: 100%;
  padding: 26px 24px;
  text-align: center;
  background: #fffffff5;
  border: 1px solid #e0e6e0;
  border-radius: 5px;
  box-shadow: 0 8px 28px #21372614;
}
.result-card h2 {
  font-size: 24px;
  font-weight: 500;
  margin: 0 0 10px;
}
.result-card p {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 18px;
}
.result-card #lichess-analysis {
  display: inline-block;
  font-size: 14px;
  margin-bottom: 22px;
}
.result-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}
.result-actions button {
  font-size: 14px;
  padding: 8px 12px;
}

body.embedded {
  background: transparent;
}
.embedded main {
  margin: 0 auto;
  padding: 8px 10px;
}
.embedded footer {
  display: none;
}
.embedded .moves-panel {
  margin-bottom: 8px;
}
