:root {
  --paper: #efe6d4;
  --paper-deep: #e2d4b8;
  --ink: #1a1a1a;
  --ink-soft: #3d3d3d;
  --ink-faint: rgba(26, 26, 26, 0.45);
  --cinnabar: #9a2d2d;
  --cinnabar-deep: #7a1f1f;
  --line: rgba(26, 26, 26, 0.14);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #2b2b2b;
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.stage {
  position: relative;
  width: 390px;
  height: 844px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

@media (max-height: 860px), (max-width: 420px) {
  body {
    min-height: 100dvh;
    display: grid;
    place-items: center;
  }

  .stage {
    transform: scale(min(100vw / 390, 100dvh / 844));
    transform-origin: center;
  }
}

.paper {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 18% 12%, rgba(255, 255, 255, 0.28), transparent 36%),
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(90, 70, 40, 0.025) 4px),
    repeating-linear-gradient(90deg, transparent, transparent 5px, rgba(60, 40, 20, 0.02) 6px);
  z-index: 1;
}

.topbar,
.wallet,
.scene,
.dock,
.sheet {
  position: relative;
  z-index: 2;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 22px 22px 0;
}

.title-block h1 {
  margin: 0;
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 34px;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.subtitle,
.ink-label,
.meta-row,
.sheet-lead,
.node-lv,
.tap-hint {
  color: var(--ink-faint);
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  letter-spacing: 0.28em;
}

.seal {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid var(--cinnabar);
  color: var(--cinnabar);
  font-family: "Ma Shan Zheng", serif;
  font-size: 22px;
  transform: rotate(-8deg);
  box-shadow: inset 0 0 0 1px rgba(154, 45, 45, 0.35);
}

.wallet {
  padding: 14px 22px 8px;
}

.ink-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.ink-label {
  font-size: 13px;
  letter-spacing: 0.2em;
}

#inkValue {
  font-size: 36px;
  line-height: 1;
  letter-spacing: 0.02em;
}

#inkValue.is-punch {
  animation: punch 0.22s ease-out;
}

@keyframes punch {
  50% {
    transform: scale(1.08);
    color: var(--cinnabar);
  }
}

.meta-row {
  margin-top: 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.dot {
  margin: 0 6px;
}

.scene {
  position: relative;
  height: 430px;
  margin: 6px 12px 0;
  border: 1px solid var(--line);
  background: #eadfc8;
  overflow: hidden;
}

.scroll,
.fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.fx {
  pointer-events: none;
}

.layer {
  transition: opacity 0.6s ease;
}

.layer.is-dim {
  opacity: 0.28;
}

.layer.is-on {
  opacity: 1;
}

.node-btn {
  position: absolute;
  min-width: 68px;
  padding: 6px 8px 7px;
  border: 1px solid rgba(26, 26, 26, 0.35);
  background: rgba(239, 230, 212, 0.78);
  text-align: center;
  line-height: 1.15;
}

.node-btn.is-locked {
  opacity: 0.42;
}

.node-btn.is-selected {
  border-color: var(--cinnabar);
  box-shadow: 0 0 0 1px rgba(154, 45, 45, 0.25);
}

.node-name {
  display: block;
  font-size: 15px;
}

.node-lv {
  display: block;
  margin-top: 2px;
  font-size: 10px;
}

.n-mountain { top: 46px; left: 154px; }
.n-bamboo { top: 168px; left: 28px; }
.n-stream { top: 176px; right: 24px; }
.n-inkstone { bottom: 78px; left: 50%; transform: translateX(-50%); }
.n-seal { top: 18px; right: 16px; }

.tap-pad {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 176px;
  height: 74px;
  transform: translateX(-50%);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: rgba(26, 26, 26, 0.78);
  box-shadow: 0 0 0 6px rgba(26, 26, 26, 0.06);
  animation: pulse 2.4s ease-in-out infinite;
}

.tap-pad:active {
  transform: translateX(-50%) scale(0.96);
  animation: none;
}

.tap-hint {
  font-size: 20px;
  letter-spacing: 0.42em;
  color: var(--paper);
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 11px rgba(26, 26, 26, 0);
  }
}

.dock {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  display: flex;
  gap: 10px;
}

.dock-btn {
  flex: 1;
  min-height: 52px;
  border: 1px solid var(--ink);
  background: transparent;
  letter-spacing: 0.16em;
}

.dock-btn.primary {
  background: var(--ink);
  color: var(--paper);
}

.dock-btn.accent {
  border-color: var(--cinnabar);
  color: var(--cinnabar);
}

.dock-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 34%;
  padding: 10px 16px calc(18px + var(--safe-bottom));
  background: rgba(239, 230, 212, 0.97);
  border-top: 1px solid var(--line);
  overflow: auto;
  z-index: 5;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 10px;
  background: rgba(26, 26, 26, 0.18);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-head h2,
.card h2 {
  margin: 0;
  font-family: "Ma Shan Zheng", serif;
  font-size: 28px;
  font-weight: 400;
}

.text-btn {
  font-size: 13px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
}

.sheet-lead {
  margin: 8px 0 12px;
  font-size: 12px;
}

.node-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.node-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
}

.node-card.is-selected {
  border-color: var(--cinnabar);
}

.node-card h3 {
  margin: 0;
  font-size: 16px;
}

.node-card p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
}

.node-card .buy {
  grid-row: 1 / span 2;
  align-self: center;
  min-width: 92px;
  min-height: 40px;
  border: 1px solid var(--ink);
  letter-spacing: 0.08em;
}

.node-card .buy:disabled {
  opacity: 0.4;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(20, 18, 14, 0.42);
}

.overlay[hidden],
.sheet[hidden],
.seal[hidden],
.toast[hidden],
.dock[hidden],
button[hidden] {
  display: none !important;
}

.card {
  width: min(320px, calc(100vw - 40px));
  padding: 28px 24px 22px;
  background: var(--paper);
  border: 1px solid var(--ink);
  text-align: center;
}

.card p {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}

.gate-card {
  position: relative;
}

.seal-mark {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 36px;
  height: 36px;
  margin: 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--cinnabar);
  color: var(--cinnabar);
  font-family: "Ma Shan Zheng", serif;
  font-size: 20px;
  transform: rotate(10deg);
}

.gate-actions {
  display: flex;
  gap: 8px;
  margin-top: 22px;
}

.offline-value {
  display: block;
  margin: 16px 0 18px;
  font-size: 34px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 9;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  letter-spacing: 0.12em;
}

.float-plus {
  position: absolute;
  pointer-events: none;
  font-size: 22px;
  font-weight: 700;
  color: var(--cinnabar);
  text-shadow: 0 1px 0 #f7f1e4, 0 0 10px rgba(239, 230, 212, 0.9);
  animation: rise 0.95s ease-out forwards;
  z-index: 4;
}

@keyframes rise {
  to {
    transform: translateY(-46px);
    opacity: 0;
  }
}
