:root {
  --paper: #ffffff;
  --paper-shadow: rgba(10, 57, 130, 0.18);
  --ink: #0b2f6b;
  --muted: #3f5f93;
  --line: #b6ddff;
  --accent: #2e7fd8;
  --accent-strong: #0b3a82;
  --accent-soft: #e9f5ff;
  --good: #159b5f;
  --good-soft: #dcf8eb;
  --bad: #dc3f5f;
  --bad-soft: #ffe8ed;
  --blue: #7ec8f8;
  --blue-deep: #0b3a82;
  --gold: #f9bf38;
  --purple-soft: #ebf4ff;
  --mint-soft: #dbf4ff;
  --card-peach: #eef8ff;
  --unit-cube-size: 24px;
  --unit-cube-gap: 8px;
  --progress-mascot-image: url("./condor.webp");
  --module-accent-start: #2e95f0;
  --module-accent-end: #0b3a82;
  --module-soft: #e9f5ff;
  --module-line: #b6ddff;
  --module-ink: #0b2f6b;
  --school-badge-image: url("./sscc.jpeg");
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 12%, rgba(126, 200, 248, 0.22) 0, rgba(126, 200, 248, 0) 18%),
    radial-gradient(circle at 86% 18%, rgba(11, 58, 130, 0.12) 0, rgba(11, 58, 130, 0) 18%),
    linear-gradient(180deg, #f5fbff 0%, #e8f5ff 52%, #ffffff 100%);
  position: relative;
}

body[data-module="suma-con-agrupacion"] {
  --module-accent-start: #2e95f0;
  --module-accent-end: #0b3a82;
  --module-soft: #e9f5ff;
  --module-line: #b6ddff;
  --module-ink: #0b2f6b;
}

body[data-module="suma-sin-agrupacion"] {
  --module-accent-start: #1ea974;
  --module-accent-end: #0f7a57;
  --module-soft: #e7f9f0;
  --module-line: #bfe8d2;
  --module-ink: #0f4f3b;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  pointer-events: none;
}

body::before {
  right: 18px;
  bottom: 14px;
  width: clamp(150px, 30vw, 300px);
  aspect-ratio: 320 / 180;
  background-image: var(--school-badge-image);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  opacity: 0.13;
  filter: saturate(0.92) contrast(1.02);
}

body::after {
  display: none;
}

button,
input {
  font: inherit;
}

.page-lines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    radial-gradient(circle at 8% 14%, rgba(255, 255, 255, 0.9) 0 4px, transparent 5px),
    radial-gradient(circle at 91% 22%, rgba(255, 255, 255, 0.7) 0 5px, transparent 6px),
    radial-gradient(circle at 76% 81%, rgba(255, 255, 255, 0.75) 0 4px, transparent 5px);
}

.app-shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px 28px;
}

.app-footer {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  opacity: 0.62;
  padding: 6px 16px 18px;
  letter-spacing: 0.01em;
}

.home-screen {
  display: grid;
  gap: 16px;
}

.home-header {
  padding: 22px 20px;
}

.home-header h1 {
  margin: 8px 0 6px;
  font-size: clamp(1.8rem, 5.4vw, 2.5rem);
}

.home-eyebrow {
  display: inline-block;
}

.home-copy {
  margin: 0;
  color: var(--muted);
  max-width: 40ch;
}

.reward-panel,
.module-panel {
  padding: 18px;
}

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

.reward-head h2,
.module-panel h2 {
  margin: 0;
  font-size: clamp(1.1rem, 3.8vw, 1.4rem);
}

.global-star-text {
  margin: 0;
  font-weight: 900;
  color: var(--blue-deep);
  font-size: clamp(1.02rem, 3.8vw, 1.36rem);
  line-height: 1.25;
}

