/* 团子游戏屋 · 基础样式
   纸感 + 马克笔描边 + 砖红点缀。所有尺寸用 clamp，手机优先。 */

:root {
  --paper: #FFFBF5;
  --paper-2: #FBF5EC;
  --paper-3: #F6EEE2;
  --paper-4: #F0E6D8;
  --ink: #2B211B;
  --ink-2: #57493F;
  --ink-3: #8C7C70;
  --line: #2B211B;

  --red: #C8161E;
  --red-dark: #A30F17;
  --red-soft: #FCE7E1;
  --coral: #F35737;
  --orange: #FDA535;
  --yellow: #E2CE2E;
  --green: #8DCD66;
  --blue: #73BBDB;
  --indigo: #8799D2;
  --purple: #7356A8;
  --lav: #B093CC;
  --mascot-ink: #8C6262;

  --shadow: 4px 5px 0 rgba(43, 33, 27, .14);
  --shadow-sm: 2px 3px 0 rgba(43, 33, 27, .16);
  --shadow-lg: 8px 10px 0 rgba(43, 33, 27, .12);
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --r-xl: 30px;
  --bw: 2.5px;

  --font: "Nunito", "Quicksand", ui-rounded, "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --maxw: 1120px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --bounce: cubic-bezier(.34, 1.56, .64, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

/* 纸纹：极淡的噪声 + 网点，纯 CSS/SVG，无图片请求 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(rgba(43, 33, 27, .055) 1px, transparent 1.2px),
    radial-gradient(rgba(200, 22, 30, .05) 1px, transparent 1.2px);
  background-size: 22px 22px, 38px 38px;
  background-position: 0 0, 11px 13px;
  opacity: .55;
  mix-blend-mode: multiply;
}

img { max-width: 100%; display: block; }
a { color: inherit; }
button { font: inherit; color: inherit; }

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -.015em;
  font-weight: 900;
}

p { margin: 0; }

::selection { background: var(--red); color: #fff; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px);
  position: relative;
  z-index: 1;
}

/* ---------- 按钮 ---------- */
.btn {
  --bg: var(--ink);
  --fg: var(--paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  padding: .82em 1.5em;
  border: var(--bw) solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font-weight: 900;
  font-size: clamp(15px, 1.5vw, 17px);
  letter-spacing: .01em;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s var(--ease), box-shadow .12s var(--ease), background .15s;
  will-change: transform;
  user-select: none;
}
.btn:hover { transform: translate(-1px, -2px); box-shadow: 6px 7px 0 rgba(43, 33, 27, .15); }
.btn:active { transform: translate(3px, 4px); box-shadow: 0 0 0 rgba(0, 0, 0, 0); }
.btn--red { --bg: var(--red); --fg: #fff; }
.btn--paper { --bg: var(--paper); --fg: var(--ink); }
.btn--lg { padding: 1em 1.9em; font-size: clamp(17px, 2vw, 20px); }
.btn--sm { padding: .5em .95em; font-size: 14px; box-shadow: var(--shadow-sm); }
.btn--ghost { --bg: transparent; --fg: var(--ink); box-shadow: none; border-color: transparent; }
.btn--ghost:hover { box-shadow: none; background: rgba(43, 33, 27, .06); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- 通用小件 ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  padding: .28em .7em;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: .02em;
  white-space: nowrap;
}
.chip--red { background: var(--red-soft); border-color: var(--red); color: var(--red-dark); }
.chip--soft { border-color: var(--paper-4); background: var(--paper-2); color: var(--ink-2); }
.chip--coin { background: #FFF7DC; border-color: #D9B23A; color: #7A5A00; }

.tag {
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }

/* 手绘波浪下划线 */
.wavy {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='8' viewBox='0 0 120 8'%3E%3Cpath d='M0 5c8-4 16-4 24 0s16 4 24 0 16-4 24 0 16 4 24 0 16-4 24 0' fill='none' stroke='%23C8161E' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: 0 100%;
  background-size: 120px 8px;
  padding-bottom: .16em;
}

/* 纸胶带 */
.tape {
  position: absolute;
  width: 92px;
  height: 26px;
  background: rgba(253, 165, 53, .34);
  border-left: 1px dashed rgba(43, 33, 27, .18);
  border-right: 1px dashed rgba(43, 33, 27, .18);
  transform: rotate(-4deg);
  box-shadow: 0 1px 2px rgba(43, 33, 27, .06);
  pointer-events: none;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  background: rgba(255, 251, 245, .78);
  border-bottom: 2px solid rgba(43, 33, 27, .08);
}
.topbar__in {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 18px);
  height: 62px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-weight: 900;
  font-size: 17px;
  letter-spacing: -.01em;
  margin-right: auto;
  flex-shrink: 0;
}
.brand img { width: 32px; height: 32px; object-fit: contain; }
.brand small {
  display: block;
  font-size: 10px;
  letter-spacing: .16em;
  color: var(--ink-3);
  font-weight: 800;
  line-height: 1;
  margin-top: 2px;
}
.topbar__nav { display: flex; align-items: center; gap: 6px; }

.iconbtn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border: 2px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background .15s, transform .12s;
}
.iconbtn:hover { background: rgba(43, 33, 27, .06); }
.iconbtn:active { transform: scale(.92); }
.iconbtn svg { width: 21px; height: 21px; }

/* ---------- 页脚 ---------- */
.foot {
  margin-top: clamp(48px, 8vw, 96px);
  border-top: 2px solid rgba(43, 33, 27, .1);
  padding: 28px 0 calc(34px + var(--safe-b));
  font-size: 13px;
  color: var(--ink-2);
  position: relative;
  z-index: 1;
}
.foot__in { display: flex; flex-wrap: wrap; gap: 14px 26px; align-items: center; justify-content: space-between; }
.foot a { text-decoration: none; border-bottom: 1.5px solid rgba(43, 33, 27, .25); }
.foot a:hover { border-color: var(--red); color: var(--red); }
.foot__links { display: flex; gap: 16px; flex-wrap: wrap; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(43, 33, 27, .42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s;
}
.modal[data-open="1"] { opacity: 1; visibility: visible; }
.modal__box {
  width: min(680px, 100%);
  max-height: min(86vh, 780px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border: var(--bw) solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: clamp(20px, 3.4vw, 32px);
  transform: translateY(14px) scale(.985);
  transition: transform .24s var(--bounce);
  position: relative;
}
.modal[data-open="1"] .modal__box { transform: none; }
.modal__x {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--paper);
  font-size: 17px; cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.modal__x:active { transform: translate(2px, 2px); box-shadow: none; }
.modal h2 { font-size: clamp(22px, 3vw, 28px); margin-bottom: 6px; }
.modal__lead { color: var(--ink-2); font-size: 14.5px; margin-bottom: 18px; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + var(--safe-b));
  transform: translate(-50%, 20px);
  z-index: 120;
  background: var(--ink);
  color: var(--paper);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(43, 33, 27, .28);
  opacity: 0;
  transition: opacity .2s, transform .28s var(--bounce);
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast[data-open="1"] { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 引导 ---------- */
.onboard {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(255, 251, 245, .96);
  backdrop-filter: blur(10px);
  opacity: 0; visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.onboard[data-open="1"] { opacity: 1; visibility: visible; }
.onboard__box {
  width: min(460px, 100%);
  text-align: center;
  position: relative;
}
.onboard__art {
  height: clamp(150px, 26vh, 210px);
  display: grid; place-items: center;
  margin-bottom: 6px;
}
.onboard__art img {
  height: clamp(140px, 24vh, 200px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
  animation: float 4s ease-in-out infinite;
}
.onboard__step { font-size: 12px; font-weight: 900; letter-spacing: .2em; color: var(--red); }
.onboard h2 { font-size: clamp(24px, 5vw, 34px); margin: 10px 0 10px; }
.onboard p { color: var(--ink-2); font-size: 15px; min-height: 3.2em; }
.onboard__dots { display: flex; gap: 7px; justify-content: center; margin: 20px 0 22px; }
.onboard__dots i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--paper-4);
  transition: background .2s, width .2s;
}
.onboard__dots i[data-on="1"] { background: var(--red); width: 22px; border-radius: 999px; }
.onboard__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- 动效 ---------- */
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-10px) rotate(1.5deg); }
}
@keyframes pop {
  0% { transform: scale(.86); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes wobble {
  0%, 100% { transform: rotate(-1.2deg); }
  50% { transform: rotate(1.2deg); }
}
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(.08); }
}
@keyframes drift {
  0% { transform: translate(0, 0); }
  50% { transform: translate(6px, -8px); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* 声音关闭时隐藏音符 */
[data-muted="1"] .snd-on, [data-muted="0"] .snd-off { display: none; }

/* ---------- 角色选择网格（大厅与游戏页共用） ---------- */
.chargrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 9px;
}
.chargrid__item {
  border: 2.5px solid var(--line);
  background: var(--paper-2);
  border-radius: 16px;
  padding: 8px 6px 9px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform .12s var(--ease), box-shadow .12s;
  box-shadow: var(--shadow-sm);
}
.chargrid__item:hover { transform: translateY(-2px); box-shadow: 4px 5px 0 rgba(43, 33, 27, .14); }
.chargrid__item img { width: 100%; height: 62px; object-fit: contain; }
.chargrid__item b { font-size: 12.5px; }
.chargrid__item span { font-size: 10px; color: var(--ink-2); text-align: center; line-height: 1.25; }
.chargrid__item em { font-style: normal; font-size: 9px; color: var(--ink-3); text-align: center; line-height: 1.25; }
.chargrid__item.is-on { background: var(--red-soft); border-color: var(--red); box-shadow: 0 0 0 3px rgba(200, 22, 30, .12); }
.chargrid__item.is-locked { opacity: .68; }
.chargrid__item.is-locked img { filter: grayscale(.55); }

/* 看起来像链接的按钮 */
.linklike {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-bottom: 1.5px solid currentColor;
}

/* ---------- 彩蛋特效 ---------- */
.egg-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 9999; }
.egg-confetti i {
  position: absolute; width: 8px; height: 8px; background: var(--c);
  border-radius: 2px; animation: egg-fly 1.15s cubic-bezier(.2,.7,.4,1) forwards;
}
@keyframes egg-fly {
  0% { transform: translate(-50%, -50%) scale(.6) rotate(0); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--r)); opacity: 0; }
}
.egg-flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 9998;
  background: radial-gradient(circle at 50% 42%, rgba(255,214,90,.55), rgba(200,22,30,.12) 46%, transparent 70%);
  animation: egg-flash .68s ease-out forwards;
}
@keyframes egg-flash { 0% { opacity: 0; } 22% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .egg-confetti, .egg-flash { display: none; }
}

