/* Mancala, laid out as Branch Birds is: the game's name and its button across the top, over the
   round's own area, which mancala.js lays the board out in. The panel's size is
   game-layout.css's (data-ideal); the stage fills it. */

.game-root[data-game="mancala"] {
  position: relative; display: block; padding: 0; overflow: hidden; text-align: left;
  background: linear-gradient(160deg, #f3ede2 0%, #e9eef2 55%, #f0e8ee 100%);
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.mn-stage { position: absolute; inset: 0; }

/* --- the top row: the game's name at the left, its button at the right ----------------------- */
.mn-top {
  position: absolute; top: 14px; left: 18px; right: 18px; z-index: 2;
  display: flex; flex-direction: column; gap: 2px; pointer-events: none; text-align: left;
}
.mn-namerow { display: flex; align-items: baseline; gap: 10px; }
.mn-game { font-weight: 700; color: #3c4a5a; }
.mn-tools { position: absolute; top: 12px; right: 14px; z-index: 4; display: flex; gap: 8px; }
.mn-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border: 1px solid var(--c-border); border-radius: 999px;
  background: rgba(255, 255, 255, .7); color: var(--c-text-soft);
  font: inherit; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.mn-pill:hover:not(:disabled) { border-color: var(--c-primary); color: var(--c-text); }
.mn-pill:disabled { opacity: .45; cursor: default; }
.mn-pill .mn-icon { width: 16px; height: 16px; }

/* --- the round's own area --------------------------------------------------------------------
   The top padding clears the row above. A vertical swipe still scrolls the page; a pit acts on a
   tap. */
.mn {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 56px 12px 10px; box-sizing: border-box; overflow: hidden;
  background: #efeae0; text-align: left;
  touch-action: pan-y; -webkit-tap-highlight-color: transparent;
}
.mn-canvas {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block;
  user-select: none; -webkit-user-select: none;
}
.mn-canvas.is-pit { cursor: pointer; }
/* Above the canvas but letting every press through to it. */
.mn-hud, .mn-fit, .mn-cap { position: relative; pointer-events: none; }
.mn > .mn-hud, .mn > .mn-cap { flex: none; }

.mn-hud {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; max-width: 560px; color: #4a3a2c;
}
.mn-name { min-width: 0; overflow: hidden; font-weight: 800; font-size: .92rem; white-space: nowrap; text-overflow: ellipsis; }
/* Whose turn it is: a dot in the side's colour and the words. */
.mn-turn {
  flex: none; display: inline-flex; align-items: center; gap: 7px;
  font-size: .85rem; font-weight: 700; color: #4a3a2c; transition: opacity .25s ease;
}
.mn-turn::before {
  content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--c, #5cc98d);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, #5cc98d) 25%, transparent);
}
.mn-turn.is-off { opacity: 0; }

/* At the stage's two sides, halfway down; under the card's panel (z-index 5). */
.mn-arrow {
  position: absolute; top: 50%; z-index: 3; transform: translateY(-50%);
  display: grid; place-items: center; width: 42px; height: 42px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: rgba(74, 58, 44, .45); cursor: pointer;
}
.mn-prev { left: 6px; }
.mn-next { right: 6px; }
.mn-arrow:hover:not(:disabled) { background: rgba(255, 255, 255, .7); color: #4a3a2c; }
/* Faint on the icon, not the button: an opacity on the button would fade its tip with it. */
.mn-arrow:disabled { cursor: default; }
.mn-arrow:disabled .mn-icon { opacity: .12; }
.mn-arrow[hidden] { display: none; }
/* Where a press goes, beside the arrow on hover. */
.mn-arrow::after {
  content: attr(data-tip); position: absolute; top: 50%; transform: translateY(-50%);
  padding: 5px 10px; border-radius: 999px; background: rgba(255, 255, 255, .95); color: #4a3a2c;
  box-shadow: 0 1px 4px rgba(20, 30, 50, .18); font-size: .8rem; font-weight: 600; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .12s ease;
}
.mn-prev::after { left: calc(100% + 4px); }
.mn-next::after { right: calc(100% + 4px); }
.mn-arrow:hover::after, .mn-arrow:focus-visible::after { opacity: 1; }
.mn-arrow .mn-icon { width: 28px; height: 28px; stroke-width: 2.4; }

.mn-fit { flex: 1 1 0; min-height: 0; width: 100%; }

/* Two lines tall whatever it says, empty included: the board is laid out in what this leaves,
   so a caption that changed height would move the board as a note comes and goes. */
.mn-cap {
  display: flex; align-items: center; justify-content: center; box-sizing: border-box;
  height: 3em; overflow: hidden; line-height: 1.5; margin: 0; width: 100%; max-width: 560px; padding: 0 46px;
  color: #5a4634; font-size: .86rem; font-weight: 600; text-align: center;
}
/* The rules' notes run to three lines on a phone; two would cut them off. */
@media (max-width: 520px) {
  .mn-cap { height: 4.5em; padding: 0 8px; }
}
/* A note: in, one glow, out. 6s is NOTE_MS in mancala.js. */
.mn-cap.is-note { animation: mn-note 6s ease-in-out both; }
/* A short word on a free turn or a capture. 2.2s is FLASH_MS in mancala.js. */
.mn-cap.is-flash { animation: mn-flash 2.2s ease-in-out both; }
@keyframes mn-note {
  0% { opacity: 0; }
  6%, 92% { opacity: 1; }
  14%, 40% { transform: translateY(-3px); text-shadow: 0 0 10px rgba(92, 201, 141, .45); }
  52% { transform: translateY(0); text-shadow: none; }
  100% { opacity: 0; }
}
@keyframes mn-flash {
  0% { opacity: 0; transform: translateY(4px); }
  12% { opacity: 1; transform: translateY(-3px); text-shadow: 0 0 10px rgba(92, 201, 141, .45); }
  30%, 80% { opacity: 1; transform: translateY(0); text-shadow: none; }
  100% { opacity: 0; }
}
/* Moves with the hand: 3.2s is DEMO.cycle in mancala.js; the two change together. */
.mn-cap.is-on { animation: mn-say 3.2s ease-in-out infinite; }
@keyframes mn-say {
  0%, 10% { transform: translateY(0); text-shadow: none; }
  20%, 50% { transform: translateY(-3px); text-shadow: 0 0 10px rgba(92, 201, 141, .45); }
  62%, 100% { transform: translateY(0); text-shadow: none; }
}

/* The lesson's hand. mancala.js places it with transform each frame; the offsets put the
   fingertip (34.4% 5.9% of the icon) on the point it is moved to. */
.mn-hand {
  position: absolute; left: -16px; top: -3px; z-index: 2; pointer-events: none;
  width: 46px; aspect-ratio: 32 / 34; transform-origin: 34.4% 5.9%; opacity: 0;
}
.mn-hand[hidden] { display: none; }
.mn-hand svg { position: relative; display: block; width: 100%; height: 100%; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .3)); }
.mn-hand::before {
  content: ''; position: absolute; left: 34.4%; top: 5.9%; width: 70%; aspect-ratio: 1;
  border-radius: 50%; background: rgba(92, 201, 141, .5); box-shadow: 0 0 0 2px rgba(255, 255, 255, .8);
  transform: translate(-50%, -50%) scale(0); opacity: 0; transition: transform .25s ease-out, opacity .25s ease-out;
}
.mn-hand.is-down::before { transform: translate(-50%, -50%) scale(1); opacity: 1; }

/* New game and Undo, side by side in the middle under the caption, level with the speaker. */
.mn-ctrl { position: relative; z-index: 2; flex: none; display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 38px; }
/* The pills' words and icon, in the round buttons' white and shadow. */
.mn-ctrl .mn-pill {
  height: 38px; padding: 0 16px; box-sizing: border-box; border: 0;
  background: rgba(255, 255, 255, .78); color: #4a3a2c;
  box-shadow: 0 1px 4px rgba(20, 30, 50, .18);
}
.mn-ctrl .mn-pill:hover:not(:disabled) { background: #fff; color: #4a3a2c; }
.mn-round {
  width: 38px; height: 38px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .78); color: #4a3a2c; cursor: pointer;
  box-shadow: 0 1px 4px rgba(20, 30, 50, .18);
}
.mn-round:hover { background: #fff; }
.mn-round .mn-icon, .mn-round .mn-sicon { width: 22px; height: 22px; }

/* The speaker, and the dots beside it that open the menu. The dots take no room until shown
   (hover, focus, or the menu open); a screen that cannot hover shows them always, dimmer. The
   menu opens upward. */
.mn-audio { position: absolute; right: 12px; bottom: 10px; z-index: 3; display: flex; align-items: center; }
.mn-more {
  display: grid; place-items: center; width: 0; height: 38px; padding: 0; overflow: hidden;
  border: 0; background: none; color: rgba(74, 58, 44, .6); cursor: pointer; opacity: 0;
  transition: opacity .15s ease;
}
.mn-audio:hover .mn-more, .mn-audio:focus-within .mn-more, .mn-audio.is-open .mn-more { width: 30px; opacity: 1; }
@media (hover: none) { .mn-more { width: 30px; opacity: .6; } }
.mn-more .mn-sicon { width: 22px; height: 22px; }
.mn-ellipsis { stroke-width: 3.4; }
.mn-menu {
  position: absolute; right: 0; bottom: 46px; min-width: 200px; padding: 6px; box-sizing: border-box;
  border: 1px solid rgba(74, 58, 44, .18); border-radius: 12px; background: rgba(253, 251, 248, .97);
  box-shadow: 0 6px 20px rgba(40, 30, 20, .18);
}
.mn-menu[hidden] { display: none; }
.mn-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 9px 10px;
  border: 0; border-radius: 8px; background: none; color: #4a3a2c; font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; text-align: left;
}
.mn-opt:hover, .mn-opt:focus-visible { background: rgba(74, 58, 44, .07); }
.mn-sw { position: relative; flex: none; width: 34px; height: 20px; border-radius: 999px; background: rgba(74, 58, 44, .22); transition: background .15s ease; }
.mn-sw::after {
  content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s ease;
}
.mn-opt[aria-checked="true"] .mn-sw { background: #5cc98d; }
.mn-opt[aria-checked="true"] .mn-sw::after { transform: translateX(14px); }
.mn-sicon { display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mn-cone { fill: currentColor; stroke: none; }
.mn-sound.off .mn-waves { display: none; }
.mn-sound:not(.off) .mn-slash { display: none; }
.mn-icon { width: 18px; height: 18px; flex: none; }

/* --- over the stage: the panel blurs it, and a sheet in its middle holds the card ------------- */
.mn-win { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.mn-panel {
  position: absolute; inset: 0; pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 20px; text-align: center; overflow-y: auto;
  background: rgba(242, 237, 228, .58);
  -webkit-backdrop-filter: blur(14px) saturate(1.15); backdrop-filter: blur(14px) saturate(1.15);
  animation: mn-in .35s ease-out;
}
@keyframes mn-in { from { opacity: 0; } }
/* Centred with auto margins rather than justify-content: a sheet taller than the stage scrolls
   from its top instead of losing it. */
.mn-panel > * { flex: none; }
.mn-panel > :first-child { margin-top: auto; margin-bottom: auto; }
.mn-sheet {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(440px, 100%); box-sizing: border-box;
  padding: 26px 18px; border: 1px solid rgba(255, 255, 255, .55); border-radius: 20px;
  background: linear-gradient(160deg, rgba(255, 255, 255, .6), rgba(242, 236, 226, .46));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85), 0 12px 32px rgba(30, 20, 10, .22);
  -webkit-backdrop-filter: blur(18px) saturate(1.3); backdrop-filter: blur(18px) saturate(1.3);
}
.mn-title { margin: 0; font-size: 1.6rem; font-weight: 700; color: #2f3b4a; }
/* Each letter's delay is set by mancala.js. */
.mn-word { white-space: nowrap; }
.mn-ch { display: inline-block; animation: mn-wave .5s ease-in-out both; }
@keyframes mn-wave { 40% { transform: translateY(-.35em); } }
.mn-view { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.mn-view p { margin: 0; }
.mn-view-title { font-weight: 800; color: #4a3a2c; }
.mn-view-line { color: #4a3a2c; }
.mn-view-small { font-size: .8rem; color: #8a96a3; }
.mn-ask { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #4a5766; }
.mn-ask p { margin: 0; }
.mn-moods { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.mn-mood {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px;
  border: 1px solid var(--c-border); border-radius: 999px; background: #fff; color: var(--c-text);
  font: inherit; cursor: pointer;
}
.mn-mood:hover { border-color: var(--c-primary); }
.mn-mood.on { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.mn-mood .mn-icon { width: 22px; height: 22px; }
.mn-ask .mn-note { min-height: 1.3em; margin: 0; font-size: .9rem; color: var(--c-text-soft); }
.mn-key {
  display: inline-block; min-width: 1.6em; padding: 1px 6px; margin: 0 1px;
  border: 1px solid #c9ced8; border-bottom-width: 2px; border-radius: 5px; background: #fff;
  font: inherit; font-size: .85em; font-weight: 700; line-height: 1.4; text-align: center; color: var(--c-text);
}
.mn-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.mn-choices .btn { display: inline-flex; align-items: center; gap: 8px; }
.mn-choices .mn-icon { stroke-width: 2.2; }
/* The last level's award: a green badge that pops in, with one shine across it. */
.mn-badge {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 8px; margin: 0;
  padding: 7px 18px 7px 13px; border-radius: 999px;
  background: linear-gradient(180deg, #ecf9f1, #d5f0df); border: 1.5px solid #8fd3a9;
  box-shadow: 0 4px 12px rgba(46, 140, 87, .18);
  color: #237a4a; font-size: 1.12rem; font-weight: 800;
  animation: mn-badge-in .55s cubic-bezier(.2, .9, .3, 1.35) .15s both;
}
.mn-badge::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -40%; width: 30%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .8), transparent);
  transform: skewX(-18deg); animation: mn-badge-shine .9s ease-in-out .8s both;
}
.mn-cap-icon { flex: none; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.mn-cap-top { fill: currentColor; }
@keyframes mn-badge-in { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: none; } }
@keyframes mn-badge-shine { from { left: -40%; } to { left: 120%; } }

/* The rules before the first game: a sentence, a small board of real stones, the scene dots. The
   board is drawn at a fixed size (MINI in mancala.js) and only scaled to fit. */
.mn-sheet.mn-intro { gap: 16px; width: min(480px, 100%); }
.mn-intro-line {
  display: flex; align-items: center; justify-content: center; min-height: 4.5em; margin: 0;
  color: #4a3a2c; font-weight: 700; line-height: 1.5; text-align: center;
}
.mn-mini { position: relative; width: 100%; transition: opacity .22s ease; }
.mn-mini.is-reset { opacity: 0; }
.mn-mini-in { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.mn-mini-board {
  position: absolute; border-radius: 12px;
  background: linear-gradient(180deg, #cf9661, #c0844f 50%, #a96f40);
  box-shadow: 0 4px 10px rgba(60, 35, 15, .3), inset 0 0 0 1px rgba(255, 232, 196, .35);
}
.mn-mini-pit {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle at 50% 62%, #7d4e2b, #5f3a1f 72%, #4a2b15);
  box-shadow: inset 0 3px 3px rgba(30, 14, 4, .45), 0 1px 0 rgba(255, 226, 180, .35);
}
.mn-mini-pit.is-store { border-radius: 999px; }
.mn-mini-pit.is-glow { animation: mn-mini-glow .6s ease-out; }
@keyframes mn-mini-glow {
  from { box-shadow: inset 0 3px 3px rgba(30, 14, 4, .45), 0 0 0 3px rgba(255, 236, 190, .9); }
}
/* 9.18px across: 2 x 0.135 x MINI.d (34) in mancala.js, the real board's stone to pit. */
.mn-mini-stone {
  position: absolute; left: 0; top: 0; width: 9.18px; height: 9.18px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, var(--l), var(--b) 45%, var(--e));
  box-shadow: 1px 1.5px 1.5px rgba(40, 20, 6, .3);
  transition: transform .3s cubic-bezier(.3, .7, .4, 1);
}
/* Positioned by transform (mancala.js), so the hop animates `translate`, not `transform`. */
.mn-mini-stone.is-hop { animation: mn-mini-hop .35s ease-out; }
@keyframes mn-mini-hop { 50% { translate: 0 -4px; } }
.mn-mini.is-instant .mn-mini-stone, .mn-mini.is-instant .mn-hand { transition: none; }
.mn-mini-num {
  position: absolute; transform: translate(-50%, -50%); line-height: 1;
  font-size: 9px; font-weight: 800; color: rgba(255, 244, 226, .95);
}
.mn-mini-side {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap; line-height: 1;
  font-size: 10px; font-weight: 600; color: #6a5442;
}
.mn-mini-side b { font-size: 12px; font-weight: 800; color: #9a5f17; }
.mn-mini-side.is-you b { color: #2c7a50; }
.mn-mini-say {
  position: absolute; z-index: 90; transform: translate(-50%, -100%);
  padding: 3px 8px; border-radius: 999px; background: #3fae73; color: #fff;
  font-size: 10px; font-weight: 800; white-space: nowrap; box-shadow: 0 2px 6px rgba(20, 60, 40, .25);
  animation: mn-mini-say .4s cubic-bezier(.3, 1.6, .5, 1) both;
}
@keyframes mn-mini-say { from { opacity: 0; scale: .4; } }
/* Smaller here; left/top keep the fingertip (34.4% 5.9% of the icon) on its point. */
.mn-mini-in .mn-hand {
  z-index: 100; width: 30px; left: -10.3px; top: -1.9px;
  transition: transform .5s cubic-bezier(.2, .7, .3, 1), opacity .3s ease;
}
.mn-steps { display: flex; gap: 8px; }
.mn-steps i { display: block; width: 8px; height: 8px; border-radius: 50%; background: rgba(74, 58, 44, .22); transition: background .25s ease; }
.mn-steps i.on { background: #5cc98d; }

/* The review build's tools, under the game panel and outside it. */
.mn-review {
  display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap;
  margin: 10px auto 0; padding: 8px; font-size: .85rem; color: #4a5766;
}
.mn-review select, .mn-review button { font: inherit; padding: 4px 8px; border-radius: 8px; border: 1px solid #ccc; background: #fff; }

/* #game-root itself is the element that goes full screen; these same rules are the
   fixed-position fallback for a browser without the Fullscreen API. game-layout.css gives a
   [data-ideal] panel an explicit width and height, which would beat the fallback's inset. */
#game-root.mn-fs {
  position: fixed; inset: 0; z-index: 200; margin: 0; padding: 0;
  width: auto; height: auto; max-width: none;
  border: 0; border-radius: 0; box-shadow: none; min-height: 0; overflow: hidden;
}
body.mn-locked { overflow: hidden; }