.global-star-segments {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.star-segment {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 2px solid #aacff5;
  background: #f2f9ff;
  color: #8fb8e7;
  font-size: 1.24rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, color 120ms ease;
}

.star-segment.is-filled {
  background: linear-gradient(180deg, #ffd772 0%, #f9bf38 100%);
  border-color: #f0b324;
  color: #8a5a00;
}

.star-segment.is-empty:hover {
  transform: translateY(-1px) scale(1.02);
  background: #e8f3ff;
  color: #74a9df;
}

.reward-video-wrap {
  margin-top: 12px;
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid #b8d9f8;
  aspect-ratio: 16 / 9;
  background: #0b3a82;
}

.reward-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reward-video-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: #ffffff;
  padding: 16px;
  gap: 6px;
  background: linear-gradient(180deg, rgba(5, 32, 73, 0.62) 0%, rgba(5, 32, 73, 0.8) 100%);
}

.reward-video-overlay.unlocked {
  background: linear-gradient(180deg, rgba(5, 32, 73, 0.28) 0%, rgba(5, 32, 73, 0.5) 100%);
}

.reward-overlay-title {
  margin: 0;
  font-size: 1.14rem;
  font-weight: 900;
}

.reward-overlay-copy {
  margin: 0;
  max-width: 32ch;
}

.reward-hint {
  margin: 10px 2px 0;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.reward-hint:empty {
  display: none;
}

.reward-video-mask {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
}

.mask-tile {
  border-radius: 10px;
  background: linear-gradient(180deg, #0b3a82 0%, #2f7ecf 100%);
  border: 1px solid rgba(255, 255, 255, 0.24);
  transition: opacity 220ms ease, transform 220ms ease;
}

.mask-tile.is-open {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.module-panel {
  display: grid;
  gap: 12px;
}

.module-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.module-card {
  --module-card-bg: #f6fbff;
  --module-card-border: #cae2fb;
  --module-card-ink: #10306a;
  --module-card-soft: #eaf4ff;
  --module-card-line: #b9d7ff;
  border: 2px solid var(--module-card-border);
  border-radius: 18px;
  padding: 0;
  background: var(--module-card-bg);
}

.module-button {
  width: 100%;
}

.module-card.is-locked {
  opacity: 0.78;
}

.module-tile-button {
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--module-card-ink);
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px;
  text-align: left;
}

.module-tile-button:hover {
  transform: none;
}

.module-tile-button:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.module-math {
  border: 2px solid var(--module-card-line);
  border-radius: 12px;
  background: var(--module-card-soft);
  padding: 8px;
  display: grid;
  justify-items: end;
  align-items: center;
  min-height: 94px;
}

.module-math-top,
.module-math-middle,
.module-math-result {
  margin: 0;
  font-weight: 900;
  line-height: 1;
  font-size: 1.05rem;
  color: var(--module-card-ink);
}

.module-math-top {
  display: inline-flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 3px;
}

.module-index {
  position: absolute;
  top: -8px;
  left: 0;
  font-size: 0.54rem;
  line-height: 1;
  font-weight: 900;
}

.module-carry-digit {
  position: relative;
  display: inline-block;
}

.module-borrow-digit {
  position: relative;
  display: inline-block;
  padding-left: 3px;
}

.module-borrow-digit .module-index {
  left: -3px;
}

.module-strike {
  position: relative;
  display: inline-block;
}

.module-rewrite-digit {
  position: absolute;
  top: -8px;
  right: 8px;
  font-size: 0.54rem;
  line-height: 1;
  font-weight: 900;
}

.module-strike::after {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  top: 48%;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.9;
}

.module-math-line {
  display: block;
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: var(--module-card-border);
  margin: 3px 0 4px;
}

.module-copy h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.2;
  color: var(--module-card-ink);
}

.module-copy p {
  margin: 6px 0 0;
  font-size: 0.88rem;
  font-weight: 900;
  color: var(--module-card-ink);
  opacity: 0.82;
}

.module-card.theme-suma-sin {
  --module-card-bg: #eefbf5;
  --module-card-border: #9ed8bb;
  --module-card-ink: #146048;
  --module-card-soft: #e2f6eb;
  --module-card-line: #b9e8d2;
}

.module-card.theme-suma-con {
  --module-card-bg: #eef6ff;
  --module-card-border: #a6cbf7;
  --module-card-ink: #163f84;
  --module-card-soft: #e3f0ff;
  --module-card-line: #c1d9ff;
}

.module-card.theme-resta-sin {
  --module-card-bg: #fff5ef;
  --module-card-border: #f1c8aa;
  --module-card-ink: #8b4a22;
  --module-card-soft: #ffeede;
  --module-card-line: #f7d7be;
}

.module-card.theme-resta-con {
  --module-card-bg: #f5f0ff;
  --module-card-border: #c9b7ef;
  --module-card-ink: #52308c;
  --module-card-soft: #eee6ff;
  --module-card-line: #d9c8fa;
}

/* Module-specific exceptions live here. Keep shared layout/styles above. */
body[data-module="suma-sin-agrupacion"] .instruction-text {
  color: #0f4f3b;
}

body[data-module="suma-sin-agrupacion"] .sum-card {
  background:
    radial-gradient(circle at top right, rgba(30, 169, 116, 0.18) 0, transparent 36%),
    var(--paper);
}

body[data-module="suma-con-agrupacion"] .instruction-text {
  color: #0b2f6b;
}

.game-global-chip {
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

body[data-view="game"] .game-global-chip {
  color: var(--module-ink);
}

.game-chip-count {
  display: inline-block;
  font-weight: 900;
  font-size: 0.98rem;
}

.game-chip-stars {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.game-chip-star {
  width: 28px;
  height: 28px;
  pointer-events: none;
  border-width: 1px;
  font-size: 1rem;
}

.back-home-button {
  justify-self: start;
  white-space: nowrap;
}

.unlock-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(9, 40, 87, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
}

.unlock-card {
  max-width: 440px;
  width: 100%;
  padding: 20px;
  text-align: center;
}

.unlock-card h2 {
  margin: 0;
}

.unlock-card p {
  margin: 10px 0 0;
  color: var(--muted);
}

.unlock-actions {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.panel {
  background: var(--paper);
  border: 3px solid var(--line);
  border-radius: 30px;
  box-shadow:
    0 16px 32px var(--paper-shadow),
    inset 0 -2px 0 rgba(255, 255, 255, 0.7);
  position: relative;
}

body[data-view="game"] .panel {
  border-color: var(--module-line);
}

.panel::after {
  display: none;
}

.hidden {
  display: none !important;
}

.eyebrow,
.section-label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.74rem;
  color: var(--blue-deep);
  font-weight: 900;
}

.eyebrow {
  display: none;
}

.section-label {
  display: none;
}

.start-screen {
  max-width: 540px;
  margin: 8vh auto 0;
  padding: 28px 22px;
}

.start-screen h1 {
  margin: 8px 0 10px;
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1.05;
}

.intro-copy {
  margin: 0 0 22px;
  max-width: 34ch;
  color: #5a4a37;
  line-height: 1.45;
}

.field {
  display: grid;
  gap: 8px;
}

.field input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 2px solid #cdbfa9;
  border-radius: 16px;
  background: #fffefb;
}

.start-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.primary-button,
.secondary-button,
.step-button,
.choice-button,
.mini-control {
  border: 3px solid transparent;
  border-radius: 18px;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.primary-button:hover,
.secondary-button:hover,
.step-button:hover,
.choice-button:hover,
.mini-control:hover {
  transform: translateY(-2px) scale(1.01);
}

.primary-button {
  background: linear-gradient(180deg, var(--module-accent-start) 0%, var(--module-accent-end) 100%);
  color: white;
  padding: 12px 18px;
  box-shadow: none;
  font-weight: 900;
}

#next-exercise-button {
  box-shadow: none;
}

.primary-button:hover,
.secondary-button:hover,
.step-button:hover,
.choice-button:hover,
.mini-control:hover {
  box-shadow: none;
}

.secondary-button {
  background: var(--module-soft);
  border-color: var(--module-line);
  color: var(--ink);
  padding: 12px 18px;
}

.worksheet-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.worksheet-header h2 {
  margin: 6px 0 0;
  font-size: clamp(1.45rem, 5vw, 2.35rem);
  line-height: 1.05;
}

.session-progress {
  display: none;
}

.session-track {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  width: 100%;
}

.session-fill {
  display: none;
}

.session-mascot {
  display: none;
}

.session-track .session-star {
  width: 28px;
  height: 28px;
  pointer-events: none;
  border-width: 1px;
}

.session-progress-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 900;
  color: var(--blue-deep);
}

.student-chip {
  margin: 6px 0 0;
  padding: 10px 14px;
  background: rgba(255, 253, 247, 0.8);
  border: 2px dashed #d9c7af;
  border-radius: 999px;
  white-space: nowrap;
}

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

.sum-card,
.table-card {
  padding: 18px;
}

.sum-card {
  background:
    radial-gradient(circle at top right, rgba(255, 212, 92, 0.22) 0, transparent 36%),
    var(--paper);
}

.table-card {
  background:
    radial-gradient(circle at top left, rgba(99, 167, 255, 0.16) 0, transparent 34%),
    var(--paper);
}

.vertical-sum {
  margin-top: 10px;
  margin-left: auto;
  width: 154px;
  display: grid;
  grid-template-columns: 40px 48px 48px;
  grid-template-rows: 20px 42px 42px 12px 42px;
  align-items: center;
  justify-items: center;
}

.sum-sign {
  font-size: 2rem;
  align-self: end;
  color: var(--accent-strong);
}

.sum-digit,
.carry-slot {
  min-width: 24px;
  min-height: 24px;
  display: grid;
  place-items: center;
  font-size: 1.9rem;
  font-weight: 900;
}

.carry-slot {
  font-size: 1.1rem;
  color: var(--accent-strong);
  align-self: end;
}

.carry-slot.borrow-mini {
  font-size: 0.95rem;
  color: #0f7a57;
  font-weight: 900;
}

.carry-slot.borrow-mini.active {
  text-shadow: 0 0 10px rgba(26, 137, 96, 0.28);
}

.carry-slot.carry-active {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  border-radius: 50%;
  border: 2px solid #ff9f7a;
  background: #fff4ee;
  box-shadow: 0 2px 0 rgba(255, 143, 90, 0.22);
}

.sum-line {
  grid-column: 2 / span 2;
  width: 100%;
  border-bottom: 4px solid #7c68bb;
  border-radius: 999px;
}

.sum-digit.placeholder {
  color: rgba(61, 51, 36, 0.22);
}

.sum-digit.subtraction-borrow-tens,
.sum-digit.subtraction-borrow-units {
  position: relative;
  min-width: 32px;
}

.sum-digit .digit-base {
  position: relative;
  z-index: 1;
}

.sum-digit .digit-base.digit-strike {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: #5d6d84;
}

.sum-digit.subtraction-borrow-tens .digit-rewrite {
  position: absolute;
  top: -13px;
  left: 2px;
  font-size: 1rem;
  color: #4b648b;
  font-weight: 900;
}

.sum-digit.subtraction-borrow-units .borrow-rewrite {
  position: absolute;
  top: -13px;
  left: -2px;
  font-size: 0.95rem;
  color: #0f7a57;
  font-weight: 900;
}

.carry-appear {
  animation: carry-pop 920ms cubic-bezier(0.22, 1.35, 0.3, 1);
  text-shadow: 0 0 14px rgba(217, 117, 52, 0.36);
}

.result-appear {
  animation: result-pop 860ms cubic-bezier(0.22, 1.35, 0.3, 1);
  text-shadow: 0 0 16px rgba(61, 51, 36, 0.24);
}

.table-wrap {
  margin-top: 12px;
}

.place-table-head,
.place-table-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.place-table-body {
  margin-top: 8px;
  grid-template-rows: minmax(148px, auto) minmax(148px, auto);
}

.head-cell {
  display: grid;
  place-items: center;
  font-weight: 900;
}

.head-cell,
.place-cell {
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #d9cdf6;
  border-radius: 22px;
}

.place-cell {
  position: relative;
  overflow: hidden;
  padding: 12px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
  min-height: 148px;
}

.place-cell.no-footer {
  grid-template-rows: 1fr;
}

.place-cell.place-d .block-area {
  --ten-gap: 8px;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: flex-end;
  width: 100%;
  min-height: calc((2 * var(--unit-cube-size)) + var(--unit-cube-gap));
  gap: var(--ten-gap);
  padding-right: 2px;
}

.place-cell::before {
  display: none;
}

.block-area {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: flex-end;
  gap: var(--unit-cube-gap);
}

.place-cell.no-footer .block-area {
  height: 100%;
  align-content: center;
  align-items: center;
}

.place-cell.place-d.no-footer .block-area {
  align-items: center;
}

.cell-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 8px;
  border-top: 2px solid #ebe4fb;
}

.mini-control {
  min-width: 52px;
  min-height: 52px;
  background: #ffe6b8;
  border-color: #f9c56f;
  color: var(--ink);
  appearance: none;
  font-weight: 900;
  box-shadow: none;
}

.mini-control:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.control-count {
  min-width: 18px;
  text-align: center;
  font-weight: 700;
}

.cell-count-readonly {
  min-width: 22px;
  text-align: center;
  font-weight: 900;
  font-size: 1.05rem;
}

.ten-bar,
.unit-cube,
.mini-ten,
.mini-cube {
  flex: 0 0 auto;
}

.ten-bar {
  width: 28px;
  height: calc((2 * var(--unit-cube-size)) + var(--unit-cube-gap));
  border-radius: 12px;
  border: 3px solid #ffae37;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28) 0, transparent 36%),
    linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  box-shadow: inset 0 -5px 0 rgba(255, 170, 32, 0.24);
}

.place-cell.place-d .ten-bar {
  width: clamp(7px, calc((100% - (8 * var(--ten-gap))) / 9), 24px);
}

.place-cell.place-u .block-area {
  display: grid;
  grid-template-columns: repeat(5, var(--unit-cube-size));
  grid-template-rows: repeat(2, var(--unit-cube-size));
  justify-content: end;
  align-content: end;
  justify-items: center;
  align-items: center;
  gap: max(6px, var(--unit-cube-gap));
  width: calc((5 * var(--unit-cube-size)) + (4 * var(--unit-cube-gap)));
  max-width: 100%;
  margin-left: auto;
}

.place-cell.place-u.no-footer .block-area {
  align-content: center;
  align-items: center;
}

.unit-cube {
  width: var(--unit-cube-size);
  height: var(--unit-cube-size);
  border-radius: 8px;
  border: 3px solid #5f7bff;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35) 0, transparent 35%),
    #8dc3ff;
  appearance: none;
  padding: 0;
  box-shadow: inset 0 -4px 0 rgba(62, 108, 233, 0.24);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.unit-cube.sunken {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35) 0, transparent 35%),
    #8dc3ff;
  border-color: #5f7bff;
  box-shadow: inset 0 -4px 0 rgba(62, 108, 233, 0.24);
  opacity: 1;
}

