:root {
  --wall: #243056;
  --wall-deep: #18233f;
  --bed: #5b4660;
  --sheet: #efe4d4;
  --blanket: #6d90aa;
  --pillow: #f7f1e6;
  --skin: #f3c7a8;
  --skin-shadow: #e3a888;
  --hair: #4a3226;
  --phone: #1b1c22;
  --screen: #d7ecff;
  --accent: #ff7f59;
  --accent-deep: #e45b38;
  --text: #fff8f0;
  --ink: #2a2430;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: #0f1322;
  color: var(--text);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic",
    sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
}

button {
  font-family: inherit;
  cursor: pointer;
}

#app {
  position: relative;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--wall-deep);
  container-type: size;
  container-name: stage;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 18px 60px rgba(0, 0, 0, 0.4);
}

#app.is-shaking {
  animation: screen-shake 0.42s ease-out;
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  18% {
    transform: translate(-2.2cqi, 1.1cqi);
  }
  36% {
    transform: translate(2.4cqi, -0.8cqi);
  }
  54% {
    transform: translate(-1.4cqi, -1cqi);
  }
  72% {
    transform: translate(1.2cqi, 0.7cqi);
  }
}

.hud {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(2.4cqh + var(--safe-top)) 5cqi 0;
  text-align: center;
  pointer-events: none;
}

.title {
  margin: 0;
  font-size: clamp(22px, 7.4cqi, 42px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.25;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

#app.is-playing .title {
  font-size: clamp(16px, 5.2cqi, 28px);
}

.tagline {
  margin: 1.2cqh 0 0;
  font-size: clamp(13px, 3.8cqi, 20px);
  font-weight: 700;
  opacity: 0.92;
}

.fatigue {
  margin: 1.6cqh auto 0;
  width: min(82cqi, 340px);
  text-align: left;
  padding: 1.1cqh 2.4cqi 1.3cqh;
  border-radius: 2.4cqi;
  background: rgba(12, 16, 32, 0.45);
}

.fatigue-label {
  font-size: clamp(14px, 4.2cqi, 22px);
  font-weight: 800;
}

.fatigue-track {
  margin-top: 0.7cqh;
  height: 1.7cqh;
  min-height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}

.fatigue-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8be0a4, #f3d36b 55%, #ff7f59);
  clip-path: inset(0 100% 0 0);
}

.fatigue.is-critical .fatigue-label {
  animation: pulse 0.7s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
}

.wall {
  position: absolute;
  inset: 0 0 38%;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(255, 214, 170, 0.18), transparent 46%),
    linear-gradient(180deg, #1a2444 0%, var(--wall) 100%);
}

.window {
  position: absolute;
  top: 28%;
  right: 7%;
  width: 14cqi;
  height: 14cqh;
  border: 0.7cqi solid #d9c7a6;
  border-radius: 1cqi;
  background: linear-gradient(180deg, #141a33, #2b3a63);
  box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.08);
}

.moon {
  position: absolute;
  top: 18%;
  left: 22%;
  width: 5cqi;
  height: 5cqi;
  border-radius: 50%;
  background: #f4ecc4;
  box-shadow: 0 0 10px rgba(244, 236, 196, 0.7);
}

.bed {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 0;
  height: 48%;
}

.bed-frame {
  position: absolute;
  inset: 8% 0 0;
  background: var(--bed);
  border-radius: 6cqi 6cqi 0 0;
}

.sheet {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 14%;
  bottom: 0;
  background: var(--sheet);
  border-radius: 5cqi 5cqi 0 0;
}

