@font-face {
  font-family: "Cormorant Garamond";
  src: url("/fonts/cormorant-garamond.woff2?__frsh_c=355a529c967996a857c00a84eb786b7a9dd5d78e") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

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

* {
  margin: 0;
}

:root {
  color: #171512;
  background: #e7cb8e;
  font-family: "Cormorant Garamond", "Yu Mincho", "Hiragino Mincho ProN", serif;
  line-height: 1.5;
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  overflow: hidden;
}

body {
  background: #e7cb8e;
}

button,
a {
  color: inherit;
}

button {
  font: inherit;
}

::selection {
  color: #f2e7cf;
  background: #7c2d22;
}

.karakuri-page {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  overflow: hidden;
}

.karakuri-page::before {
  position: absolute;
  inset: -2%;
  z-index: -3;
  background: url("/art/washi-ground.webp?__frsh_c=355a529c967996a857c00a84eb786b7a9dd5d78e") center / cover;
  content: "";
  filter: saturate(.68) contrast(.66) brightness(1.01);
  opacity: .36;
  pointer-events: none;
}

.karakuri-page::after {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 54% 70% at 53% 49%, rgb(255 241 205 / 36%),
    transparent 68%),
    linear-gradient(100deg, rgb(255 235 182 / 11%), rgb(124 45 34 / 5%));
  box-shadow: inset 0 0 11vw rgb(102 61 28 / 9%);
  content: "";
  pointer-events: none;
}

.king-calligraphy {
  position: absolute;
  top: .25%;
  left: 33%;
  z-index: -1;
  width: min(42vw, 720px);
  height: 62%;
  object-fit: contain;
  opacity: .073;
  filter: sepia(.18) contrast(1.12);
  mix-blend-mode: multiply;
  pointer-events: none;
  user-select: none;
}

.karakuri-hero {
  display: grid;
  grid-template-columns: minmax(20rem, 28vw) minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-height: 100svh;
  margin-inline: auto;
  padding: 0 6vw 0 12vw;
}

.invitation {
  z-index: 2;
  align-self: center;
  padding-bottom: clamp(1rem, 8vh, 5rem);
  transition: opacity 180ms ease-out, visibility 0s linear;
}

.karakuri-hero:has(.karakuri-stage.is-board) .invitation {
  visibility: hidden;
  opacity: 0;
  transition: opacity 180ms ease-in, visibility 0s linear 180ms;
}

.invitation h1 {
  max-width: none;
  font-size: clamp(2.75rem, 3.15vw, 4.1rem);
  font-weight: 400;
  line-height: .95;
  letter-spacing: -.018em;
  white-space: nowrap;
}

.invitation p {
  margin-top: .58rem;
  color: #43241a;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(1.18rem, 1.56vw, 1.75rem);
  letter-spacing: .055em;
}

.karakuri-stage {
  position: relative;
  width: min(82vw, 1260px);
  aspect-ratio: 7 / 5;
  justify-self: end;
  transition: transform 1150ms cubic-bezier(.4, 0, .2, 1);
}

@media (min-width: 781px) {
  .karakuri-stage.is-flat {
    transform: translateX(clamp(7rem, 10vw, 12rem)) scale(.9);
  }
}

.karakuri-stage::before {
  position: absolute;
  right: -1%;
  bottom: 3%;
  left: 2%;
  z-index: -1;
  height: 21%;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 61% 49%, rgb(45 22 10 / 37%) 0 14%,
    rgb(65 36 17 / 20%) 34%, transparent 72%);
  filter: blur(21px);
  content: "";
  transform: translate(2.4%, 2.5%) rotate(-2deg);
  pointer-events: none;
}

