* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #020617;
  --card: rgba(15, 23, 42, 0.84);
  --card-strong: rgba(2, 8, 23, 0.94);
  --border: rgba(148, 163, 184, 0.22);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --soft: #94a3b8;
  --blue: #38bdf8;
  --cyan: #22d3ee;
  --green: #22c55e;
  --orange: #fb923c;
  --purple: #a855f7;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: manipulation;
  color: var(--text);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 10% 10%, rgba(56, 189, 248, 0.24), transparent 28%),
    radial-gradient(circle at 90% 18%, rgba(168, 85, 247, 0.18), transparent 30%),
    radial-gradient(circle at 50% 100%, rgba(34, 197, 94, 0.14), transparent 30%),
    linear-gradient(180deg, #020617 0%, #0f172a 100%);
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.page {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 900;
  background: linear-gradient(135deg, #38bdf8, #2563eb, #a855f7);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.35);
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.brand em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.back-link,
.small-action {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-radius: 999px;
  color: #e0f2fe;
  font-weight: 900;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(125, 211, 252, 0.26);
}

.game-shell {
  display: grid;
  gap: 18px;
}

.hero-card,
.play-card,
.tips-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 28px;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.16), transparent 36%),
    linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(2, 8, 23, 0.96));
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 30px;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -70px;
  top: -90px;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  background: #38bdf8;
  opacity: 0.22;
  filter: blur(5px);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 10px;
  color: #7dd3fc;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(40px, 8vw, 72px);
  line-height: 1.05;
  letter-spacing: 1px;
}