.unit-cube.sunken.pacman {
  position: relative;
  border-radius: 8px;
  border-color: #5f7bff;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35) 0, transparent 35%),
    #8dc3ff;
  box-shadow: inset 0 -4px 0 rgba(62, 108, 233, 0.24);
  opacity: 1;
  animation: pacman-chomp 1200ms ease-in-out infinite;
  /* Rotada 90° a la izquierda (boca hacia arriba) y escalable por tamaño del cubo */
  clip-path: polygon(0 0, 48% 0, 50% 10%, 52% 0, 100% 0, 100% 100%, 0 100%);
}

.unit-cube.sunken.pacman::before {
  content: "";
  position: absolute;
  left: 62%;
  top: 44%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #2f5e9d;
  opacity: 0.9;
}

.unit-cube.sunken.pacman::after {
  content: none;
}

.unit-cube.unit-hole {
  background: transparent;
  border-style: dashed;
  border-color: rgba(95, 123, 255, 0.35);
  box-shadow: none;
  opacity: 0.38;
  pointer-events: none;
}

.ten-bar.sunken {
  border-color: #ffae37;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28) 0, transparent 36%),
    linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  box-shadow: inset 0 -5px 0 rgba(255, 170, 32, 0.24);
  opacity: 1;
}

.ten-bar.sunken.pacman-ten {
  position: relative;
  border-color: #ffae37;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28) 0, transparent 36%),
    linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  box-shadow: inset 0 -5px 0 rgba(255, 170, 32, 0.24);
  opacity: 1;
  animation: ten-pacman-chomp 1400ms ease-in-out infinite;
  clip-path: polygon(0 0, 44% 0, 50% 9%, 56% 0, 100% 0, 100% 100%, 0 100%);
}

