:root {
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  color: #294854;
  background: #96bed8;
  font-synthesis: none;
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button {
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled {
  cursor: default;
}
button:focus-visible,
.purification-credit:focus-visible,
canvas:focus-visible {
  outline: 2px solid #376e8a;
  outline-offset: 5px;
}
svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.app {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 580px;
  overflow: hidden;
  background: #96bed8;
}
.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.room-light {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 45%,
    rgba(141, 185, 220, 0.2) 58%,
    rgba(161, 201, 230, 0.67) 80%,
    rgba(161, 201, 230, 0.85)
  );
  pointer-events: none;
  transition: opacity 1s;
}
.scene-controls {
  position: absolute;
  left: 32px;
  top: 29px;
  display: flex;
  gap: 10px;
  z-index: 2;
}
.icon-button {
  border: 0;
  background: transparent;
  color: #577583;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition:
    background 0.2s,
    color 0.2s,
    opacity 0.2s;
}
.icon-button:hover:not(:disabled) {
  background: rgba(52, 83, 69, 0.09);
  color: #244c3c;
}
.icon-button.selected {
  background: #d8e9ef;
  color: #2d5f74;
}
.icon-button:disabled {
  opacity: 0.27;
}
.room-button {
  background: rgba(245, 250, 244, 0.42);
  color: #3c6376;
  backdrop-filter: blur(12px);
}
.sound-on {
  display: none;
}
[aria-pressed='true'] .sound-on {
  display: initial;
}
[aria-pressed='true'] .sound-off {
  display: none;
}
.writing-panel {
  position: absolute;
  left: 62%;
  top: 50%;
  width: min(30vw, 440px);
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 25px;
  transition:
    opacity 0.5s,
    transform 0.65s;
  z-index: 3;
}
.paper-wrap {
  position: relative;
  flex: none;
  min-height: 0;
  width: 100%;
  aspect-ratio: 0.758;
  perspective: 900px;
  filter: drop-shadow(3px 20px 18px rgba(45, 71, 52, 0.12));
}
.paper {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  background: #fcfbf6;
  transform: rotate(1.5deg);
  box-shadow:
    0 1px 2px #69776520,
    inset 0 0 45px #c8bfa413;
  border-radius: 1px;
  overflow: hidden;
}
.paper:after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' opacity='.5' filter='url(%23n)'/%3E%3C/svg%3E");
}
#ink {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
#ink.eraser {
  cursor: cell;
}
#typed-text {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: var(--text-padding, 7.5%);
  border: 0;
  border-radius: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: #293e4a;
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  font-size: var(--text-size, 20px);
  font-weight: 400;
  line-height: 1.8;
  letter-spacing: 0;
  font-kerning: none;
  word-break: break-all;
  white-space: pre-wrap;
  touch-action: manipulation;
}
.paper.is-typing .paper-prompt {
  opacity: 0;
  visibility: hidden;
}
.writing-controls {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 23px;
  width: 100%;
}
.tools {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  background: rgba(251, 253, 247, 0.67);
  border: 1px solid #ffffff4d;
  border-radius: 30px;
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 14px #355b4010;
}
.tool-divider {
  height: 19px;
  width: 1px;
  background: #6c857032;
  margin: 0 3px;
}
.flush-button,
.again-button {
  border: 0;
  border-radius: 40px;
  background: #24577c;
  color: #fffef6;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  height: 56px;
  padding: 0 28px;
  font-size: 15px;
  letter-spacing: 0.06em;
  box-shadow: 0 7px 18px #31563e18;
  transition:
    opacity 0.25s,
    background 0.25s,
    transform 0.25s;
}
.flush-button:hover:not(:disabled),
.again-button:hover {
  background: #1b4265;
  transform: translateY(-2px);
}
.flush-button:disabled {
  opacity: 0.35;
}
.flush-button svg {
  width: 23px;
  height: 23px;
}
.again-button {
  white-space: nowrap;
  width: max-content;
  max-width: calc(100% - 32px);
  min-width: 220px;
  position: absolute;
  left: 50%;
  bottom: 9%;
  transform: translateX(-50%);
  z-index: 5;
  animation: appear 0.6s both;
}
.again-button svg {
  flex: none;
}
.again-button:hover {
  transform: translate(-50%, -2px);
}
[hidden] {
  display: none !important;
}
.app[data-phase='flushing'] .writing-panel {
  pointer-events: none;
}
.app[data-phase='flushing'] .writing-controls {
  opacity: 0;
  transition: opacity 0.3s;
}
.app[data-phase='flushing'] .room-light,
.app[data-phase='done'] .room-light {
  opacity: 0;
}
.app[data-phase='done'] .writing-panel {
  opacity: 0;
  pointer-events: none;
}
.app[data-phase='flushing'] .scene-controls,
.app[data-phase='done'] .scene-controls {
  opacity: 0;
  pointer-events: none;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
.error {
  position: absolute;
  inset: 30% 12%;
  padding: 30px;
  background: #fcfbf6;
  border-radius: 6px;
  line-height: 1.8;
  z-index: 10;
}
@keyframes appear {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Final moment: white Mincho lettering and light rising through the water. */
.purification {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
  isolation: isolate;
  animation: purification-appear 1.4s ease-out both;
}
.purification::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 112%, #d7f4ff55 0%, #b2e4ff16 38%, transparent 70%);
}
.purification-content {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: calc(100% - 40px);
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(24px, 3.5svh, 38px);
}
.purification-word {
  position: relative;
  margin: 0;
  flex: none;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', YuMincho, 'Noto Serif JP', serif;
  font-size: clamp(84px, 15svh, 144px);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: #fff;
  white-space: nowrap;
  text-shadow:
    0 2px 24px #d9f5ff66,
    0 0 60px #e4f7ff22;
  animation: purification-word 1.8s cubic-bezier(0.2, 0.65, 0.25, 1) both;
}
.purification-credit {
  font-size: 10px;
  letter-spacing: 0.1em;
}
.purification-count {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: #fff;
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', YuMincho, 'Noto Serif JP', serif;
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.purification-count-total {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}
.purification-count-number {
  font-size: clamp(34px, 4.8svh, 44px);
  line-height: 1.1;
  letter-spacing: 0.02em;
}
.purification-count[data-state='unavailable'] {
  visibility: hidden;
}
.site-footer {
  position: absolute;
  left: 50%;
  bottom: max(15px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  white-space: nowrap;
  font-size: 11px;
  line-height: 14px;
}
.site-footer a {
  padding: 2px 0;
  color: #426981;
  opacity: 0.8;
  text-decoration: none;
}
.site-footer a:hover {
  opacity: 1;
  text-decoration: underline;
}
.site-footer a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}
.app[data-phase='done'] .site-footer a {
  color: #fff;
}
html[lang='en'] .purification-word {
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(56px, 10vw, 108px);
  letter-spacing: 0.03em;
  text-indent: 0;
}
html[lang='en'] .paper-prompt {
  font-size: clamp(20px, 1.9vw, 28px);
}
html[lang='en'] .purification-message {
  font-family: Georgia, 'Times New Roman', serif;
}
html[lang='en'] .purification-count {
  font-family: Georgia, 'Times New Roman', serif;
}
.purification-lights {
  position: absolute;
  inset: 0;
}
.purification-light {
  position: absolute;
  left: var(--x);
  bottom: -6vh;
  width: var(--size);
  height: var(--size);
  opacity: 0;
  will-change: transform, opacity;
  animation: purification-rise var(--duration) linear var(--delay) infinite both;
}
.purification-light i {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 50%;
  box-shadow:
    0 0 7px 2px #e1f7ff88,
    0 0 18px #d5f3ff66;
  animation: purification-glint var(--glint-duration) ease-in-out infinite alternate;
}
.purification-light i.star {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--size) * 2.8);
  height: calc(var(--size) * 2.8);
  transform: translate(-50%, -50%);
  border-radius: 0;
  clip-path: polygon(50% 0%, 59% 40%, 100% 50%, 59% 60%, 50% 100%, 41% 60%, 0% 50%, 41% 40%);
  filter: drop-shadow(0 0 4px #e9fcff);
}
@keyframes purification-appear {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes purification-word {
  from {
    opacity: 0;
    filter: blur(8px);
    translate: 0 18px;
  }
  to {
    opacity: 1;
    filter: blur(0);
    translate: 0 0;
  }
}
@keyframes purification-rise {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0);
  }
  12% {
    opacity: var(--brightness);
  }
  78% {
    opacity: var(--brightness);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--drift), -118svh, 0);
  }
}
@keyframes purification-glint {
  0%,
  15% {
    opacity: 0.3;
    scale: 0.65;
  }
  60% {
    opacity: 1;
    scale: 1.18;
  }
  100% {
    opacity: 0.55;
    scale: 0.85;
  }
}

