/* ============================================================
   幸运数字机 · 卡通风格随机数抽号
   版式：单列，屏幕是主角（占满宽度、尽量高），历史记录是一条窄条
   ============================================================ */

@font-face {
  font-family: 'Baloo2';
  src: url('fonts/baloo2-800.woff2') format('woff2');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* 卡通描边色 */
  --ink: #20304f;
  --ink-soft: #42557f;

  /* 天空与草地 */
  --sky-1: #7ed2ff;
  --sky-2: #d9f4ff;
  --sky-3: #eafbff;
  --grass-1: #a8eab0;
  --grass-2: #7ddb92;

  /* 奶油卡片 */
  --cream: #fffcee;
  --cream-2: #fff2cd;

  /* 主题色 */
  --yellow: #ffd84d;
  --yellow-2: #ffb01f;
  --pink: #ff77a9;
  --teal: #3fd6c2;
  --purple: #a98bff;
  --orange: #ff9f45;

  /* 屏幕 */
  --screen-1: #2c3768;
  --screen-2: #161d3d;
  --num: #ffef9a;

  --radius: 30px;
  --bw: 4px;
  --hard: 0 9px 0 var(--ink);
  --soft: 0 18px 32px rgba(32, 48, 79, .16);

  --font: 'Baloo2', 'PingFang SC', 'HarmonyOS Sans SC', 'MiSans', 'Microsoft YaHei',
    'Noto Sans SC', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 46%, var(--sky-3) 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

:focus-visible {
  outline: 4px solid var(--purple);
  outline-offset: 3px;
}

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

/* ============================================================
   背景
   ============================================================ */

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.sun {
  position: absolute;
  top: -40px;
  right: -34px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #fff6b8 0%, var(--yellow) 48%, var(--orange) 100%);
  border: var(--bw) solid var(--ink);
  box-shadow: 0 7px 0 rgba(32, 48, 79, .18);
}

.sun::after {
  content: '';
  position: absolute;
  inset: -24px;
  border-radius: 50%;
  border: 8px dashed rgba(255, 216, 77, .85);
  animation: spin 44s linear infinite;
}

.cloud {
  position: absolute;
  width: 168px;
  height: auto;
  fill: #ffffff;
  stroke: var(--ink);
  stroke-width: 6;
  stroke-linejoin: round;
  opacity: .96;
  filter: drop-shadow(0 8px 0 rgba(32, 48, 79, .08));
}

.cloud--1 { top: 9%;  left: -26px; width: 132px; animation: drift 26s ease-in-out infinite; }
.cloud--2 { top: 22%; right: -34px; width: 108px; animation: drift 34s ease-in-out infinite reverse; }
.cloud--3 { top: 44%; left: -52px; width: 96px; opacity: .72; animation: drift 40s ease-in-out infinite; }

.hill {
  position: absolute;
  left: -10%;
  width: 120%;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}

.hill--back {
  bottom: 1%;
  height: min(13vh, 132px);
  background: var(--grass-1);
  border-top: var(--bw) solid var(--ink);
  border-radius: 48% 52% 0 0 / 100% 100% 0 0;
  opacity: .95;
}

.hill--front {
  bottom: -9%;
  height: min(11vh, 110px);
  background: var(--grass-2);
  border-top: var(--bw) solid var(--ink);
  border-radius: 58% 42% 0 0 / 100% 100% 0 0;
}

/* ============================================================
   页面骨架：顶栏 · 抽号机（居中） · 记录条（贴底）
   ============================================================ */

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  min-height: 100vh;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top, 0px) + 10px)
    calc(env(safe-area-inset-right, 0px) + 12px)
    calc(env(safe-area-inset-bottom, 0px) + 12px)
    calc(env(safe-area-inset-left, 0px) + 12px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: clamp(17px, 4.6vw, 22px);
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  text-shadow:
    0 2px 0 var(--ink),
    0 3px 0 var(--ink),
    2px 2px 0 var(--ink),
    -2px 2px 0 var(--ink),
    0 8px 14px rgba(32, 48, 79, .22);
}

