/* =====================================================================
   数字华容道 · 通用组件
   按钮 / 图标按钮 / 弹窗 / 庆祝 / 吐司 / 撒花
   ===================================================================== */

/* —— 主按钮 —— */
.btn {
  --btn-bg: var(--pumpkin);
  --btn-deep: var(--pumpkin-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  font-family: var(--font-hand);
  font-size: var(--fs-md);
  font-weight: 700;
  color: #fff;
  background: var(--btn-bg);
  border: 3px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: 0 5px 0 var(--btn-deep), 0 7px 0 var(--ink), var(--shadow-soft);
  transition: transform var(--dur-fast) var(--ease-bounce),
              box-shadow var(--dur-fast) var(--ease-bounce);
  user-select: none;
  -webkit-user-select: none;
  min-height: 54px;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
  touch-action: manipulation;
}
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--btn-deep), 0 2px 0 var(--ink), var(--shadow-press);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn--primary { --btn-bg: var(--pumpkin); --btn-deep: var(--pumpkin-deep); }
.btn--mint    { --btn-bg: var(--mint-deep); --btn-deep: #5DAE7E; }
.btn--sky     { --btn-bg: var(--sky-deep); --btn-deep: #5A95C9; }
.btn--cherry  { --btn-bg: var(--cherry-deep); --btn-deep: #D47688; }
.btn--sunny   { --btn-bg: var(--sunny-deep); --btn-deep: #C9A91F; color: var(--ink); text-shadow: none; }
.btn--ghost {
  background: var(--paper);
  color: var(--ink);
  --btn-deep: var(--paper-deep);
  text-shadow: none;
}
.btn--lg { padding: 18px 40px; font-size: var(--fs-lg); min-height: 66px; border-radius: var(--r-lg); }
.btn--block { width: 100%; }
.btn svg { width: 1.15em; height: 1.15em; flex-shrink: 0; }

@media (hover: hover) {
  .btn:hover { transform: translateY(-2px); }
  .btn:active { transform: translateY(4px); }
}

/* —— 图标按钮 —— */
.icon-btn {
  width: 50px;
  height: 50px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--paper-deep), 0 5px 0 var(--ink);
  transition: transform var(--dur-fast) var(--ease-bounce), box-shadow var(--dur-fast);
  color: var(--ink);
  touch-action: manipulation;
}
.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--paper-deep), 0 2px 0 var(--ink);
}
.icon-btn svg { width: 25px; height: 25px; }
@media (hover: hover) {
  .icon-btn:hover { transform: translateY(-2px) rotate(-3deg); }
}

/* 音效 / 全屏 图标按状态切换 */
#soundBtn .icon-sound-off { display: none; }
#soundBtn.is-muted .icon-sound-on { display: none; }
#soundBtn.is-muted .icon-sound-off { display: block; }
#soundBtn.is-muted { color: var(--ink-faint); }

#fullBtn .icon-full-off { display: none; }
#fullBtn.is-fullscreen .icon-full-on { display: none; }
#fullBtn.is-fullscreen .icon-full-off { display: block; }
#fullBtn.is-fullscreen { background: var(--sunny); }

/* —— 徽章 —— */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  background: var(--paper);
  box-shadow: 0 3px 0 var(--ink);
  white-space: nowrap;
}
.chip[data-difficulty] { background: var(--diff); }

/* —— 分段控制（难度切换） —— */
.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--paper-warm);
  border: 3px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: inset 0 3px 0 rgba(90, 74, 58, 0.06);
}
.seg__btn {
  min-height: 44px;
  padding: 4px 6px;
  border: 2.5px solid transparent;
  border-radius: 8px;
  font-family: var(--font-num);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--ink-soft);
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
  touch-action: manipulation;
}
.seg__btn[aria-checked="true"] {
  background: var(--diff);
  border-color: var(--ink);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  transform: translateY(-1px);
}
@media (hover: hover) {
  .seg__btn:not([aria-checked="true"]):hover { background: rgba(90, 74, 58, 0.07); color: var(--ink); }
}

/* —— 提示文字 —— */
.hint {
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.7;
}
.hint__kbd { color: var(--ink-faint); font-size: 0.92em; }
.fineprint {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--ink-faint);
}
@media (hover: none) {
  .hint__kbd { display: none; }
}

