:root {
  --ink: #1D1A15;
  --ink-soft: #4E493F;
  --ink-faint: #7C7467;
  --paper: #F4EDE0;
  --paper-deep: #E9DFCC;
  --orange: #FF8A3D;
  --orange-deep: #E56A22;
  --font-ink: "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --font-kai: "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif CJK SC", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #E9E0CF;
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.vignette,
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.vignette {
  z-index: 2;
  background:
    radial-gradient(120% 92% at 50% 42%, rgba(255, 255, 255, 0) 54%, rgba(41, 34, 24, 0.17) 100%),
    linear-gradient(180deg, rgba(250, 244, 232, 0.12), rgba(0, 0, 0, 0) 18%, rgba(0, 0, 0, 0) 80%, rgba(20, 16, 10, 0.12));
}

.grain {
  z-index: 3;
  opacity: 0.27;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.86' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.42'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

.ui {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---------- 开始界面 ---------- */

.start {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

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

.title-wrap {
  position: absolute;
  left: max(22px, calc(50% - 288px));
  top: calc(env(safe-area-inset-top, 0px) + 8.5vh);
  max-width: 78vw;
  will-change: transform, opacity;
}

.title-wrap::before {
  content: "";
  position: absolute;
  left: -30px;
  top: -26px;
  width: 240px;
  height: 210px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(250, 244, 231, 0.62), rgba(250, 244, 231, 0));
  z-index: -1;
  pointer-events: none;
}

.kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 13px;
  font-size: 10px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: 0.46em;
  color: var(--ink-faint);
  animation: rise-in 0.7s 0.04s both;
}

.kicker-brush {
  width: 24px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--orange), rgba(255, 138, 61, 0));
  transform: rotate(-3deg);
}

.game-title {
  margin: 0;
  font-family: var(--font-kai);
  font-weight: 700;
  font-size: clamp(44px, 13.6vw, 64px);
  line-height: 1.02;
  letter-spacing: 0.035em;
  color: var(--ink);
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.42)) drop-shadow(0 12px 20px rgba(46, 38, 26, 0.13));
}

.line {
  display: block;
}

.line-1 {
  animation: rise-in 0.8s 0.12s both;
}

.line-2 {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 0.08em;
  animation: rise-in 0.8s 0.24s both;
}

.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.56em;
  height: 0.66em;
  font-style: normal;
  font-family: var(--font-ink);
  font-size: 0.44em;
  line-height: 1;
  color: #FFF6E6;
  background: linear-gradient(145deg, #FF9A52, #F17424);
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(198, 92, 24, 0.3), inset 0 0 0 1px rgba(120, 48, 8, 0.12);
  transform: rotate(-7deg) translateY(-0.06em);
  animation: stamp-in 0.55s 0.58s both;
}

.tagline {
  margin: 15px 0 0;
  font-family: var(--font-ink);
  font-size: 12px;
  letter-spacing: 0.34em;
  color: var(--ink-soft);
  animation: rise-in 0.8s 0.4s both;
}

.inscription {
  position: absolute;
  top: 35.5%;
  right: max(20px, calc(50% - 290px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  animation: ink-fade 1.4s 0.85s both;
  pointer-events: none;
}

.inscription-text {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: var(--font-kai);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.52em;
  color: rgba(45, 40, 31, 0.56);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.42);
}

.inscription-seal {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(229, 106, 34, 0.6);
  border-radius: 3px;
  color: rgba(229, 106, 34, 0.78);
  font-family: var(--font-kai);
  font-size: 12px;
  line-height: 1;
  transform: rotate(6deg);
}

.start-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(4vh, calc(env(safe-area-inset-bottom, 0px) + 1.5vh));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 22px;
  pointer-events: none;
  animation: rise-in 0.85s 0.55s both;
}

.start-btn {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(252px, 68vw);
  height: 58px;
  padding: 0 20px;
  border: 1px solid rgba(255, 138, 61, 0.62);
  border-radius: 999px;
  background: linear-gradient(163deg, #FDF8EC 0%, #F4E9D7 58%, #EEDFC7 100%);
  color: var(--ink);
  font-family: var(--font-kai);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.14em;
  cursor: pointer;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.3),
    0 2px 0 rgba(255, 255, 255, 0.7) inset,
    0 -3px 8px rgba(137, 94, 44, 0.1) inset;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
  -webkit-appearance: none;
  appearance: none;
}

.start-btn::before {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid rgba(255, 160, 96, 0.3);
  border-radius: inherit;
  pointer-events: none;
  animation: ring-breathe 3.2s ease-in-out 1.2s infinite;
}

.start-btn::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(78, 62, 42, 0.12);
  border-radius: inherit;
  pointer-events: none;
}

.start-btn:active {
  transform: scale(0.962);
  box-shadow:
    0 5px 14px rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.6) inset;
  filter: brightness(0.985);
}

.start-btn:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 3px;
}

.start-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: linear-gradient(150deg, #FF9E58, #EF6E20);
  color: #24170C;
  box-shadow: 0 3px 8px rgba(190, 82, 20, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.38);
}

.start-icon .mp-icon {
  width: 19px;
  height: 19px;
}

.hint {
  margin: 15px 0 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: rgba(246, 238, 224, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.32);
}

