:root {
  color-scheme: light;
  --background: #e5d5b6;
  --ink: #604b35;
  --brush: "Ma Shan Zheng", "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--background); }
body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  background: var(--background);
}
button, canvas { -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible { outline: 2px solid #856841; outline-offset: 3px; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }
.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.layout {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100vw, 46.2vh);
  width: min(100vw, 46.2dvh);
  height: 100vh;
  height: 100dvh;
  background: #efe4cc;
  box-shadow: 0 0 0 1px #a3895b25, 0 0 55px #614d2617;
}
.paper {
  position: absolute;
  pointer-events: none;
  z-index: -1;
  inset: 0;
  background: url("./paper.png") center / cover;
  filter: saturate(.44) brightness(1.04);
  transition: filter .85s ease;
}
.paper::before, .paper::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1s ease;
}
.paper::before {
  background: url("./mineral-paper.png") center / cover;
}
.paper::after {
  background:
    radial-gradient(ellipse at 42% 31%, #fbfff8eb, transparent 54%),
    radial-gradient(ellipse at 85% 72%, #92b3a279, transparent 64%),
    radial-gradient(ellipse at 0% 80%, #a0b8a75c, transparent 61%),
    linear-gradient(151deg, #c2d0ca76, #fff5de2b 66%);
}
.layout[data-form="2"] .paper {
  filter: saturate(1.15) contrast(1.015);
}
.layout[data-form="2"] .paper::before {
  opacity: .92;
}
.layout[data-form="3"] .paper {
  filter: saturate(.88);
}
.layout[data-form="3"] .paper::after {
  opacity: 1;
}
.layout[data-form="4"] .paper {
  filter: saturate(.67) contrast(1.09);
}
.layout[data-form="4"] .paper::before {
  opacity: .2;
}
.layout[data-form="3"] {
  --ink: #364f46;
}
.layout[data-form="4"] {
  --ink: #332c24;
}
.experience {
  position: absolute;
  inset: 0;
  opacity: 1;
  transition: opacity 1.45s cubic-bezier(.38, .03, .36, 1);
}
.layout[data-opening] .experience { opacity: 0; pointer-events: none; }
.opening {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 100%;
  margin: 0;
  padding-inline-start: .21em;
  text-align: center;
  color: #322d27;
  font: 400 clamp(25px, min(11vw, 11vh), 64px)/1.35 var(--brush);
  letter-spacing: .21em;
  white-space: nowrap;
  pointer-events: none;
}
.opening.appearing { animation: opening-ink 3s ease-in-out both; }
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .opening {
    color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    background-image: linear-gradient(155deg, #292621 16%, #493e31 46%, #38312a 69%, #554737);
  }
}
@keyframes opening-ink {
  0% { opacity: 0; filter: blur(1.4px); }
  26%, 72% { opacity: 1; filter: blur(0); }
  100% { opacity: 0; filter: blur(.9px); }
}
.effects {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#flower {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline-offset: -4px;
  touch-action: none;
  cursor: grab;
}
#flower:active { cursor: grabbing; }
.poem {
  position: absolute;
  inset: max(17%, calc(env(safe-area-inset-top) + 18px)) 0 auto;
  margin: 0;
  text-align: center;
  pointer-events: none;
  color: var(--ink);
  transition: color .45s ease;
  font: 400 clamp(25px, 7.6vw, 37px)/1.28 var(--brush);
  letter-spacing: .25em;
  padding-inline-start: .25em;
  white-space: nowrap;
}
.poem.appearing { animation: poem-ink 4s ease-in-out both; }
@keyframes poem-ink {
  0%, 100% { opacity: 0; }
  17%, 77% { opacity: 1; }
}

.controls {
  position: absolute;
  inset: auto max(10px, env(safe-area-inset-right)) max(16px, calc(env(safe-area-inset-bottom) + 9px)) max(10px, env(safe-area-inset-left));
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(2px, 1vw, 7px);
}
.icon-button {
  appearance: none;
  display: grid;
  place-items: center;
  width: clamp(36px, 11vw, 44px);
  height: 44px;
  padding: 0;
  border: 1px solid #70583835;
  border-radius: 50%;
  color: var(--ink);
  background: #f8edd5a0;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.icon-button svg, .phase-icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.icon-button.primary {
  flex: 0 0 51px;
  height: 51px;
  border-color: #7957326a;
  color: #634728;
  background: #dcc49bbd;
}
.icon-button.primary svg { width: 22px; height: 22px; }
.icon-button:disabled { cursor: default; }
.icon-button[data-busy] { animation: breathe 1.65s ease-in-out infinite alternate; }
.icon-button[data-error] { border-color: #a85233; }
@media (hover: hover) {
  .icon-button:not(:disabled):hover { border-color: #8d694b97; background: #e4cba5; }
}
@keyframes breathe {
  from { box-shadow: 0 0 0 0 #89633b00; }
  to { box-shadow: 0 0 0 4px #89633b33; }
}
.indicators {
  position: absolute;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 67px));
  left: 50%;
  width: 76px;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 7px;
  color: var(--ink);
  pointer-events: none;
}
.ink-dots { display: flex; gap: 12px; align-items: center; justify-content: center; }
.ink-dots i {
  width: 9px;
  height: 9px;
  border-radius: 46% 58% 44% 54%;
  background: #4d3d2c55;
  box-shadow: 0 0 2px #51402d60;
  transition: background .23s, box-shadow .23s;
}
.ink-dots .done {
  background: #d99334;
  box-shadow: 0 0 2px #96611b, 0 0 9px #edaf47d4, 0 0 18px #e9b66b76;
}
.meter { width: 100%; height: 2px; background: #90724b37; border-radius: 6px; overflow: hidden; }
.meter span { display: block; width: 100%; height: 100%; background: #79542d; transform: scaleX(var(--progress, 0)); transform-origin: left; transition: transform .1s ease; }
.camera {
  position: absolute;
  width: min(25%, 95px);
  left: max(13px, env(safe-area-inset-left));
  bottom: max(98px, calc(env(safe-area-inset-bottom) + 90px));
  aspect-ratio: 4 / 3;
  border: 1px solid #f6c29457;
  border-radius: 8px;
  background: #20171b;
  overflow: hidden;
  pointer-events: none;
}
.camera video, .camera canvas { position: absolute; width: 100%; height: 100%; inset: 0; object-fit: contain; transform: scaleX(-1); }
.camera i { position: absolute; width: 6px; height: 6px; border-radius: 50%; top: 6px; right: 6px; background: #edcdb1; box-shadow: 0 0 0 2px #20171b99; }
.camera[data-ring] { border-color: #f4d49d; }
.camera[data-ring] i { background: #f5bc60; }
@media (min-width: 900px) and (min-height: 535px) and (orientation: landscape) {
  .layout {
    width: min(100vw, 177.78vh);
    width: min(100vw, 177.78dvh);
    height: min(100vh, 56.25vw);
    height: min(100dvh, 56.25vw);
  }
  .poem { inset-block-start: max(10%, calc(env(safe-area-inset-top) + 18px)); }
}
@media (max-width: 650px) and (orientation: portrait) {
  .layout { width: 100%; }
}
@media (max-height: 535px) and (orientation: landscape) {
  .poem { font-size: 21px; }
  .controls { gap: 2px; bottom: 8px; inset-inline: 3px; }
  .icon-button { width: 29px; height: 29px; }
  .icon-button.primary { height: 35px; flex-basis: 35px; }
  .indicators { bottom: 49px; }
  .camera { bottom: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