.ten-bar.sunken.pacman-ten::before {
  content: "";
  position: absolute;
  left: 58%;
  top: 32%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #b57718;
  opacity: 0.9;
}

.ten-bar.ten-hole {
  background: transparent;
  border-style: dashed;
  border-color: rgba(255, 174, 55, 0.46);
  box-shadow: none;
  opacity: 0.45;
  pointer-events: none;
}

.ten-button {
  cursor: pointer;
  touch-action: manipulation;
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
}

.subtract-target {
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.subtract-invite {
  animation: subtract-invite-bounce 920ms ease-in-out infinite;
}

.ten-bar.subtract-invite {
  animation: subtract-invite-bounce-ten 920ms ease-in-out infinite;
}

.subtract-decompose-target {
  cursor: pointer;
  border-color: #ffae37;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28) 0, transparent 36%),
    linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
}

.subtract-target:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.subtract-decompose-target:hover {
  transform: translateY(-1px) scale(1.01);
  filter: brightness(1.08);
}

.subtract-target-hit {
  transform: scale(0.96);
  filter: brightness(1.08);
}

.subtract-target-merge {
  animation: subtract-merge 180ms ease;
}

.subtract-source {
  pointer-events: none;
}

.subtract-fading {
  opacity: 0.45;
}

.subtract-flyer {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  border-radius: 8px;
  border: 3px solid #5f7bff;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35) 0, transparent 35%),
    #8dc3ff;
  box-shadow: inset 0 -4px 0 rgba(62, 108, 233, 0.24);
  transition:
    left 360ms cubic-bezier(0.22, 0.61, 0.36, 1),
    top 360ms cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 360ms cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 180ms ease;
}

.subtract-flyer.is-ten {
  border-radius: 4px;
  border-color: #ffae37;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28) 0, transparent 36%),
    linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  box-shadow: inset 0 -4px 0 rgba(196, 126, 20, 0.24);
}

.decompose-flyer {
  position: fixed;
  z-index: 42;
  width: 14px;
  height: 42px;
  border-radius: 5px;
  border: 3px solid #ffae37;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28) 0, transparent 36%),
    linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  box-shadow: 0 4px 10px rgba(163, 100, 12, 0.22);
  pointer-events: none;
  transition: left 420ms cubic-bezier(0.22, 0.61, 0.36, 1), top 420ms cubic-bezier(0.22, 0.61, 0.36, 1), transform 420ms ease;
}

.decompose-flyer-burst {
  animation: decompose-burst 140ms ease forwards;
}

.subtract-flyer.subtract-fade-out {
  opacity: 0;
}

@keyframes subtract-merge {
  0% { transform: scale(1); filter: brightness(1); }
  45% { transform: scale(0.88); filter: brightness(1.15); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes decompose-burst {
  0% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1.35); opacity: 0; }
}

@keyframes pacman-chomp {
  0%, 100% {
    clip-path: polygon(0 0, 48% 0, 50% 10%, 52% 0, 100% 0, 100% 100%, 0 100%);
  }
  50% {
    /* La abertura usa 0% y 100% del lado superior: escala con el tamaño del cubo */
    clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  }
}

@keyframes ten-pacman-chomp {
  0%, 100% {
    clip-path: polygon(0 0, 44% 0, 50% 9%, 56% 0, 100% 0, 100% 100%, 0 100%);
  }
  50% {
    clip-path: polygon(0 0, 50% 30%, 100% 0, 100% 100%, 0 100%);
  }
}

.unit-cube.selected,
.unit-cube.more-units {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35) 0, transparent 35%),
    #ff9f7a;
  border-color: #ff7043;
  box-shadow: inset 0 -4px 0 rgba(232, 99, 53, 0.26);
}

