@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: #d9f2ff;
  --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), #eef9ff);
  color: var(--ink);
}

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

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem;
}

.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: 1.1rem;
}

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

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

.title-squirrel {
  width: 76px;
  height: auto;
  display: block;
}

.title-row .title-squirrel:last-child {
  transform: scaleX(-1);
}

.header p {
  margin: 0.9rem 0 0;
}

.range-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin: 2.1rem 0 0.75rem;
}

.mode-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin: 0 0 0.75rem;
}

.level-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin: 0 0 1.35rem;
}

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

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

.mode-btn {
  border: 0;
  border-radius: 999px;
  background: #a9ddf5;
  color: #05324b;
  font-weight: 700;
  font-size: 1.08rem;
  padding: 0.58rem 1.22rem;
  cursor: pointer;
}

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

.level-btn {
  border: 0;
  border-radius: 999px;
  background: #a9ddf5;
  color: #05324b;
  font-weight: 700;
  font-size: 1.08rem;
  padding: 0.58rem 1.22rem;
  cursor: pointer;
}

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

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

.play-row > .sack-card:first-child {
  transform: translateX(34px);
}

.play-row > .sack-card:last-child {
  transform: translateX(-20px);
}

.sack-card {
  background: transparent;
  border-radius: 22px;
  border: 0;
  padding: 0.6rem;
  min-height: 230px;
  overflow: hidden;
  width: 82%;
  justify-self: center;
  position: relative;
}

.sack-card h2 {
  position: absolute;
  top: 2.4rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  z-index: 2;
  text-align: center;
  font-size: 1.1rem;
  font-family: "Vanilla Caramel", "Chewy", "Comic Sans MS", "Chalkboard SE", "Marker Felt", cursive;
  pointer-events: none;
}

.result-card {
  position: relative;
}

.answer-hint {
  margin: 0 0 0.2rem;
  padding: 0.15rem 0.55rem;
  border-radius: 14px;
  background: #fff;
  color: var(--warn);
  font-weight: 800;
  font-size: 0.95rem;
  text-align: center;
  max-width: 280px;
  line-height: 1.15;
}

.answer-hint span {
  display: block;
}

.sack-content {
  min-height: 515px;
  border: 0;
  border-radius: 0;
  position: relative;
  margin: 0;
  padding: 12.95rem 1.5rem 2.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.06rem;
  align-content: flex-start;
  justify-content: center;
  max-width: 310px;
  margin-left: auto;
  margin-right: auto;
}

.sack-content::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("./assets/sac_1-transparent.png");
  background-repeat: no-repeat;
  background-position: center 48%;
  background-size: 111% auto;
  filter: brightness(1.14) saturate(0.9);
  opacity: 0.76;
  pointer-events: none;
  z-index: 0;
}

.sack-content > * {
  position: relative;
  z-index: 1;
}

.sack-content .token.units {
  width: 36px;
  height: 36px;
}

.sack-content .token.tens + .token.tens {
  margin-left: -1.6rem;
}

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

.token.tens {
  width: 74px;
  height: 42px;
}

.middle-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.squirrel {
  width: 165px;
  height: auto;
  display: block;
}

.squirrel.is-sliding {
  animation: squirrel-slide 900ms ease-in-out;
}

@keyframes squirrel-slide {
  0% {
    transform: translateX(-45px);
  }
  100% {
    transform: translateX(40px);
  }
}

.operation-card {
  background: var(--cloud);
  border-radius: 16px;
  border: 2px solid rgba(0, 0, 0, 0.07);
  min-width: 170px;
  min-height: 94px;
  padding: 0.4rem 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.15rem;
}

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

.op-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: #2c627f;
}

.op-images {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.08rem;
  max-width: 180px;
  min-height: 34px;
}

.op-image {
  width: 52px;
  height: 52px;
  object-fit: contain;
  cursor: pointer;
  touch-action: none;
}

.op-image.tens {
  width: 78px;
  height: 46px;
}

.op-image.hundreds {
  width: 72px;
  height: 56px;
}

.op-images .op-image + .op-image {
  margin-left: -1.8rem;
}

.flow-arrow {
  font-size: 3.8rem;
  color: #2f9ed4;
  line-height: 1;
  font-weight: 900;
  text-shadow: 0 1px 0 #2f9ed4, 0 -1px 0 #2f9ed4, 1px 0 0 #2f9ed4, -1px 0 0 #2f9ed4;
  margin-top: -24px;
}

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

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

.controls > .counter-card:first-child {
  transform: translateX(78px);
}

.controls > .counter-card:last-child {
  transform: translateX(-78px);
}

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

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

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

.counter-image {
  width: 88px;
  height: 54px;
  object-fit: contain;
  cursor: grab;
  touch-action: none;
}

.counter-image.unit-image {
  width: 82px;
  height: 56px;
}

.counter-image.dragging {
  opacity: 0.6;
}

.touch-drag-preview {
  position: fixed;
  z-index: 1200;
  pointer-events: none;
  opacity: 0.9;
}

.operation-card.drop-ready {
  outline: 3px dashed #2f9ed4;
  outline-offset: 3px;
}

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

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

.round-report {
  margin-top: 0.05rem;
  text-align: center;
  font-weight: 700;
  font-family: "ScriptEcole2", "Trebuchet MS", Arial, sans-serif;
}

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

.bottom {
  margin-top: -0.1rem;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.check-btn {
  border: 0;
  border-radius: 999px;
  background: #3da8df;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.7rem 1.5rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

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

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

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

.hidden {
  display: none;
}

.operation-card {
  position: relative;
}

.operation-card.show-wrong-cross::after {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #d01f2f;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 900;
  pointer-events: none;
  z-index: 5;
}

.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) {
  .header h1 {
    font-size: 2rem;
  }

  .title-squirrel {
    width: 56px;
  }

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

  .flow-arrow {
    display: none;
  }

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

@media (prefers-reduced-motion: reduce) {
  .squirrel.is-sliding {
    animation: none;
  }
}
