/* 公共组件：按钮、卡片、底部弹层、数字键盘、星星、彩带 */

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: var(--fs-body);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
}

.topbar .grow {
  flex: 1 1 auto;
}

.icon-btn {
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  font-size: 26px;
  line-height: 1;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.icon-btn:active {
  background: rgba(0, 0, 0, 0.06);
}

a.icon-btn {
  text-decoration: none;
}

.level-tag {
  font-size: var(--fs-small);
  color: var(--ink-soft);
  white-space: nowrap;
}

/* 大标准牌子 */
.banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 12px 6px;
  padding: 10px 16px;
  border-radius: var(--r-m);
  background: var(--bg-2);
  font-size: var(--fs-q);
  font-weight: 700;
}

/* ---------- 星星 ---------- */
.stars {
  display: inline-flex;
  gap: 2px;
  font-size: 22px;
  line-height: 1;
}

.stars .star {
  color: #d9cdb6;
}

.stars .star.on {
  color: #ffc635;
}

.stars.big {
  font-size: 44px;
  gap: 6px;
}

/* ---------- 按钮 ---------- */
.btn {
  min-height: var(--tap);
  padding: 12px 28px;
  border: 0;
  border-radius: var(--r-l);
  background: var(--bg-2);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-body);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

/* ---------- 遮罩 / 卡片 / 底部弹层 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  background: rgba(40, 30, 15, 0.28);
  animation: fade 0.18s ease-out;
}

.backdrop.center {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.backdrop.bottom {
  align-items: flex-end;
}

.card {
  width: 100%;
  max-width: 420px;
  padding: 24px 20px;
  border-radius: var(--r-l);
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop-in 0.26s cubic-bezier(0.2, 1.4, 0.5, 1);
}

/* 底部弹层打开时，页面底部撑开一个弹层那么高的空间，
   要看的东西就一定在弹层上面。实在放不下时才允许上半部分滑动。 */
.app.sheet-open {
  padding-bottom: calc(var(--sheet-h, 0px) + var(--safe-b));
}

.app.sheet-open .stage {
  overflow-y: auto;
  touch-action: pan-y;
}

.sheet {
  width: 100%;
  padding: 18px 16px calc(18px + var(--safe-b));
  border-radius: var(--r-l) var(--r-l) 0 0;
  background: var(--card);
  box-shadow: var(--shadow);
  animation: rise 0.24s cubic-bezier(0.2, 1.2, 0.5, 1);
}

.card .kicker {
  font-size: var(--fs-small);
  color: var(--ink-soft);
}

.card .emoji {
  font-size: 56px;
  line-height: 1.1;
}

.card .title {
  margin: 4px 0;
  font-size: var(--fs-title);
  font-weight: 800;
}

.card .line {
  margin: 6px 0;
  color: var(--ink-soft);
}

.card .line b {
  color: var(--ink);
}

.card .btn,
.sheet .btn {
  margin-top: 16px;
}

.card .buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

/* 弹层里的问题 */
.sheet-q {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: var(--fs-q);
  font-weight: 700;
  text-align: center;
}

.sheet-hint {
  color: var(--accent);
  font-size: var(--fs-small);
  text-align: center;
}

/* 没提示的时候一点高度都不占，给上面的图多留空间 */
.sheet-hint:not(:empty) {
  min-height: 26px;
  margin-top: 10px;
}

/* ---------- 数字键盘 ---------- */
.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.numpad .num {
  height: var(--tap);
  border: 2px solid var(--line);
  border-radius: var(--r-s);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
}

.numpad .num:active {
  background: var(--bg-2);
}

.numpad .num.ok {
  border-color: var(--ok);
  background: #e4f8ea;
  color: var(--ok);
}

.numpad .num.no {
  border-color: var(--c-red);
  opacity: 0.45;
}

/* ---------- 两位数键盘（乘法的积会到 40，用不了一行 5 个的那种）---------- */
.bignum-display {
  display: grid;
  place-items: center;
  min-height: 58px;
  margin-bottom: 12px;
  border: 3px solid var(--line);
  border-radius: var(--r-m);
  background: #fff;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--ink);
}

.bignum-display.empty {
  color: var(--line);
}

.bignum-display.right {
  border-color: var(--ok);
  background: #e4f8ea;
  color: var(--ok);
}

.numpad.bignum {
  grid-template-columns: repeat(5, 1fr);
}

.bignum-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  margin-top: 8px;
}

.bignum-btn {
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: var(--r-s);
  background: #fff;
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.bignum-btn.go {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.bignum-btn:active {
  transform: translateY(2px);
}

/* ---------- 选择题 ---------- */
/* 74px 是为了让 4 个选项也能排成一行（3 个选项时空轨道会自动合并） */
.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 10px;
}

.choices .choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 96px;
  padding: 10px 6px;
  border: 2px solid var(--line);
  border-radius: var(--r-m);
  background: #fff;
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.choices .choice svg {
  width: 40px;
  height: 46px;
}

/* 选项文字长的时候，一个选项占一整行 */
.choices.rows {
  grid-template-columns: 1fr;
}

.choices.rows .choice {
  flex-direction: row;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  font-size: var(--fs-body);
}

.choices .choice:active {
  background: var(--bg-2);
}

.choices .choice.ok {
  border-color: var(--ok);
  background: #e4f8ea;
}

.choices .choice.no {
  border-color: var(--c-red);
  opacity: 0.45;
}

/* ---------- 小提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + var(--safe-t));
  z-index: 70;
  max-width: 88vw;
  padding: 10px 18px;
  border-radius: var(--r-l);
  background: rgba(59, 50, 38, 0.9);
  color: #fff;
  font-size: var(--fs-small);
  text-align: center;
  transform: translateX(-50%);
  animation: fade 0.2s ease-out;
}

/* ---------- 彩带 ---------- */
.confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -24px;
  width: 10px;
  height: 15px;
  border-radius: 2px;
  animation: fall 1.6s ease-in forwards;
}

/* ---------- 动画 ---------- */
@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
}

@keyframes rise {
  from {
    transform: translateY(100%);
  }
}

@keyframes fall {
  from {
    transform: translateY(0) rotate(var(--r, 0deg));
  }
  to {
    transform: translateY(110vh) rotate(calc(var(--r, 0deg) + 540deg));
    opacity: 0.3;
  }
}

@keyframes shake {
  10%,
  50%,
  90% {
    transform: translateX(-7px);
  }
  30%,
  70% {
    transform: translateX(7px);
  }
}

.shake {
  animation: shake 0.4s ease-in-out;
}

@keyframes bump {
  40% {
    transform: translateY(-10px) scale(1.05);
  }
}

.bump {
  animation: bump 0.36s ease-out;
}

@keyframes pop {
  from {
    transform: scale(0);
  }
  60% {
    transform: scale(1.35);
  }
}

.pop {
  animation: pop 0.32s cubic-bezier(0.2, 1.4, 0.5, 1);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
  }
}