/* —— 弹窗 —— */
body.is-modal-open { overflow: hidden; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(90, 74, 58, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 900;
  padding: var(--sp-4);
  padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom));
  animation: fadeIn var(--dur) var(--ease-soft) both;
  overscroll-behavior: contain;
  overflow-y: auto;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  width: min(460px, 100%);
  margin: auto;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--r-xl);
  box-shadow: 0 10px 0 var(--paper-deep), 0 12px 0 var(--ink), 0 30px 50px rgba(90, 74, 58, 0.3);
  padding: var(--sp-5) var(--sp-4) var(--sp-4);
  animation: modalPop var(--dur) var(--ease-bounce) both;
}
@keyframes modalPop {
  from { transform: translateY(30px) scale(0.9); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal__close {
  position: absolute;
  top: -16px;
  right: -16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--cherry-deep);
  color: #fff;
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
.modal__close:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.modal__title {
  font-family: var(--font-hand);
  font-size: var(--fs-xl);
  text-align: center;
  margin-bottom: var(--sp-3);
}
.modal__text {
  text-align: center;
  color: var(--ink-soft);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-3);
}

/* —— 庆祝弹窗 —— */
.celeb {
  width: min(430px, 100%);
  text-align: center;
  padding-top: var(--sp-4);
}
.celeb__stars {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: var(--sp-2);
}
.celeb__star {
  font-size: clamp(42px, 10vw, 56px);
  line-height: 1;
  color: var(--paper-deep);
  text-shadow: 0 3px 0 var(--ink);
  transform-origin: center;
}
.celeb__star.is-on {
  color: var(--star);
  filter: drop-shadow(0 0 8px rgba(245, 200, 66, 0.6));
}
.celeb__stats {
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
  margin-top: var(--sp-2);
  flex-wrap: wrap;
}
.celeb__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--paper-warm);
  border: 3px solid var(--ink);
  border-radius: var(--r-sm);
  box-shadow: 0 3px 0 var(--paper-deep), 0 4px 0 var(--ink);
  min-width: 100px;
}
.celeb__stat span { font-size: var(--fs-xs); color: var(--ink-soft); }
.celeb__stat b { font-size: var(--fs-md); color: var(--pumpkin-deep); font-family: var(--font-num); }
.celeb__record {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--sp-3);
  padding: 4px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--sunny);
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  box-shadow: 0 3px 0 var(--ink);
  animation: recordPop 0.6s var(--ease-bounce) both;
}
@keyframes recordPop {
  0% { transform: scale(0.6) rotate(-4deg); opacity: 0; }
  60% { transform: scale(1.08) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.celeb__actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--sp-4);
}
.celeb__actions .btn { flex: 1 1 140px; }

/* —— 玩法说明 —— */
.help-section { margin-bottom: var(--sp-3); }
.help-section:last-child { margin-bottom: 0; }
.help-section h3 {
  font-size: var(--fs-md);
  color: var(--pumpkin-deep);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.help-section p,
.help-section li {
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  line-height: 1.7;
}
.help-section ul { margin: 0; padding-left: 1.2em; }
.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-xs);
  margin-top: 4px;
}
.help-table th,
.help-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1.5px dashed var(--paper-deep);
  color: var(--ink-soft);
}
.help-table th { font-family: var(--font-hand); color: var(--ink); }
.help-table td:last-child { text-align: right; font-family: var(--font-num); }

/* —— 吐司提示 —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 1100;
  transform: translate(-50%, 20px);
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 20px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 var(--paper-deep), 0 5px 0 var(--ink), var(--shadow-soft);
  font-family: var(--font-hand);
  font-size: var(--fs-sm);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast), transform var(--dur-fast) var(--ease-bounce);
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* —— 撒花 —— */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  animation: confettiFall var(--dur-slow) linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0.9; }
}

/* —— 抖动 —— */
.shake { animation: shake 0.4s var(--ease-soft); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

/* —— 视图进入 —— */
.view-enter { animation: viewIn var(--dur) var(--ease-bounce) both; }
@keyframes viewIn {
  0%   { opacity: 0; transform: translateY(14px) scale(0.985); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* —— 无脚本提示 —— */
.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--paper);
  z-index: 9999;
  font-family: var(--font-hand);
}

/* =====================================================================
   矮屏弹窗：庆祝 / 帮助在小高度窗口里保持紧凑，按钮不被推到屏幕外
   ===================================================================== */

@media (max-height: 560px) {
  .modal { padding: 22px 20px 16px; border-radius: 26px; }
  .modal__title { font-size: clamp(22px, 4vh, 30px); margin-bottom: 10px; }
  .modal__text { font-size: 13px; margin-bottom: 8px; }
  .modal__close { width: 38px; height: 38px; font-size: 18px; top: -12px; right: -12px; }

  .celeb { padding-top: 4px; }
  .celeb__stars { gap: 8px; margin-bottom: 4px; }
  .celeb__star { font-size: 38px; }
  .celeb__stats { margin-top: 6px; gap: 8px; }
  .celeb__stat { padding: 6px 10px; min-width: 86px; }
  .celeb__stat span { font-size: 11px; }
  .celeb__stat b { font-size: 14px; }
  .celeb__record { margin-top: 8px; padding: 2px 10px; font-size: 13px; }
  .celeb__actions { margin-top: 12px; gap: 8px; }
  .celeb__actions .btn { min-height: 44px; padding: 8px 12px; font-size: 16px; }

  .help-section { margin-bottom: 10px; }
  .help-section h3 { font-size: 15px; }
  .help-section p,
  .help-section li { font-size: 13px; line-height: 1.55; }
  .help-table { font-size: 11px; }
}

/* 手机上的庆祝弹窗：三项成绩与两个按钮尽量保持单行，减少纵向压迫 */
@media (max-width: 520px) {
  .celeb { padding-top: 6px; }
  .celeb__stats { gap: 8px; }
  .celeb__stat { flex: 1 1 0; min-width: 0; padding: 8px 6px; }
  .celeb__stat span { font-size: 11px; }
  .celeb__stat b { font-size: 13px; line-height: 1.25; }
  .celeb__actions { gap: 8px; }
  .celeb__actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 8px;
    font-size: var(--fs-md);
    gap: 4px;
  }
}
