:root {
  color-scheme: dark;
  --ink: #11172b;
  --night: #233a68;
  --cream: #f5eddb;
  --paper: #fff9ec;
  --gold: #e3b85a;
  --wine: #7d1f33;
  --teal: #1f6f68;
  --shadow: rgba(4, 7, 17, 0.52);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 0%, #30395b 0, #13182b 45%, #080b14 100%);
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

body { min-height: 100svh; }
button { font: inherit; }

.page-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 0;
}

.game-card {
  position: relative;
  width: min(100vw, 430px);
  min-height: 100svh;
  overflow: hidden;
  background: var(--ink);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
}

/* Treat the whole game as an interactive surface on mobile. Long presses and
   multi-touch controls must never invoke text selection or the copy menu. */
.game-card,
.game-card * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.game-card img,
.game-card canvas {
  -webkit-user-drag: none;
  user-drag: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 8px;
  color: var(--paper);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  text-shadow: 2px 2px 0 rgba(17, 23, 43, 0.68);
  pointer-events: none;
}

.hud div { display: grid; gap: 2px; }
.hud div:nth-child(2) { text-align: center; }
.hud div:last-child { text-align: right; }
.hud span { font-size: 10px; letter-spacing: 0.15em; opacity: 0.66; }
.hud strong { font-size: 12px; letter-spacing: 0.02em; white-space: nowrap; }

.canvas-wrap {
  position: relative;
  width: 100%;
  height: calc(100svh - 96px);
  min-height: 610px;
  overflow: hidden;
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  image-rendering: pixelated;
  touch-action: none;
}

.start-screen,
.memory-modal,
.finish-screen,
.portal-flash,
.fail-screen,
.box-hint {
  position: absolute;
  inset: 0;
  z-index: 10;
}

.start-screen {
  z-index: 20;
  display: block;
  color: #fff9e8;
  background-color: #75cce7;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04), rgba(75, 133, 91, 0.12)),
    url("assets/cover-chapel-pixel-v1.png") center -208px / auto calc(100% + 270px) no-repeat;
  background-blend-mode: normal, normal;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  image-rendering: pixelated;
}

.start-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.cover-scroll {
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: clamp(140px, 20svh, 168px) 20px calc(34px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(80, 192, 220, 0.06), rgba(87, 166, 145, 0.10) 43%, rgba(20, 94, 76, 0.28));
  font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", "Microsoft YaHei", monospace;
  font-variant-ligatures: none;
}

.cover-scroll::-webkit-scrollbar { display: none; }

.cover-kicker {
  margin: 0 0 14px;
  transform: translateY(-56px);
  color: #fff4c8;
  font: 900 12px/1 ui-monospace, "Cascadia Mono", monospace;
  letter-spacing: 0.22em;
  text-align: center;
  text-shadow: 2px 2px 0 #47735b;
}

.cover-hero {
  position: relative;
  flex: 0 0 auto;
  width: min(100%, 370px);
  height: clamp(250px, 35svh, 310px);
  max-width: 370px;
  margin: 0 auto 36px;
}

.cover-hero::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 24px;
  width: 176px;
  height: 16px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(36, 83, 50, 0.42) 0 42%, rgba(36, 83, 50, 0) 74%);
  opacity: 0.82;
  image-rendering: pixelated;
}

.cover-hero img {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 24px;
  width: auto;
  height: calc(100% - 42px);
  transform: translateX(-50%);
  object-fit: contain;
  filter: drop-shadow(4px 5px 0 rgba(31, 82, 55, 0.42));
  image-rendering: pixelated;
}

.cover-dialogue {
  position: absolute;
  z-index: 2;
  left: 4px;
  right: 4px;
  bottom: -28px;
  padding: 10px 12px;
  color: #fff3d0;
  background: rgba(128, 79, 36, 0.92);
  border: 4px solid #5d331d;
  outline: 3px solid #e0b761;
  box-shadow: 4px 5px 0 rgba(63, 35, 18, 0.48);
  font: 900 15px/1.45 ui-monospace, "Cascadia Mono", "Microsoft YaHei", monospace;
  text-align: center;
  text-shadow: 2px 2px 0 rgba(63, 35, 18, 0.62);
}

.mission-card {
  width: min(100%, 370px);
  margin: 0 auto;
  padding: 12px 14px 15px;
  color: #263523;
  background: rgba(241, 228, 177, 0.94);
  border: 4px solid #7b512c;
  outline: 3px solid #d4a95c;
  box-shadow: 5px 6px 0 rgba(22, 47, 28, 0.52);
}

.mission-card h1 {
  width: max-content;
  margin: 0 auto 7px;
  padding: 0 8px 4px;
  border-bottom: 5px solid #d19b3d;
  font: 900 27px/1 ui-monospace, "Cascadia Mono", "Microsoft YaHei", monospace;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 #fff3c9;
}

