:root {
  color-scheme: light;
  --background: #fdfcf8;
  --surface: #dce6c4;
  --text: #171916;
  --muted: #50584d;
  --accent: #244f3c;
  --heading: #0e110f;
  font-family: Charter, "Bitstream Charter", Georgia, serif;
  font-size: 18.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--background);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: #171c22;
    --surface: #353c45;
    --text: #eee7dc;
    --muted: #bcb2a3;
    --accent: #ffffff;
    --heading: #ffffff;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --background: #fdfcf8;
  --surface: #dce6c4;
  --text: #171916;
  --muted: #50584d;
  --accent: #244f3c;
  --heading: #0e110f;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #171c22;
  --surface: #353c45;
  --text: #eee7dc;
  --muted: #bcb2a3;
  --accent: #ffffff;
  --heading: #ffffff;
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--surface);
}

body {
  width: min(100% - 2rem, 720px);
  margin: 0 auto;
}

.knight-widget {
  position: fixed;
  bottom: 1.25rem;
  left: 0.75rem;
  z-index: 2;
}

.clock-widget {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 2;
}

@media (max-width: 1300px) {
  .knight-widget,
  .clock-widget {
    display: none;
  }
}

.clock-trigger {
  display: block;
  width: 5rem;
  height: 5rem;
  padding: 0;
  color: inherit;
  line-height: 0;
  text-decoration: none;
}

.corner-clock {
  display: block;
  width: 5rem;
  height: 5rem;
  transition: filter 180ms ease, transform 180ms ease;
}

.clock-trigger:hover .corner-clock,
.clock-trigger:focus-visible .corner-clock {
  filter: brightness(1.06);
  transform: translateY(-0.15rem) scale(1.035);
}

.clock-outline {
  fill: #2c2b29;
}

.clock-ticks,
.clock-center-border {
  fill: #2c2b29;
}

@media (prefers-color-scheme: dark) {
  .clock-outline {
    fill: #ffffff;
  }

  .clock-ticks,
  .clock-center-border {
    fill: #ffffff;
  }
}

:root[data-theme="light"] .clock-outline {
  fill: #2c2b29;
}

:root[data-theme="light"] .clock-ticks,
:root[data-theme="light"] .clock-center-border {
  fill: #2c2b29;
}

:root[data-theme="dark"] .clock-outline {
  fill: #ffffff;
}

:root[data-theme="dark"] .clock-ticks,
:root[data-theme="dark"] .clock-center-border {
  fill: #ffffff;
}

.clock-contact {
  position: absolute;
  right: 3.2rem;
  bottom: 4.85rem;
  width: 10rem;
  padding-right: 1rem;
  text-align: right;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition: opacity 180ms ease 180ms, transform 180ms ease 180ms;
}

.clock-contact::after {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 2px;
  height: 0;
  background: #4298cd;
  content: "";
  transition: height 300ms ease;
}

.time-travel-form label {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 600;
}

.time-travel-form input {
  width: 3rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--muted);
  border-radius: 3px;
  color: var(--text);
  background: var(--background);
  font: inherit;
}

.clock-widget.is-open .clock-contact {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.clock-widget.is-open .clock-contact::after {
  height: 100%;
}

.past-view {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 1rem;
  color: #eee7dc;
  background: #171c22;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 350ms ease, visibility 0s linear 350ms;
}

.past-view.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.past-view:focus,
main:focus {
  outline: none;
}

.past-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0 0.75rem;
  font-size: 0.9rem;
}

.past-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.past-actions a,
.past-close {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: inherit;
  white-space: nowrap;
}

.past-action-icon {
  width: 18px;
  height: 18px;
  flex: none;
}

.past-close {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.past-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #353c45;
  border-radius: 8px;
  background: #0a0f18;
}

.past-frame {
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 500ms ease;
}

.past-view.is-loaded .past-frame {
  opacity: 1;
  pointer-events: auto;
}

.past-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  margin: 0;
  color: #a9afa6;
  transform: translate(-50%, -50%);
}

.past-view.is-loaded .past-loading {
  opacity: 0;
  pointer-events: none;
}

main,
.knight-widget,
.clock-widget {
  transition: opacity 300ms ease, filter 300ms ease, transform 300ms ease;
}

body.is-time-traveling {
  overflow: hidden;
}

body.is-time-traveling main,
body.is-time-traveling .knight-widget,
body.is-time-traveling .clock-widget {
  animation: screen-shake 75ms linear 8 250ms;
}

body.is-time-traveling main,
body.is-time-traveling .knight-widget,
body.is-time-traveling .clock-widget {
  opacity: 0;
  filter: blur(8px);
  transform: scale(0.985);
  transition: opacity 550ms ease 650ms, filter 550ms ease 650ms, transform 550ms ease 650ms;
}

body.is-time-traveling .time-travel-form input {
  animation: lens-vibrate 70ms linear 8;
  border-color: #4285f4;
  box-shadow: -3px 0 8px #4285f4, 3px 0 8px #c84dde, 0 -3px 8px #f05f78, 0 3px 8px #f5b642;
}