.brand-emoji {
  font-size: 1.1em;
  filter: drop-shadow(0 2px 2px rgba(32, 48, 79, .25));
  animation: wiggle 3.6s ease-in-out infinite;
}

.sound-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 5px 0 var(--ink);
  font-size: 19px;
  line-height: 1;
  transition: transform .12s ease, box-shadow .12s ease, background .18s ease;
}

.sound-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.sound-btn[aria-pressed="false"] { background: #ffe1e9; }
.sound-ico { display: block; transform: translateY(-1px); }

/* ============================================================
   抽号机
   ============================================================ */

.machine {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
  width: 100%;
  margin: auto 0;            /* 上下自动留白 → 机器居中，顶栏贴顶、记录条贴底 */
  padding: 14px 13px 14px;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-2) 100%);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--hard), var(--soft);
}

.antenna {
  position: absolute;
  top: -26px;
  left: 50%;
  width: 8px;
  height: 26px;
  margin-left: -4px;
  background: var(--ink);
  border-radius: 6px;
}

.antenna::after {
  content: '';
  position: absolute;
  top: -18px;
  left: 50%;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff8cf, var(--pink) 72%);
  border: var(--bw) solid var(--ink);
  transform-origin: 50% 130%;
  animation: swing 2.8s ease-in-out infinite;
}

/* ---- 屏幕：整个页面的主角 ---- */
.screen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: clamp(250px, 43vh, 440px);
  padding: 18px 12px 42px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(124, 146, 255, .34) 0%, rgba(124, 146, 255, 0) 62%),
    linear-gradient(180deg, var(--screen-1) 0%, var(--screen-2) 100%);
  border: var(--bw) solid var(--ink);
  border-radius: 26px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .28), inset 0 8px 18px rgba(0, 0, 0, .32);
  overflow: hidden;
  container-type: size;
}

.glare {
  position: absolute;
  top: -30%;
  left: -10%;
  width: 62%;
  height: 90%;
  background: linear-gradient(150deg, rgba(255, 255, 255, .17), rgba(255, 255, 255, 0));
  border-radius: 50%;
  transform: rotate(-16deg);
  pointer-events: none;
}

.bolt {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .3);
  border: 2px solid rgba(255, 255, 255, .45);
}

.bolt--tl { top: 9px; left: 10px; }
.bolt--tr { top: 9px; right: 10px; }
.bolt--bl { bottom: 9px; left: 10px; }
.bolt--br { bottom: 9px; right: 10px; }

.number {
  position: relative;
  z-index: 1;
  font-family: var(--font);
  font-weight: 800;
  font-size: clamp(88px, 28vh, 190px);   /* 不支持容器查询时的兜底 */
  line-height: .9;
  letter-spacing: -.02em;
  white-space: nowrap;
  color: var(--num);
  text-shadow:
    0 5px 0 rgba(0, 0, 0, .42),
    0 0 34px rgba(255, 226, 120, .55);
  transform-origin: 50% 60%;
  transition: color .2s ease;
}

.number[data-len="3"] { font-size: clamp(64px, 20vh, 140px); }
.number[data-len="1"] { padding-left: .04em; }

@supports (container-type: size) {
  /* 按屏幕自身的尺寸缩放：竖屏手机也能占满大半个屏幕 */
  .number { font-size: min(70cqh, 70cqw); }
  .number[data-len="3"] { font-size: min(50cqh, 46cqw); }
}

.number.is-idle { animation: float 3.2s ease-in-out infinite; }

.number.is-rolling {
  animation: jitter .09s steps(2, end) infinite;
  filter: blur(.6px);
}

.number.is-landed { animation: land .66s cubic-bezier(.22, 1.42, .36, 1); }

.screen.is-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 55%, rgba(255, 238, 150, .55), rgba(255, 238, 150, 0) 68%);
  animation: flash .7s ease-out forwards;
  pointer-events: none;
}

