:root {
  color-scheme: dark;
  font-family: "Courier New", "Songti SC", "SimSun", monospace;
  --ink: #fff6d9;
  --ui-dark: #21151e;
  --button-top: #ffe98b;
  --button-mid: #e7b950;
  --button-bottom: #b86f37;
  --button-ink: #2c1920;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #120b11;
}

body {
  height: 100dvh;
  min-height: 100svh;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

.game {
  position: fixed;
  inset: 0;
  isolation: isolate;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background: #e7dcc8 url("./assets/pixel-home-day-background-v2.png") center / cover no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(16, 8, 14, 0.02) 0, rgba(16, 8, 14, 0.02) 2px, rgba(0, 0, 0, 0.08) 2px, rgba(0, 0, 0, 0.08) 3px, transparent 3px, transparent 5px);
  mix-blend-mode: multiply;
}

.game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  border: 4px solid #160d14;
  box-shadow: inset 0 0 0 3px rgba(255, 225, 145, 0.12), inset 0 0 0 8px rgba(20, 11, 17, 0.18);
}

.cake-stage {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 50%;
  width: min(58vw, 100vh, 560px);
  aspect-ratio: 4 / 3;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  filter: drop-shadow(6px 7px 0 rgba(25, 13, 17, 0.42));
}

.cake {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  animation: cake-arrive 620ms steps(5, end) both;
}

.cake-shadow,
.cake-halo {
  display: none;
}

.note-layer {
  --note-dim: 0;
  position: absolute;
  inset: 0;
  z-index: 8;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  background: rgb(16 8 14 / var(--note-dim));
}

.note-layer.is-visible {
  visibility: visible;
}

.note-layer.is-open .note-paper {
  pointer-events: auto;
}

.note-paper {
  position: absolute;
  left: 62%;
  top: 70%;
  width: min(68vw, 430px);
  min-height: clamp(148px, 42vh, 184px);
  max-height: min(50dvh, 196px);
  margin: 0;
  padding: 30px 48px 24px;
  overflow: hidden;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, calc(100% - 8px) 4px, 100% 4px, 100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px), calc(100% - 4px) 100%, 8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px), 4px calc(100% - 8px), 0 calc(100% - 8px), 0 8px, 4px 8px, 4px 4px, 8px 4px);
  color: #4a2a27;
  text-align: center;
  background:
    repeating-linear-gradient(180deg, transparent 0 25px, rgba(146, 106, 64, 0.16) 25px 27px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.15) 0 3px, transparent 3px 7px),
    #fff0be;
  border: 0;
  box-shadow:
    inset 0 0 0 4px #e7b978,
    inset 0 0 0 7px #fff7d5,
    8px 8px 0 rgba(24, 12, 17, 0.74);
  transform: translate(-50%, -50%) scaleX(0.16) scaleY(0.28);
  transform-origin: center;
  opacity: 0;
  will-change: transform, opacity, left, top;
}

.note-paper::before,
.note-paper::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 86px;
  height: 86px;
  border: 3px solid rgba(149, 102, 60, 0.26);
  transform: rotate(45deg);
}

.note-paper::before {
  left: -48px;
  top: 42px;
}

.note-paper::after {
  right: -48px;
  bottom: 42px;
}

.note-paper__tape {
  position: absolute;
  left: 50%;
  top: 0;
  width: 74px;
  height: 14px;
  transform: translateX(-50%);
  background: rgba(244, 203, 107, 0.72);
  box-shadow: inset 4px 0 0 rgba(255, 240, 166, 0.74), inset -4px 0 0 rgba(163, 102, 48, 0.24);
}

.note-paper__crease {
  position: absolute;
  top: 18px;
  bottom: 16px;
  width: 2px;
  background: repeating-linear-gradient(180deg, rgba(139, 89, 54, 0.28) 0 5px, transparent 5px 10px);
}

.note-paper__crease--left {
  left: 33.333%;
}