.mission-row,
.dress-code {
  display: grid;
  grid-template-columns: 60px 1fr;
  align-items: center;
  gap: 7px;
  padding: 5px 1px;
  border-bottom: 1px dashed rgba(67, 78, 43, 0.3);
  font-size: 14px;
}

.mission-row span,
.dress-code > span {
  font: 900 13px/1 ui-monospace, "Cascadia Mono", "Microsoft YaHei", monospace;
  letter-spacing: 0.06em;
  text-shadow: 1px 1px 0 rgba(255, 247, 211, 0.9);
}

.mission-row strong {
  font-size: 14px;
  font-weight: 900;
  line-height: 1.4;
  letter-spacing: 0.03em;
  text-shadow: 1px 1px 0 rgba(255, 247, 211, 0.72);
}

.mission-location strong { color: #6e302d; }

.dress-code {
  grid-template-rows: auto auto;
  border-bottom: 0;
}

.dress-code p {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.45;
  text-shadow: 1px 1px 0 rgba(255, 247, 211, 0.72);
}

.dress-swatches {
  grid-column: 2;
  display: flex;
  gap: 12px;
  padding-top: 2px;
}

.dress-swatches i {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(51, 64, 39, 0.22);
  border-radius: 50%;
  background: #fffdf3;
}

.dress-swatches i:nth-child(2) { background: #eadfbd; }
.dress-swatches i:nth-child(3) { background: #c7d79b; }
.dress-swatches i:nth-child(4) { background: #e6cfd0; }
.dress-swatches i:nth-child(5) { background: #cfb28c; }

.cover-actions {
  width: min(100%, 370px);
  margin: 18px auto 0;
  display: grid;
  grid-template-columns: 1fr 1.16fr;
  gap: 10px;
}

.cover-button {
  min-height: 58px;
  padding: 9px 8px;
  border: 4px solid #704627;
  outline: 3px solid #e3bc6d;
  color: #302d1d;
  background: #f0d28b;
  box-shadow: 4px 5px 0 rgba(25, 38, 21, 0.55);
  font: 900 16px/1.1 ui-monospace, "Cascadia Mono", "Microsoft YaHei", monospace;
  letter-spacing: 0.03em;
  text-shadow: 1px 1px 0 #fff0bd;
  cursor: pointer;
  image-rendering: pixelated;
}

.cover-button-alt { background: #e7c57e; }
.cover-button:active { transform: translate(3px, 3px); box-shadow: 1px 2px 0 rgba(25, 38, 21, 0.55); }
.cover-button:disabled { cursor: wait; opacity: 0.76; }

.kicker {
  margin: 0 0 14px;
  color: #e8c879;
  font: 600 11px/1 ui-monospace, monospace;
  letter-spacing: 0.28em;
}

@media (max-height: 720px) {
  .cover-hero { height: 210px; }
  .mission-row, .dress-code { padding-block: 4px; }
  .cover-actions { margin-top: 12px; }
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 0;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.12em;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.primary-button {
  min-width: 176px;
  padding: 15px 24px;
  color: var(--ink);
  background: var(--gold);
  box-shadow: 5px 5px 0 #7d1f33;
}

.primary-button:active,
.secondary-button:active { transform: translate(3px, 3px); }
.primary-button:active { box-shadow: 2px 2px 0 #7d1f33; }

.microcopy {
  margin-top: 22px;
  color: rgba(255, 249, 236, 0.46);
  font: 10px/1.7 ui-monospace, monospace;
}

.controls {
  position: absolute;
  z-index: 8;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(96px + env(safe-area-inset-bottom));
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 58px 58px 1fr 92px;
  gap: 9px;
  background: linear-gradient(180deg, #171d32, #0d1120);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.35s ease, opacity 0.35s ease;
  touch-action: none;
  overscroll-behavior: contain;
}

.game-card.is-finished .controls {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}

.game-card.is-finished .canvas-wrap { height: 100svh; }

.controls button {
  border: 1px solid rgba(255, 249, 236, 0.18);
  color: var(--cream);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.24);
  font: 700 18px/1 ui-monospace, monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.controls button.is-pressed { transform: translateY(2px); filter: brightness(1.3); }
.controls .jump-button {
  justify-self: end;
  width: 92px;
  border-radius: 50%;
  color: var(--paper);
  background: var(--wine);
  border-color: rgba(255, 255, 255, 0.22);
  font-size: 13px;
  letter-spacing: 0.12em;
}

.controls .fire-button {
  align-self: center;
  justify-self: end;
  width: 76px;
  height: 48px;
  border-radius: 24px;
  color: #fff4c6;
  background: linear-gradient(180deg, #d95158, #8f283b);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.controls .fire-button.is-locked {
  color: #7e8797;
  background: #252c3e;
  filter: grayscale(1);
}

.memory-modal {
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 11, 20, 0.76);
  backdrop-filter: blur(7px);
}

.memory-modal[hidden],
.finish-screen[hidden] { display: none; }

.memory-card {
  position: relative;
  width: min(100%, 338px);
  padding: 12px 12px 18px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 10px 10px 0 var(--wine);
  animation: cardIn 0.38s cubic-bezier(.2,.8,.2,1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) rotate(-2deg) scale(0.94); }
  to { opacity: 1; transform: none; }
}

.memory-index {
  padding: 8px 4px 12px;
  color: var(--wine);
  font: 800 11px/1 ui-monospace, monospace;
  letter-spacing: 0.18em;
}

.memory-card img {
  display: block;
  width: 100%;
  height: min(52svh, 410px);
  object-fit: contain;
  background: #11172b;
  filter: saturate(0.94) contrast(1.02);
}

.memory-modal.is-loading .memory-card img {
  opacity: 0.18;
}

.memory-modal.is-loading .memory-card::after {
  content: "照片加载中…";
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  color: var(--ink);
  font: 700 13px/1.2 ui-monospace, monospace;
  letter-spacing: 0.08em;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.memory-card p {
  margin: 14px 6px;
  font-family: "Noto Serif SC", SimSun, serif;
  font-size: 15px;
  letter-spacing: 0.08em;
}

.secondary-button {
  width: calc(100% - 12px);
  margin: 0 6px;
  padding: 12px;
  color: var(--paper);
  background: var(--ink);
}

.portal-flash {
  z-index: 9;
  display: grid;
  place-items: center;
  color: var(--paper);
  background: var(--ink);
  clip-path: circle(0 at 50% 65%);
  pointer-events: none;
  transition: clip-path 0.55s ease;
}

.portal-flash.is-active { clip-path: circle(110% at 50% 65%); }
.portal-flash.is-power { background: #8f1f32; }
.portal-flash span {
  font: 700 14px/1 ui-monospace, monospace;
  letter-spacing: 0.2em;
}

.fail-screen {
  z-index: 14;
  display: grid;
  place-items: center;
  padding: 28px;
  color: var(--paper);
  background: rgba(10, 13, 24, 0.82);
  backdrop-filter: blur(5px);
}

.fail-screen[hidden] { display: none; }
.fail-box {
  width: min(100%, 330px);
  padding: 32px 22px;
  text-align: center;
  background: #7d1f33;
  border: 6px solid #f5eddb;
  box-shadow: 10px 10px 0 #11172b;
  animation: cardIn .28s ease both;
}
.fail-box p {
  margin: 0 0 14px;
  color: #f2d589;
  font: 900 34px/1 ui-monospace, monospace;
  letter-spacing: -.05em;
}
.fail-box h2 { margin: 0 0 10px; font: 700 20px/1.4 "Noto Serif SC", serif; }
.fail-box span { font: 11px/1.5 ui-monospace, monospace; opacity: .65; }

.box-hint {
  z-index: 16;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--paper);
  background: rgba(10, 13, 24, 0.78);
  backdrop-filter: blur(5px);
}

.box-hint[hidden] { display: none; }

.box-hint-card {
  width: min(100%, 330px);
  padding: 26px 22px 22px;
  text-align: center;
  background: #315b58;
  border: 6px solid #f5eddb;
  box-shadow: 10px 10px 0 #11172b;
  animation: cardIn .28s ease both;
}

.box-hint-kicker {
  margin: 0 0 14px;
  color: #f2d589;
  font: 900 13px/1 ui-monospace, monospace;
  letter-spacing: .12em;
}

.box-hint-card h2 {
  margin: 0 0 22px;
  font: 700 20px/1.55 "Noto Serif SC", "Microsoft YaHei", sans-serif;
}

.box-hint-card .secondary-button {
  width: 100%;
  margin: 0;
  color: var(--ink);
  background: #f2d589;
}

.finish-screen {
  overflow-y: auto;
  padding: max(52px, env(safe-area-inset-top)) 18px 30px;
  color: var(--paper);
  background: rgba(9, 12, 23, 0.94);
  backdrop-filter: blur(10px);
}

.finish-panel {
  width: min(100%, 360px);
  margin: 0 auto;
  text-align: center;
}

.finish-panel h2 {
  margin: 0;
  font: 700 34px/1.25 "Noto Serif SC", SimSun, serif;
  letter-spacing: 0.08em;
}

.finish-meta {
  margin: 14px 0 22px;
  color: rgba(255, 249, 236, 0.6);
  font-size: 12px;
  letter-spacing: 0.1em;
}

.finish-panel video {
  display: block;
  width: min(100%, 286px);
  margin: 0 auto 20px;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #000;
  box-shadow: 10px 10px 0 var(--wine);
}

.finish-actions { display: grid; justify-items: center; gap: 14px; }
.text-button {
  border: 0;
  color: rgba(255, 249, 236, 0.62);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

@media (min-width: 600px) {
  .page-shell { padding: 24px; }
  .game-card {
    min-height: min(900px, calc(100svh - 48px));
    height: min(900px, calc(100svh - 48px));
    border: 1px solid rgba(255,255,255,.1);
  }
  .canvas-wrap { height: calc(100% - 96px); }
  .game-card.is-finished .canvas-wrap { height: 100%; }
}

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