:root {
  color-scheme: light;
  --ink: #233043;
  --muted: #66738a;
  --paper: #fffaf1;
  --panel: #ffffff;
  --line: #d7deea;
  --blue: #2864d8;
  --blue-dark: #184bb0;
  --green: #1f9b6d;
  --pink: #e25382;
  --yellow: #f5b82e;
  --shadow: 0 20px 45px rgba(49, 65, 96, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(245, 184, 46, 0.24), transparent 28rem),
    radial-gradient(circle at 86% 18%, rgba(40, 100, 216, 0.16), transparent 24rem),
    linear-gradient(135deg, #f8fbff 0%, #fff4e0 100%);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  width: min(1180px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  align-items: stretch;
}

.play-area,
.side-panel {
  border: 1px solid rgba(215, 222, 234, 0.84);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.play-area {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 28px;
  border-radius: 8px;
}

.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.score-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(86px, 1fr));
  gap: 10px;
  flex: 0 0 auto;
}

.score-board div {
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: center;
}

.score-board span {
  display: block;
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1.1;
}

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

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.difficulty-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill,
.icon-button,
.secondary,
.primary-action,
.operators button {
  min-height: 44px;
  border-radius: 8px;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.pill {
  padding: 0 18px;
  background: #eef3ff;
  color: var(--blue-dark);
  font-weight: 900;
}

.pill.active {
  background: var(--blue);
  color: white;
  box-shadow: 0 10px 22px rgba(40, 100, 216, 0.24);
}

.icon-button {
  width: 48px;
  background: var(--ink);
  color: white;
  font-size: 1.65rem;
  line-height: 1;
}

.cards-panel {
  display: grid;
  place-items: center;
  min-height: 250px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(40, 100, 216, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(40, 100, 216, 0.08) 1px, transparent 1px),
    #f9fbff;
  background-size: 28px 28px;
  border: 1px solid var(--line);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(88px, 132px));
  gap: 14px;
  width: min(100%, 590px);
  padding: 22px;
}

.number-card {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 5;
  border: 3px solid #1f2f4a;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(255, 250, 241, 0.94)),
    var(--panel);
  color: var(--ink);
  box-shadow: 0 14px 26px rgba(35, 48, 67, 0.16);
  font-size: clamp(2rem, 7vw, 4.8rem);
  font-weight: 950;
}

.number-card::before,
.number-card::after {
  position: absolute;
  color: var(--pink);
  font-size: 1.1rem;
  content: "24";
}

.number-card::before {
  top: 10px;
  left: 10px;
}

.number-card::after {
  right: 10px;
  bottom: 10px;
  transform: rotate(180deg);
}

.number-card.selected {
  border-color: var(--yellow);
  transform: translateY(-8px) rotate(-1deg);
  box-shadow: 0 18px 34px rgba(245, 184, 46, 0.34);
}

.number-card.used {
  opacity: 0.42;
  transform: scale(0.96);
  cursor: not-allowed;
}

.workbench {
  display: grid;
  gap: 14px;
}

.expression-panel {
  display: grid;
  gap: 8px;
  min-height: 90px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

#expression {
  overflow-wrap: anywhere;
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 900;
}

.operators {
  display: grid;
  grid-template-columns: repeat(4, minmax(58px, 1fr));
  gap: 10px;
}

.operators button {
  background: var(--ink);
  color: white;
  font-size: 1.9rem;
  font-weight: 900;
}

.operators button.active {
  background: var(--green);
  box-shadow: 0 10px 22px rgba(31, 155, 109, 0.24);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.secondary {
  padding: 0 12px;
  background: #eef3ff;
  color: var(--blue-dark);
  font-weight: 900;
}

.primary-action {
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  background: var(--green);
  color: white;
  font-size: 1.05rem;
  font-weight: 950;
  box-shadow: 0 14px 24px rgba(31, 155, 109, 0.28);
}

.message-panel {
  min-height: 98px;
  padding: 16px;
  border-radius: 8px;
  background: #233043;
  color: white;
}

.message-panel p {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.55;
}

.hint-text {
  margin-top: 8px;
  color: #ffe19a;
  font-weight: 800;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-radius: 8px;
  overflow: hidden;
}

.mascot-scene {
  position: relative;
  min-height: 190px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.36), transparent),
    #bfe3ff;
  border: 1px solid #94c9f1;
}

