:root {
  --ink: #3a2a1c;
  --ink-soft: #6a5340;
  --paper: #f6ead4;
  --paper-2: #efe0c4;
  --wood: #6b4a2e;
  --wood-deep: #4a321f;
  --gold: #c9a25a;
  --pill: rgba(246, 234, 212, 0.92);
  --pill-edge: rgba(90, 64, 40, 0.18);
  --shadow: 0 8px 28px rgba(40, 24, 10, 0.22);
  --serif: "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #c9b189; }
body { font-family: var(--sans); color: var(--ink); user-select: none; -webkit-user-select: none; }
#app, #view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#view { touch-action: none; }

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

#hud { position: fixed; inset: 0; z-index: 12; pointer-events: none; transition: opacity .4s ease; }
#hud button, #hud input { pointer-events: auto; font-family: inherit; }

.top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(12px + env(safe-area-inset-top)) 16px 0;
}
.top-left, .top-right { display: flex; gap: 8px; align-items: flex-start; }
.top-right { flex-direction: column; align-items: flex-end; }
.top-right-row { display: flex; gap: 8px; align-items: center; }

.pill {
  border: 1px solid var(--pill-edge);
  background: var(--pill);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.pill:hover { background: #fff6e6; }
.pill:active { transform: scale(0.97); }
.pill.primary {
  background: var(--wood);
  color: var(--paper);
  border-color: transparent;
  padding: 10px 28px;
  font-size: 16px;
}
.pill.on, #btn-chant.on, .act.on {
  background: var(--wood);
  color: var(--paper);
  border-color: transparent;
}
.icon-btn { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; }
.brand { position: relative; }
.brand-btn { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--wood); color: var(--paper);
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 14px;
}
.brand-name { font-family: var(--serif); font-size: 16px; letter-spacing: 0.12em; }
.caret { font-size: 11px; opacity: 0.7; }

.menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 168px;
  background: var(--pill);
  border: 1px solid var(--pill-edge);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px;
  backdrop-filter: blur(12px);
  display: flex; flex-direction: column; gap: 2px;
  pointer-events: auto;
  z-index: 8;
}
.menu-title {
  font-size: 11px; color: var(--ink-soft); letter-spacing: 0.16em;
  padding: 6px 10px 4px;
}
.menu button {
  appearance: none; border: 0; background: transparent;
  text-align: left; padding: 8px 12px; border-radius: 10px;
  font-size: 14px; color: var(--ink); cursor: pointer;
}
.menu button:hover { background: rgba(107, 74, 46, 0.1); }

.toast, .world-hint {
  position: absolute; left: 50%; top: 18%;
  transform: translate(-50%, 0);
  background: rgba(246, 234, 212, 0.94);
  border: 1px solid var(--pill-edge);
  color: var(--ink);
  padding: 8px 16px; border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px; letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
}
.world-hint { top: 22%; }

.context-actions {
  position: absolute; left: 50%; bottom: 118px;
  transform: translateX(-50%);
  display: flex; gap: 10px;
  pointer-events: none;
}
.context-actions .pill { pointer-events: auto; }
.pill.context { font-size: 15px; padding: 9px 18px; }

.bottom-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  padding: 0 16px calc(18px + env(safe-area-inset-bottom));
}
.action-dock {
  pointer-events: auto;
  display: flex; gap: 4px;
  background: var(--pill);
  border: 1px solid var(--pill-edge);
  border-radius: 28px;
  padding: 8px 10px 6px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.act {
  appearance: none; border: 0; background: transparent;
  min-width: 72px; padding: 4px 10px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--ink); cursor: pointer; border-radius: 18px;
  font-size: 12px; letter-spacing: 0.08em;
}
.act:hover { background: rgba(107, 74, 46, 0.08); }
.act.on { background: var(--wood); color: var(--paper); }
.act-icon { width: 28px; height: 28px; display: grid; place-items: center; }
.act-icon svg { width: 26px; height: 26px; }

.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(40, 24, 10, 0.35);
  display: grid; place-items: center;
  padding: 24px;
}
.modal[hidden], .overlay[hidden], .menu[hidden], .toast[hidden],
.world-hint[hidden], .context-actions[hidden], [hidden] { display: none !important; }