.best-line {
  margin: 8px 0 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(246, 238, 224, 0.58);
}

.best-line b {
  margin: 0 2px;
  font-family: var(--font-kai);
  font-size: 15px;
  color: rgba(255, 166, 108, 0.94);
}

/* ---------- 游戏 HUD ---------- */

.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: max(18px, calc(50% - 292px));
  right: max(18px, calc(50% - 292px));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  opacity: 0;
  transform: translateY(-7px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.hud.show {
  opacity: 1;
  transform: none;
}

.score-box {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-left: 11px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55), 0 4px 12px rgba(255, 250, 240, 0.3);
}

.score-box::before {
  content: "";
  position: absolute;
  left: 0;
  top: 3px;
  bottom: 3px;
  width: 3px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--orange), rgba(255, 138, 61, 0.08));
}

.hud-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.38em;
  color: var(--ink-soft);
}

.hud-score {
  display: flex;
  align-items: baseline;
  gap: 4px;
  color: var(--ink);
}

.hud-score b {
  font-family: var(--font-kai);
  font-size: clamp(28px, 8vw, 36px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.hud-score em {
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.best-pill {
  padding: 7px 11px;
  border: 1px solid rgba(60, 50, 38, 0.12);
  border-radius: 999px;
  background: rgba(247, 241, 230, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: 0 3px 10px rgba(50, 40, 28, 0.06);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}

.best-pill b {
  margin-left: 2px;
  font-family: var(--font-kai);
  font-size: 13px;
  color: var(--ink);
}

/* ---------- 结束界面 ---------- */

.over {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(24, 20, 14, 0.44);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.over-card {
  position: relative;
  width: min(330px, 86vw);
  padding: 30px 24px 23px;
  overflow: hidden;
  border: 1px solid rgba(70, 56, 38, 0.16);
  border-radius: 24px;
  background: linear-gradient(165deg, #FCF6E9 0%, #F3E9D6 62%, #EDE1CB 100%);
  box-shadow:
    0 30px 64px rgba(0, 0, 0, 0.36),
    0 2px 0 rgba(255, 255, 255, 0.8) inset,
    0 -8px 22px rgba(128, 96, 58, 0.08) inset;
  text-align: center;
  transform: translateY(12px) scale(0.965);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.over:not(.is-hidden) .over-card {
  transform: none;
}

.over-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(120, 100, 72, 0.14);
  border-radius: 17px;
  pointer-events: none;
}

.over-stamp {
  position: absolute;
  top: 17px;
  right: 17px;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1.5px solid rgba(240, 118, 38, 0.64);
  border-radius: 5px;
  color: rgba(229, 106, 34, 0.92);
  font-family: var(--font-kai);
  font-size: 17px;
  line-height: 1;
  transform: rotate(8deg);
}

.over-eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.4em;
  color: var(--ink-faint);
}

.over-eyebrow.is-record {
  color: var(--orange-deep);
}

.over-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 15px 0 0;
  font-family: var(--font-kai);
  font-size: 62px;
  font-weight: 700;
  line-height: 0.95;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.over-score em {
  font-style: normal;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.brush-divider {
  width: 72%;
  height: 2px;
  margin: 20px auto 14px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(48, 41, 31, 0), rgba(48, 41, 31, 0.5) 18%, rgba(48, 41, 31, 0.18) 82%, rgba(48, 41, 31, 0));
  transform: rotate(-1deg);
}

.over-best {
  margin: 0 0 20px;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.over-best b {
  font-family: var(--font-kai);
  font-size: 17px;
  color: var(--orange-deep);
}

.retry-btn {
  width: 100%;
  height: 54px;
  font-size: 18px;
}

.over-hint {
  margin: 13px 0 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
}

/* ---------- 动效 ---------- */

@keyframes rise-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes stamp-in {
  0% { opacity: 0; transform: scale(1.75) rotate(-7deg); }
  62% { opacity: 1; transform: scale(0.94) rotate(-7deg); }
  100% { opacity: 1; transform: scale(1) rotate(-7deg); }
}

@keyframes ring-breathe {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.018); }
}

@keyframes ink-fade {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 0.92; transform: translateY(0); }
}

@media (max-height: 660px) {
  .title-wrap { top: calc(env(safe-area-inset-top, 0px) + 5vh); }
  .game-title { font-size: clamp(38px, 11.5vw, 50px); }
  .tagline { margin-top: 9px; }
  .start-actions { bottom: max(3vh, calc(env(safe-area-inset-bottom, 0px) + 1vh)); }
  .start-btn { height: 52px; font-size: 18px; }
  .hint { margin-top: 9px; }
  .best-line { margin-top: 5px; }
  .over-card { padding-top: 24px; }
  .over-score { font-size: 52px; margin-top: 11px; }
  .brush-divider { margin: 15px auto 11px; }
  .over-best { margin-bottom: 15px; }
  .retry-btn { height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .kicker,
  .line-1,
  .line-2,
  .tagline,
  .start-actions,
  .seal,
  .inscription,
  .start-btn::before {
    animation: none;
  }
  .inscription { opacity: 0.92; }
  .over-card,
  .start,
  .over,
  .hud {
    transition: none;
  }
}