/* 英文数字（抽中后出现，和发音同步） */
.en {
  position: relative;
  z-index: 1;
  margin: 0;
  min-height: 1.1em;
  font-size: clamp(13px, 3.4vh, 26px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: .04em;
  color: #ffe6a0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .38);
  opacity: .92;
  transition: opacity .2s ease;
}

.en:empty { opacity: 0; }

@supports (container-type: size) {
  .en { font-size: max(12px, min(7.4cqh, 9cqw)); }
}

.pill {
  padding: 2px 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  background: #fff3cf;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .3);
  white-space: nowrap;
}

.pill b { font-size: 1.16em; color: var(--pink); }

.pill--remain {
  position: absolute;
  left: 50%;
  bottom: 10px;
  z-index: 1;
  transform: translateX(-50%);
}

/* ---- 抽号按钮 ---- */
.draw {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 12px 22px;
  font-size: clamp(20px, 5.4vw, 26px);
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffe680 0%, var(--yellow) 42%, var(--yellow-2) 100%);
  border: var(--bw) solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 9px 0 var(--ink), 0 16px 22px rgba(32, 48, 79, .2);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.draw:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 11px 0 var(--ink), 0 18px 24px rgba(32, 48, 79, .22); }

.draw:active:not(:disabled) {
  transform: translateY(6px);
  box-shadow: 0 3px 0 var(--ink), 0 6px 12px rgba(32, 48, 79, .18);
}

.draw:disabled {
  cursor: not-allowed;
  filter: grayscale(.55) brightness(1.03);
  box-shadow: 0 9px 0 var(--ink);
}

.draw.is-busy { cursor: progress; }
.draw.is-busy:disabled { filter: none; cursor: progress; }

.draw-face {
  position: relative;
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding-bottom: 4px;
}

.draw-face .eye {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
  animation: blink 4.4s ease-in-out infinite;
}

.draw-face .mouth {
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 13px;
  height: 7px;
  margin-left: -6.5px;
  border: 3px solid var(--ink);
  border-top: none;
  border-radius: 0 0 12px 12px;
}

.draw.is-busy .draw-face .mouth {
  width: 10px;
  height: 10px;
  border: 3px solid var(--ink);
  border-radius: 50%;
}

.machine.is-shaking { animation: shake .5s cubic-bezier(.36, .07, .19, .97); }

/* ============================================================
   记录条
   ============================================================ */

.history {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 11px 11px;
  background: var(--cream);
  border: var(--bw) solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink), 0 12px 20px rgba(32, 48, 79, .14);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .5px;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  vertical-align: middle;
  font-size: 14px;
  color: var(--ink);
  background: var(--teal);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
}

.reset {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, background .18s ease;
}

.reset:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.reset.is-armed {
  color: #fff;
  background: var(--pink);
  animation: bob .7s ease-in-out infinite;
}

.reset:disabled {
  color: rgba(32, 48, 79, .42);
  background: #f1eee3;
  box-shadow: 0 3px 0 rgba(32, 48, 79, .28);
  cursor: default;
}

.chips {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 1px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 46px;
  padding: 0 6px;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  animation: chipPop .4s cubic-bezier(.34, 1.56, .64, 1) both;
}

.chip--new {
  position: relative;
  animation: chipPop .46s cubic-bezier(.34, 1.56, .64, 1) both, glow 1.1s ease-out .1s both;
}

/* 三位数（100）缩小一点字号，保持和其他号码一样是方形小方块 */
.chip[data-len="3"] {
  font-size: 16px;
  padding: 0 3px;
}

/* ============================================================
   Toast / 彩带
   ============================================================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  z-index: 60;
  max-width: min(88vw, 400px);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--ink);
  transform: translate(-50%, 160%);
  opacity: 0;
  pointer-events: none;
  transition: transform .34s cubic-bezier(.34, 1.4, .64, 1), opacity .22s ease;
}

.toast.is-show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 55;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ============================================================
   动画
   ============================================================ */

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(26px, -12px, 0); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-9px) rotate(1.5deg); }
}

@keyframes swing {
  0%, 100% { transform: rotate(-9deg); }
  50% { transform: rotate(9deg); }
}

@keyframes wiggle {
  0%, 88%, 100% { transform: rotate(0); }
  91% { transform: rotate(-11deg); }
  95% { transform: rotate(9deg); }
}

