:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #526057;
  --paper: #f7f4ec;
  --card: #fffdf8;
  --line: #c8c5ba;
  --green: #155b3a;
  --green-dark: #0c3d27;
  --gold: #f2c14e;
  --danger: #8b1e2d;
  --light-square: #e8ddc4;
  --dark-square: #48604f;
  --focus: #005fcc;
  --shadow: 0 12px 35px rgba(28, 37, 31, 0.1);
}

* { box-sizing: border-box; }

html { font-size: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 85% 5%, rgba(242, 193, 78, 0.18), transparent 24rem),
    var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button, input, select { font: inherit; }

button, select, input {
  min-height: 46px;
  border: 2px solid #737b75;
  border-radius: 0.55rem;
  background: #fff;
  color: var(--ink);
}

button {
  padding: 0.65rem 1rem;
  font-weight: 750;
  cursor: pointer;
}

button:hover:not(:disabled) { background: #edf1ee; }

button:disabled, input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input, select { padding: 0.6rem 0.75rem; }

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  transform: translateY(-160%);
  padding: 0.7rem 1rem;
  border-radius: 0.4rem;
  background: #fff;
  color: #000;
  font-weight: 800;
}

.skip-link:focus { transform: none; }

.site-header,
.notation-guide,
main,
footer {
  width: min(1180px, calc(100% - 2rem));
  margin-inline: auto;
}

.notation-guide {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--card);
  box-shadow: var(--shadow);
}

.notation-guide summary {
  padding: 0.9rem 1rem;
  color: var(--green-dark);
  font-weight: 850;
  cursor: pointer;
}

.notation-guide-content {
  padding: 0 1rem 1rem;
}

.notation-guide-content p { margin-bottom: 0.65rem; }
.notation-guide-content ul { margin: 0; padding-left: 1.4rem; }
.notation-guide-content li + li { margin-top: 0.5rem; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 2.7rem 0 1.8rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0.35rem; font-family: Georgia, serif; font-size: clamp(2.2rem, 5vw, 4.2rem); line-height: 1; }
h2 { margin-bottom: 0.8rem; font-family: Georgia, serif; font-size: clamp(1.35rem, 2vw, 1.8rem); line-height: 1.2; }

.eyebrow {
  margin-bottom: 0.25rem;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.subtitle { max-width: 46rem; margin-bottom: 0; color: var(--muted); font-size: 1.08rem; }

.king-mark {
  flex: 0 0 auto;
  color: var(--green);
  font-family: Georgia, serif;
  font-size: clamp(4rem, 10vw, 7.5rem);
  line-height: 1;
  filter: drop-shadow(0 5px 0 rgba(21, 91, 58, 0.12));
}

.card {
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--card);
  box-shadow: var(--shadow);
}

.setup-card { margin-bottom: 1.25rem; padding: 1.25rem; }

.form-grid {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(12rem, 1fr) auto;
  align-items: end;
  gap: 1rem;
}

.field { display: grid; gap: 0.35rem; }
.field label, .move-entry > label { font-weight: 800; }

.primary {
  border-color: var(--green-dark);
  background: var(--green);
  color: #fff;
}

.primary:hover:not(:disabled) { background: var(--green-dark); }

.danger { border-color: var(--danger); color: var(--danger); }
.danger:hover:not(:disabled) { background: #fff0f2; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(18rem, 0.85fr);
  align-items: start;
  gap: 1.25rem;
}

.game-card { padding: clamp(1rem, 3vw, 1.5rem); }
.side-column { display: grid; gap: 1.25rem; }
.status-card, .moves-card { padding: 1.25rem; }

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.badge {
  display: inline-block;
  max-width: 15rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid #9ba39d;
  border-radius: 999px;
  background: #edf1ee;
  font-size: 0.86rem;
  font-weight: 750;
  text-align: center;
}

.move-entry {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.65rem; margin-top: 0.4rem; }
.input-row input { width: 100%; font-size: 1.08rem; }

kbd {
  padding: 0.08rem 0.3rem;
  border: 1px solid #9ba39d;
  border-bottom-width: 2px;
  border-radius: 0.25rem;
  background: #fff;
  font-family: ui-monospace, monospace;
}

.button-row { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1.1rem; }

.status-message { margin-bottom: 0; font-size: 1.05rem; }
.error-message { margin: 0.8rem 0 0; padding: 0.75rem; border-left: 5px solid var(--danger); background: #fff0f2; color: #651421; font-weight: 700; }

.move-count {
  display: grid;
  place-items: center;
  min-width: 2.3rem;
  min-height: 2.3rem;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 850;
}

.empty-state { color: var(--muted); font-style: italic; }

.moves-list {
  max-height: 29rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.moves-list li {
  padding: 0.62rem 0.2rem;
  border-top: 1px solid #dedbd2;
  font-variant-numeric: tabular-nums;
}

.moves-list li:first-child { border-top: 0; }
.move-side { display: inline-block; min-width: 4.9rem; color: var(--muted); font-size: 0.88rem; font-weight: 750; }
.move-san { font-family: ui-monospace, "Cascadia Mono", monospace; font-size: 1.03rem; font-weight: 800; }

footer { padding: 1.8rem 0 2.5rem; color: var(--muted); text-align: center; }
footer p { margin: 0; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 820px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 650px) {
  .site-header { padding-top: 1.8rem; }
  .king-mark { display: none; }
  .form-grid, .side-column { grid-template-columns: 1fr; }
  .form-grid .primary { width: 100%; }
  .input-row { grid-template-columns: 1fr; }
  .input-row button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