.sheet {
  width: min(440px, 100%);
  background: var(--paper);
  border-radius: 20px;
  padding: 20px 22px 24px;
  box-shadow: var(--shadow);
  color: var(--ink);
  max-height: calc(100vh - 48px);
  overflow: auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.sheet h2 { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: 0.12em; }
.text-btn {
  appearance: none; border: 0; background: none;
  color: var(--wood); cursor: pointer; font-size: 14px;
}
.row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid rgba(90, 64, 40, 0.12);
  font-size: 15px;
}
.row.col { flex-direction: column; align-items: stretch; gap: 10px; }
.row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--wood); }
.seg { display: flex; background: rgba(107, 74, 46, 0.08); border-radius: 12px; padding: 3px; }
.seg button {
  flex: 1; appearance: none; border: 0; background: transparent;
  padding: 8px 0; border-radius: 10px; cursor: pointer; color: var(--ink);
}
.seg button.on { background: #fff; box-shadow: 0 1px 6px rgba(40,24,10,.12); color: var(--wood-deep); font-weight: 600; }
.help { margin-top: 16px; font-size: 13px; line-height: 1.7; color: var(--ink-soft); }
.help h3 { font-size: 13px; color: var(--ink); margin-bottom: 6px; letter-spacing: 0.1em; }

.overlay {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(32, 20, 10, 0.45);
  display: grid; place-items: center;
  padding: 16px;
}
.intro-card, .beads-panel, .load-inner {
  text-align: center;
}
.intro-card {
  background: var(--paper);
  border-radius: 24px;
  padding: 36px 36px 28px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
}
.intro-seal, .load-inner .intro-seal {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border: 2px solid var(--wood);
  border-radius: 8px;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 22px; letter-spacing: 0.2em;
  color: var(--wood);
  transform: rotate(-8deg);
}
h1 { font-family: var(--serif); font-weight: 600; font-size: 36px; letter-spacing: 0.28em; }
.slogan { margin: 8px 0 18px; color: var(--ink-soft); letter-spacing: 0.4em; font-size: 14px; }
.intro-body { font-size: 14px; line-height: 1.8; color: var(--ink-soft); text-align: left; margin-bottom: 22px; }

#loading {
  position: fixed; inset: 0; z-index: 40;
  background: linear-gradient(180deg, #d7c09a 0%, #c9b189 40%, #b9976c 100%);
  display: grid; place-items: center;
  transition: opacity .6s ease;
}
#loading.fade { opacity: 0; pointer-events: none; }
.load-inner h1 { color: var(--wood-deep); }
.bar {
  width: 200px; height: 4px; margin: 18px auto 10px;
  background: rgba(74, 50, 31, 0.2); border-radius: 99px; overflow: hidden;
}
#load-bar { height: 100%; width: 8%; background: var(--wood); border-radius: 99px; transition: width .3s ease; }
#load-text { font-size: 13px; color: var(--ink-soft); letter-spacing: 0.12em; }

.beads-panel {
  width: min(520px, 100%);
  background: var(--paper);
  border-radius: 24px;
  padding: 16px 16px 20px;
  box-shadow: var(--shadow);
}
.beads-top { display: flex; align-items: center; gap: 12px; padding: 4px 6px 8px; }
.beads-title { font-family: var(--serif); font-size: 20px; letter-spacing: 0.2em; }
.beads-count { flex: 1; text-align: center; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--wood); }
#beads-canvas { width: 100%; height: auto; aspect-ratio: 1; display: block; touch-action: none; cursor: grab; }
#beads-canvas:active { cursor: grabbing; }
.beads-hint { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }

@media (max-width: 640px) {
  .act { min-width: 62px; font-size: 11px; }
  h1 { font-size: 30px; }
  .context-actions { bottom: 108px; }
}


/* Floating ritual overlays (木鱼 / 念珠). HUD stays above so the dock remains clickable. */
.ritual-overlay {
  position: fixed; inset: 0; z-index: 8;
  background: rgba(22, 14, 8, 0.42);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 16px 16px 130px;
  pointer-events: auto;
}
.ritual-overlay[hidden] { display: none !important; }

