:root {
  color-scheme: dark;
  --bg: #0f1424;
  --panel: #1b2134;
  --ink: #edf2fa;
  --muted: #a4afc4;
  --accent: #b7b3ff;
  --light: #edf2f8;
  --dark: #6e93bf;
  --board-size: min(calc(100vw - 64px), calc(100dvh - 204px), 960px);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 20%, #292955 0%, var(--bg) 65%);
  -webkit-font-smoothing: antialiased;
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
  color: inherit;
  border: 1px solid #ffffff20;
  background: #ffffff08;
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 16px;
}
button:hover {
  background: #ffffff16;
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
a {
  color: var(--accent);
}
.hidden,
[hidden] {
  display: none !important;
}
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(20px, env(safe-area-inset-left));
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 750;
  font-size: 13px;
  letter-spacing: 0.12em;
}
.brand em {
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: -0.06em;
  color: var(--accent);
}
.icon-button {
  font-size: 24px;
  border: 0;
  background: transparent;
  width: 48px;
  height: 48px;
  padding: 4px;
}
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0 max(12px, env(safe-area-inset-bottom));
}
.player {
  height: 30px;
  width: var(--board-size);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
}
.player span:first-child {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.player-top {
  justify-content: flex-end;
}
.turn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.turn-dot:not(.active) {
  visibility: hidden;
}
.board-frame {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 3px;
  box-shadow:
    0 14px 50px #0004,
    0 0 0 1px #ffffff16;
}
#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  isolation: isolate;
}
.square {
  position: relative;
  border: 0;
  border-radius: 0;
  min-height: 0;
  min-width: 0;
  padding: 0;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  color: #172033;
  background: var(--light);
}
.square.dark {
  background: var(--dark);
}
.square:hover {
  background: var(--light);
}
.square.dark:hover {
  background: var(--dark);
}
.square:active {
  transform: none;
}
.square.last:before,
.square.selected:before {
  content: "";
  position: absolute;
  inset: 0;
  background: #e6dd5377;
  pointer-events: none;
}
.square.selected:before {
  background: #9b8cff88;
}
.square.target:after {
  content: "";
  width: 24%;
  height: 24%;
  background: #17203335;
  border-radius: 50%;
  position: absolute;
  pointer-events: none;
}
.square.target:has(img):after {
  width: 88%;
  height: 88%;
  background: none;
  border: 5px solid #17203335;
}
.piece {
  width: 95%;
  height: 95%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 1px #0003);
  z-index: 1;
  transition: transform 120ms;
}
.square.holding .piece {
  transform: scale(1.4);
  z-index: 5;
}
.square.drag-source .piece {
  opacity: 0.15;
}
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  width: var(--ghost-size);
  height: var(--ghost-size);
  filter: drop-shadow(0 8px 6px #0005);
  transform: scale(1.16);
}
.drag-ghost img {
  width: 100%;
  height: 100%;
}
.coord {
  position: absolute;
  pointer-events: none;
  font-size: clamp(9px, 1.7vw, 13px);
  font-weight: 750;
  z-index: 2;
}
.coord-file {
  right: 3px;
  bottom: 1px;
}
.coord-rank {
  left: 3px;
  top: 1px;
}
.files,
.ranks {
  position: absolute;
  display: grid;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.files {
  grid-template-columns: repeat(8, 1fr);
  left: 0;
  right: 0;
  bottom: -19px;
  text-align: center;
}
.ranks {
  grid-template-rows: repeat(8, 1fr);
  top: 0;
  bottom: 0;
  left: -21px;
  width: 16px;
  text-align: center;
  align-items: center;
}
.player-bottom {
  margin-top: 17px;
}
.coord {
  display: none;
}
#navigation {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}
#navigation button {
  width: 68px;
  font-size: 30px;
  line-height: 1;
  padding: 0;
  background: transparent;
  border-color: transparent;
}
#navigation button:hover {
  background: #ffffff12;
}
dialog {
  color: var(--ink);
  background: var(--panel);
  border: 1px solid #ffffff20;
  border-radius: 22px;
  padding: 0;
  box-shadow: 0 30px 100px #0008;
  max-width: calc(100vw - 24px);
}
dialog::backdrop {
  background: #080b16aa;
  backdrop-filter: blur(8px);
}
#panel {
  width: 520px;
  max-height: 85dvh;
}
.panel-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid #ffffff13;
}
h1 {
  font-size: 18px;
  margin: 0;
}
h2 {
  font-size: 20px;
}
.panel-head h1 {
  letter-spacing: -0.02em;
}
#panel-content {
  padding: 18px;
  overflow-wrap: anywhere;
}
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.menu-grid button {
  text-align: left;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 78px;
  font-weight: 650;
}
.menu-grid small {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}
.menu-grid .wide {
  grid-column: 1/-1;
  background: #a49bff18;
}
.section-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin: 22px 0 8px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0 0 17px;
  font-size: 14px;
}
.field input,
.field select,
.field textarea,
input,
textarea,
select {
  width: 100%;
  border: 1px solid #ffffff26;
  border-radius: 10px;
  color: var(--ink);
  background: #0f1424;
  padding: 12px;
  font-size: 16px;
}
textarea {
  resize: vertical;
  min-height: 130px;
  line-height: 1.6;
}
select option {
  background: #0f1424;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.primary {
  background: #b7b3ff !important;
  color: #14152b !important;
  font-weight: 700;
  border-color: transparent;
}
.help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}
.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #ffffff12;
}
.settings-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}
#toast {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: 90vw;
  width: max-content;
  border: 1px solid #ffffff28;
  background: #252e46;
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: 0 5px 30px #0005;
  font-size: 14px;
}
#save-warning {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 16px;
  background: #7e2436;
  color: white;
  z-index: 20;
  font-size: 13px;
}
#panel.moves {
  width: min(1000px, 96vw);
  height: 90dvh;
  max-height: 94dvh;
}
.scoresheet {
  display: grid;
  grid-template-columns: 45px 1fr 1fr;
  gap: 5px;
  font-size: clamp(24px, 4vw, 40px);
  line-height: 1.55;
}
.scoresheet .number {
  font-size: 0.55em;
  align-self: center;
  color: var(--muted);
  text-align: center;
}
.move {
  font: inherit;
  min-height: 48px;
  text-align: left;
  padding: 4px 10px;
  border-color: transparent;
  border-radius: 7px;
  background: transparent;
}
.move.current {
  background: #b7b3ff28;
  color: var(--accent);
}
.pgn-tree {
  font-size: 25px;
  line-height: 1.8;
}
.pgn-tree .move {
  display: inline;
  font-size: inherit;
  padding: 3px 6px;
}
.variation {
  display: block;
  border-left: 2px solid #b7b3ff50;
  margin: 6px 0 10px 12px;
  padding-left: 14px;
  color: var(--muted);
  font-size: 0.86em;
}
.move-comment {
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  display: inline;
}
.scoresheet .variation {
  grid-column: 1/-1;
}
.scoresheet .move-note {
  display: block;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  font-weight: 400;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chips button {
  font-size: 23px;
  min-width: 48px;
}
.mini-piece {
  width: 42px;
  height: 42px;
}
#promotion {
  padding: 22px;
  text-align: center;
}
#promotion-choices {
  display: flex;
  gap: 6px;
  margin: 20px 0;
}
#promotion-choices button {
  width: 64px;
  height: 70px;
  padding: 4px;
}
#promotion-choices img {
  width: 100%;
  height: 100%;
}
#editor-tools {
  width: min(100%, 620px);
  padding: 12px;
  text-align: center;
}
#piece-palette {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 12px;
}
#piece-palette button {
  padding: 3px;
  min-width: 0;
  height: 48px;
}
#piece-palette button.active {
  border: 2px solid var(--accent);
  background: #b7b3ff28;
}
#piece-palette img {
  max-width: 100%;
  height: 38px;
}
body.editing {
  --board-size: min(calc(100vw - 64px), calc(100dvh - 330px), 800px);
}
.engine-line {
  padding: 12px;
  background: #ffffff08;
  border-radius: 10px;
  margin: 10px 0;
  line-height: 1.7;
  font-size: 18px;
}
.error {
  color: #ffb1bc;
}
.success {
  color: #a0e5be;
}
.lichess-feedback {
  margin-top: 14px;
  font-size: 14px;
  line-height: 1.7;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.palette-preview {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--light) 50%, var(--dark) 50%);
  margin-bottom: 16px;
}
body[data-look="repo"] {
  --bg: #0d0d0c;
  --panel: #1a1a18;
  --ink: #f1efe9;
  --muted: #b4b1a8;
  --accent: #f1efe9;
  background: var(--bg);
}
body[data-look="repo"] dialog,
body[data-look="repo"] button {
  border-radius: 3px;
}
body[data-look="repo"] input,
body[data-look="repo"] select,
body[data-look="repo"] textarea {
  background: #0d0d0c;
}
body[data-look="photo"] {
  --bg: #151412;
  --panel: #22211e;
  --accent: #e5c09a;
  background: var(--bg);
}
@media (max-width: 600px), (max-height: 560px) {
  :root {
    --board-size: min(100vw, calc(100dvh - 138px));
  }
  .topbar {
    height: 54px;
    padding-top: env(safe-area-inset-top);
    height: calc(54px + env(safe-area-inset-top));
  }
  .brand {
    font-size: 11px;
    letter-spacing: 0.1em;
  }
  .stage {
    padding-top: max(0px, calc((100dvh - var(--board-size) - 155px) / 2));
  }
  .player {
    height: 26px;
    padding: 0 9px;
    font-size: 12px;
  }
  .player-bottom {
    margin-top: 0;
  }
  .files,
  .ranks {
    display: none;
  }
  .coord {
    display: block;
  }
  body[data-coords="none"] .coord {
    display: none;
  }
  #navigation {
    display: none;
  }
  .board-frame {
    border-radius: 0;
  }
  dialog {
    border-radius: 20px;
    max-width: 100vw;
  }
  #panel {
    width: 100vw;
    max-height: 91dvh;
    margin: auto 0 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #panel.moves {
    height: 94dvh;
    max-height: 94dvh;
    width: 100vw;
  }
  .menu-grid button {
    padding: 13px;
  }
  body.editing {
    --board-size: min(100vw, calc(100dvh - 310px));
  }
  .stage:has(#editor-tools:not([hidden])) {
    padding-top: 0;
  }
}
@media (min-width: 601px) and (min-height: 850px) {
  :root {
    --board-size: min(calc(100vw - 80px), calc(100dvh - 220px), 1100px);
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