.note-paper__crease--right {
  right: 33.333%;
}

.note-number,
.note-copy {
  position: relative;
  z-index: 2;
}

.note-number {
  margin: 0 0 12px;
  color: #8a4b3f;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-shadow: 1px 1px 0 #fff5cd;
}

.note-copy {
  margin: 0 auto;
  max-width: 330px;
  max-height: 96px;
  overflow: auto;
  font-family: "Songti SC", "SimSun", serif;
  font-size: clamp(1rem, 2.25vw, 1.25rem);
  font-weight: 700;
  line-height: 1.7;
  letter-spacing: 0.08em;
  opacity: 0;
  transform: translateY(8px);
  text-shadow: 1px 1px 0 rgba(255, 250, 220, 0.78);
  -webkit-user-select: text;
  user-select: text;
  scrollbar-width: thin;
}

.note-spark {
  position: absolute;
  z-index: 3;
  width: 6px;
  height: 6px;
  background: #d49b43;
  box-shadow: 6px 0 0 #d49b43, 0 6px 0 #d49b43;
}

.note-spark--one {
  left: 20px;
  top: 24px;
}

.note-spark--two {
  right: 25px;
  bottom: 28px;
  transform: rotate(180deg);
}

.game.note-active .cake-stage {
  filter: brightness(0.6) drop-shadow(6px 7px 0 rgba(25, 13, 17, 0.42));
}

.game.is-reassembling .cake-stage {
  filter:
    brightness(calc(1 + var(--join-glow, 0) * 3.2))
    drop-shadow(0 0 calc(4px + var(--join-glow, 0) * 34px) rgba(255, 252, 220, 0.96));
}

.final-reveal {
  --scene-opacity: 0;
  --banner-open: 0.04;
  --banner-opacity: 0;
  --banner-text-opacity: 0;
  position: absolute;
  inset: 0;
  z-index: 18;
  overflow: hidden;
  visibility: hidden;
  opacity: var(--scene-opacity);
  pointer-events: none;
  background: #6a432a;
  image-rendering: auto;
}

.final-reveal.is-visible {
  visibility: visible;
}

.final-reveal:focus {
  outline: none;
}

.final-reveal__scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  image-rendering: auto;
  transform: scale(1.025);
}

.final-reveal__warmth {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(49, 25, 11, 0.22), transparent 32%),
    radial-gradient(circle at 50% 62%, transparent 35%, rgba(38, 19, 8, 0.18) 100%);
}

.scroll-banner {
  position: absolute;
  z-index: 2;
  top: max(12px, calc(env(safe-area-inset-top) + 6px));
  left: 50%;
  display: grid;
  grid-template-columns: clamp(16px, 2.5vw, 24px) minmax(0, 1fr) clamp(16px, 2.5vw, 24px);
  align-items: stretch;
  width: min(
    76vw,
    690px,
    calc(100vw - max(18px, env(safe-area-inset-left)) - max(18px, env(safe-area-inset-right)))
  );
  min-height: clamp(62px, 18vh, 92px);
  opacity: var(--banner-opacity);
  transform: translateX(-50%) scaleX(var(--banner-open));
  transform-origin: center;
  filter: drop-shadow(0 8px 12px rgba(44, 20, 7, 0.38));
}

.scroll-banner__paper {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 10px clamp(16px, 3vw, 34px);
  color: #5a2f1d;
  background:
    linear-gradient(90deg, rgba(133, 75, 29, 0.18), transparent 10%, transparent 90%, rgba(133, 75, 29, 0.18)),
    repeating-linear-gradient(0deg, transparent 0 8px, rgba(132, 77, 33, 0.035) 8px 9px),
    #f6dfaa;
  border-block: 3px solid #9f622c;
  box-shadow: inset 0 3px 0 rgba(255, 249, 208, 0.78), inset 0 -4px 0 rgba(124, 69, 27, 0.16);
}