.blanket {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 38%;
  bottom: 0;
  background: linear-gradient(180deg, #7ea0b8, var(--blanket));
  border-radius: 40% 40% 0 0 / 18% 18% 0 0;
  box-shadow: 0 -1cqi 0 rgba(255, 255, 255, 0.12) inset;
}

.pillow {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 10%;
  height: 16%;
  background: var(--pillow);
  border-radius: 40%;
  box-shadow: 0 1cqi 0 #e2d5c3;
}

.person {
  position: absolute;
  left: 50%;
  bottom: 22%;
  width: 46cqi;
  height: 24cqh;
  transform: translateX(-50%);
  z-index: 2;
}

.head {
  position: absolute;
  left: 50%;
  top: 0;
  width: 34cqi;
  height: 34cqi;
  transform: translateX(-50%);
}

.hair-back,
.hair-front {
  position: absolute;
  background: var(--hair);
}

.hair-back {
  inset: -4% -6% 42%;
  border-radius: 50% 50% 40% 40%;
}

.hair-front {
  top: -2%;
  left: 8%;
  right: 8%;
  height: 28%;
  border-radius: 50% 50% 40% 40%;
}

.ear {
  position: absolute;
  top: 42%;
  width: 7cqi;
  height: 9cqi;
  background: var(--skin);
  border-radius: 50%;
}

.ear-l {
  left: -4%;
}

.ear-r {
  right: -4%;
}

.face {
  position: absolute;
  inset: 12% 8% 6%;
  background: var(--skin);
  border-radius: 46% 46% 50% 50%;
  box-shadow:
    0 0 8cqi rgba(180, 220, 255, 0.28),
    inset 0 -1.4cqi 1.6cqi var(--skin-shadow);
}

.eye {
  position: absolute;
  top: 38%;
  width: 6.4cqi;
  height: 7.4cqi;
  background: #fff;
  border: 0.45cqi solid #2b2430;
  border-radius: 50%;
  overflow: hidden;
}

.eye-l {
  left: 16%;
}

.eye-r {
  right: 16%;
}

.pupil {
  position: absolute;
  left: 50%;
  top: 8%;
  width: 3.1cqi;
  height: 3.6cqi;
  background: #2b2430;
  border-radius: 50%;
  transform: translateX(-50%);
}

.brow {
  position: absolute;
  top: 28%;
  width: 7cqi;
  height: 1cqi;
  background: #2b2430;
  border-radius: 999px;
  opacity: 0.85;
}

.brow-l {
  left: 16%;
  transform: rotate(-8deg);
}

.brow-r {
  right: 16%;
  transform: rotate(8deg);
}

.mouth {
  position: absolute;
  left: 50%;
  top: 68%;
  width: 6cqi;
  height: 1.1cqi;
  background: #c07a72;
  border-radius: 999px;
  transform: translateX(-50%);
}

.blush {
  position: absolute;
  top: 58%;
  width: 5.5cqi;
  height: 2.4cqi;
  background: rgba(255, 120, 120, 0.28);
  border-radius: 50%;
  opacity: 0;
}

.blush-l {
  left: 10%;
}

.blush-r {
  right: 10%;
}

.person.is-hurt .eye {
  background: transparent;
  border: 0;
  height: 4cqi;
}

.person.is-hurt .eye::before,
.person.is-hurt .eye::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  height: 0.8cqi;
  background: #2b2430;
  border-radius: 999px;
}

.person.is-hurt .eye-l::before,
.person.is-hurt .eye-r::after {
  top: 20%;
  transform: rotate(22deg);
}

.person.is-hurt .eye-l::after,
.person.is-hurt .eye-r::before {
  top: 55%;
  transform: rotate(-22deg);
}

.person.is-hurt .pupil,
.person.is-hurt .brow {
  display: none;
}

.person.is-hurt .mouth {
  top: 66%;
  width: 7cqi;
  height: 5.4cqi;
  border-radius: 40% 40% 50% 50%;
  background: #c45b5b;
  box-shadow: inset 0 1.4cqi 0 #f3c7a8;
}

.person.is-hurt .blush {
  opacity: 1;
}

.rig {
  position: absolute;
  left: 50%;
  top: 22%;
  width: 64cqi;
  height: 42cqh;
  transform: translateX(-50%);
  z-index: 4;
  pointer-events: none;
  transform-origin: 50% 100%;
}

.arm {
  position: absolute;
  top: 10%;
  width: 8cqi;
  height: 92%;
  background: var(--skin);
  border-radius: 999px;
  z-index: 1;
  transform-origin: top center;
}

.arm-l {
  left: 20%;
  transform: rotate(14deg);
}

.arm-r {
  right: 20%;
  transform: rotate(-14deg);
}

.cluster {
  position: absolute;
  left: 50%;
  top: 0;
  width: 56cqi;
  height: 52cqi;
  transform: translateX(-50%);
  transform-origin: 50% 58%;
  z-index: 6;
}

.hand {
  position: absolute;
  top: 30%;
  width: 12.5cqi;
  height: 11cqi;
  background: var(--skin);
  border-radius: 46%;
  z-index: 7;
  box-shadow: 0 0.4cqi 0 var(--skin-shadow);
}

.hand-l {
  left: 10%;
}

.hand-r {
  right: 10%;
}

.phone {
  position: absolute;
  left: 50%;
  top: 0;
  width: 28cqi;
  height: 48cqi;
  padding: 3cqi 3cqi 4cqi;
  border: 0;
  background: transparent;
  transform: translateX(-50%);
  pointer-events: auto;
  z-index: 6;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.phone-bezel {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--phone);
  border-radius: 3.2cqi;
  box-shadow:
    0 1.4cqi 3cqi rgba(0, 0, 0, 0.35),
    0 0 4cqi rgba(170, 210, 255, 0.35);
}

