:root {
  --bg: #161512;
  --surface: #262421;
  --surface2: #302e2c;
  --text: #bababa;
  --text-hi: #e8e6e3;
  --dim: #787570;
  --green: #629924;
  --green-hi: #73b52c;
  --blue: #3692e7;
  --border: #3a3836;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Noto Sans', 'Segoe UI', Roboto, sans-serif;
  touch-action: manipulation;
}

body {
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 20px) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 20px);
}

.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1020px;
  margin: 0 auto 20px;
}

h1 {
  margin: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  font-size: 24px;
  font-weight: 500;
  color: var(--text-hi);
}
h1 .logo { height: 42px; display: block; }
h1 span { line-height: 1; padding-bottom: 2px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 14px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
}
.status-pill:hover { color: var(--text-hi); background: var(--surface2); }
.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
}
.status-pill.online .dot {
  background: var(--green-hi);
  box-shadow: 0 0 0 3px rgba(115, 181, 44, .25);
}
.status-pill.playing .dot {
  background: var(--blue);
  box-shadow: 0 0 0 3px rgba(54, 146, 231, .25);
}

.main {
  max-width: 1020px;
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

/* Board */
.board-wrap {
  width: min(100%, 480px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 3px;
  overflow: hidden;
  user-select: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.clickable { cursor: pointer; }
.sq.clickable:hover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, .14);
  pointer-events: none;
}
.sq.removed::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(rgba(220, 70, 50, .6) 18%, transparent 21%);
  pointer-events: none;
}
.sq piece {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
}
.sq .coord-file, .sq .coord-rank {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  opacity: .72;
}
.sq.light .coord-file, .sq.light .coord-rank { color: var(--sq-dark); }
.sq.dark .coord-file, .sq.dark .coord-rank { color: var(--sq-light); }
.sq .coord-rank { top: 2px; left: 3px; }
.sq .coord-file { bottom: 2px; right: 3px; }

.odds-name {
  margin: 10px 0 0;
  text-align: center;
  color: var(--text-hi);
  font-size: 16px;
  min-height: 22px;
}

/* Controls */
.opts {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(100%, 480px);
  margin: 0 auto;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.presets button {
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 13.5px;
}
.presets button:hover { background: var(--surface2); }
.presets button.on { background: var(--blue); color: #fff; }
.presets button .rating { margin-left: 4px; opacity: .65; font-variant-numeric: tabular-nums; }

.colors {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.colors button {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  background: var(--surface);
  display: grid;
  place-items: center;
}
.colors button:hover { background: var(--surface2); }
.colors button.on { background: var(--green); }

.cg-wrap.icon { position: relative; display: block; width: 46px; height: 46px; }
.cg-wrap.icon piece {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Chess960 toggle switch */
.frc-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  color: var(--text);
  font-size: 14px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex: none;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border-radius: 22px;
  transition: background .16s;
}
.switch .slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--text-hi);
  border-radius: 50%;
  transition: transform .16s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--blue); outline-offset: 2px; }

.frc-opts {
  display: flex;
  gap: 6px;
  align-items: center;
}
.frc-opts input {
  width: 68px;
  background: var(--surface);
  color: var(--text-hi);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font: 14px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.frc-opts button, .fen-row button {
  padding: 5px 10px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-hi);
  font-size: 13px;
}
.frc-opts button:hover, .fen-row button:hover { background: var(--surface2); }

.fen-row {
  display: flex;
  gap: 6px;
}
#fen-out {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: var(--text-hi);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 9px;
  font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fen-row button.copied { background: var(--green); color: #fff; }

.primary {
  display: block;
  width: 100%;
  padding: 13px;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.primary:hover, .primary:active { background: var(--green-hi); }

/* Desktop 2-column layout */
@media (min-width: 820px) {
  body { padding: 24px 36px 36px; }
  .head { margin-bottom: 24px; }
  .main {
    grid-template-columns: minmax(0, 1fr) 340px;
    column-gap: 40px;
    align-items: start;
  }
  .board-wrap { width: min(100%, 100dvh - 165px); margin: 0; }
  .odds-name { text-align: left; }
  .opts { width: 100%; margin: 0; min-height: min(100%, 100dvh - 165px); }
  .presets { justify-content: flex-start; }
  .colors { justify-content: flex-start; }
  .primary { margin-top: auto; }
}
