:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --text: #1d1d1b;
  --muted: #66665f;
  --line: #d9d8cf;
  --link: #175c8a;
  --link-hover: #0f3f60;
  --button-bg: #fff;
}

body.dark {
  color-scheme: dark;
  --bg: #171817;
  --text: #f1f0e8;
  --muted: #aaa79b;
  --line: #3a3b37;
  --link: #83c7ed;
  --link-hover: #b6def5;
  --button-bg: #22231f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.55;
  transition: background 160ms ease, color 160ms ease;
}

.page {
  width: min(760px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 72px;
}

.theme-switch {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 36px;
}

.theme-switch button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.theme-switch button:hover {
  border-color: var(--link);
  color: var(--link);
  background: var(--button-bg);
}

.theme-switch button.active {
  border-color: var(--link);
  color: var(--link);
  background: var(--button-bg);
}

#chess-toggle {
  font: 700 1.05rem "Times New Roman", Georgia, serif;
}

.theme-icon {
  grid-area: 1 / 1;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sun-icon {
  display: none;
}

body.dark .moon-icon {
  display: none;
}

body.dark .sun-icon {
  display: block;
}

.intro {
  padding-bottom: 34px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 36px;
}

body.chess-mode .page {
  min-height: 100vh;
}

body.chess-mode .intro,
body.chess-mode section:not(#puzzle-section) {
  display: none;
}

body.chess-mode #puzzle-section {
  display: grid;
  min-height: calc(100vh - 140px);
  place-content: center;
}

body.chess-mode #puzzle-heading {
  text-align: center;
}

body.chess-mode .puzzle-widget {
  --board-size: min(78vw, 500px);
  --piece-size: clamp(1.9rem, 7.1vw, 3.25rem);
  width: var(--board-size);
  margin: 0 auto;
}

body.chess-mode .puzzle-board {
  width: var(--board-size);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.1rem, 6.4vw, 3.5rem);
  line-height: 1;
  font-weight: 500;
}

h2 {
  margin-bottom: 14px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.affiliation {
  max-width: 560px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 1.15rem;
}

.contact {
  margin-bottom: 0;
}

section + section {
  margin-top: 38px;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.course-list {
  border-top: 1px solid var(--line);
}

.course-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 0.42fr);
  gap: 20px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.course-list span {
  color: var(--muted);
  font-size: 0.96rem;
}

.puzzle-widget {
  width: min(100%, 400px);
  --board-size: min(100%, 400px);
  --piece-size: clamp(1.45rem, 8.5vw, 2.6rem);
}

.puzzle-board {
  display: grid;
  width: var(--board-size);
  aspect-ratio: 1;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
}

.board-square {
  appearance: none;
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  border: 0;
  font-family: "Times New Roman", Georgia, serif;
  font-size: var(--piece-size);
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.light-square {
  background: #f0d9b5;
}

.dark-square {
  background: #b58863;
}

.board-square.selected {
  box-shadow: inset 0 0 0 4px #f6cf55;
}

.board-square:focus-visible {
  outline: 3px solid var(--link);
  outline-offset: -3px;
}

.piece {
  display: block;
  line-height: 1;
}

.white-piece {
  color: #fff;
  text-shadow: 0 1px 2px rgba(38, 34, 29, 0.78);
}

.black-piece {
  color: #1d1712;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.28);
}

.puzzle-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}

body.dark .puzzle-board {
  border-color: var(--line);
}

body.dark .light-square {
  background: #7f6a4f;
}

body.dark .dark-square {
  background: #4f3b2d;
}

body.dark .board-square.selected {
  box-shadow: inset 0 0 0 4px #d5aa32;
}

body.dark .black-piece {
  color: #0f0d0b;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.18);
}

@supports not (aspect-ratio: 1) {
  .puzzle-board {
    height: 400px;
  }
}

.link-list li + li {
  margin-top: 8px;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--link-hover);
}

@media (max-width: 560px) {
  .page {
    width: min(100% - 28px, 760px);
    padding: 20px 0 42px;
  }

  .theme-switch {
    margin-bottom: 28px;
  }

  .course-list li {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