.phone-notch {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 34%;
  height: 4%;
  transform: translateX(-50%);
  background: #0b0b10;
  border-radius: 999px;
}

.phone-screen {
  position: absolute;
  inset: 9% 8% 10%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 28%),
    var(--screen);
  border-radius: 1.6cqi;
  overflow: hidden;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 8%;
  padding: 18% 10% 10%;
  height: 100%;
}

.feed span {
  display: block;
  height: 14%;
  border-radius: 999px;
  background: rgba(70, 110, 160, 0.28);
}

.feed span:first-child {
  width: 70%;
  height: 22%;
  border-radius: 1cqi;
}

.phone.is-held {
  cursor: grab;
}

.phone.is-dragging {
  cursor: grabbing;
}

.event-layer {
  position: absolute;
  inset: 28% 8% auto;
  z-index: 8;
  text-align: center;
  font-size: clamp(22px, 8cqi, 48px);
  font-weight: 900;
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  min-height: 10cqh;
}

.event-layer.is-zzz {
  color: #dce7ff;
  letter-spacing: 0.12em;
}

.event-layer.is-heavy {
  font-size: clamp(16px, 5.4cqi, 28px);
  color: #ffe7a8;
}

.impact-text {
  position: absolute;
  left: 50%;
  top: 58%;
  z-index: 9;
  margin: 0;
  font-size: clamp(40px, 16cqi, 84px);
  font-weight: 900;
  color: #fff4d6;
  text-shadow:
    0.5cqi 0.5cqi 0 #c45b38,
    0 0 4cqi rgba(255, 220, 140, 0.45);
  transform: translate(-50%, -50%) scale(0.4);
  pointer-events: none;
}

.impact-text.is-pop {
  display: block;
  animation: impact-pop 0.5s cubic-bezier(0.2, 1.4, 0.3, 1) forwards;
}

@keyframes impact-pop {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0;
  }
  40% {
    transform: translate(-50%, -60%) scale(1.12);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -70%) scale(1);
    opacity: 1;
  }
}

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  padding: 0 8cqi calc(4.5cqh + var(--safe-bottom));
}

.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 1.2cqi 0 var(--accent-deep);
}

.btn-play {
  min-height: 12cqh;
  font-size: clamp(28px, 10cqi, 52px);
  background: var(--accent);
}

.btn:active {
  transform: translateY(0.6cqi);
  box-shadow: 0 0.4cqi 0 var(--accent-deep);
}

.result {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8cqh 8cqi calc(6cqh + var(--safe-bottom));
  background: rgba(18, 16, 28, 0.72);
  text-align: center;
}

.result[hidden],
.fatigue[hidden],
.impact-text[hidden],
.controls[hidden] {
  display: none !important;
}

.result-hit {
  margin: 0;
  font-size: clamp(36px, 12cqi, 64px);
  font-weight: 900;
  letter-spacing: 0.06em;
}

.result-comment {
  margin: 1.6cqh 0 0;
  font-size: clamp(18px, 5.6cqi, 30px);
  font-weight: 800;
}

.result-stats {
  margin: 4cqh 0 0;
  padding: 0;
  list-style: none;
  font-size: clamp(16px, 4.8cqi, 24px);
  font-weight: 700;
  line-height: 1.7;
}

.new-best {
  margin: 1.6cqh 0 0;
  color: #ffe18a;
  font-size: clamp(18px, 5.6cqi, 28px);
  font-weight: 900;
  animation: pulse 0.9s ease-in-out infinite;
}

.btn-retry {
  margin-top: 4.5cqh;
  min-height: 9cqh;
  font-size: clamp(20px, 6.2cqi, 32px);
  background: var(--accent);
}

.rig.is-tremor-low {
  animation: tremor 0.28s linear infinite;
}

.rig.is-tremor-mid {
  animation: tremor 0.16s linear infinite;
}

.rig.is-tremor-high {
  animation: tremor 0.09s linear infinite;
}

@keyframes tremor {
  0% {
    margin-left: -0.5cqi;
  }
  50% {
    margin-left: 0.6cqi;
  }
  100% {
    margin-left: -0.3cqi;
  }
}

.phone.is-falling {
  pointer-events: none;
  z-index: 10;
  transition: transform 0.48s cubic-bezier(0.55, 0.05, 0.9, 0.25);
}

@media (min-width: 900px) {
  #app {
    border-radius: 18px;
  }
}
