*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-subtle: #fafaf9;
  --bg: #ffffff;
  --fg: #0c0a09;
  --fg-muted: #78716c;
  --border: #e7e5e4;
  --fill-muted: #f3efed;
  --accent: #f26522;
  --accent-strong: #ea580c;
  --r-1: 2px;
  --header-h: 60px;
  --footer-h: 32px;
  --board-material-offset: 38px;
  --board-size: min(560px, calc(100dvh - var(--header-h) - var(--footer-h) - 72px));
  --panel-btn-h: 36px;
  --light: #ead9b5;
  --dark: #b58863;
  --selected: #cdd26a;
  --target: rgba(0, 0, 0, 0.22);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-synthesis: none;
}

html,
body {
  min-height: 100%;
}

@media (min-width: 761px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }
}

body {
  background: var(--bg-subtle);
  color: var(--fg);
  font-family: "Geist", Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-feature-settings: "cv11", "ss01";
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 1px dotted var(--accent-strong);
  outline-offset: 3px;
  border-radius: 4px;
}

.home-page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

@media (min-width: 761px) {
  .home-page {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
}

.container-1312 {
  width: 100%;
  max-width: 1408px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 24px;
  padding-right: 24px;
}

@media (min-width: 768px) {
  .container-1312 {
    padding-left: 32px;
    padding-right: 32px;
  }
}

@media (min-width: 1024px) {
  .container-1312 {
    padding-left: 64px;
    padding-right: 64px;
  }
}

/* --- Header (landing chrome) --- */

.site-header {
  position: fixed;
  top: 0;
  inset-inline: 0;
  z-index: 50;
  width: 100%;
  height: var(--header-h);
  background-color: var(--bg-subtle);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.site-header__logo-link {
  display: flex;
  flex-shrink: 0;
  align-items: center;
}

.site-header__logo {
  display: block;
  height: 20px;
  width: auto;
}

.site-header__nav {
  display: flex;
  align-items: center;
}

.site-header__nav .btn-slide {
  align-items: center;
  color: var(--fg);
  display: inline-flex;
  font-size: 14px;
  font-weight: 500;
  height: 36px;
  line-height: 20px;
  padding: 8px 16px;
}

.site-header__yc {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.yc-square__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.yc-square .yc-square-bg {
  fill: #0c0a09;
  transition: fill 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.yc-square:hover .yc-square-bg,
.yc-square:focus-visible .yc-square-bg {
  fill: var(--accent);
}

/* --- Shared slide button --- */

.btn-slide {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-1) !important;
  isolation: isolate;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.btn-slide-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 460ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
  pointer-events: none;
  z-index: 0;
  background: var(--fill-muted);
}

.btn-slide-fill--accent {
  background: var(--accent-strong);
}

.btn-slide:hover .btn-slide-fill,
.btn-slide:focus-visible .btn-slide-fill {
  transform: scaleX(1);
}

.btn-slide-content {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 24px;
  background: #0c0a09;
  color: #ffffff;
  font-size: 16px;
  font-weight: 500;
}

.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn-primary:disabled:hover .btn-slide-fill {
  transform: scaleX(0);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--border) !important;
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.btn-secondary:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn-secondary:disabled:hover .btn-slide-fill {
  transform: scaleX(0);
}

/* --- Main / chess layout --- */

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: var(--header-h);
}

@media (min-width: 761px) {
  .home-main {
    min-height: calc(100dvh - var(--footer-h));
    overflow: hidden;
  }
}

.app {
  display: grid;
  gap: 32px;
  grid-template-columns: minmax(280px, 560px) minmax(240px, 300px);
  align-items: start;
  justify-content: center;
  width: 100%;
}

@media (min-width: 761px) {
  .app {
    flex: 1;
    align-content: center;
    align-items: start;
    column-gap: 32px;
    max-height: calc(100dvh - var(--header-h) - var(--footer-h));
    min-height: calc(100dvh - var(--header-h) - var(--footer-h));
    overflow: hidden;
    padding: 0;
  }

  .board {
    height: var(--board-size);
    max-height: var(--board-size);
    max-width: var(--board-size);
    width: var(--board-size);
  }

  .panel {
    position: relative;
    width: 100%;
  }

  .panel-title {
    margin-top: var(--board-material-offset);
  }

  .panel__actions {
    left: 0;
    margin-top: 0;
    position: absolute;
    right: 0;
    top: calc(
      var(--board-material-offset) + var(--board-size) - var(--panel-btn-h)
    );
    transform: none;
  }

  .move-log:not([hidden]) {
    max-height: calc(
      var(--board-size) - var(--board-material-offset) - 9.5rem
    );
    padding-bottom: calc(var(--panel-btn-h) + 16px);
  }
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
}

.panel-title {
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field-label {
  color: var(--fg-muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.select-shell {
  position: relative;
}

.select-shell::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--fg-muted);
  content: "";
  pointer-events: none;
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-35%);
}

.field select {
  appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-1);
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  max-width: 100%;
  padding: 11px 36px 11px 12px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  width: 100%;
}

.field select:hover:not(:disabled) {
  border-color: #d6d3d1;
}

.field select:focus {
  border-color: #a8a29e;
  box-shadow: 0 0 0 3px rgba(12, 10, 9, 0.06);
  outline: none;
}

.field select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.status {
  color: var(--fg-muted);
  font-size: 0.9375rem;
  margin-bottom: 12px;
  min-height: 1.5em;
}

.move-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  max-height: calc(10 * 30px + 16px);
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 8px;
  scrollbar-width: thin;
}

.panel__actions {
  flex-shrink: 0;
  padding-top: 0;
}

