:root {
  --bg: #0b0e1a;
  --bg2: #121729;
  --panel: #161c30;
  --panel2: #1b2238;
  --line: #2a3350;
  --text: #e8ecf8;
  --dim: #8b96b4;
  --water: #7fd4ff;
  --water-deep: #2f7fa8;
  --mud: #a8814f;
  --warm: #f0b26b;
  --ok: #6ee7a8;
  --warn: #f0b26b;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

/* 夜雨是本体，不跟随系统浅色 —— 正式版接入 --tg-theme-bg-color 后由 Telegram 决定外框 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(127, 212, 255, .14), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}

#app {
  max-width: 460px;
  margin: 0 auto;
  padding: calc(8px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- 顶部 ---------- */
.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 0;
}

.who { display: flex; align-items: center; gap: 7px; min-width: 0; }
.who .name, .who .en {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--water);
  box-shadow: 0 0 10px var(--water);
  animation: pulse 3.2s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: .55 } 50% { opacity: 1 } }

.name { font-size: 17px; font-weight: 700; letter-spacing: .06em; }
.en { font-size: 11px; color: var(--dim); letter-spacing: .12em; text-transform: uppercase; }

.res { font-size: 12px; color: var(--dim); flex: 0 0 auto; white-space: nowrap; }
.res b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; margin-left: 4px; }
.res .sep, .res .u { margin-left: 2px; }

.resbar {
  height: 5px; border-radius: 99px;
  background: rgba(127, 212, 255, .12);
  overflow: hidden;
}
.resbar i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--water-deep), var(--water));
  border-radius: 99px;
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}

/* ---------- 场景 ---------- */
.scene-wrap {
  position: relative;
  width: -moz-fit-content;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a0d18;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .05);
  line-height: 0;
}

canvas { display: block; margin: 0 auto; width: 100%; height: auto; touch-action: none; }

.badge {
  position: absolute; right: 8px; top: 8px;
  font-size: 10px; letter-spacing: .04em;
  color: rgba(255, 255, 255, .62);
  background: rgba(0, 0, 0, .38);
  border: 1px solid rgba(255, 255, 255, .1);
  padding: 3px 7px; border-radius: 99px;
  backdrop-filter: blur(6px);
  line-height: 1.2;
}

/* ---------- 订单 ---------- */
.orders {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 0 2px; min-height: 22px;
}

.order {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 11px; color: var(--dim);
  transition: border-color .25s, color .25s;
}
.order i { font-style: normal; }
.order b { color: var(--text); font-variant-numeric: tabular-nums; }
.order.ok { border-color: rgba(110, 231, 168, .45); color: var(--ok); }
.order.ok b { color: var(--ok); }

/* ---------- 状态条 ---------- */
.status {
  display: flex; align-items: center; gap: 14px;
  padding: 2px 4px;
}

.stat { font-size: 12px; color: var(--dim); display: flex; align-items: baseline; gap: 4px; }
.stat b { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }
.stat .u { font-size: 11px; }

.chapterbar {
  display: flex; gap: 6px; margin: 8px 0 0;
}

.chapterbar button {
  flex: 1; display: flex; align-items: baseline; justify-content: center; gap: 5px;
  padding: 5px 4px; border-radius: 9px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .02);
  color: var(--dim); font: inherit; font-size: 12px; letter-spacing: .5px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}

.chapterbar button i {
  font-style: normal; font-size: 10px; opacity: .55;
}

.chapterbar button.on {
  color: var(--water); border-color: rgba(127, 212, 255, .45);
  background: rgba(127, 212, 255, .08);
}

.chapterbar button.on i { opacity: .85; }

.chip.lock {
  opacity: .28; cursor: default;
  border-style: dashed;
}

.chips { margin-left: auto; display: flex; gap: 6px; }

.chip {
  border: 1px solid var(--line); background: transparent; color: var(--dim);
  width: 26px; height: 26px; border-radius: 8px;
  font-size: 12px; font-variant-numeric: tabular-nums;
  cursor: pointer; padding: 0;
}
.chip.on { color: var(--text); border-color: var(--water); background: rgba(127, 212, 255, .12); }

.hint {
  margin: 0; padding: 0 4px;
  font-size: 12px; color: var(--dim);
  min-height: 18px;
}

/* ---------- 手牌 ---------- */
.hand {
  display: flex; gap: 8px; flex-wrap: wrap;
  min-height: 62px;
  padding: 2px;
}

