/* ============ HUD ============ */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--hud-h);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  max-width: 752px;
  margin: 0 auto;
}

.hud__spacer { flex: 1; }

.hud--hidden { display: none; }
.is-fullbleed .app { padding-top: 16px; }

.hud__title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, .7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ Buttons ============ */
.btn {
  --c: var(--blue);
  --c-deep: var(--blue-deep);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  border: 0;
  cursor: pointer;
  font-weight: 600;
  color: #fff;
  background: var(--c);
  border-radius: var(--r-pill);
  padding: 14px 26px;
  font-size: 1.1rem;
  box-shadow: 0 5px 0 var(--c-deep), 0 10px 18px rgba(42, 53, 87, .18);
  transition: transform .1s var(--swift), box-shadow .1s var(--swift), filter .15s;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.05); }
.btn:active,
.btn.is-pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--c-deep), 0 4px 10px rgba(42, 53, 87, .18);
}
.btn:focus-visible { outline: 4px solid rgba(255, 255, 255, .9); outline-offset: 3px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

.btn--ghost {
  background: rgba(255, 255, 255, .92);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(42, 53, 87, .14), 0 8px 16px rgba(42, 53, 87, .12);
}
.btn--ghost:active { box-shadow: 0 1px 0 rgba(42, 53, 87, .14); }

.btn--round {
  width: 46px; height: 46px;
  padding: 0;
  font-size: 1.3rem;
  border-radius: 50%;
}

.btn--big { padding: 18px 34px; font-size: 1.3rem; }
.btn--block { width: 100%; }

/* ============ Star counter ============ */
.stars {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, .94);
  border-radius: var(--r-pill);
  padding: 7px 16px 7px 12px;
  box-shadow: var(--lift-1);
  font-weight: 700;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}
.stars__icon { font-size: 1.25rem; display: inline-block; }
.stars__value { min-width: 1.4ch; text-align: left; }
.stars--gain { animation: pop .45s var(--bounce); }
.stars--loss { animation: shake .4s var(--swift); }

/* ============ Avatar ============ */
.avatar {
  display: block;
  border-radius: 50%;
  object-fit: cover;
  /* The portrait is head-and-shoulders, so bias the square crop upward. */
  object-position: 50% 20%;
  background: linear-gradient(180deg, #EAF6FF, #FFFFFF);
  border: 5px solid #fff;
  box-shadow: 0 10px 22px rgba(42, 53, 87, .28);
}
.avatar--lg { width: 118px; height: 118px; }
.avatar--xl { width: min(210px, 52vw); height: min(210px, 52vw); border-width: 7px; }

/* ============ Cards ============ */
.card {
  background: var(--paper);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--lift-1);
}

.tile {
  --c: var(--blue);
  --c-deep: var(--blue-deep);
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  border: 0;
  cursor: pointer;
  background: var(--paper);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  box-shadow: 0 5px 0 rgba(42, 53, 87, .12), 0 12px 22px rgba(42, 53, 87, .12);
  transition: transform .12s var(--bounce), box-shadow .12s var(--swift);
  overflow: hidden;
  touch-action: manipulation;
}
.tile::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 8px;
  background: var(--c);
}
.tile:hover { transform: translateY(-3px); }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(42, 53, 87, .12); }
.tile:focus-visible { outline: 4px solid var(--c); outline-offset: 3px; }

.tile__emoji {
  flex: none;
  width: 58px; height: 58px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  background: color-mix(in srgb, var(--c) 18%, #fff);
  border-radius: var(--r-md);
}
.tile__body { flex: 1; min-width: 0; }
.tile__title { font-size: 1.15rem; font-weight: 600; }
.tile__sub { font-size: .88rem; color: var(--ink-soft); margin-top: 2px; }
.tile__chev { flex: none; font-size: 1.4rem; color: var(--c); }

/* Big section tiles on the home screen */
.tile--hero {
  flex-direction: column;
  text-align: center;
  gap: 10px;
  padding: 26px 18px 22px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 22%, #fff), #fff 70%);
}
.tile--hero .tile__emoji {
  width: 86px; height: 86px;
  font-size: 3rem;
  background: #fff;
  box-shadow: var(--lift-1);
  animation: float-y 3.4s ease-in-out infinite;
}
.tile--hero .tile__title { font-size: 1.5rem; }
.tile--hero::before { width: 100%; height: 8px; bottom: auto; }

/* ============ Bottom sheet (level picker) ============ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(42, 53, 87, .45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in .2s var(--swift) both;
}
@keyframes fade-in { from { opacity: 0; } }

.sheet {
  width: min(560px, 100%);
  background: var(--paper);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom));
  animation: sheet-up .3s var(--bounce) both;
  max-height: 88dvh;
  overflow-y: auto;
}
@keyframes sheet-up { from { transform: translateY(100%); } }

.sheet__grip {
  width: 52px; height: 5px;
  border-radius: var(--r-pill);
  background: #DCE3F2;
  margin: 4px auto 14px;
}
.sheet__title { font-size: 1.3rem; font-weight: 600; text-align: center; }
.sheet__sub { text-align: center; color: var(--ink-soft); font-size: .92rem; margin-top: 4px; }
.sheet__list { display: grid; gap: 12px; margin-top: 18px; }

/* ============ Progress dots ============ */
.progress {
  display: flex;
  gap: 7px;
  justify-content: center;
  flex-wrap: wrap;
}
.progress__dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .75);
  box-shadow: inset 0 0 0 2px rgba(42, 53, 87, .12);
  transition: transform .25s var(--bounce), background .25s;
}
.progress__dot--current { transform: scale(1.35); background: var(--sun); box-shadow: inset 0 0 0 2px var(--sun-deep); }
.progress__dot--right   { background: var(--mint); box-shadow: inset 0 0 0 2px var(--mint-deep); }
.progress__dot--wrong   { background: var(--coral); box-shadow: inset 0 0 0 2px var(--coral-deep); }

