* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --accent: #FF8A3D;
  --ink: #211f1b;
  --paper: #f3efe4;
  --muted: #746e63;
}
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background: #191815;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.hidden { display: none !important; }
.game {
  position: relative;
  width: 100%; max-width: 540px; height: 100%; height: 100dvh;
  margin: 0 auto; overflow: hidden; isolation: isolate;
  background: #e9e4d8;
}
.scene {
  position: absolute; inset: 0; z-index: -3;
  width: 100%; height: 100%; object-fit: cover; object-position: center top;
  pointer-events: none;
  transform: scale(1.025);
  transition: transform .22s ease, object-position .22s ease;
}
.legibility {
  position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background: linear-gradient(180deg, rgba(245,241,230,.16) 0%, rgba(245,241,230,0) 32%, rgba(25,23,19,.06) 53%, rgba(25,23,19,.52) 100%);
}
.home-screen, .play-screen { position: absolute; inset: 0; }
.home-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(48px, calc(env(safe-area-inset-top) + 34px)) 24px max(28px, calc(env(safe-area-inset-bottom) + 20px));
}
.title-wrap { position: relative; text-align: center; color: #24211c; text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.eyebrow { margin: 0 0 8px; font-family: "Songti SC", SimSun, serif; font-size: 13px; letter-spacing: .48em; text-indent: .48em; }
h1 {
  margin: 0; font-family: "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: clamp(34px, 9.4vw, 50px); font-weight: 700; letter-spacing: .08em; line-height: 1.18;
}
.title-seal {
  display: inline-grid; place-items: center; width: 26px; height: 30px; margin: 12px 0 0 8px;
  background: var(--accent); color: #fff9ee; border-radius: 4px;
  font-family: "KaiTi", serif; font-size: 18px; line-height: 1;
  transform: rotate(3deg);
}
.home-menu { width: min(100%, 360px); display: grid; gap: 12px; }
.ink-button {
  min-height: 54px; border-radius: 15px; display: flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 650; letter-spacing: .12em; font-size: 17px;
  transition: transform .1s ease, opacity .1s ease;
}
.ink-button:active, .move-button:active, .round-button:active { transform: scale(.96); }
.ink-button.primary {
  min-height: 62px; background: var(--accent); color: #fffaf1;
  box-shadow: 0 8px 24px rgba(74,42,21,.24), inset 0 0 0 1px rgba(255,255,255,.2);
  font-size: 19px;
}
.ink-button .mp-icon { width: 23px; height: 23px; }
.secondary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ink-button.secondary {
  background: rgba(244,240,229,.9); border: 1px solid rgba(54,48,39,.2);
  box-shadow: 0 5px 16px rgba(25,22,17,.12); backdrop-filter: blur(7px);
}
.best-line { margin: 1px 0 0; text-align: center; color: rgba(255,252,242,.9); font-size: 13px; letter-spacing: .08em; text-shadow: 0 1px 4px #27231d; }
.best-line strong { margin-left: 6px; color: #fff; font-size: 16px; }
.hud {
  position: absolute; z-index: 5; left: 18px; right: 18px;
  top: max(16px, calc(env(safe-area-inset-top) + 10px));
  display: flex; align-items: center; justify-content: space-between;
}
.score-card {
  min-width: 94px; padding: 9px 15px 10px; border-radius: 14px;
  background: rgba(244,240,229,.88); border: 1px solid rgba(44,40,33,.14); backdrop-filter: blur(6px);
  display: flex; align-items: baseline; gap: 10px;
}
.score-card span { color: var(--muted); font-size: 12px; }
.score-card strong { font-family: Georgia, serif; font-size: 26px; line-height: 1; }
.round-button, .close-button {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(244,240,229,.9); border: 1px solid rgba(44,40,33,.14); backdrop-filter: blur(6px);
}
.round-button .mp-icon { width: 25px; height: 25px; }
.token-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.ink-token {
  position: absolute; width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 9px; background: var(--accent); color: #fff8ec;
  border: 2px solid rgba(255,248,235,.8); box-shadow: 0 3px 12px rgba(44,28,17,.24);
  font-family: "KaiTi", "STKaiti", serif; font-size: 24px; font-weight: 700;
  transform: rotate(4deg); will-change: top, left;
}
.ink-token.collected { opacity: 0; transform: scale(1.5) rotate(12deg); transition: opacity .16s, transform .16s; }
.runner {
  position: absolute; z-index: 2; width: 104px; height: 132px; left: 50%; top: 56%;
  overflow: hidden; pointer-events: none; transform: translateX(-50%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 35%, rgba(0,0,0,.9) 50%, transparent 73%);
  mask-image: radial-gradient(ellipse at center, #000 35%, rgba(0,0,0,.9) 50%, transparent 73%);
  transition: left .18s ease-out;
}
.runner img { position: absolute; max-width: none; pointer-events: none; }
.lane-hint {
  position: absolute; left: 50%; bottom: max(116px, calc(env(safe-area-inset-bottom) + 108px));
  transform: translateX(-50%); white-space: nowrap; padding: 7px 14px; border-radius: 20px;
  background: rgba(30,27,22,.56); color: #fffaf0; font-size: 12px; letter-spacing: .08em;
  transition: opacity .3s;
}
.move-controls {
  position: absolute; z-index: 4; left: 22px; right: 22px;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 14px));
  display: flex; align-items: center; justify-content: space-between;
}
.move-button {
  width: 72px; height: 64px; border-radius: 19px; display: grid; place-items: center;
  color: #28241e; background: rgba(245,241,230,.9); border: 1px solid rgba(44,40,33,.17);
  box-shadow: 0 4px 14px rgba(20,18,15,.16); backdrop-filter: blur(7px);
}
.move-button .mp-icon { width: 38px; height: 38px; }
.move-label { color: rgba(255,250,239,.9); font-family: "KaiTi", serif; font-size: 14px; letter-spacing: .2em; text-shadow: 0 1px 5px #242019; }
.modal { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,18,15,.55); backdrop-filter: blur(2px); }
.paper-panel {
  position: relative; width: 100%; max-height: 82%; overflow-y: auto;
  padding: 30px 24px max(24px, calc(env(safe-area-inset-bottom) + 18px));
  border-radius: 24px 24px 0 0; background: var(--paper);
  box-shadow: 0 -12px 36px rgba(20,17,13,.18);
}
.close-button { position: absolute; top: 16px; right: 16px; width: 42px; height: 42px; background: #e7e1d4; }
.close-button .mp-icon { width: 22px; height: 22px; }
.panel-kicker { margin: 0 0 5px; color: #a55225; font-size: 12px; letter-spacing: .28em; }
.paper-panel h2 { margin: 0 0 20px; font-family: "KaiTi", "Songti SC", serif; font-size: 30px; letter-spacing: .08em; }
.panel-body { color: #554f45; font-size: 15px; line-height: 1.8; }
.panel-body p { margin: 0 0 14px; }
.rule-row { display: flex; align-items: center; gap: 14px; margin: 14px 0; }
.rule-icon { flex: 0 0 46px; height: 46px; display: grid; place-items: center; border-radius: 13px; background: #e7dfd0; color: #342e25; }
.rule-icon .mp-icon { width: 26px; height: 26px; }
.rule-row strong { display: block; color: #28241e; font-size: 16px; }
.rule-row span { font-size: 13px; color: #746d60; }
.setting-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid #dcd4c5; }
.setting-row:first-child { border-top: 0; }
.switch { position: relative; width: 52px; height: 32px; border-radius: 20px; background: #c7c0b3; }
.switch::after { content: ""; position: absolute; width: 26px; height: 26px; top: 3px; left: 3px; border-radius: 50%; background: white; transition: left .16s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 23px; }
.panel-actions { display: grid; gap: 10px; margin-top: 22px; }
.panel-actions:empty { display: none; }
.panel-actions .ink-button.secondary { background: #e7e0d3; box-shadow: none; }
.toast {
  position: absolute; z-index: 30; left: 50%; top: 19%; transform: translate(-50%, 8px);
  max-width: 80%; padding: 9px 16px; border-radius: 20px; background: rgba(30,27,22,.86); color: #fffaf0;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-height: 650px) {
  .home-screen { padding-top: max(28px, calc(env(safe-area-inset-top) + 22px)); }
  .eyebrow { margin-bottom: 4px; }
  h1 { font-size: 34px; }
  .title-seal { margin-top: 6px; }
  .home-menu { gap: 9px; }
  .ink-button.primary { min-height: 56px; }
  .ink-button.secondary { min-height: 49px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