.live-board-link {
  position: fixed;
  top: max(1.35rem, env(safe-area-inset-top));
  left: max(1.5rem, env(safe-area-inset-left));
  z-index: 5;
  padding: .58rem 1rem .52rem;
  border: 1px solid rgb(67 36 26 / 74%);
  border-radius: .35rem;
  background: rgb(231 203 142 / 91%);
  box-shadow: 0 .5rem 1.4rem rgb(69 36 20 / 15%);
  color: #28160d;
  font-size: 1rem;
  letter-spacing: .025em;
  line-height: 1;
  text-decoration: none;
  transition: background-color 160ms ease-out, box-shadow 160ms ease-out,
    transform 160ms ease-out;
}

.live-board-link:hover {
  background: #eed8a8;
  box-shadow: 0 .7rem 1.6rem rgb(69 36 20 / 19%);
  transform: translateY(-1px);
}

.live-board-link:active {
  transform: translateY(1px);
}

.live-board-link:focus-visible {
  outline: 3px solid #7c2d22;
  outline-offset: 3px;
}

.karakuri-page:has(.live-board-link) .leaf-one {
  opacity: 0;
}

.karakuri-trigger {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: visible;
  border: 0;
  outline: 0;
  background: transparent;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.karakuri-stage.is-board .karakuri-trigger {
  cursor: grab;
  touch-action: none;
}

.karakuri-stage.is-board.is-dragging .karakuri-trigger {
  cursor: grabbing;
}

.karakuri-trigger::after {
  position: absolute;
  inset: 1% 10% 2%;
  border-radius: .75rem;
  border: 2px solid #7c2d22;
  content: "";
  opacity: 0;
  pointer-events: none;
}

.karakuri-trigger:focus-visible::after {
  opacity: 1;
}

.karakuri-trigger canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.qr-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(41, 1fr);
  width: min(66%, 33rem);
  aspect-ratio: 1;
  margin: auto;
  gap: 1px;
  padding: 4%;
  background: #d9a862;
  filter: drop-shadow(0 18px 20px rgb(45 27 15 / 16%));
}

.qr-fallback i {
  background: #d9a862;
  box-shadow: inset 0 0 0 1px rgb(255 229 171 / 20%);
}

.qr-fallback .is-dark {
  background: #28160d;
}

.leaf {
  position: absolute;
  z-index: 1;
  width: clamp(3rem, 4.1vw, 4.8rem);
  fill: #9b3e2f;
  opacity: .72;
  filter: drop-shadow(0 4px 5px rgb(67 35 20 / 15%));
  pointer-events: none;
  transition: opacity 180ms ease-out;
  will-change: transform;
}

.leaf-one {
  top: 6.5%;
  left: 3.5%;
  animation: leaf-one 15s ease-in-out infinite alternate;
}

.leaf-two {
  top: 11%;
  right: 3.5%;
  width: clamp(2.4rem, 3.3vw, 3.8rem);
  animation: leaf-two 18s ease-in-out -7s infinite alternate;
}

.leaf-three {
  right: 6%;
  bottom: 3.5%;
  width: clamp(2.7rem, 3.7vw, 4.3rem);
  animation: leaf-three 17s ease-in-out -4s infinite alternate;
}

@keyframes leaf-one {
  to {
    transform: translate3d(4vw, 4vh, 0) rotate(42deg);
  }
}

@keyframes leaf-two {
  to {
    transform: translate3d(-3vw, 5vh, 0) rotate(-58deg);
  }
}

@keyframes leaf-three {
  to {
    transform: translate3d(-3vw, -3vh, 0) rotate(36deg);
  }
}

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

@media (max-width: 780px) {
  .karakuri-hero {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-content: center;
    gap: 0;
    padding: max(1.25rem, env(safe-area-inset-top)) 1.2rem max(1.5rem,
      env(safe-area-inset-bottom));
  }

  .karakuri-stage {
    grid-row: 1;
    width: min(116vw, 46rem);
    margin-inline: -8vw;
    justify-self: center;
  }

  .karakuri-stage.is-board {
    transform: scale(.82);
  }

  .invitation {
    grid-row: 2;
    padding: 0 0 2.5vh;
    text-align: center;
  }

  .invitation h1 {
    max-width: none;
    font-size: clamp(2.1rem, 10.2vw, 4.2rem);
  }

  .invitation p {
    margin-top: .55rem;
  }

  .king-calligraphy {
    top: -2%;
    left: 17%;
    width: 72vw;
    height: 61%;
  }

  .leaf {
    width: clamp(2.25rem, 10vw, 3.1rem);
  }

  .leaf-two,
  .leaf-three {
    width: clamp(1.8rem, 8vw, 2.5rem);
  }
}

