:root {
  --ink: #1c1a17;
  --ink-2: #3c3a36;
  --paper: #f4efe6;
  --paper-2: #e7dfd1;
  --line: #cfc5b3;
  --accent: #b0492f;
  --accent-2: #2f6b4f;
  --gold: #c08a2e;
  --water: #4a7fa5;
  --shadow: rgba(28, 26, 23, .18);
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: #14130f;
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
}
#app {
  position: relative;
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(180deg, #faf6ee 0%, #efe8db 100%);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- HUD ---------- */
#hud { padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); background: rgba(250,246,238,.92); }
.hud-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
#hud h1 { font-size: 19px; margin: 0; letter-spacing: .5px; font-weight: 700; }
.badge { font-size: 11px; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; background: var(--paper); white-space: nowrap; }
.goal { margin: 4px 0 8px; font-size: 12.5px; color: var(--ink-2); }
.hud-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 5px 6px; text-align: center; }
.stat b { display: block; font-size: 17px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10px; color: #7d7566; letter-spacing: .5px; }
.stat.hot b { color: var(--accent); }
.stat.good b { color: var(--accent-2); }

/* ---------- 舞台 ---------- */
#stage { position: relative; flex: 0 0 auto; padding: 8px 10px 0; }
#cv { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: #6f9a5a; box-shadow: 0 6px 18px -10px var(--shadow); }
.bubble {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 10px; max-width: 92%;
  background: #fffdf8; border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.45;
  box-shadow: 0 8px 20px -12px rgba(0,0,0,.45);
}
.bubble .who { color: var(--accent); font-weight: 700; margin-right: 4px; }

/* ---------- 底部操作区 ---------- */
#dock { flex: 1 1 auto; padding: 10px 12px 18px; }
.hint { margin: 0 0 8px; font-size: 12.5px; color: #6f6656; }
.actors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.actor {
  border: 1px solid var(--line); background: var(--paper); border-radius: 9px;
  padding: 7px 4px 6px; text-align: center; cursor: pointer; min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.actor.sel { border-color: var(--accent); background: #fdf4ec; box-shadow: inset 0 0 0 1px var(--accent); }
.actor .nm { font-size: 13px; font-weight: 700; }
.actor .pl { font-size: 10px; color: #7d7566; }
.actor .dot { width: 22px; height: 22px; }

.compose { margin-top: 10px; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 10px; }
.compose h3 { margin: 0 0 6px; font-size: 13px; }
.compose h3 span { color: var(--accent); }
.kv { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.kv i { font-style: normal; font-size: 11px; color: var(--ink-2); background: #fffdf8; border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; }
.opt {
  display: block; width: 100%; text-align: left; margin-bottom: 6px;
  border: 1px solid var(--line); background: #fffdf8; border-radius: 8px;
  padding: 9px 10px; font-size: 13.5px; line-height: 1.4; cursor: pointer;
}
.opt b { color: var(--accent-2); font-weight: 700; margin-right: 5px; font-size: 11px; }
.opt:active { background: #f3ece0; }
.free { display: flex; gap: 6px; margin-top: 8px; }
.free input { flex: 1; min-width: 0; font-size: 16px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fffdf8; }
.free button { flex: 0 0 auto; }
button.primary { background: var(--ink); color: #f7f3ea; border: 0; border-radius: 9px; padding: 11px 16px; font-size: 15px; font-weight: 700; cursor: pointer; width: 100%; }
button.ghost { background: #fffdf8; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font-size: 14px; cursor: pointer; }
button.primary:disabled, button.ghost:disabled { opacity: .45; }
.note { font-size: 12px; color: var(--accent); margin: 8px 0 0; }
.note.warn { color: var(--accent); }
.note.info { color: #6f6656; }

/* ---------- 小镇此刻 ---------- */
.status { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.status h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: 1px; color: #8a8172; font-weight: 600; }
.status .row { display: grid; grid-template-columns: 44px 52px 1fr; gap: 6px; align-items: baseline; padding: 3px 0; font-size: 12.5px; }
.status .row b { font-weight: 700; }
.status .row span { color: #7d7566; font-size: 11.5px; }
.status .row em { font-style: normal; color: var(--ink-2); }
.status .row.ev { grid-template-columns: 24px 1fr; }
.status .row.ev span { color: var(--accent); font-size: 11px; }
.status .row.ev em { font-size: 12px; color: #6f6656; }
.skiprow { margin-top: 10px; }
.skiprow button { width: 100%; font-size: 13px; }

/* ---------- 演出 & 结果 ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20,19,15,.55); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet .panel {
  width: 100%; max-width: 520px; max-height: 86dvh; overflow-y: auto;
  background: linear-gradient(180deg,#faf6ee,#f1eade);
  border-radius: 14px 14px 0 0; padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 30px -10px rgba(0,0,0,.5);
}
.sheet h2 { margin: 0 0 2px; font-size: 22px; letter-spacing: .5px; }
.sheet .sub { color: #6f6656; font-size: 12.5px; margin: 0 0 12px; }
.sheet .verdict { border-left: 3px solid var(--accent-2); padding-left: 10px; margin: 10px 0 14px; }
.sheet .verdict.loss { border-color: var(--accent); }
.sheet .verdict b { display: block; font-size: 17px; margin-bottom: 2px; }
.sheet .verdict p { margin: 0; font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.cost { display: inline-block; margin-top: 6px; font-size: 12px; color: var(--gold); border: 1px solid var(--gold); border-radius: 999px; padding: 2px 8px; }
.tl { border-top: 1px solid var(--line); margin-top: 6px; }
.tl h3 { font-size: 13px; margin: 12px 0 8px; color: #6f6656; letter-spacing: .5px; }
.ev { display: grid; grid-template-columns: 40px 1fr; gap: 8px; padding: 9px 0; border-bottom: 1px dashed #ded4c2; }
.ev .ph { font-size: 11px; color: #8a8172; padding-top: 3px; }
.ev .txt { font-size: 13px; line-height: 1.6; }
.ev .txt em { font-style: normal; color: var(--accent); font-weight: 700; }
.ev.cause .txt { padding-left: 12px; position: relative; }
.ev.cause .txt::before { content: "↳"; position: absolute; left: 0; color: #b3a894; }
.keys { display: flex; gap: 10px; margin: 14px 0 4px; }
.keys div { flex: 1; background: #fffdf8; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 11px; color: #6f6656; }
.keys b { display: block; font-size: 13px; color: var(--ink); word-break: break-all; font-family: ui-monospace, Menlo, monospace; }
.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions button { flex: 1; }

.fx { position: fixed; z-index: 60; pointer-events: none; }
.hidden { display: none !important; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- 起始页 ---------- */
.start { position: fixed; inset: 0; z-index: 80; background: linear-gradient(180deg,#1c1a17,#2a2620); color: #f4efe6; display: flex; align-items: center; justify-content: center; padding: 24px; }
.start-inner { max-width: 420px; width: 100%; }
.start .kicker { font-size: 11px; letter-spacing: 2px; color: var(--gold); margin: 0 0 8px; }
.start h2 { font-size: 30px; margin: 0 0 10px; letter-spacing: 1px; }
.start .lead { font-size: 14px; line-height: 1.7; color: #d8d0c2; margin: 0 0 16px; }
.start .facts { list-style: none; padding: 0; margin: 0 0 20px; border-top: 1px solid #3d3830; }
.start .facts li { padding: 9px 0; border-bottom: 1px solid #3d3830; font-size: 13px; color: #cfc7b8; }
.start .facts b { color: var(--gold); font-size: 16px; margin-right: 6px; }
.start .tiny { font-size: 11px; color: #8b8478; margin: 14px 0 0; line-height: 1.6; }
.start button.primary { background: var(--gold); color: #1c1a17; }

/* ---------- 小镇闲聊记录 ---------- */
.chatwrap { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.chatwrap > summary { font-size: 12px; color: #7a7266; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; }
.chatwrap > summary::-webkit-details-marker { display: none; }
.chatwrap > summary::before { content: '▸'; color: var(--accent); font-size: 11px; }
.chatwrap[open] > summary::before { content: '▾'; }
.chatlog { margin-top: 8px; display: grid; gap: 8px; max-height: 232px; overflow-y: auto; }
.cmsg { background: #faf7f0; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; }
.chead { font-size: 10px; color: #948b7c; margin-bottom: 3px; letter-spacing: .3px; }
.cl { font-size: 12.5px; line-height: 1.65; color: #3a342c; }
.cl b { color: var(--accent); font-weight: 600; }
