.appearance-dialog {
  width: min(36rem, 100% - 1.5rem);
}

#appearance-controls {
  display: grid;
  gap: .83rem;
}

.appearance-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .62rem 1rem;
  padding: .65rem;
  border: 1px solid #475d4b;
  border-radius: .65rem;
  background: linear-gradient(120deg, #273d2a, #14251c);
}

.appearance-preview-actions {
  display: grid;
  justify-items: start;
  gap: .35rem;
}

.appearance-preview-label {
  color: #dae6cd;
  font-size: .84rem;
  font-weight: 700;
}

.appearance-wood-set {
  min-height: 2.15rem;
  padding: .37rem .58rem;
  background: #2b3e30;
  font-size: .79rem;
}

.appearance-preview-board {
  display: grid;
  flex: 0 1 11rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  aspect-ratio: 2;
  min-width: 0;
  overflow: hidden;
  border-radius: .31rem;
  box-shadow: 0 0 0 1px #101c14, 0 6px 12px #09170f59;
}

.appearance-group {
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.appearance-group legend {
  margin-bottom: .36rem;
  padding: 0;
  color: var(--ink);
  font-size: .92rem;
  font-weight: 720;
}

.appearance-choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .37rem;
}

.appearance-surfaces {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.appearance-choice {
  display: grid;
  min-height: 2.6rem;
  justify-items: center;
  align-content: center;
  gap: .38rem;
  border: 1px solid #415646;
  border-radius: .44rem;
  padding: .38rem .24rem;
  background: #1e3125;
  font-size: .84rem;
  font-weight: 650;
  line-height: 1.17;
  text-align: center;
  overflow-wrap: anywhere;
}

.appearance-choice:hover {
  border-color: #7f9472;
}

.appearance-choice[aria-pressed="true"] {
  border-color: #a9bc7a;
  background: #354b30;
  color: #f3f6e6;
}

.appearance-palette {
  min-height: 3.5rem;
}

.appearance-swatch {
  width: 2.55rem;
  height: .98rem;
  border-radius: .21rem;
  background: linear-gradient(90deg, var(--swatch-light) 50%, var(--swatch-dark) 50%);
  box-shadow: 0 0 0 1px #0e1a13b0;
}

.appearance-colors {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .37rem;
  margin-top: .37rem;
}

.appearance-color {
  display: flex;
  min-height: 2.9rem;
  align-items: center;
  gap: .62rem;
  border: 1px solid #3d5142;
  border-radius: .44rem;
  padding: .33rem .45rem;
  background: #1a2c21;
  color: var(--ink);
  font-size: .84rem;
  font-weight: 630;
  line-height: 1.18;
  cursor: pointer;
}

.appearance-color input[type="color"] {
  width: 1.91rem;
  height: 1.72rem;
  flex: none;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.appearance-color input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.appearance-color input::-webkit-color-swatch {
  border: 1px solid #728478;
  border-radius: .26rem;
}

.appearance-color input::-moz-color-swatch {
  border: 1px solid #728478;
  border-radius: .26rem;
}

.appearance-color output {
  display: block;
  margin-top: .11rem;
  color: var(--muted);
  font: .73rem/1.1 var(--mono);
}

.appearance-coordinates {
  display: inline-flex;
  width: max-content;
  align-items: center;
  gap: .55rem;
  color: var(--ink);
  font-size: .89rem;
  font-weight: 640;
  cursor: pointer;
}

.appearance-coordinates input {
  width: 1.08rem;
  height: 1.08rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.appearance-actions {
  margin-top: .1rem;
  padding-top: .67rem;
  border-top: 1px solid #3c5040;
}

[data-chess-coordinates="false"] :is(#files, #ranks) {
  visibility: hidden;
}

[data-chess-surface="wood"] {
  --board-texture-light: url("./textures/maple.webp");
  --board-texture-dark: url("./textures/walnut.webp");
}

[data-chess-surface="marble"] {
  --board-texture-light: url("./textures/ivory-marble.webp");
  --board-texture-dark: url("./textures/forest-marble.webp");
}

[data-chess-surface]:not([data-chess-surface="smooth"]) :is(.board, .appearance-preview-board, .analysis-board) .square-light:not(.selected, .in-check) {
  background-image: var(--board-texture-light);
}

[data-chess-surface]:not([data-chess-surface="smooth"]) :is(.board, .appearance-preview-board, .analysis-board) .square-dark:not(.selected, .in-check) {
  background-image: var(--board-texture-dark);
}

[data-chess-surface]:not([data-chess-surface="smooth"]) .square {
  background-size: 150% 150%;
  background-blend-mode: soft-light;
}

[data-chess-surface]:not([data-chess-surface="smooth"]) .square:nth-child(3n) {
  background-position: 70% 15%;
}

[data-chess-surface]:not([data-chess-surface="smooth"]) .square:nth-child(3n + 1) {
  background-position: 20% 85%;
}

.appearance-texture-definitions {
  position: absolute;
  inset: 0 auto auto 0;
  pointer-events: none;
}

[data-chess-pieces="wood"] {
  --piece-light-fill: url(#appearance-fill-wood-light);
  --piece-dark-fill: url(#appearance-fill-wood-dark);
  --piece-light-edge: #512d1c;
  --piece-dark-edge: #28170f;
  --piece-light-glint: #ffedcf;
  --piece-dark-glint: #ac7855;
}

[data-chess-pieces="marble"] {
  --piece-light-fill: url(#appearance-fill-marble-light);
  --piece-dark-fill: url(#appearance-fill-marble-dark);
  --piece-light-edge: #3f5048;
  --piece-dark-edge: #10221a;
  --piece-light-glint: #fffdf2;
  --piece-dark-glint: #93aa95;
}

[data-chess-pieces="metal"] {
  --piece-light-fill: url(#appearance-fill-metal-light);
  --piece-dark-fill: url(#appearance-fill-metal-dark);
  --piece-light-edge: #344450;
  --piece-dark-edge: #11191c;
  --piece-light-glint: #f8ffff;
  --piece-dark-glint: #aebac1;
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) .chess-piece {
  filter: drop-shadow(0 1px .55px #0c1d12a2);
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) :is(.chess-piece--light > g, .chess-piece > g[stroke="#27362e"]) {
  stroke: var(--piece-light-edge);
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) :is(.chess-piece--dark > g, .chess-piece > g[stroke="#14221c"]) {
  stroke: var(--piece-dark-edge);
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) :is(.chess-piece--light > g, .chess-piece > g[stroke="#27362e"]) > path:nth-child(-n + 2) {
  fill: var(--piece-light-fill);
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) :is(.chess-piece--dark > g, .chess-piece > g[stroke="#14221c"]) > path:nth-child(-n + 2) {
  fill: var(--piece-dark-fill);
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) :is(.chess-piece--light, .chess-piece:has(> g[stroke="#27362e"])) > path {
  stroke: var(--piece-light-glint);
}

[data-chess-pieces]:not([data-chess-pieces="classic"]) :is(.chess-piece--dark, .chess-piece:has(> g[stroke="#14221c"])) > path {
  stroke: var(--piece-dark-glint);
}

html .square.legal:not(.capture)::after {
  background: #14271b87;
  box-shadow: inset 0 0 0 1px #fff8d28c;
}

html .square.capture::after {
  border-color: #2135238f;
  box-shadow: 0 0 0 1px #eff2c5a1;
}

@media (max-width: 420px) {
  .appearance-choice {
    padding-inline: .18rem;
    font-size: .73rem;
  }

  .appearance-swatch {
    width: min(2.1rem, 84%);
  }
}