.scroll-banner__paper::before,
.scroll-banner__paper::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  width: 1px;
  background: rgba(122, 66, 28, 0.26);
}

.scroll-banner__paper::before {
  left: 10px;
}

.scroll-banner__paper::after {
  right: 10px;
}

.scroll-banner__paper p {
  margin: 0;
  opacity: var(--banner-text-opacity);
  font-family: "Kaiti SC", "STKaiti", "KaiTi", serif;
  font-size: clamp(1.12rem, 3vw, 1.9rem);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.08em;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 250, 213, 0.84);
  white-space: nowrap;
}

.scroll-banner__roller {
  position: relative;
  z-index: 2;
  border: 2px solid #6f3c1d;
  border-radius: 999px;
  background:
    linear-gradient(90deg, #70401f 0 12%, #b97838 25%, #dca75f 48%, #9a5b2a 74%, #5d3118 100%);
  box-shadow: inset 2px 0 0 rgba(255, 220, 151, 0.42), 0 3px 5px rgba(43, 20, 8, 0.42);
}

.scroll-banner__roller::before,
.scroll-banner__roller::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 130%;
  height: 10px;
  transform: translateX(-50%);
  border: 2px solid #633417;
  border-radius: 999px;
  background: #a96831;
}

.scroll-banner__roller::before {
  top: -6px;
}

.scroll-banner__roller::after {
  bottom: -6px;
}