.intro {
  max-width: 640px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

.score-board {
  position: relative;
  z-index: 1;
  min-width: 220px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.score-board div {
  padding: 16px 12px;
  border-radius: 20px;
  text-align: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.score-board span {
  display: block;
  color: #fff;
  font-size: 34px;
  font-weight: 900;
}

.score-board small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.play-card {
  padding: 24px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  color: #f8fafc;
  font-size: 22px;
  font-weight: 900;
}

.small-action {
  min-height: 38px;
  cursor: pointer;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.number-card {
  min-height: 104px;
  border: 1px solid rgba(125, 211, 252, 0.42);
  border-radius: 24px;
  color: #fff;
  font-size: clamp(34px, 10vw, 54px);
  font-weight: 900;
  cursor: pointer;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.58), rgba(14, 165, 233, 0.28)),
    rgba(15, 23, 42, 0.92);
  box-shadow: 0 0 22px rgba(56, 189, 248, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.number-card:active,
.operator-grid button:active,
.action-grid button:active,
.small-action:active {
  transform: translateY(1px) scale(0.99);
}

.number-card.used {
  cursor: not-allowed;
  color: rgba(226, 232, 240, 0.42);
  border-color: rgba(148, 163, 184, 0.14);
  background: rgba(51, 65, 85, 0.42);
  box-shadow: none;
}

.expression-panel {
  padding: 16px;
  border-radius: 22px;
  background: rgba(2, 6, 23, 0.44);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.expression-label {
  margin-bottom: 8px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 900;
}

.expression-box {
  min-height: 54px;
  display: flex;
  align-items: center;
  overflow-wrap: anywhere;
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.35;
}

.expression-box.empty {
  color: rgba(203, 213, 225, 0.62);
  font-size: 18px;
  font-weight: 700;
}

.operator-grid,
.action-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.operator-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.operator-grid button,
.action-grid button {
  min-height: 58px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 18px;
  color: #f8fafc;
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.07);
}

.operator-grid button {
  color: #e0f2fe;
  border-color: rgba(125, 211, 252, 0.28);
}

.action-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.action-grid button {
  font-size: 17px;
}

.action-grid .primary {
  color: #022c22;
  background: linear-gradient(135deg, #86efac, #22d3ee);
  border-color: rgba(134, 239, 172, 0.6);
}

.message,
.answer-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 18px;
  color: var(--muted);
  line-height: 1.6;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.message:empty {
  display: none;
}

.message.success {
  color: #dcfce7;
  border-color: rgba(34, 197, 94, 0.5);
  background: rgba(34, 197, 94, 0.14);
}

.message.warn {
  color: #ffedd5;
  border-color: rgba(251, 146, 60, 0.5);
  background: rgba(251, 146, 60, 0.14);
}

.message.error {
  color: #fee2e2;
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.14);
}

.answer-box strong {
  color: #7dd3fc;
}

.tips-card {
  padding: 20px 24px;
}

.tips-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.tips-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.win-modal[hidden] {
  display: none;
}

.win-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.win-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(8px);
}

.win-dialog {
  position: relative;
  width: min(420px, 100%);
  overflow: hidden;
  padding: 34px 24px 24px;
  border-radius: 30px;
  text-align: center;
  border: 1px solid rgba(125, 211, 252, 0.42);
  background:
    radial-gradient(circle at 18% 18%, rgba(34, 197, 94, 0.34), transparent 28%),
    radial-gradient(circle at 82% 22%, rgba(56, 189, 248, 0.34), transparent 30%),
    radial-gradient(circle at 50% 100%, rgba(168, 85, 247, 0.28), transparent 34%),
    linear-gradient(135deg, rgba(15, 23, 42, 0.98), rgba(2, 8, 23, 0.98));
  box-shadow:
    0 0 42px rgba(56, 189, 248, 0.36),
    0 28px 80px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
  animation: winPop 0.42s cubic-bezier(0.2, 1.4, 0.35, 1) both;
}

.win-badge {
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 999px;
  color: #022c22;
  font-size: 34px;
  font-weight: 900;
  background: linear-gradient(135deg, #bbf7d0, #67e8f9, #c4b5fd);
  box-shadow: 0 0 26px rgba(125, 211, 252, 0.62);
}

.win-dialog h2 {
  position: relative;
  margin: 0;
  font-size: 30px;
  color: #fff;
}

.win-dialog p {
  position: relative;
  margin: 10px 0 20px;
  color: var(--muted);
  line-height: 1.6;
}

.win-dialog button:not(.win-close) {
  position: relative;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 18px;
  color: #022c22;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  background: linear-gradient(135deg, #86efac, #22d3ee);
  box-shadow: 0 16px 32px rgba(34, 211, 238, 0.22);
}

.win-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: #e2e8f0;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
}

.sparkles span {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #fef08a;
  box-shadow: 0 0 18px currentColor;
  animation: sparkle 1.15s ease-in-out infinite;
}

.sparkles span:nth-child(1) { left: 16%; top: 18%; color: #fef08a; animation-delay: 0s; }
.sparkles span:nth-child(2) { left: 82%; top: 20%; color: #7dd3fc; animation-delay: .12s; }
.sparkles span:nth-child(3) { left: 22%; top: 78%; color: #86efac; animation-delay: .24s; }
.sparkles span:nth-child(4) { left: 74%; top: 72%; color: #c4b5fd; animation-delay: .36s; }
.sparkles span:nth-child(5) { left: 48%; top: 12%; color: #f0abfc; animation-delay: .48s; }
.sparkles span:nth-child(6) { left: 50%; top: 86%; color: #67e8f9; animation-delay: .6s; }

@keyframes winPop {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes sparkle {
  0%, 100% {
    opacity: .35;
    transform: scale(.75);
  }
  50% {
    opacity: 1;
    transform: scale(1.35);
  }
}

@media (max-width: 760px) {
  .page {
    width: min(100% - 18px, 1120px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand strong {
    font-size: 18px;
  }

  .back-link {
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
    white-space: nowrap;
  }

  .hero-card {
    display: block;
    padding: 24px 20px;
    border-radius: 24px;
  }

  .intro {
    font-size: 15px;
  }

  .score-board {
    width: 100%;
    min-width: 0;
    margin-top: 18px;
  }

  .play-card {
    padding: 18px;
    border-radius: 24px;
  }

  .section-head {
    font-size: 20px;
  }

  .number-grid {
    gap: 10px;
  }

  .number-card {
    min-height: 82px;
    border-radius: 20px;
  }

  .operator-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .operator-grid button,
  .action-grid button {
    min-height: 56px;
  }

  .action-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .expression-box {
    font-size: 21px;
  }

  .win-dialog {
    border-radius: 26px;
    padding: 30px 20px 22px;
  }

  .win-dialog h2 {
    font-size: 26px;
  }
}

@media (max-width: 380px) {
  .number-card {
    min-height: 74px;
    border-radius: 18px;
  }

  .action-grid button {
    font-size: 15px;
  }
}