@media (max-height: 620px) and (min-width: 781px) {
  .karakuri-hero {
    padding-block: 1rem;
  }

  .karakuri-stage {
    width: min(74vw, 820px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Read-only game surfaces */
.utility-page {
  position: relative;
  min-height: 100svh;
  height: 100svh;
  padding: clamp(2rem, 5vw, 5rem);
  overflow: auto;
  background:
    linear-gradient(rgb(243 226 189 / 88%), rgb(231 203 142 / 92%)),
    url("/art/washi-ground.webp?__frsh_c=355a529c967996a857c00a84eb786b7a9dd5d78e") center / cover;
  scrollbar-color: #7c2d22 #d9a862;
}

.utility-page button,
.utility-page input {
  border-radius: .4rem;
  font: inherit;
}

.utility-page button,
.platform-refresh {
  border: 1px solid #5d3024;
  background: #28160d;
  color: #f2e7cf;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 160ms ease-out, transform 160ms ease-out;
}

.utility-page button:hover,
.platform-refresh:hover {
  background: #5d3024;
}

.utility-page button:active,
.platform-refresh:active {
  transform: translateY(1px);
}

.utility-page button:focus-visible,
.utility-page input:focus-visible,
.platform-refresh:focus-visible,
.utility-page summary:focus-visible {
  outline: 3px solid #7c2d22;
  outline-offset: 3px;
}

.utility-page button:disabled {
  cursor: wait;
  opacity: .64;
}

.live-page {
  display: grid;
  grid-template-columns: minmax(16rem, 25rem) minmax(20rem, 44rem);
  align-items: center;
  justify-content: center;
  gap: clamp(2.5rem, 7vw, 7rem);
}

.utility-calligraphy {
  position: fixed;
  top: -10vh;
  left: 4vw;
  color: #5d3024;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: min(65vw, 52rem);
  line-height: 1;
  opacity: .045;
  pointer-events: none;
  user-select: none;
}

.utility-intro,
.live-code-form,
.live-board-panel {
  position: relative;
  z-index: 1;
}

.utility-intro h1,
.platform-header h1 {
  font-size: clamp(3rem, 6vw, 5.6rem);
  font-weight: 400;
  line-height: .92;
  letter-spacing: -.025em;
  text-wrap: balance;
}

.utility-intro p,
.platform-header p,
.platform-empty p {
  max-width: 34ch;
  margin-top: 1rem;
  color: #5d3024;
  font-size: clamp(1.1rem, 1.8vw, 1.4rem);
}

.live-code-form {
  width: min(100%, 38rem);
  padding: clamp(1.5rem, 4vw, 3rem);
  border: 1px solid rgb(93 48 36 / 44%);
  background: rgb(242 231 207 / 66%);
  box-shadow: 0 1rem 2.5rem rgb(69 36 20 / 12%);
}

.live-code-form > label {
  display: block;
  margin-bottom: .55rem;
  color: #43241a;
  font-size: 1.15rem;
}

.live-code-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .7rem;
}

.live-code-entry input {
  min-width: 0;
  padding: .65rem .85rem;
  border: 1px solid #5d3024;
  background: #fff9ea;
  color: #171512;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(1.55rem, 4vw, 2.15rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: .22em;
  caret-color: #7c2d22;
}

.live-code-entry input::placeholder {
  color: #7b6450;
  opacity: .76;
}

.live-code-entry button,
.clear-button,
.clear-all button {
  padding: .72rem 1.15rem;
}

.form-message,
.connection-status,
.live-code-label {
  margin-top: .8rem;
  color: #5d3024;
}

.live-board-panel {
  width: min(100%, 44rem);
}

.live-board-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.live-board-heading h2 {
  font-size: clamp(2rem, 4vw, 3.15rem);
  font-weight: 400;
  line-height: 1;
}

.text-button {
  padding: .55rem .8rem;
  white-space: nowrap;
}

.capture-tray {
  display: flex;
  min-height: 2.25rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-inline: .15rem;
  color: #5d3024;
}

.capture-tray.is-engine {
  margin-bottom: .35rem;
}

.capture-tray.is-player {
  margin-top: .35rem;
}

.capture-tray-label {
  font-size: clamp(.9rem, 2vw, 1.05rem);
}

.capture-tray-pieces {
  display: flex;
  min-width: 8rem;
  align-items: center;
  justify-content: flex-end;
  gap: .08rem;
}

.capture-piece {
  font-family: "Times New Roman", "Arial Unicode MS", serif;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  line-height: 1;
}

.capture-piece.is-white {
  color: #fff9ea;
  filter: drop-shadow(0 1px 0 #28160d) drop-shadow(1px 0 0 #28160d)
    drop-shadow(-1px 0 0 #28160d);
}

.capture-piece.is-black {
  color: #28160d;
  filter: drop-shadow(0 1px 0 rgb(255 249 234 / 45%));
}

.capture-tray-empty {
  color: rgb(93 48 36 / 78%);
  font-size: .9rem;
  font-style: italic;
}

.chess-board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: clamp(.35rem, 1vw, .7rem) solid #28160d;
  background: #28160d;
  box-shadow: 0 1.4rem 2.8rem rgb(45 22 13 / 20%);
}

.chess-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
}

.chess-square.is-light {
  background: #eed8b5;
}

.chess-square.is-dark {
  background: #9e6b4c;
}

.chess-square.is-last-move {
  background: #d2b54a;
  box-shadow: inset 0 0 0 2px rgb(93 48 36 / 40%);
}

.chess-square.is-check {
  background: #be4343;
}

.chess-piece {
  z-index: 1;
  font-family: "Times New Roman", "Arial Unicode MS", serif;
  font-size: 10cqw;
  line-height: 1;
  transform: translateY(-.02em);
  user-select: none;
}

.chess-piece.is-white {
  color: #fff9ea;
  filter: drop-shadow(0 1px 0 #28160d) drop-shadow(1px 0 0 #28160d)
    drop-shadow(-1px 0 0 #28160d);
}

.chess-piece.is-black {
  color: #28160d;
  filter: drop-shadow(0 1px 0 rgb(255 249 234 / 45%));
}

.board-coordinate {
  position: absolute;
  z-index: 2;
  padding: .08em .16em;
  border-radius: .12rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(.75rem, 2.4cqw, .92rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.chess-square.is-light .board-coordinate {
  background: rgb(242 231 207 / 78%);
  color: #28160d;
  text-shadow: 0 1px 0 rgb(255 249 234 / 70%);
}

.chess-square.is-dark .board-coordinate {
  background: rgb(40 22 13 / 72%);
  color: #fff9ea;
  text-shadow: 0 1px 1px rgb(23 21 18 / 85%);
}

.chess-square.is-last-move .board-coordinate {
  background: rgb(242 231 207 / 82%);
  color: #28160d;
  text-shadow: 0 1px 0 rgb(255 249 234 / 75%);
}

.chess-square.is-check .board-coordinate {
  background: rgb(40 22 13 / 78%);
  color: #fff9ea;
  text-shadow: 0 1px 1px rgb(23 21 18 / 90%);
}

.rank-label {
  top: .25rem;
  left: .25rem;
}

.file-label {
  right: .25rem;
  bottom: .2rem;
}

.platform-page {
  padding-inline: clamp(1.2rem, 4vw, 4rem);
}

.platform-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  width: min(100%, 96rem);
  margin: 0 auto clamp(2rem, 5vw, 4rem);
}

.platform-header h1 {
  font-size: clamp(2.75rem, 5vw, 5rem);
}

.platform-refresh {
  padding: .65rem 1rem;
  border-radius: .4rem;
}

.conversation-grid {
  display: grid;
  width: min(100%, 96rem);
  margin-inline: auto;
  gap: 1.5rem;
}

.conversation-card {
  display: grid;
  grid-template-columns: minmax(15rem, 26rem) minmax(18rem, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  padding-block: clamp(1.5rem, 3vw, 2.5rem);
  border-top: 1px solid rgb(93 48 36 / 35%);
}

.conversation-board .chess-board {
  box-shadow: 0 .8rem 1.8rem rgb(45 22 13 / 16%);
}

.board-placeholder {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  place-items: center;
  padding: 2rem;
  border: .5rem solid #28160d;
  background: rgb(242 231 207 / 60%);
  color: #5d3024;
  text-align: center;
}

.conversation-details {
  min-width: 0;
}

.conversation-details h2,
.platform-empty h2 {
  font-size: clamp(1.75rem, 3vw, 2.6rem);
  font-weight: 400;
  line-height: 1.05;
}

.conversation-details > code {
  display: block;
  margin-top: .6rem;
  overflow-wrap: anywhere;
  color: #5d3024;
  font-size: .88rem;
}

.conversation-details dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(8rem, 1fr));
  margin-block: 1.5rem;
  border-top: 1px solid rgb(93 48 36 / 24%);
}

.conversation-details dl div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .55rem 0;
  border-bottom: 1px solid rgb(93 48 36 / 24%);
}

.conversation-details dl div:nth-child(odd) {
  padding-right: 1.25rem;
}

.conversation-details dt {
  color: #5d3024;
}

.conversation-details dd {
  font-variant-numeric: tabular-nums;
  text-transform: capitalize;
}

.conversation-details details {
  margin-bottom: 1.25rem;
}

.conversation-details summary {
  width: fit-content;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: .2em;
}

.conversation-details pre {
  max-width: 70ch;
  margin-top: .65rem;
  padding: 1rem;
  overflow: auto;
  background: rgb(255 249 234 / 64%);
  white-space: pre-wrap;
}

.clear-button,
.clear-all button {
  background: #7c2d22 !important;
}

.platform-empty {
  width: min(100%, 96rem);
  min-height: 35vh;
  margin-inline: auto;
  padding-block: 4rem;
  border-top: 1px solid rgb(93 48 36 / 35%);
}

.clear-all {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 96rem);
  margin: clamp(3rem, 7vw, 7rem) auto 0;
  padding-top: 1.5rem;
  border-top: 1px solid #7c2d22;
  gap: 1.5rem;
}

.clear-all label {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.clear-all input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: #7c2d22;
}

@media (max-width: 780px) {
  .utility-page {
    padding: max(1.5rem, env(safe-area-inset-top)) 1.1rem max(2rem,
      env(safe-area-inset-bottom));
  }

  .live-page {
    grid-template-columns: 1fr;
    align-content: start;
    gap: 2rem;
  }

  .utility-intro {
    padding-top: 1.5rem;
  }

  .live-code-entry,
  .conversation-card {
    grid-template-columns: 1fr;
  }

  .live-code-entry button {
    min-height: 3rem;
  }

  .live-board-heading,
  .platform-header,
  .clear-all {
    align-items: flex-start;
    flex-direction: column;
  }

  .conversation-card {
    gap: 1.4rem;
  }

  .conversation-board {
    width: min(100%, 28rem);
  }

  .conversation-details dl {
    grid-template-columns: 1fr;
  }

  .conversation-details dl div:nth-child(odd) {
    padding-right: 0;
  }

  .clear-all button {
    width: 100%;
  }
}