@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(.12); }
}

@keyframes jitter {
  0% { transform: translate(-3px, 2px) rotate(-1.6deg) scale(1.02); }
  50% { transform: translate(3px, -2px) rotate(1.6deg) scale(.98); }
  100% { transform: translate(-2px, -1px) rotate(-1deg) scale(1.01); }
}

@keyframes land {
  0% { transform: scale(.55) rotate(-8deg); }
  46% { transform: scale(1.22) rotate(4deg); }
  70% { transform: scale(.94) rotate(-2deg); }
  86% { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes flash {
  0% { opacity: 0; }
  22% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px) rotate(-.5deg); }
  20%, 80% { transform: translateX(4px) rotate(.7deg); }
  30%, 50%, 70% { transform: translateX(-6px) rotate(-.9deg); }
  40%, 60% { transform: translateX(6px) rotate(.9deg); }
}

@keyframes chipPop {
  0% { transform: scale(.3) rotate(-14deg); opacity: 0; }
  70% { transform: scale(1.12) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes glow {
  0% { box-shadow: 0 4px 0 var(--ink), 0 0 0 0 rgba(255, 216, 77, .9); }
  100% { box-shadow: 0 4px 0 var(--ink), 0 0 0 16px rgba(255, 216, 77, 0); }
}

/* ============================================================
   响应式
   ============================================================ */

/* 矮一点的手机：压缩留白，屏幕仍然尽量大 */
@media (max-height: 700px) {
  .stage { gap: 8px; }
  .machine { gap: 9px; padding: 11px 11px 11px; }
  .screen { height: clamp(215px, 40vh, 330px); padding: 14px 10px 36px; }
  .draw { min-height: 56px; }
  .chips { min-height: 42px; }
  .chip { min-width: 42px; height: 42px; font-size: 18px; }
  .brand { font-size: 16px; }
}

/* 平板 / 桌面：更宽的机器 → 更大的屏幕 */
@media (min-width: 700px) {
  .stage {
    max-width: 720px;
    padding: 22px 24px 20px;
    gap: 14px;
  }
  .machine { padding: 18px 18px 18px; gap: 14px; }
  .screen { height: clamp(320px, 46vh, 500px); padding: 22px 16px 46px; border-radius: 30px; }
  .draw { min-height: 74px; font-size: 28px; }
  .history { padding: 10px 14px 12px; border-radius: 24px; }
  .history-head h2 { font-size: 16px; }
  .chips { min-height: 52px; }
  .chip { min-width: 52px; height: 52px; font-size: 22px; border-radius: 16px; }
  .reset { font-size: 13px; padding: 5px 14px; }
}

@media (min-width: 1100px) {
  .stage { max-width: 840px; }
  .screen { height: clamp(360px, 50vh, 540px); }
}

/* 横屏（矮屏）：压缩道具、屏幕仍然要够大 */
@media (max-height: 540px) and (orientation: landscape) {
  .stage {
    max-width: 880px;
    padding: 4px 14px 6px;
    gap: 6px;
  }
  .topbar { padding: 0; }
  .brand { font-size: 15px; }
  .sound-btn { width: 32px; height: 32px; font-size: 14px; }
  .machine { padding: 6px 10px; gap: 6px; margin: 0; }
  .antenna { display: none; }
  .screen { height: clamp(150px, 42vh, 230px); padding: 8px 10px 30px; border-radius: 20px; }
  .en { font-size: 15px; }
  .pill--remain { bottom: 6px; font-size: 11px; padding: 1px 9px; }
  .draw { min-height: 46px; padding: 6px 16px; font-size: 19px; }
  .history { padding: 4px 10px 6px; gap: 3px; border-radius: 18px; }
  .history-head h2 { font-size: 12px; }
  .count { min-width: 22px; height: 22px; font-size: 12px; }
  .reset { font-size: 11px; padding: 3px 10px; }
  .chips { min-height: 38px; }
  .chip { min-width: 38px; height: 38px; font-size: 16px; border-radius: 12px; }
}

/* 尊重系统的减少动态效果设置 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
