@import url("https://fonts.googleapis.com/css2?family=Chewy&family=Patrick+Hand:wght@400;700&display=swap");

@font-face {
  font-family: "ScriptEcole2";
  src: url("./ScriptEcole2.ttf") format("truetype");
  font-display: swap;
}

h1,
h2 {
  font-family: "Vanilla Caramel", "Chewy", "Comic Sans MS", "Chalkboard SE", "Marker Felt", cursive;
}

:root {
  --sky: #bfeaff;
  --sky-dark: #8fd4f5;
  --cloud: #ffffff;
  --ink: #12344a;
  --ok: #1d8f4d;
  --warn: #c2473f;
  --btn: #77c5ea;
  --btn-active: #4daede;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "ScriptEcole2", "Trebuchet MS", Arial, sans-serif;
  background: linear-gradient(180deg, var(--sky), #dff4ff);
  color: var(--ink);
  overflow-x: hidden;
  position: relative;
}

button,
input,
select,
textarea {
  font-family: "ScriptEcole2", "Trebuchet MS", Arial, sans-serif;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  pointer-events: none;
  opacity: 0.45;
  background-repeat: no-repeat;
}

body::before {
  inset: 3% auto auto 2%;
  width: min(44vw, 520px);
  height: min(24vw, 260px);
  background-image:
    radial-gradient(ellipse at 20% 60%, #ffffff 0 34%, transparent 36%),
    radial-gradient(ellipse at 43% 45%, #ffffff 0 35%, transparent 37%),
    radial-gradient(ellipse at 63% 62%, #ffffff 0 33%, transparent 35%),
    radial-gradient(ellipse at 82% 56%, #ffffff 0 28%, transparent 30%),
    radial-gradient(ellipse at 12% 22%, #ffffff 0 18%, transparent 20%),
    radial-gradient(ellipse at 30% 16%, #ffffff 0 20%, transparent 22%),
    radial-gradient(ellipse at 47% 24%, #ffffff 0 17%, transparent 19%),
    radial-gradient(ellipse at 68% 18%, #ffffff 0 16%, transparent 18%),
    radial-gradient(ellipse at 86% 22%, #ffffff 0 14%, transparent 16%);
}

body::after {
  inset: auto 3% 6% auto;
  width: min(40vw, 470px);
  height: min(21vw, 230px);
  opacity: 0.38;
  background-image:
    radial-gradient(ellipse at 15% 55%, #ffffff 0 31%, transparent 33%),
    radial-gradient(ellipse at 38% 45%, #ffffff 0 33%, transparent 35%),
    radial-gradient(ellipse at 58% 58%, #ffffff 0 30%, transparent 32%),
    radial-gradient(ellipse at 80% 50%, #ffffff 0 25%, transparent 27%),
    radial-gradient(ellipse at 24% 22%, #ffffff 0 18%, transparent 20%),
    radial-gradient(ellipse at 44% 18%, #ffffff 0 17%, transparent 19%),
    radial-gradient(ellipse at 64% 24%, #ffffff 0 16%, transparent 18%),
    radial-gradient(ellipse at 84% 20%, #ffffff 0 14%, transparent 16%);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
  position: relative;
  z-index: 1;
}

.home-link {
  display: inline-flex;
  text-decoration: none;
  font-weight: 800;
  color: #0f5d8f;
  background: #ffffffcc;
  border: 2px solid #9ecded;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  margin-bottom: 0.35rem;
}

.home-link:hover,
.home-link:focus-visible {
  border-color: #4daede;
}

.header {
  text-align: center;
  margin-bottom: 0.6rem;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-family: "Vanilla Caramel", "Chewy", "Comic Sans MS", "Chalkboard SE", "Marker Felt", cursive;
}

.title-with-planes {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.title-plane {
  width: clamp(42px, 5.6vw, 62px);
  height: auto;
  object-fit: contain;
}

.title-plane-left {
  transform: scaleX(-1);
}

.header p {
  margin: 0.3rem 0 0;
  font-size: clamp(0.95rem, 2vw, 1.1rem);
}

.range-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.op-mode-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.level-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.range-btn {
  border: 0;
  border-radius: 999px;
  background: var(--btn);
  color: #05324b;
  font-weight: 700;
  padding: 0.45rem 1rem;
  cursor: pointer;
}

.op-mode-btn {
  border: 0;
  border-radius: 999px;
  background: #a9ddf5;
  color: #05324b;
  font-weight: 700;
  padding: 0.45rem 1rem;
  cursor: pointer;
}

.level-btn {
  border: 0;
  border-radius: 999px;
  background: #bfe6f9;
  color: #05324b;
  font-weight: 700;
  padding: 0.45rem 1rem;
  cursor: pointer;
}

.level-subtext {
  font-size: 0.78em;
}

.range-btn.active {
  background: var(--btn-active);
  color: #fff;
}

.op-mode-btn.active {
  background: #2f9ed4;
  color: #fff;
}

.level-btn.active {
  background: #2a93c7;
  color: #fff;
}

.play-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.8rem;
  align-items: center;
}

.box {
  background: var(--cloud);
  border-radius: 26px;
  border: 2px solid rgba(0, 0, 0, 0.06);
  min-height: 220px;
  padding: 0.7rem;
}

.answer-box {
  position: relative;
}

.answer-top-hint {
  position: absolute;
  left: 50%;
  top: -64px;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.2rem 0.55rem;
  border-radius: 14px;
  background: #ffffff;
  color: #c2473f;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.answer-top-arrow {
  display: block;
  line-height: 1;
  font-size: 1.35rem;
  margin-top: 0.08rem;
}

.box h2 {
  margin: 0 0 0.3rem;
  text-align: center;
  font-size: 1.1rem;
}

.cloud-content {
  min-height: 165px;
  border: 2px dashed #95cce7;
  border-radius: 18px;
  background: #f7fcff;
  padding: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.45rem;
  justify-content: center;
}

#answer-cloud {
  position: relative;
}

#answer-cloud.show-wrong-cross::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d01f2f;
  font-size: clamp(3.5rem, 8vw, 6.2rem);
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
  pointer-events: none;
}

.token {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.token.tens {
  width: 84px;
  height: 48px;
}

.token.hundreds {
  width: 90px;
  height: 72px;
}

#answer-cloud .token.hundreds {
  transform: translateY(-4px);
}

#start-cloud .token.hundreds {
  transform: translateY(-4px);
}

#start-cloud .token.tens,
#answer-cloud .token.tens {
  transform: translateY(8px);
}

#start-cloud .token.units,
#answer-cloud .token.units {
  transform: translateY(8px);
}

#answer-cloud.drag-target-active {
  border-color: #4daede;
  background: #eef9ff;
}

#start-cloud.drop-forbidden-active {
  border-color: #d88484;
  background: #fff5f5;
}

.balloon-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  position: relative;
  z-index: 3;
}

.balloon {
  order: 1;
  width: clamp(62px, 8.8vw, 100px);
  height: auto;
  object-fit: contain;
  display: block;
  transform: scaleX(-1);
  margin-top: 34px;
  will-change: transform;
}

.balloon.plane-sliding {
  animation: plane-slide var(--plane-slide-duration, 850ms) ease-in-out;
}

@keyframes plane-slide {
  0% {
    transform: translateX(var(--plane-slide-from, 0px)) scaleX(-1);
  }
  100% {
    transform: translateX(var(--plane-slide-to, 0px)) scaleX(-1);
  }
}

.operation-card {
  background: var(--cloud);
  border-radius: 16px;
  border: 2px solid rgba(0, 0, 0, 0.07);
  min-width: 170px;
  min-height: 98px;
  padding: 0.45rem 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

.flow-arrow {
  order: 2;
  font-size: clamp(3.1rem, 7vw, 4.8rem);
  line-height: 1;
  color: #2f9ed4;
  font-weight: 900;
  text-shadow: 0 1px 0 #2f9ed4, 0 -1px 0 #2f9ed4, 1px 0 0 #2f9ed4, -1px 0 0 #2f9ed4;
  margin-top: -26px;
  margin-bottom: 0;
}

.operation-card {
  order: 3;
}

.op-sign {
  font-size: 2rem;
  font-weight: 700;
}

.op-images {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.15rem;
  max-width: 120px;
}

.op-image {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.op-image.op-tens {
  width: 44px;
  height: 28px;
}

.op-image.op-hundreds {
  width: 42px;
  height: 34px;
}

.controls {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}

.controls.no-hundreds {
  grid-template-columns: repeat(2, minmax(0, 240px));
  justify-content: center;
  gap: 0.2rem;
}

.controls.no-hundreds > .counter-card {
  width: 100%;
}

.round-report {
  margin-top: 0.7rem;
  text-align: center;
  font-weight: 700;
}

.round-report p {
  margin: 0.15rem 0;
}

.counter-card {
  background: var(--cloud);
  border-radius: 18px;
  border: 2px solid rgba(0, 0, 0, 0.05);
  padding: 0.55rem;
  text-align: center;
}

.counter-card p {
  margin: 0 0 0.25rem;
  font-weight: 700;
}

.counter-image {
  width: 92px;
  height: 60px;
  object-fit: contain;
}

.token-pool-img {
  cursor: grab;
  touch-action: none;
}

.token-pool-img.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1200;
}

.drag-ghost-hundreds {
  width: 80px;
  height: 70px;
  object-fit: contain;
}

.drag-ghost-tens {
  width: 80px;
  height: 48px;
  object-fit: contain;
}

.drag-ghost-units {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.counter-buttons {
  margin-top: 0.3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.45rem;
}

.counter-buttons button {
  border: 0;
  border-radius: 12px;
  width: 34px;
  height: 34px;
  font-size: 1.3rem;
  font-weight: 700;
  color: #05324b;
  background: var(--btn);
  cursor: pointer;
}

.counter-buttons span {
  min-width: 22px;
  font-size: 1.1rem;
  font-weight: 700;
}

.bottom {
  margin-top: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.check-btn {
  border: 0;
  border-radius: 999px;
  background: #3da8df;
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  padding: 0.8rem 1.8rem;
  cursor: pointer;
}

.feedback {
  margin: 0;
  min-height: 1.5rem;
  font-weight: 700;
  width: 100%;
  text-align: center;
}

.feedback.ok {
  color: var(--ok);
}

.feedback.bad {
  color: var(--warn);
}

.hidden {
  display: none;
}

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

.confetti-piece {
  position: absolute;
  top: -14px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  opacity: 0.95;
  animation: confetti-fall 1300ms ease-in forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(640deg);
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .page {
    padding: 0.55rem 0.7rem 0.8rem;
  }

  .header {
    margin-bottom: 0.35rem;
  }

  .range-row,
  .op-mode-row,
  .level-row {
    margin-bottom: 0.45rem;
  }

  .title-plane {
    width: 46px;
  }

  .play-row {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .balloon-box {
    order: 0;
  }

  .balloon {
    margin-top: 2px;
    width: clamp(56px, 8.2vw, 82px);
  }

  .box {
    min-height: 162px;
    padding: 0.52rem;
  }

  .cloud-content {
    min-height: 112px;
    padding: 0.4rem;
  }

  .controls {
    grid-template-columns: 1fr;
    margin-top: 0.3rem;
    gap: 0.5rem;
  }

  .flow-arrow {
    display: none;
  }

  .answer-top-hint {
    top: -52px;
    font-size: 0.92rem;
  }
}