/* ============ Keypad ============ */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 340px;
  width: 100%;
  margin: 0 auto;
}
.key {
  border: 0;
  cursor: pointer;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.65rem;
  font-weight: 600;
  padding: 14px 0;
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 #C9D4EA, 0 8px 14px rgba(42, 53, 87, .12);
  transition: transform .08s var(--swift), box-shadow .08s var(--swift);
  touch-action: manipulation;
  font-variant-numeric: tabular-nums;
}
.key:active, .key.is-pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #C9D4EA;
}
.key:focus-visible { outline: 4px solid var(--blue); outline-offset: 2px; }
.key--del { background: #FFE7E3; color: var(--coral-deep); box-shadow: 0 4px 0 #F3C6BF; }
.key--del:active { box-shadow: 0 1px 0 #F3C6BF; }
.key--go { background: var(--mint); color: #fff; box-shadow: 0 4px 0 var(--mint-deep); }
.key--go:active { box-shadow: 0 1px 0 var(--mint-deep); }
.key[disabled] { opacity: .4; cursor: not-allowed; }

/* ============ Answer box ============ */
.answer-box {
  min-height: 74px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 4px dashed #CBD8F0;
  border-radius: var(--r-lg);
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: border-color .2s, background .2s;
}
.answer-box--empty { color: #B9C4DC; }
.answer-box--right { border: 4px solid var(--mint); background: #E9FBF3; color: var(--mint-deep); }
.answer-box--wrong { border: 4px solid var(--coral); background: #FFEFEC; color: var(--coral-deep); }

/* ============ Feedback overlay ============ */
.feedback {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.feedback__bubble {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 34px;
  border-radius: var(--r-xl);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--lift-2);
  animation: feedback-pop .5s var(--bounce) both;
}
@keyframes feedback-pop {
  from { transform: scale(.5) rotate(-8deg); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.feedback__emoji { font-size: 3.4rem; line-height: 1; }
.feedback__text { font-size: 1.35rem; font-weight: 600; }
.feedback__hint { font-size: 1rem; color: var(--ink-soft); }
.feedback--right .feedback__text { color: var(--mint-deep); }
.feedback--wrong .feedback__text { color: var(--coral-deep); }

/* ============ Flying star ============ */
.fly-star {
  position: fixed;
  font-size: 1.6rem;
  will-change: transform, opacity;
  z-index: 60;
}

/* ============ Abacus ============ */
.abacus {
  --bead-h: 26px;
  --slot: 30px;
  --rod-w: 52px;
  display: inline-flex;
  gap: 6px;
  padding: 14px 14px 10px;
  background: linear-gradient(170deg, var(--wood) 0%, var(--wood-dark) 100%);
  border: 6px solid var(--wood-frame);
  border-radius: var(--r-md);
  box-shadow: var(--lift-2), inset 0 2px 8px rgba(0, 0, 0, .25);
}

.abacus__rod {
  position: relative;
  width: var(--rod-w);
  display: flex;
  flex-direction: column;
}
.abacus__rod::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 2px; bottom: 26px;
  width: 5px;
  margin-left: -2.5px;
  background: linear-gradient(90deg, #6B4525, #A5713F, #6B4525);
  border-radius: 3px;
}

.abacus__heaven { position: relative; height: calc(var(--slot) * 2); }
.abacus__earth  { position: relative; height: calc(var(--slot) * 5); }

.abacus__bar {
  height: 9px;
  background: linear-gradient(180deg, #F3D9A8, #C99A55);
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35);
  margin: 2px -2px;
  position: relative;
  z-index: 2;
}

.bead {
  position: absolute;
  border: 0;
  padding: 0;
  appearance: none;
  left: 50%;
  top: 0;
  width: calc(var(--rod-w) - 2px);
  height: var(--bead-h);
  margin-left: calc((var(--rod-w) - 2px) / -2);
  border-radius: 50% / 42%;
  background: radial-gradient(ellipse at 32% 30%, #FFF3C9 0%, var(--sun) 42%, var(--sun-deep) 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, .3);
  cursor: pointer;
  transform: translateY(calc(var(--slot) * var(--pos, 0)));
  transition: transform .16s var(--bounce);
  touch-action: manipulation;
}
.bead::after {
  content: "";
  position: absolute;
  inset: 42% 8% auto;
  height: 2px;
  background: rgba(0, 0, 0, .18);
  border-radius: 2px;
}
.bead--active {
  background: radial-gradient(ellipse at 32% 30%, #FFE4F0 0%, var(--pink) 42%, var(--pink-deep) 100%);
}
.bead--nudged { animation: bead-tick .18s var(--swift); }
@keyframes bead-tick { 50% { filter: brightness(1.35); } }

.abacus--locked .bead { cursor: default; }

.abacus__label {
  height: 22px;
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 600;
  color: #FFE9C9;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

.abacus-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.abacus-readout {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: rgba(255, 255, 255, .94);
  padding: 8px 20px;
  border-radius: var(--r-pill);
  box-shadow: var(--lift-1);
  font-variant-numeric: tabular-nums;
}
.abacus-readout__label { font-size: .85rem; color: var(--ink-soft); }
.abacus-readout__value { font-size: 1.6rem; font-weight: 700; }