.muyu-stage, .beads-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(560px, 100%);
  pointer-events: auto;
}
#muyu-canvas {
  width: min(460px, 86vw);
  height: auto;
  aspect-ratio: 900 / 780;
  display: block;
  cursor: pointer;
  touch-action: none;
}
#beads-canvas {
  width: min(380px, 78vw);
  height: auto;
  aspect-ratio: 720 / 960;
  display: block;
  touch-action: none;
  cursor: grab;
}
#beads-canvas:active { cursor: grabbing; }

.beads-count-block {
  position: absolute;
  left: 0;
  top: 42%;
  transform: translate(-10%, -50%);
  text-align: left;
  color: #f3e6c8;
  text-shadow: 0 2px 10px rgba(20,10,0,0.45);
  pointer-events: none;
  z-index: 1;
}
.beads-num {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}
#beads-n {
  font-size: 64px;
  color: #f0d9a8;
}
.beads-total {
  font-size: 22px;
  color: rgba(243,230,200,0.75);
  margin-left: 4px;
}
.beads-lap {
  margin-top: 8px;
  font-size: 15px;
  letter-spacing: 0.16em;
  color: rgba(243,230,200,0.8);
}

.ritual-controls {
  display: flex;
  align-items: center;
  gap: 0;
  margin-top: 6px;
  background: var(--pill);
  border: 1px solid var(--pill-edge);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 4px 6px;
}
.ritual-pill {
  box-shadow: none;
  background: transparent;
  border: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  padding: 8px 14px;
}
.ritual-pill:hover { background: rgba(107, 74, 46, 0.08); }
#btn-muyu-auto.on, .ritual-pill.on {
  color: var(--wood-deep);
  font-weight: 600;
}
.ritual-sep {
  width: 1px;
  height: 22px;
  background: rgba(90, 64, 40, 0.2);
  margin: 0 2px;
}
.ritual-x, .ritual-mute {
  appearance: none;
  border: 0;
  background: transparent;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.ritual-x:hover, .ritual-mute:hover { background: rgba(107, 74, 46, 0.08); }
.ritual-mute { font-size: 16px; }
.ritual-mute.muted { opacity: 0.45; }

@media (max-width: 640px) {
  .beads-count-block { left: 4px; transform: translate(0, -50%); }
  #beads-n { font-size: 48px; }
  .beads-total { font-size: 18px; }
  #muyu-canvas { width: min(420px, 92vw); }
}


/* Wish pond forms */
.wish-sheet { width: min(420px, 100%); }
.wish-lead { font-size: 13px; line-height: 1.7; color: var(--ink-soft); margin-bottom: 12px; }
.wish-label { display: block; font-size: 13px; letter-spacing: 0.12em; margin-bottom: 6px; color: var(--ink); }
#wish-text {
  width: 100%;
  border: 1px solid var(--pill-edge);
  background: #fffaf0;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  resize: vertical;
  min-height: 84px;
  outline: none;
}
#wish-text:focus { border-color: var(--wood); }
.wish-actions { margin-top: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.wish-ul { list-style: none; max-height: 46vh; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.wish-ul li {
  background: rgba(107, 74, 46, 0.06);
  border-radius: 12px;
  padding: 10px 12px;
}
.wish-ul .wish-name { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.08em; margin-bottom: 4px; }
.wish-ul .wish-body { font-family: var(--serif); font-size: 15px; line-height: 1.6; }

#muyu-auto-icon { display: inline-grid; place-items: center; width: 1em; }

.donate-sheet { width: min(400px, 100%); text-align: center; }
.donate-sheet .wish-lead { text-align: left; }
.donate-qr-wrap {
  margin: 4px auto 0;
  padding: 10px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 2px 12px rgba(40, 24, 10, 0.08);
  width: min(280px, 86%);
}
.donate-qr-wrap img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
  pointer-events: auto;
}
.donate-hint { font-size: 12px; color: var(--ink-soft); margin-top: 12px; line-height: 1.6; }