@keyframes screen-shake {
  0%,
  100% {
    translate: 0 0;
  }

  25% {
    translate: -2px 1px;
  }

  50% {
    translate: 2px -1px;
  }

  75% {
    translate: 1px 2px;
  }
}

@keyframes lens-vibrate {
  0%,
  100% {
    transform: translate(0);
  }

  25% {
    transform: translate(-1px, 1px);
  }

  50% {
    transform: translate(1px, -1px);
  }

  75% {
    transform: translate(1px, 1px);
  }
}

.clock-hour-hand,
.clock-minute-hand {
  fill: #2c2b29;
  transform-origin: 36px 36px;
}

@media (prefers-color-scheme: dark) {
  .clock-hour-hand,
  .clock-minute-hand {
    fill: #ffffff;
  }
}

:root[data-theme="light"] .clock-hour-hand,
:root[data-theme="light"] .clock-minute-hand {
  fill: #2c2b29;
}

:root[data-theme="dark"] .clock-hour-hand,
:root[data-theme="dark"] .clock-minute-hand {
  fill: #ffffff;
}

.clock-hour-hand {
  transform: rotate(305deg);
}

.clock-minute-hand {
  transform: rotate(60deg);
}

.knight-trigger {
  display: block;
  width: 5rem;
  height: auto;
  padding: 0;
  color: inherit;
  line-height: 0;
  text-decoration: none;
}

.corner-knight {
  display: block;
  width: 5rem;
  height: auto;
  transform: rotate(8deg);
  transform-origin: bottom center;
}

.knight-outline {
  fill: #2c2b29;
}

@media (prefers-color-scheme: dark) {
  .knight-outline {
    fill: #ffffff;
  }
}

:root[data-theme="light"] .knight-outline {
  fill: #2c2b29;
}

:root[data-theme="dark"] .knight-outline {
  fill: #ffffff;
}

.knight-widget:not(.is-open) .knight-trigger:hover .corner-knight {
  animation: knight-dance 700ms ease-in-out infinite;
}

.knight-widget.is-open .corner-knight {
  animation: none;
}

.knight-contact {
  position: absolute;
  bottom: 4.4rem;
  left: 3.2rem;
  width: 12rem;
  padding-left: 1rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(0.5rem);
  transition: opacity 180ms ease 180ms, transform 180ms ease 180ms;
}

.knight-contact::before {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 2px;
  height: 0;
  background: #69923e;
  content: "";
  transition: height 300ms ease;
}

.knight-contact p {
  margin: 0 0 0.45rem;
  font-weight: 600;
}

.chess-links {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chess-links a {
  display: inline-flex;
  color: var(--heading);
}

.chess-links svg {
  width: 1.8rem;
  height: 1.8rem;
  fill: currentColor;
}

.chess-links .chesscom-link {
  color: #81b64c;
}

.chess-links .lichess-link {
  color: var(--heading);
}

.knight-widget.is-open .knight-contact {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.knight-widget.is-open .knight-contact::before {
  height: 100%;
}

@keyframes knight-dance {
  0%,
  100% {
    transform: translateY(0) rotate(8deg);
  }

  25% {
    transform: translateY(-0.3rem) rotate(2deg);
  }

  50% {
    transform: translateY(0) rotate(8deg);
  }

  75% {
    transform: translateY(-0.3rem) rotate(14deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .knight-trigger:hover .corner-knight {
    animation: none;
  }

  .knight-contact,
  .knight-contact::before,
  .clock-contact,
  .clock-contact::after {
    transition: none;
  }

  .corner-clock {
    transition: none;
  }

  .past-view,
  .past-frame,
  main,
  .knight-widget,
  .clock-widget {
    transition: none;
  }

  body.is-time-traveling main,
  body.is-time-traveling .knight-widget,
  body.is-time-traveling .clock-widget {
    transition: none;
  }

  body.is-time-traveling main,
  body.is-time-traveling .knight-widget,
  body.is-time-traveling .clock-widget {
    animation: none;
  }
}

@media (max-width: 600px) {
  .past-view {
    padding: 0;
  }

  .past-bar {
    align-items: flex-start;
    flex-direction: column;
    padding: 0.75rem;
  }

  .past-actions {
    width: 100%;
    justify-content: space-between;
  }

  .past-stage {
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 0;
  }
}

header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 2rem 0;
  font-size: 0.9rem;
}

nav {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

main {
  padding: 3rem 0 6rem;
}

section + section {
  margin-top: 4rem;
}

h1,
h2,
h3 {
  color: var(--heading);
  line-height: 1.25;
}

h1 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 1.5rem;
  font-size: 1.7rem;
}

.introduction-content {
  display: block;
}

.introduction-content > div {
  min-width: 0;
}

.introduction-content p:first-child {
  margin: 0;
}

#theme-toggle {
  display: inline-flex;
  width: 2rem;
  height: 2rem;
  margin-left: auto;
  align-items: center;
  justify-content: center;
  color: #c58b00;
  line-height: 1;
  text-decoration: none;
}

.theme-icon {
  width: 1.8rem;
  height: 1.8rem;
}

.social-links {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.social-links a {
  display: inline-flex;
  color: var(--heading);
}

.social-links svg {
  width: 1.8rem;
  height: 1.8rem;
  fill: currentColor;
}

.social-links .github-link {
  color: #181717;
}

.social-links .linkedin-link {
  color: #0a66c2;
}

@media (prefers-color-scheme: dark) {
  .social-links .github-link,
  .social-links .linkedin-link {
    color: #ffffff;
  }
}

:root[data-theme="light"] .social-links .github-link {
  color: #181717;
}

:root[data-theme="light"] .social-links .linkedin-link {
  color: #0a66c2;
}

:root[data-theme="dark"] .social-links .github-link,
:root[data-theme="dark"] .social-links .linkedin-link {
  color: #ffffff;
}

.moon-icon {
  display: none;
  width: 1.65rem;
  height: 1.65rem;
}

#theme-toggle:hover .sun-icon {
  animation: sun-turn 4s linear infinite;
}

#theme-toggle:hover .moon-icon {
  animation: moon-swing 1.1s ease-in-out infinite alternate;
}

@keyframes sun-turn {
  to {
    transform: rotate(360deg);
  }
}

@keyframes moon-swing {
  from {
    transform: rotate(-7deg);
  }

  to {
    transform: rotate(7deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  #theme-toggle:hover .theme-icon {
    animation: none;
  }
}

@media (prefers-color-scheme: dark) {
  .sun-icon {
    display: none;
  }

  .moon-icon {
    display: block;
  }

  #theme-toggle {
    color: #e8edf3;
  }
}

:root[data-theme="light"] .sun-icon {
  display: block;
}

:root[data-theme="light"] .moon-icon {
  display: none;
}

:root[data-theme="light"] #theme-toggle {
  color: #c58b00;
}