/* ---------- 命令面板 ⌘K ---------- */
.cp {
  position: fixed; inset: 0; z-index: 9997;
  display: grid; place-items: start center;
  padding-top: min(16vh, 140px);
  opacity: 0; transition: opacity .16s ease;
}
.cp[data-open="1"] { opacity: 1; }
.cp__backdrop {
  position: absolute; inset: 0;
  background: rgba(43, 33, 27, .34);
  backdrop-filter: blur(3px);
}
.cp__panel {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  background: var(--paper);
  border: 2.5px solid var(--line);
  border-radius: 18px;
  box-shadow: 10px 14px 0 rgba(43, 33, 27, .18), 0 24px 60px rgba(43, 33, 27, .18);
  overflow: hidden;
  transform: translateY(-8px) scale(.99);
  transition: transform .18s cubic-bezier(.2, .9, .3, 1.1);
}
.cp[data-open="1"] .cp__panel { transform: none; }
.cp__bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 2px solid var(--paper-4);
  color: var(--ink-3);
}
.cp__input {
  flex: 1; min-width: 0;
  border: 0; outline: none; background: none;
  font: inherit; font-size: 15px; font-weight: 700;
  color: var(--ink);
}
.cp__input::placeholder { color: var(--ink-3); font-weight: 600; }
.cp__kbd {
  font-size: 10px; font-weight: 900; letter-spacing: .1em;
  border: 1.5px solid var(--paper-4); border-radius: 6px;
  padding: 2px 5px; color: var(--ink-3);
}
.cp__list { max-height: min(52vh, 380px); overflow: auto; padding: 6px; }
.cp-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  border: 0; background: none; cursor: pointer;
  padding: 9px 10px; border-radius: 11px;
  color: var(--ink);
}
.cp-item.is-on { background: var(--red-soft); }
.cp-item:hover { background: var(--paper-3, #FBEFE2); }
.cp-no {
  flex: 0 0 auto; width: 26px; text-align: center;
  font-size: 13px; font-weight: 900; color: var(--red);
  font-variant-numeric: tabular-nums;
}
.cp-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cp-body b { font-size: 13.5px; }
.cp-body i { font-style: normal; font-size: 11px; color: var(--ink-3); }
.cp-go { font-size: 11px; color: var(--ink-3); opacity: 0; }
.cp-item.is-on .cp-go { opacity: 1; }
.cp__foot {
  display: flex; gap: 14px;
  padding: 8px 14px; border-top: 2px solid var(--paper-4);
  font-size: 10.5px; color: var(--ink-3); font-weight: 700;
}
.cp-empty { padding: 22px 14px; font-size: 13px; color: var(--ink-3); text-align: center; }

/* 顶栏里的搜索入口 */
.iconbtn--search { width: auto; padding: 0 10px; gap: 6px; }
.iconbtn--search span { font-size: 11px; font-weight: 800; color: var(--ink-3); }

/* ---------- 入场验证（轻量人机） ---------- */
.gate {
  position: fixed; inset: 0; z-index: 9996;
  display: grid; place-items: center;
  background: rgba(43, 33, 27, .42);
  backdrop-filter: blur(6px);
  padding: 20px;
  transition: opacity .38s ease;
}
.gate.is-out { opacity: 0; pointer-events: none; }
.gate__box {
  width: min(360px, 100%);
  background: var(--paper);
  border: 2.5px solid var(--line);
  border-radius: 20px;
  box-shadow: 10px 12px 0 rgba(43, 33, 27, .16);
  padding: 22px 22px 18px;
  text-align: center;
}
.gate__mascot {
  width: 64px; height: 64px; margin: 0 auto 10px;
  display: grid; place-items: center;
  border: 2.5px solid var(--line); border-radius: 50%;
  background: var(--paper-2); font-weight: 900; font-size: 22px;
  color: var(--red);
}
.gate__box h2 { font-size: 19px; margin-bottom: 6px; }
.gate__box p { font-size: 12.5px; color: var(--ink-2); line-height: 1.6; }
.gate__btn {
  position: relative; overflow: hidden;
  width: 100%; margin: 16px 0 10px;
  padding: 13px 16px;
  border: 2.5px solid var(--line); border-radius: 14px;
  background: var(--paper-2);
  font: inherit; font-weight: 900; color: var(--ink);
  cursor: pointer; touch-action: none;
  box-shadow: 3px 4px 0 rgba(43, 33, 27, .16);
}
.gate__btn:active, .gate__btn.is-down { transform: translateY(2px); box-shadow: 1px 2px 0 rgba(43, 33, 27, .16); }
.gate__hold {
  position: absolute; inset: 0; transform-origin: 0 50%; transform: scaleX(0);
  background: rgba(200, 22, 30, .16);
}
.gate__btn b { position: relative; }
.gate__hint { font-size: 11px !important; color: var(--ink-3) !important; }
