/**
 * ACE shared design tokens + activity UI primitives (grades 1–5 ESL).
 * Loaded from index.html — keep class names stable for activities.
 */

:root {
  --ace-font: "Comic Sans MS", "Comic Sans", "Chalkboard SE", sans-serif;
  --ace-primary: #2196f3;
  --ace-primary-dark: #1565c0;
  --ace-primary-soft: #e3f2fd;
  --ace-ink: #1a2a6c;
  --ace-success: #4caf50;
  --ace-success-dark: #2e7d32;
  --ace-success-soft: #e8f5e9;
  --ace-danger: #f44336;
  --ace-danger-dark: #b71c1c;
  --ace-danger-soft: #ffebee;
  --ace-accent: #ff5722;
  --ace-gold: #ffd700;
  --ace-gold-dark: #b8860b;
  --ace-gold-ink: #b8860b;
  --ace-surface: #ffffff;
  --ace-muted: #bdbdbd;
  --ace-border-thick: 6px;
  --ace-border: 3px;
  --ace-radius-lg: 20px;
  --ace-radius-md: 14px;
  --ace-radius-sm: 12px;
  --ace-radius-pill: 999px;
  --ace-space-xs: 4px;
  --ace-space-sm: 8px;
  --ace-space-md: 8px;
  --ace-space-lg: 12px;
  --ace-shadow-press: 0 5px 0 #bbdefb;
  --ace-shadow-press-muted: 0 5px 0 #bdc3c7;
  --ace-shadow-gold: 0 6px 0 var(--ace-gold-dark);
  --ace-shadow-gold-lg: 0 8px 0 var(--ace-gold-dark);
  --ace-tap-min: 44px;
}

/* Activity outer frame (replaces repeated inline shells) */
.ace-activity-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--ace-surface);
  padding: var(--ace-space-md);
  border: var(--ace-border-thick) solid var(--ace-primary);
  border-radius: var(--ace-radius-lg);
  box-sizing: border-box;
  overflow: hidden;
  font-family: var(--ace-font);
}

/* Fill #player-body: every mounted activity root participates in the flex chain (no outer scroll). */
#player-body > * {
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

@media (max-width: 600px) {
  .ace-activity-shell {
    padding: 6px;
    border-width: 4px;
    border-radius: 16px;
  }
}

@media (max-height: 640px) {
  .ace-activity-shell {
    padding: 4px 6px;
  }
}

/* Top row: step / HUD */
.ace-hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: var(--ace-space-sm);
  margin-bottom: var(--ace-space-xs);
}

.ace-hud-step {
  font-weight: 900;
  color: var(--ace-accent);
  font-size: 1rem;
}

/* Optional inline gold chip (unused in default shell — Treasury is global) */
.ace-gold-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 5px;
  background: linear-gradient(180deg, #fff9e6 0%, #ffe8b8 100%);
  border: 2px solid #c9a227;
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 0 #8b6914;
}

.ace-gold-chip-ico {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 1px rgba(74, 50, 30, 0.35));
}

.ace-gold-chip-ico svg {
  width: 22px;
  height: auto;
  display: block;
}

.ace-gold-chip-num {
  font-weight: 900;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--ace-gold-ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
  min-width: 1.25em;
  text-align: right;
}

/* Primary / gold CTA (Say word, Check, etc.) */
.ace-btn-primary {
  min-height: var(--ace-tap-min);
  padding: 10px 16px;
  border: none;
  border-radius: var(--ace-radius-pill);
  background: var(--ace-gold);
  color: var(--ace-ink);
  font-family: inherit;
  font-weight: 900;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: var(--ace-shadow-gold);
  transition: transform 0.1s ease, filter 0.1s ease, box-shadow 0.1s ease;
}

.ace-btn-primary:hover {
  filter: brightness(1.03);
}

.ace-btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 var(--ace-gold-dark);
}

/* Round speak / icon buttons */
.ace-btn-speak {
  min-width: var(--ace-tap-min);
  min-height: var(--ace-tap-min);
  border: none;
  border-radius: 50%;
  background: var(--ace-gold);
  color: var(--ace-ink);
  font-family: inherit;
  font-weight: 900;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--ace-gold-dark);
  transition: transform 0.1s ease, filter 0.1s ease;
}

.ace-btn-speak:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 var(--ace-gold-dark);
}

/* Picture / choice card */
.ace-card-picture {
  border: 4px solid var(--ace-primary-soft);
  border-radius: var(--ace-radius-md);
  background: var(--ace-surface);
  padding: var(--ace-space-xs);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ace-primary-soft);
  font-family: inherit;
}

.ace-card-picture img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}

/* Feedback line (pair with aria-live) */
.ace-feedback {
  min-height: 24px;
  text-align: center;
  font-weight: 900;
  font-size: 1rem;
  line-height: 1.2;
  color: var(--ace-ink);
}

.ace-feedback--success {
  color: var(--ace-success-dark);
}

.ace-feedback--error {
  color: var(--ace-danger);
}

/* Instruction strip */
.ace-task-hint {
  font-weight: 800;
  color: var(--ace-primary-dark);
  font-size: 0.95rem;
  text-align: center;
  margin: var(--ace-space-xs) 0;
}

/* Long words / phrases: shrink to fit card width (needs width-constrained parent). */
.ace-word-fit-wrap {
  container-type: inline-size;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.ace-word-fit {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  text-align: center;
  line-height: 1.15;
  font-size: clamp(0.7rem, min(11vw, 11cqw), 2.6rem);
}

/* Motion */
@keyframes aceShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

@keyframes acePop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

.ace-anim-shake {
  animation: aceShake 0.35s ease-in-out;
}

.ace-anim-pop {
  animation: acePop 0.22s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .ace-anim-shake {
    animation: none;
  }
  .ace-anim-pop {
    animation: none;
  }
}