.reveal-flash {
  --flash-radius: 0%;
  --flash-opacity: 0;
  position: absolute;
  inset: 0;
  z-index: 30;
  visibility: hidden;
  pointer-events: none;
  opacity: var(--flash-opacity);
  clip-path: circle(var(--flash-radius) at 50% 60%);
  background:
    radial-gradient(circle at 50% 60%, #ffffff 0 36%, #fffef4 60%, #ffffff 100%);
  filter: drop-shadow(0 0 32px #fff) brightness(1.08);
  will-change: clip-path, opacity;
}

.game.is-transforming .reveal-flash {
  visibility: visible;
}

.game.is-transforming .action-area,
.game.is-transforming .portion-status,
.game.is-revealed .action-area,
.game.is-revealed .portion-status {
  visibility: hidden;
  opacity: 0;
}

.action-area {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: max(12px, calc(env(safe-area-inset-bottom) + 6px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: max(18px, env(safe-area-inset-left), env(safe-area-inset-right));
}

.cut-button {
  position: relative;
  min-width: clamp(154px, 21vw, 190px);
  min-height: 54px;
  padding: 0 28px 4px;
  border: 4px solid var(--ui-dark);
  border-radius: 0;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, calc(100% - 8px) 4px, 100% 4px, 100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px), calc(100% - 4px) 100%, 8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px), 4px calc(100% - 8px), 0 calc(100% - 8px), 0 8px, 4px 8px, 4px 4px, 8px 4px);
  color: var(--button-ink);
  background: linear-gradient(180deg, var(--button-top) 0 18%, var(--button-mid) 18% 78%, var(--button-bottom) 78% 100%);
  box-shadow: inset 0 4px 0 rgba(255, 250, 190, 0.9), inset 0 -5px 0 rgba(112, 54, 38, 0.62), 0 6px 0 rgba(18, 9, 14, 0.82);
  font-size: clamp(1rem, 2.15vw, 1.12rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-shadow: 1px 1px 0 rgba(255, 242, 167, 0.72);
  cursor: pointer;
  transition: transform 80ms steps(2, end), filter 80ms steps(2, end);
}

.cut-button::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px solid rgba(105, 57, 37, 0.42);
  pointer-events: none;
}

.cut-button:active,
.cut-button.is-pressed {
  transform: translateY(4px);
  filter: brightness(0.92);
  box-shadow: inset 0 3px 0 rgba(255, 250, 190, 0.7), inset 0 -3px 0 rgba(112, 54, 38, 0.55), 0 2px 0 rgba(18, 9, 14, 0.82);
}

.cut-button:focus-visible {
  outline: 4px solid #fff5b0;
  outline-offset: 4px;
}

.cut-button:disabled {
  cursor: wait;
  opacity: 0.82;
  filter: saturate(0.78);
}

.ambient {
  position: absolute;
  z-index: 3;
  width: 5px;
  height: 5px;
  background: #ffd878;
  box-shadow: 5px 0 0 rgba(255, 193, 88, 0.36), 0 5px 0 rgba(255, 193, 88, 0.25);
  opacity: 0;
  animation: mote 4.2s steps(6, end) infinite;
}

.ambient--one {
  left: 23%;
  top: 28%;
}

.ambient--two {
  right: 21%;
  top: 24%;
  width: 4px;
  height: 4px;
  animation-delay: 1.4s;
}

.ambient--three {
  right: 28%;
  top: 48%;
  width: 4px;
  height: 4px;
  animation-delay: 2.7s;
}

.portion-status {
  position: absolute;
  z-index: 9;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 10px 5px;
  color: var(--ink);
  background: rgba(31, 18, 25, 0.88);
  box-shadow: 3px 3px 0 rgba(10, 5, 9, 0.7);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 #6a3c32;
}

.portion-status:empty {
  display: none;
}

.portrait-guard {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  padding: 32px;
  color: var(--ink);
  text-align: center;
  background: #1e121a;
  background-image: repeating-linear-gradient(0deg, transparent 0 6px, rgba(255, 216, 120, 0.05) 6px 8px);
}

.portrait-guard p {
  margin: 0;
  padding: 9px 12px;
  border: 3px solid #5c352f;
  background: #2a1921;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.phone-icon {
  width: 42px;
  height: 72px;
  padding: 5px;
  border: 4px solid #f9e7af;
  border-radius: 0;
  animation: rotate-phone 2.2s steps(4, end) infinite;
}

.phone-icon span {
  display: block;
  width: 12px;
  height: 4px;
  margin: 1px auto 0;
  background: #dba950;
}

@keyframes cake-arrive {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes mote {
  0% {
    opacity: 0;
    transform: translate(0, 10px);
  }
  28%,
  62% {
    opacity: 0.88;
  }
  100% {
    opacity: 0;
    transform: translate(4px, -16px);
  }
}

@keyframes rotate-phone {
  0%,
  22% {
    transform: rotate(0deg);
  }
  55%,
  82% {
    transform: rotate(90deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

@media (orientation: portrait) {
  .game {
    visibility: hidden;
  }

  .portrait-guard {
    display: flex;
  }
}

@media (max-height: 360px) and (orientation: landscape) {
  .cake-stage {
    top: 47%;
    width: min(56vw, 106vh, 450px);
  }

  .cut-button {
    min-height: 50px;
  }

  .note-paper {
    width: min(62vw, 390px);
    min-height: 136px;
    padding: 24px 42px 18px;
  }

  .note-number {
    margin-bottom: 7px;
  }

  .note-copy {
    font-size: 1rem;
    line-height: 1.55;
  }

  .scroll-banner {
    top: max(8px, calc(env(safe-area-inset-top) + 3px));
    width: min(72vw, 600px);
    min-height: 58px;
  }

  .scroll-banner__paper p {
    font-size: clamp(1rem, 2.6vw, 1.4rem);
  }
}

@media (orientation: landscape) and (max-height: 440px) {
  .scroll-banner {
    top: max(8px, calc(env(safe-area-inset-top) + 4px));
    width: min(
      72vw,
      620px,
      calc(100vw - max(18px, env(safe-area-inset-left)) - max(18px, env(safe-area-inset-right)))
    );
    min-height: clamp(54px, 17dvh, 72px);
  }

  .scroll-banner__paper p {
    font-size: clamp(1rem, 2.6vw, 1.45rem);
    letter-spacing: 0.06em;
  }
}

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

  .game.is-transforming .reveal-flash {
    display: none !important;
  }
}