.tile {
  flex: 0 0 auto;
  width: 56px; height: 58px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  color: var(--dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s;
  -webkit-tap-highlight-color: transparent;
}

.tile svg { width: 26px; height: 26px; }
.tile span { font-size: 10px; letter-spacing: .02em; }

.tile:active { transform: scale(.95); }

.tile.sel {
  color: var(--water);
  border-color: var(--water);
  box-shadow: 0 0 0 1px var(--water), 0 0 18px rgba(127, 212, 255, .25);
}

.tile.empty {
  border-style: dashed;
  color: transparent;
  background: transparent;
  cursor: default;
  opacity: .35;
}

.handnote {
  display: flex; align-items: center;
  height: 58px; padding: 0 4px;
  font-size: 12px; color: var(--dim); opacity: .75;
}

/* ---------- 广告卡 ---------- */
.adcard {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1px solid rgba(127, 212, 255, .35);
  background:
    linear-gradient(100deg, rgba(127, 212, 255, .16), rgba(127, 212, 255, .03) 55%),
    var(--panel);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s, border-color .2s, transform .1s;
}

.adcard:active { transform: scale(.99); }

.adcard .rain { font-size: 22px; filter: saturate(.9); }

.ad-main { display: flex; flex-direction: column; gap: 1px; }
.ad-main b { font-size: 14px; letter-spacing: .02em; }
.ad-main small { font-size: 11px; color: var(--dim); }

.ad-amt {
  margin-left: auto;
  font-size: 13px; font-weight: 700; color: var(--water);
  font-variant-numeric: tabular-nums;
}

.adcard[data-state="cooldown"],
.adcard[data-state="capped"],
.adcard[data-state="full"] {
  border-color: var(--line);
  background: var(--panel);
  cursor: default;
}
.adcard[data-state="cooldown"] .ad-amt,
.adcard[data-state="capped"] .ad-amt,
.adcard[data-state="full"] .ad-amt { color: var(--dim); font-weight: 500; }
.adcard[data-state="cooldown"] .rain,
.adcard[data-state="capped"] .rain { filter: grayscale(1); opacity: .5; }

.adcard.hidden { display: none; }

/* ---------- 主按钮 ---------- */
.primary {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius);
  border: 0;
  background: linear-gradient(180deg, #8fdcff, #5ab4e0);
  color: #06121c;
  font: 700 16px/1 inherit;
  letter-spacing: .14em;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(90, 180, 224, .28);
  transition: transform .1s, filter .2s;
}
.primary:active { transform: scale(.985); }
.primary:disabled { filter: none; opacity: .5; box-shadow: none; cursor: default; }

.foot {
  margin: 0; text-align: center;
  font-size: 10px; color: var(--dim); opacity: .8;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}

.foot .dot { opacity: .5; }

.adnote {
  margin: 2px 0 10px; text-align: center;
  font-size: 9.5px; line-height: 1.5; color: var(--dim); opacity: .55;
}

.linkbtn {
  font: inherit; font-size: 10px; padding: 3px 8px; cursor: pointer;
  color: var(--water); background: rgba(127, 212, 255, .08);
  border: 1px solid rgba(127, 212, 255, .22); border-radius: 999px;
}
.linkbtn:active { background: rgba(127, 212, 255, .16); }

.linkrow {
  display: block; width: 100%; margin: 0 0 12px; padding: 4px 0;
  font: inherit; font-size: 12px; text-align: center; cursor: pointer;
  color: var(--water); background: none; border: 0; opacity: .85;
}
.linkrow:active { opacity: 1; }

/* ---------- 清水榜 ---------- */
.bme {
  margin: 0 0 12px; padding: 9px 12px; border-radius: 10px;
  font-size: 12.5px; color: var(--ink);
  background: rgba(127, 212, 255, .1);
  border: 1px solid rgba(127, 212, 255, .26);
  font-variant-numeric: tabular-nums;
}
.bme.off { color: var(--dim); background: rgba(140, 176, 208, .06); border-color: var(--line); }

.blist {
  list-style: none; margin: 0 0 12px; padding: 0;
  max-height: 38vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
}
.blist li {
  display: grid; grid-template-columns: 2.1em 1fr auto auto; gap: 9px;
  align-items: baseline; padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; font-size: 12.5px;
}
.blist li i { font-style: normal; color: var(--dim); font-size: 11px; }
.blist li:nth-child(-n+3) i { color: var(--warm); font-weight: 700; }
.blist li .who { font-family: ui-monospace, Menlo, monospace; letter-spacing: .04em; font-size: 12px; }
.blist li b { color: var(--water); font-weight: 600; }
.blist li b s { text-decoration: none; color: var(--dim); font-size: 10px; margin-left: 1px; }
.blist li em { font-style: normal; color: var(--dim); font-size: 10px; }
.blist li.mine { background: rgba(127, 212, 255, .07); }

.bnote {
  margin: 0 0 14px; font-size: 11px; line-height: 1.65; color: var(--dim);
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(4, 7, 14, .82);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px 14px calc(16px + var(--safe-b));
}
.modal[hidden] { display: none; }

.sheet {
  width: 100%; max-width: 430px;
  position: relative;
  background-color: var(--panel);
  background-image: linear-gradient(rgba(12, 16, 30, .82), rgba(12, 16, 30, .92)), url("assets/panel.jpg");
  background-size: cover, 384px 384px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px 18px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  overflow: hidden;
  animation: rise .22s cubic-bezier(.2, .8, .2, 1);
}

/* 结算里的角色小像：即梦画的那位接雨人 */
.sheet-avatar {
  position: absolute; top: 0; right: 0;
  width: 86px; height: 112px;
  object-fit: cover; object-position: 62% 18%;
  border-bottom-left-radius: 18px;
  opacity: .92;
  -webkit-mask-image: linear-gradient(200deg, #000 42%, transparent 78%);
  mask-image: linear-gradient(200deg, #000 42%, transparent 78%);
  pointer-events: none;
}

@keyframes rise { from { transform: translateY(18px); opacity: 0 } to { transform: none; opacity: 1 } }

.sheet h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: .04em; }
.sheet .sub { margin: 0 0 16px; font-size: 12px; color: var(--dim); }

.stars { display: flex; gap: 8px; justify-content: center; margin: 6px 0 16px; }
.stars i {
  width: 34px; height: 34px; display: grid; place-items: center;
  font-size: 22px; font-style: normal;
  color: rgba(255, 255, 255, .16);
  transform: scale(.85);
  transition: transform .3s, color .3s;
}
.stars i.on { color: var(--warm); transform: scale(1); text-shadow: 0 0 18px rgba(240, 178, 107, .55); }

.rows { display: grid; gap: 7px; margin-bottom: 18px; }
.row { display: flex; justify-content: space-between; font-size: 13px; color: var(--dim); }
.row b { color: var(--text); font-variant-numeric: tabular-nums; }

.sheet .primary { margin-bottom: 8px; }

.ghost {
  width: 100%; padding: 12px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: transparent; color: var(--dim);
  font: 500 13px/1 inherit; cursor: pointer;
}

/* ---------- 模拟广告 ---------- */
.ad-mock {
  text-align: center;
  padding: 26px 10px 10px;
}
.ad-mock .big { font-size: 44px; margin-bottom: 10px; }
.ad-mock .t { font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.ad-mock .n { font-size: 34px; font-weight: 700; color: var(--water); font-variant-numeric: tabular-nums; }
.ad-mock .bar { height: 4px; border-radius: 99px; background: rgba(127,212,255,.15); margin-top: 18px; overflow: hidden; }
.ad-mock .bar i { display: block; height: 100%; width: 0%; background: var(--water); transition: width .1s linear; }

/* ---------- 提审截图模式（?sub=1）：把内容让开宿主悬浮角标 ---------- */
body.sub { padding-top: 36px; }
body.sub .app { padding-bottom: 2px; }
body.sub .foot { padding: 6px 0 0; }

/* ---------- 窖匠（升级） ---------- */
.ulist { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; }
.urow {
  border: 1px solid rgba(127, 212, 255, .16);
  border-radius: 12px;
  padding: 9px 11px 10px;
  background: rgba(10, 16, 30, .55);
}
.urow.full { opacity: .62; }
.uhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.uhead b { font-size: 13px; font-weight: 650; color: var(--text); }
.ulevel { font-size: 11px; color: var(--water); font-variant-numeric: tabular-nums; }
.udesc { margin: 4px 0 8px; font-size: 11.5px; line-height: 1.4; color: var(--dim); }
.ufoot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ucost { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.ubuy {
  flex: 0 0 auto;
  min-width: 84px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid rgba(127, 212, 255, .5);
  background: rgba(127, 212, 255, .12);
  color: var(--water);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.ubuy:disabled, .ubuy.off { opacity: .4; border-color: rgba(255,255,255,.14); color: var(--dim); }
.bwater { margin: 6px 0 0; font-size: 12px; color: var(--water); font-variant-numeric: tabular-nums; }
.bsub { margin: 6px 0 0; font-size: 12px; line-height: 1.5; color: var(--dim); }

/* ---------- 声音开关 ---------- */
.snd {
  position: absolute; left: 8px; top: 8px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(0, 0, 0, .38);
  color: rgba(255, 255, 255, .66);
  font-size: 13px; line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(6px);
}
.snd:active { transform: scale(.94); }
.snd[aria-pressed="true"] { color: var(--dim); opacity: .55; }
.snd[aria-pressed="true"]::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 18px; height: 1px; background: currentColor;
  transform: translate(-50%, -50%) rotate(-45deg);
}