.sun {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 18px rgba(245, 184, 46, 0.22);
  transform: translate(-50%, -50%);
}

.number-orbit {
  position: absolute;
  inset: 18px;
  animation: spin 16s linear infinite;
}

.number-orbit span {
  position: absolute;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: white;
  color: var(--blue-dark);
  font-weight: 950;
  box-shadow: 0 10px 18px rgba(35, 48, 67, 0.12);
}

.number-orbit span:nth-child(1) {
  left: 12%;
  top: 10%;
}

.number-orbit span:nth-child(2) {
  right: 8%;
  top: 22%;
}

.number-orbit span:nth-child(3) {
  left: 20%;
  bottom: 6%;
}

.number-orbit span:nth-child(4) {
  right: 18%;
  bottom: 16%;
}

.side-panel h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

.goal-list {
  display: grid;
  gap: 12px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.goal-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
}

.goal-list span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  flex: 0 0 auto;
}

.history-card {
  min-height: 180px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.history-card h3 {
  margin-bottom: 12px;
}

#history {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-weight: 750;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
}

.confetti-layer.active {
  visibility: visible;
}

.confetti-piece {
  position: absolute;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  opacity: 0;
  animation: confetti-burst 1000ms cubic-bezier(0.16, 0.86, 0.2, 1) forwards;
}

.confetti-piece:nth-child(3n) {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.confetti-piece:nth-child(4n) {
  width: 16px;
  height: 8px;
}

.praise-word {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 1;
  display: block;
  max-width: min(86vw, 760px);
  color: #ffffff;
  font-size: clamp(3rem, 11vw, 7.6rem);
  font-weight: 950;
  line-height: 0.95;
  text-align: center;
  text-shadow:
    0 5px 0 #233043,
    0 14px 34px rgba(35, 48, 67, 0.38),
    0 0 34px rgba(245, 184, 46, 0.64);
  transform: translate(-50%, -50%);
  animation: praise-pop 1400ms cubic-bezier(0.16, 0.86, 0.2, 1) forwards;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(35, 48, 67, 0.46);
  backdrop-filter: blur(8px);
}

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

.success-dialog {
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid rgba(215, 222, 234, 0.92);
  border-radius: 8px;
  background: white;
  box-shadow: 0 24px 60px rgba(35, 48, 67, 0.28);
  text-align: center;
  animation: pop-in 260ms ease-out both;
}

.success-kicker {
  margin-bottom: 8px;
  color: var(--green);
  font-weight: 950;
}

.success-dialog h2 {
  margin-bottom: 10px;
  font-size: clamp(1.45rem, 5vw, 2.1rem);
  line-height: 1.15;
}

.success-expression {
  min-height: 32px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

button:hover {
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 3px solid rgba(226, 83, 130, 0.45);
  outline-offset: 3px;
}

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

@keyframes confetti-burst {
  0% {
    opacity: 0;
    transform: translate3d(-50%, -50%, 0) scale(0.6) rotate(0deg);
  }

  12% {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) scale(1) rotate(40deg);
  }

  72% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(calc(-50% + var(--burst-x)), calc(-50% + var(--burst-y)), 0)
      scale(0.86) rotate(var(--spin));
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes praise-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.28) rotate(-8deg);
  }

  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.16) rotate(3deg);
  }

  34% {
    transform: translate(-50%, -50%) scale(0.96) rotate(-1deg);
  }

  72% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -74%) scale(1.08) rotate(0deg);
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 20px, 560px);
    margin: 10px auto;
  }

  .play-area,
  .side-panel {
    padding: 16px;
  }

  .top-bar {
    flex-direction: column;
  }

  .score-board {
    width: 100%;
  }

  .cards-grid {
    grid-template-columns: repeat(2, minmax(104px, 1fr));
    padding: 14px;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}

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