:root {
  --paper: #fffdf0;
  --line: #e3d7b6;
  --ink: #17121f;
  --muted: #8b8194;
  --purple: #3a2b52;
  --purple-2: #52406f;
  --gold: #c9a06a;
  --coral: #ef6a4c;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  min-height: 100%;
  background-color: #f7f2fa;
  background-image:
    radial-gradient(700px 500px at 10% 4%, #ffe3ec 0%, rgba(255, 227, 236, 0) 62%),
    radial-gradient(640px 480px at 90% 10%, #dbeaff 0%, rgba(219, 234, 255, 0) 62%),
    radial-gradient(560px 440px at 84% 84%, #eae1ff 0%, rgba(234, 225, 255, 0) 60%),
    radial-gradient(760px 540px at 44% 102%, #d8f5e7 0%, rgba(216, 245, 231, 0) 66%);
  background-attachment: fixed;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 16px 22px;
}

/* ================= 舞台 ================= */

.stage {
  position: relative;
  flex: none;
  width: 520px;
  height: 400px;
  transform-origin: top center;
}

@media (max-width: 580px) {
  .stage { transform: scale(0.76); height: 320px; }
}

/* ================= 像素机台 ================= */

.machine {
  position: absolute;
  left: 50%;
  top: 10px;
  width: 360px;
  height: 360px;
  margin-left: -156px;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 10px 0 rgba(60, 40, 80, 0.12));
}

#cv {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.machine.rumble { animation: rumble 0.62s steps(1, end); }

@keyframes rumble {
  0%   { transform: translate(0, 0); }
  12%  { transform: translate(-6px, 3px); }
  24%  { transform: translate(6px, -3px); }
  36%  { transform: translate(-6px, -3px); }
  48%  { transform: translate(6px, 3px); }
  60%  { transform: translate(-6px, 3px); }
  72%  { transform: translate(6px, 0); }
  84%  { transform: translate(-6px, 0); }
  100% { transform: translate(0, 0); }
}

.lever-hit {
  position: absolute;
  right: -6px;
  top: 104px;
  width: 78px;
  height: 160px;
  cursor: grab;
  touch-action: none;
}

.lever-hit:active { cursor: grabbing; }

/* ================= 平放的纸堆 ================= */

.pile {
  position: absolute;
  left: 4px;
  top: 264px;
  width: 92px;
  height: 66px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  z-index: 4;
}

.sheet {
  position: absolute;
  inset: 0;
  border: 3px solid var(--ink);
  background-color: var(--paper);
  box-shadow: 4px 4px 0 rgba(60, 40, 80, 0.14);
  transition: transform 0.16s steps(2, end);
}

.s5 { transform: translate(9px, 9px); background-color: #fdf5df; }
.s4 { transform: translate(6px, 6px); background-color: #fffbe9; }
.s3 { transform: translate(3px, 3px); background-color: #fdf5df; }
.s2 { transform: translate(0, 0); background-color: #fffbe9; }

.s1 {
  transform: translate(-3px, -3px);
  background-image: repeating-linear-gradient(to bottom, transparent 0 9px, #e6daba 9px 11px);
  background-position: 0 6px;
}

.pile:hover .s1 { transform: translate(-6px, -7px); }

/* ================= 台面 / 纸条 ================= */

.tray {
  position: absolute;
  left: 50%;
  top: 378px;
  width: 360px;
  margin-left: -180px;
  height: 130px;
  pointer-events: none;
}

.tray > * { pointer-events: auto; }

.tray.armed {
  pointer-events: auto;
  cursor: pointer;
}

.slip {
  background-color: var(--paper);
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--line) 31px 34px);
  background-origin: content-box;
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", serif;
  color: var(--ink);
  font-size: 17px;
  line-height: 34px;
  padding: 14px 18px;
  border: 3px solid var(--ink);
  word-break: break-word;
  box-shadow: 6px 6px 0 rgba(60, 40, 80, 0.14);
}

.result-slip {
  position: absolute;
  left: 50%;
  bottom: 22px;
  width: 320px;
  margin-left: -160px;
  transform-origin: 50% 100%;
  max-height: 380px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ================= 飞行纸团 ================= */

.ghost {
  position: fixed;
  pointer-events: none;
  z-index: 80;
  overflow: hidden;
  background-color: var(--paper);
  background-image: repeating-linear-gradient(to bottom, transparent 0 33px, var(--line) 33px 34px);
  background-origin: content-box;
  font-family: "Kaiti SC", "STKaiti", "KaiTi", serif;
  font-size: 17px;
  line-height: 34px;
  padding: 16px 20px;
  border: 3px solid var(--ink);
  color: var(--ink);
  transform-origin: 50% 50%;
  box-shadow: 6px 6px 0 rgba(60, 40, 80, 0.16);
  transition: border-radius 0.5s ease, box-shadow 0.5s ease;
  will-change: transform;
}

.ghost.crumpling {
  border-radius: 50%;
  border-width: 2px;
  box-shadow: 0 4px 12px rgba(60, 40, 80, 0.3);
}

.pball {
  position: fixed;
  z-index: 80;
  width: 80px;
  height: 80px;
  image-rendering: pixelated;
  transform-origin: 50% 50%;
  will-change: transform;
  cursor: pointer;
}

.pball.pickable { animation: bob 1.6s steps(2, end) infinite; }

@keyframes bob {
  0%, 100% { scale: 1; }
  50% { scale: 1.08; }
}

/* ================= 书写层 ================= */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 30, 55, 0.24);
  backdrop-filter: blur(2px);
  padding: 20px;
}

.writer {
  width: min(360px, 94vw);
  background: var(--paper);
  border: 3px solid var(--ink);
  padding: 16px 18px 12px;
  box-shadow: 8px 8px 0 rgba(60, 40, 80, 0.2);
  transform-origin: 50% 50%;
}

.writer textarea {
  display: block;
  width: 100%;
  height: 300px;
  border: none;
  outline: none;
  resize: none;
  background-color: transparent;
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--line) 31px 34px);
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: 17px;
  line-height: 34px;
  color: var(--ink);
  padding: 0;
}

.writer textarea::placeholder { color: #bdb09a; }

.writer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 3px solid var(--ink);
}

.count {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.acts { display: flex; gap: 8px; }

.btn {
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  padding: 7px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(60, 40, 80, 0.22);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.plain {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
}

.btn.plain:hover { color: var(--ink); }

.btn.primary {
  background: var(--coral);
  color: #fff8f2;
}

.btn.primary:hover:not(:disabled) { background: #d9553a; }

/* ================= 提示（只在需要时短暂出现） ================= */

.msg {
  margin: 4px auto 0;
  max-width: 400px;
  min-height: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.msg.show { opacity: 1; }

/* ================= 音效开关 ================= */

.sound {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(60, 40, 80, 0.18);
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.16s;
  opacity: 0.72;
}

.sound:hover { opacity: 1; }

.sound:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.sound.off {
  color: var(--muted);
  opacity: 0.5;
}

.sound.off::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 3px;
  background: currentColor;
  border-radius: 2px;
  transform: rotate(-45deg);
}