.purification-message {
  margin: 0;
  color: #fff;
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', YuMincho, 'Noto Serif JP', serif;
  font-size: clamp(16px, 1.7vw, 20px);
  font-weight: 400;
  line-height: 1.95;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: pre-line;
  text-shadow: 0 2px 16px #244b7270;
  animation: purification-appear 1.5s 0.65s both;
}

/* The prompt belongs to the sheet and fades as soon as handwriting begins. */
.paper-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 8px;
  color: #6b8290;
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', YuMincho, 'Noto Serif JP', serif;
  font-size: clamp(24px, 2.3vw, 32px);
  font-weight: 400;
  line-height: 1.75;
  letter-spacing: 0.03em;
  text-align: center;
  pointer-events: none;
  opacity: 0.8;
  transition: opacity 0.18s;
}
.paper.has-writing .paper-prompt {
  opacity: 0;
  visibility: hidden;
}

.flush-label-short {
  display: none;
}

.paper-prompt span {
  white-space: nowrap;
}

/* Responsive layout: the mobile toolbar shares one row to keep the sheet tall. */
@media (min-width: 1500px) {
  .writing-panel {
    left: 64%;
    width: min(27vw, 450px);
  }
}
@media (max-height: 780px) and (min-width: 761px) {
  .writing-panel {
    width: min(28vw, 345px);
    gap: 20px;
  }
  .writing-controls {
    gap: 16px;
  }
  .flush-button {
    height: 51px;
  }
}
@media (max-width: 760px) {
  .app {
    min-height: 650px;
  }
  .room-light {
    background: linear-gradient(0deg, #a1c9e6ed 0%, #a1c9e6cc 38%, transparent 65%);
  }
  .writing-panel {
    left: 50%;
    top: auto;
    bottom: max(45px, calc(env(safe-area-inset-bottom) + 30px));
    transform: translateX(-50%);
    width: min(72vw, 300px);
    gap: 14px;
  }
  .paper-wrap {
    aspect-ratio: 0.8;
  }
  .paper-prompt {
    font-size: clamp(20px, 5.6vw, 22px);
  }
  .writing-controls {
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    width: calc(100vw - 32px);
    max-width: 400px;
  }
  .tools {
    padding: 3px 6px;
    flex: none;
    gap: 4px;
  }
  .icon-button {
    width: 40px;
    height: 40px;
  }
  .flush-button {
    flex: none;
    min-width: 76px;
    height: 48px;
    padding: 0 10px;
    font-size: 14px;
    gap: 6px;
    letter-spacing: 0.03em;
  }
  .flush-button svg {
    width: 20px;
    height: 20px;
  }
  .flush-label-full {
    display: none;
  }
  .flush-label-short {
    display: inline;
  }
  .scene-controls {
    left: 17px;
    top: 18px;
    bottom: auto;
    gap: 7px;
  }
  html[lang='en'] .paper-prompt {
    font-size: clamp(17px, 4.9vw, 20px);
  }
  .again-button {
    bottom: 12%;
  }
}
@media (max-width: 760px) and (max-height: 740px) {
  .purification-content {
    top: 43%;
    gap: 18px;
  }
  .purification-word {
    font-size: clamp(72px, 13.5svh, 98px);
  }
  .app {
    min-height: 590px;
  }
  .writing-panel {
    width: min(66vw, 260px);
    bottom: max(45px, calc(env(safe-area-inset-bottom) + 30px));
    gap: 10px;
  }
  .paper-wrap {
    aspect-ratio: 0.86;
  }
}
@media (max-width: 360px) {
  .writing-controls {
    gap: 6px;
  }
  .tools {
    gap: 2px;
    padding: 3px 4px;
  }
  .tools .icon-button {
    width: 36px;
  }
  .tool-divider {
    margin: 0 1px;
  }
  .flush-button {
    min-width: 70px;
    padding: 0 7px;
    gap: 4px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *:before,
  *:after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .purification-light {
    display: none;
    animation: none !important;
  }
  .purification-word {
    animation: none;
    filter: none;
  }
  .purification-message {
    animation: none;
  }
}