:root[data-theme="dark"] .sun-icon {
  display: none;
}

:root[data-theme="dark"] .moon-icon {
  display: block;
}

:root[data-theme="dark"] #theme-toggle {
  color: #e8edf3;
}

h2 {
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
}

h3 {
  margin: 0;
  font-size: 1rem;
}

p {
  margin: 0.6rem 0 0;
}

.meta-mark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.2em;
  height: 1.2em;
  fill: #0467df;
  transform: translate(-50%, -46%);
}

.meta-initial {
  position: relative;
  display: inline-block;
  margin-left: 0.1em;
  margin-right: 0.24em;
}

.meta-letter {
  color: transparent;
}

.meta-link {
  color: #0467df;
  text-decoration: none;
}

article + article {
  margin-top: 1.5rem;
}

#projects article {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(9rem, 28vw, 12.5rem);
  grid-template-rows: auto 1fr;
  column-gap: clamp(1rem, 4vw, 2rem);
  padding-bottom: 0.8rem;
}

#projects article h3 {
  grid-column: 1;
  grid-row: 1;
}

#projects article > p {
  grid-column: 1;
  grid-row: 2;
}

#projects article.sketch-on-left {
  grid-template-columns: clamp(9rem, 28vw, 12.5rem) minmax(0, 1fr);
}

#projects article.sketch-on-left h3,
#projects article.sketch-on-left > p {
  grid-column: 2;
}

#projects article.sketch-on-left .experiment-sketch {
  grid-column: 1;
}

.experiment-sketch {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  display: block;
  width: 100%;
  max-width: 12.5rem;
  overflow: visible;
  color: var(--accent);
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.35;
  opacity: 0.5;
  pointer-events: none;
  transform: rotate(-1.5deg);
}

.experiment-sketch circle {
  fill: currentColor;
  stroke: none;
}

.sketch-matrix,
.sketch-step {
  transform-origin: center;
}

.sketch-matrix {
  transform: rotate(-1deg);
}

.sketch-rotate {
  transform: rotate(-1deg);
}

.sketch-stretch {
  transform: rotate(1deg);
}

.sketch-step path:first-child {
  stroke-dasharray: 2 3;
  opacity: 0.55;
}

.sketch-step path:nth-child(2) {
  opacity: 0.8;
}

.sketch-cross-sections ellipse {
  opacity: 0.72;
}

#projects article:nth-of-type(even) .experiment-sketch {
  transform: rotate(1.25deg);
}

@media (max-width: 720px) {
  #projects article {
    display: block;
    padding: 0 0 0.7rem;
  }

  .experiment-sketch {
    width: min(12rem, 100%);
    margin: 1rem auto -0.35rem;
  }
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

header > a {
  color: var(--heading);
  font-weight: 600;
  text-decoration: none;
}

button {
  padding: 0;
  border: 0;
  color: var(--muted);
  background: none;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

@media (max-width: 480px) {
  header {
    align-items: flex-start;
    flex-direction: column;
  }

  main {
    padding-top: 2rem;
  }

  .introduction-content > div {
    min-height: 0;
  }

}