.place-cell.good {
  background: linear-gradient(180deg, #f1fff8 0%, var(--good-soft) 100%);
  border-color: #9ae0be;
}

.place-cell.bad {
  background: linear-gradient(180deg, #fff6f8 0%, var(--bad-soft) 100%);
  border-color: #ffb2c0;
}

.place-cell.error-shake {
  animation: error-shake 320ms ease;
}

.place-cell.tap-target {
  cursor: pointer;
}

.place-cell.tap-target .unit-cube {
  pointer-events: none;
}

.place-cell.tap-target:active {
  transform: scale(0.995);
}

.place-cell.guide-pulse {
  animation: guide-pulse 920ms ease-in-out 1;
  border-color: #ffb55a;
}

.instruction-band {
  position: static;
  margin-top: 12px;
  padding: 0;
}

.instruction-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 18px 18px;
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  background:
    radial-gradient(circle at top right, rgba(255, 212, 92, 0.15) 0, transparent 26%),
    var(--paper);
  border: 3px solid #d9cdf6;
  box-shadow: 0 14px 26px rgba(61, 51, 36, 0.1);
}

.instruction-inner.instruction-focus {
  border-color: #ffb55a;
  box-shadow: 0 20px 36px rgba(255, 143, 90, 0.22);
}

.instruction-text {
  margin: 0;
  min-height: 0;
  width: 100%;
  font-size: clamp(1.06rem, 5.6vw, 1.25rem);
  font-weight: 900;
  line-height: 1.1;
  color: var(--ink);
  text-align: center;
}

.instruction-text.attention-color {
  color: #f06739;
}

.instruction-text.attention-pop {
  animation: prompt-pop 920ms cubic-bezier(0.22, 1.35, 0.3, 1);
}

.action-label {
  display: none;
}

.instruction-action {
  min-height: 0;
  margin-top: 0;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding: 0;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 0;
  color: var(--ink);
  justify-content: center;
}

.instruction-inner.has-choices {
  justify-content: center;
}

.instruction-inner.has-choices .instruction-text {
  align-self: stretch;
  margin-bottom: 0;
  text-align: center;
  font-size: clamp(1rem, 4.9vw, 1.125rem);
  line-height: 1.12;
}

.instruction-inner.has-choices .instruction-action {
  margin-top: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
}

.instruction-action.action-focus {
  border-color: #ffb55a;
  background: #fff3de;
  animation: prompt-pulse 1100ms ease-in-out 2;
}

.step-button {
  padding: 12px 18px;
  background: linear-gradient(180deg, #fff1b5 0%, #ffd56b 100%);
  border-color: #ffca52;
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 7px 0 rgba(255, 201, 77, 0.36);
}

.choice-row {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.choice-button {
  min-height: 68px;
  padding: 8px 6px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f2ff 100%);
  border-color: #d9cdf6;
  display: grid;
  justify-items: center;
  gap: 6px;
  box-shadow: 0 10px 22px rgba(95, 123, 255, 0.08);
}

.choice-button.selected-wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}

.choice-button.selected-correct {
  background: var(--good-soft);
  border-color: var(--good);
}

.choice-button:disabled {
  cursor: default;
}

.choice-button.error-shake {
  animation: error-shake 320ms ease;
}

.choice-number {
  font-weight: 900;
  font-size: 1.32rem;
}

.mini-row {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}

.mini-cube {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: #8dc3ff;
  border: 1px solid #5875ff;
}

.mini-ten {
  width: 7px;
  height: 20px;
  border-radius: 4px;
  background: linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  border: 1px solid #ffae37;
}

.feedback-inline {
  font-weight: 900;
  color: var(--ink);
  font-size: 1.125rem;
  line-height: 1.15;
  text-align: center;
}

.flying-blocks {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.flying-group {
  position: absolute;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  transition: left 480ms ease-out, top 480ms ease-out, transform 480ms ease-out, opacity 280ms ease-out;
  will-change: left, top, transform, opacity;
}

.flying-unit {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid #ff7043;
  background: #ff9f7a;
}

.flying-bar {
  position: absolute;
  width: 28px;
  height: calc((2 * var(--unit-cube-size)) + var(--unit-cube-gap));
  border-radius: 12px;
  border: 3px solid #ffae37;
  background: linear-gradient(180deg, #ffe588 0%, #ffc94d 100%);
  transition: transform 920ms ease-in-out, left 920ms ease-in-out, top 920ms ease-in-out;
  will-change: left, top, transform;
}

.flying-answer-digit {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue-deep);
  transition: left 620ms ease-in-out, top 620ms ease-in-out, transform 620ms ease-in-out, opacity 620ms ease-in-out;
  will-change: left, top, transform, opacity;
}

.celebration {
  display: grid;
  gap: 10px;
}

.celebration h3 {
  margin: 0;
  font-size: 1.5rem;
}

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

.confetti {
  position: absolute;
  width: 10px;
  height: 16px;
  opacity: 0;
  animation: confetti-fall 1800ms linear forwards;
}

@keyframes carry-pop {
  0% { transform: translateY(14px) scale(0.18) rotate(-10deg); opacity: 0; }
  32% { transform: translateY(-7px) scale(1.9) rotate(8deg); opacity: 1; }
  54% { transform: translateY(2px) scale(0.82) rotate(-5deg); }
  72% { transform: translateY(-3px) scale(1.24) rotate(2deg); }
  86% { transform: translateY(1px) scale(0.95) rotate(-1deg); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes result-pop {
  0% { transform: translateY(16px) scale(0.16) rotate(-8deg); opacity: 0; }
  34% { transform: translateY(-8px) scale(1.92) rotate(7deg); opacity: 1; }
  56% { transform: translateY(2px) scale(0.8) rotate(-4deg); }
  74% { transform: translateY(-3px) scale(1.26) rotate(2deg); }
  88% { transform: translateY(1px) scale(0.95) rotate(-1deg); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

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

@keyframes prompt-pop {
  0% { transform: translateY(10px) scale(0.86); opacity: 0.2; }
  45% { transform: translateY(-3px) scale(1.08); opacity: 1; }
  72% { transform: translateY(1px) scale(0.97); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes prompt-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.02); }
  70% { transform: scale(0.995); }
  100% { transform: scale(1); }
}

@keyframes guide-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 181, 90, 0.18); }
  45% { transform: scale(1.015); box-shadow: 0 0 0 8px rgba(255, 181, 90, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 181, 90, 0); }
}

@keyframes subtract-invite-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.04); }
}