.btn-block {
  justify-content: center;
  width: 100%;
}

.move-log__row {
  align-items: center;
  display: grid;
  gap: 6px;
  grid-template-columns: 2rem 1fr 1fr;
  height: 30px;
  min-height: 30px;
}

.move-log__num {
  color: var(--fg-muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  text-align: right;
}

.move-log__move {
  align-items: center;
  border-radius: var(--r-1);
  color: var(--fg);
  display: inline-flex;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  gap: 4px;
  min-height: 26px;
  padding: 2px 8px;
}

.move-log__move.is-latest {
  background: var(--fill-muted);
}

.move-log__glyph {
  font-family: "Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols 2",
    "DejaVu Sans", sans-serif;
  font-size: 0.9rem;
  font-variant-emoji: text;
  line-height: 1;
  opacity: 0.95;
}

.move-log__glyph.is-black {
  color: #1c1917;
  -webkit-text-fill-color: #1c1917;
}

.move-log__glyph.is-white {
  color: #78716c;
  -webkit-text-fill-color: #78716c;
}

.board-stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-self: end;
  max-width: 560px;
  width: 100%;
  --light: #ead9b5;
  --dark: #b58863;
  --selected: #cdd26a;
}

.material {
  align-items: center;
  display: flex;
  gap: 10px;
  min-height: 28px;
}

.material__label {
  color: var(--fg-muted);
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  max-width: 5.5rem;
  min-width: 2.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.material__pieces {
  align-items: center;
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 1px;
  min-height: 22px;
}

.material__score {
  color: var(--fg);
  flex-shrink: 0;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  font-weight: 600;
}

.board-meta {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: flex-start;
}

.board-meta .material {
  flex: 1;
  min-width: 0;
}

.board {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--r-1);
  box-shadow: 0 1px 2px rgba(12, 10, 9, 0.04);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  max-width: 560px;
  overflow: hidden;
  user-select: none;
  width: 100%;
}

.square {
  align-items: center;
  appearance: none;
  border: none;
  color: var(--fg);
  display: flex;
  justify-content: center;
  padding: 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.square.light {
  background: var(--light);
}

.square.dark {
  background: var(--dark);
}

.square.selected {
  background: var(--selected);
}

.square.legal::after {
  background: var(--target);
  border-radius: 50%;
  content: "";
  height: 28%;
  pointer-events: none;
  position: absolute;
  width: 28%;
}

.square.legal.has-piece::after {
  background: transparent;
  border: 3px solid rgba(0, 0, 0, 0.28);
  border-radius: 50%;
  height: 84%;
  width: 84%;
}

.piece {
  cursor: pointer;
  font-family: "Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols 2",
    "DejaVu Sans", sans-serif;
  font-size: clamp(1.8rem, 6.5vw, 3.4rem);
  font-style: normal;
  font-variant-emoji: text;
  line-height: 1;
  z-index: 1;
}

.piece.is-black,
.material__glyph.is-black {
  color: #1c1917;
  -webkit-text-fill-color: #1c1917;
}

.piece.is-white,
.material__glyph.is-white {
  color: #fafaf9;
  -webkit-text-fill-color: #fafaf9;
  text-shadow:
    0 0 1px #1c1917,
    0 1px 0 #1c1917,
    1px 0 0 #1c1917,
    0 -1px 0 #1c1917,
    -1px 0 0 #1c1917;
}

.material__glyph.is-white {
  /* Keep white fill + dark outline so captured whites read as white pieces. */
  text-shadow:
    0 0 1.5px #1c1917,
    0 1px 0 #1c1917,
    1px 0 0 #1c1917,
    0 -1px 0 #1c1917,
    -1px 0 0 #1c1917,
    1px 1px 0 #1c1917,
    -1px -1px 0 #1c1917;
}

.board.locked .piece {
  cursor: default;
}

.material__glyph {
  color: var(--fg);
  font-family: "Apple Symbols", "Segoe UI Symbol", "Noto Sans Symbols 2",
    "DejaVu Sans", sans-serif;
  font-size: 1.05rem;
  font-variant-emoji: text;
  line-height: 1;
  opacity: 0.88;
}

.coord {
  color: rgba(0, 0, 0, 0.45);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.65rem;
  font-weight: 600;
  pointer-events: none;
  position: absolute;
}

.coord.file {
  bottom: 2px;
  right: 4px;
}

.coord.rank {
  left: 3px;
  top: 2px;
}

/* --- Footer --- */

.site-footer {
  flex-shrink: 0;
  width: 100%;
  border-top: 1px solid var(--border);
  background-color: var(--bg-subtle);
  color: var(--fg-muted);
}

.site-footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--footer-h);
  font-size: 12px;
}

.site-footer a:hover {
  color: var(--fg);
  transition: color 150ms ease;
}

/* --- Responsive --- */

@media (max-width: 760px) {
  html,
  body {
    overflow: auto;
  }

  .home-page {
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .app {
    grid-template-columns: 1fr;
    padding-top: 28px;
    padding-bottom: 40px;
  }

  .panel {
    margin-top: 0;
    order: 1;
  }

  .panel-title {
    margin-top: 0;
  }

  .panel__actions {
    margin-top: 16px;
    position: static;
  }

  .board-stage {
    display: flex;
    max-width: 100%;
    order: 0;
  }
}

@media (max-width: 639px) {
  .site-header__inner {
    justify-content: center;
  }

  .site-header__logo-link,
  .site-header__yc {
    display: none;
  }

  .site-header__nav {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0;
  }

  .site-header__nav .btn-slide {
    padding-left: 8px;
    padding-right: 8px;
    font-size: 13px;
    white-space: nowrap;
  }
}