@keyframes subtract-invite-bounce-ten {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes error-shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

@media (max-width: 767px) {
  :root {
    --unit-cube-size: 19px;
    --unit-cube-gap: 6px;
    --mobile-top-panel-height: 174px;
  }

  .app-shell {
    padding: 18px 10px 16px;
  }

  .home-header,
  .reward-panel,
  .module-panel {
    padding: 14px;
  }

  .module-card {
    padding: 0;
  }

  .module-tile-button {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .module-math {
    min-height: 84px;
    padding: 7px;
  }

  .module-copy h3 {
    font-size: 0.94rem;
    line-height: 1.16;
    white-space: normal;
  }

  .module-copy p {
    margin-top: 4px;
    font-size: 0.8rem;
  }

  .global-star-segments {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .global-star-segments .star-segment {
    width: 30px;
    height: 30px;
    font-size: 1.06rem;
    flex: 0 0 auto;
  }

  .game-screen {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    grid-template-areas:
      "header header"
      "sum instructions"
      "table table";
    gap: 20px 12px;
    align-items: start;
  }

  .worksheet-header > div {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .worksheet-header {
    grid-area: header;
    margin-bottom: 0;
    gap: 10px;
  }

  .worksheet-header h2 {
    margin: 0;
    font-size: clamp(1.18rem, 5.8vw, 1.45rem);
    line-height: 1.04;
  }

  .session-progress {
    display: none !important;
  }

  .game-global-chip {
    margin-top: 4px;
    gap: 4px;
  }

  .game-chip-stars {
    gap: 4px;
  }

  .game-chip-star {
    width: 24px;
    height: 24px;
    font-size: 0.9rem;
  }

  .game-chip-count {
    display: none;
  }

  .session-track {
    width: 100%;
    min-width: 0;
  }

  .session-progress-label {
    display: block;
    font-size: 0.58rem;
    line-height: 1.1;
    text-align: right;
    color: var(--ink);
  }

  .worksheet {
    display: contents;
  }

  .section-label {
    display: none;
  }

  .worksheet-top {
    grid-area: sum;
  }

  .worksheet-middle {
    grid-area: table;
  }

  .sum-card,
  .table-card {
    padding: 10px;
    border-radius: 22px;
  }

  .sum-card {
    min-height: var(--mobile-top-panel-height);
    display: grid;
    place-items: center;
  }

  .vertical-sum {
    margin: 0;
    width: 126px;
    grid-template-columns: 28px 46px 46px;
    grid-template-rows: 18px 40px 40px 10px 40px;
  }

  .sum-sign {
    font-size: 1.72rem;
  }

  .sum-digit,
  .carry-slot {
    min-width: 22px;
    min-height: 22px;
    font-size: 1.9rem;
  }

  .carry-slot {
    font-size: 1.08rem;
    color: #d9552e;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  }

  .carry-slot.carry-active {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    border-width: 2px;
  }

  .place-table-head,
  .place-table-body {
    grid-template-columns: 1fr 1fr;
    gap: 5px;
  }

  .place-table-body {
    margin-top: 5px;
    grid-template-rows: minmax(116px, auto) minmax(116px, auto);
  }

  .head-cell,
  .place-cell {
    border-radius: 16px;
  }

  .place-cell {
    min-height: 116px;
    padding: 7px;
    gap: 6px;
  }

  .block-area {
    gap: var(--unit-cube-gap);
  }

  .place-cell.place-d .block-area {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: flex-end;
    align-items: flex-end;
    width: 100%;
    height: 100%;
    --ten-gap: 6px;
    gap: var(--ten-gap);
    padding-right: 2px;
    overflow: hidden;
  }

  .place-cell.place-d .ten-bar {
    width: clamp(6px, calc((100% - (8 * var(--ten-gap))) / 9), 16px);
  }

  .ten-bar {
    height: calc((2 * var(--unit-cube-size)) + var(--unit-cube-gap));
    border-radius: 4px;
    border-width: 2px;
  }

  .flying-bar {
    width: 12px;
    height: calc((2 * var(--unit-cube-size)) + var(--unit-cube-gap));
    border-radius: 6px;
    border-width: 2px;
  }

  .unit-cube {
    width: var(--unit-cube-size);
    height: var(--unit-cube-size);
    border-radius: 6px;
  }

  .instruction-band {
    grid-area: instructions;
    margin-top: 0;
  }

  .instruction-inner {
    min-height: var(--mobile-top-panel-height);
    height: 100%;
    border-radius: 20px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
  }

  .instruction-inner.has-choices {
    justify-content: center;
    padding-top: 0;
  }

  .instruction-text {
    min-height: 0;
    width: 100%;
  }

  .instruction-inner.has-choices .instruction-text {
    align-self: stretch;
    margin-bottom: 0;
  }

  .action-label {
    display: none;
  }

  .instruction-action {
    min-height: 0;
    margin-top: 0;
    padding: 0;
    width: 100%;
    gap: 6px;
    border: 0;
    background: transparent;
    border-radius: 0;
    color: var(--ink);
    justify-content: center;
  }

  .instruction-inner.has-choices .instruction-action {
    margin-top: 10px;
  }

  .choice-row {
    justify-content: center;
    gap: 5px;
  }

  .choice-button {
    min-height: 52px;
    padding: 6px 4px;
    gap: 4px;
  }

  .choice-number {
    font-size: 1.02rem;
  }

  .mini-cube {
    width: 8px;
    height: 8px;
  }

  .mini-ten {
    width: 6px;
    height: 16px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding: 18px 8px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .game-screen {
    grid-template-columns: 136px minmax(0, 1fr);
    gap: 20px 12px;
  }

  .worksheet-header > div {
    gap: 10px;
  }

  .session-progress {
    display: none !important;
  }

  .session-track {
    gap: 5px;
  }

  .sum-card,
  .table-card {
    padding: 8px;
    border-radius: 20px;
  }

  .place-table-head,
  .place-table-body {
    gap: 4px;
  }

  .place-cell {
    min-height: 108px;
    padding: 6px;
  }

  .head-cell,
  .place-cell {
    border-radius: 14px;
  }

  .cell-controls {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
    padding-top: 6px;
  }

  .mini-control {
    min-width: 46px;
    min-height: 46px;
    border-width: 2px;
  }

  .control-count {
    min-width: 14px;
    font-size: 1rem;
  }
}

@media (min-width: 768px) {
  .app-shell {
    padding-left: 24px;
    padding-right: 24px;
    padding-bottom: 32px;
  }

  .app-footer {
    font-size: 0.86rem;
    padding-bottom: 22px;
  }

  .home-screen {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .home-header {
    grid-column: 1 / -1;
  }

  .module-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    height: 100%;
    align-content: start;
    overflow: auto;
    padding-right: 2px;
  }

  .module-panel {
    overflow: hidden;
  }

  .module-card,
  .module-button,
  .module-tile-button {
    height: 100%;
  }

  .game-screen {
    --desktop-side-panel-height: 194px;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-areas:
      "header header"
      "sum table"
      "instructions table";
    column-gap: 20px;
    row-gap: 22px;
    align-items: start;
  }

  .worksheet-header {
    grid-area: header;
    margin-bottom: 8px;
  }

  .worksheet-header > div {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: center;
    column-gap: 18px;
  }

  .worksheet-header h2 {
    margin: 0;
  }

  .session-progress {
    margin-top: 10px;
    width: 100%;
    max-width: 320px;
    justify-self: end;
  }

  .session-track {
    margin-top: 6px;
  }

  .session-mascot {
    display: none;
  }

  .worksheet {
    display: contents;
  }

  .worksheet-top {
    grid-area: sum;
    position: static;
  }

  .worksheet-middle {
    grid-area: table;
  }

  .sum-card {
    min-height: var(--desktop-side-panel-height);
  }

  .place-table-body {
    grid-template-rows: minmax(168px, auto) minmax(168px, auto);
  }

  .instruction-band {
    grid-area: instructions;
    position: static;
    margin-top: 0;
    padding: 0;
  }

  .instruction-inner {
    width: 100%;
    max-width: none;
    min-height: var(--desktop-side-panel-height);
  }
}
