/* Craft & Learn — home screen v2 (scoped to .h2) */
.h2 {
  --sky-top: #6fc3ff; --sky-bot: #bfe6ff;
  --grass: #5fb336; --grass-hi: #8fd65a; --grass-lo: #3d7f22;
  --dirt: #8a5a35; --dirt-lo: #6b4226; --dirt-hi: #a6704a;
  --stone: #7d7d84; --ink: #2b1d14; --cream: #fff6df;
  --gold: #ffcf3a; --gold-lo: #c98a0c;
  --safe-top: max(env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px));
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  font-family: "Rubik", system-ui, sans-serif; color: var(--ink);
  background: var(--dirt-lo); user-select: none; -webkit-user-select: none;
}
.h2 * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.h2 .pixel { image-rendering: pixelated; shape-rendering: crispEdges; }

/* sky */
.h2 .sky { position: relative; padding: calc(var(--safe-top) + 14px) 16px 0; background: linear-gradient(var(--sky-top), var(--sky-bot) 85%); overflow: hidden; }
.h2 .sun { position: absolute; top: calc(var(--safe-top) + 14px); right: 22px; width: 40px; height: 40px; background: #ffe066; box-shadow: 0 0 0 4px #ffd23a, 0 0 0 8px rgba(255,224,102,.35); }
.h2 .cloud { position: absolute; height: 16px; background: #fff; box-shadow: 8px -8px 0 #fff, 24px -8px 0 #fff, 32px 0 0 #fff; opacity: .95; animation: h2drift linear infinite; }
.h2 .cloud.c1 { top: calc(var(--safe-top) + 64px); width: 48px; animation-duration: 38s; left: -80px; }
.h2 .cloud.c2 { top: calc(var(--safe-top) + 26px); width: 32px; animation-duration: 55s; left: -60px; animation-delay: -22s; }
@keyframes h2drift { to { transform: translateX(520px); } }

.h2 .hero { position: relative; display: flex; align-items: flex-end; gap: 10px; min-height: 132px; }
.h2 .leo { width: 96px; height: 96px; flex: none; position: relative; z-index: 2; cursor: pointer; animation: h2bob 2.4s steps(4) infinite; filter: drop-shadow(0 4px 0 rgba(43,29,20,.25)); }
.h2 .leo svg { width: 100%; height: 100%; display: block; }
@keyframes h2bob { 50% { transform: translateY(-4px); } }
.h2 .bubble {
  position: relative; margin-bottom: 30px; flex: 1; background: var(--cream); padding: 10px 12px;
  box-shadow: 0 -4px 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink), 4px 0 0 var(--ink), inset 0 -4px 0 #f0dfb5;
  font-weight: 700; font-size: 17px; line-height: 1.25;
}
.h2 .bubble::before { content: ""; position: absolute; left: -12px; bottom: 10px; width: 8px; height: 8px; background: var(--cream); box-shadow: -4px 4px 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink); }
.h2 .bubble .en { font-family: "Press Start 2P", monospace; font-size: 12px; display: block; margin-bottom: 6px; color: #b8541a; min-height: 12px; }
.h2 .bubble .caret { display: inline-block; width: 8px; height: 14px; background: var(--ink); vertical-align: -2px; animation: h2blink 1s steps(1) infinite; }
@keyframes h2blink { 50% { opacity: 0; } }
.h2 .ground-edge { height: 20px; margin: 0 -16px; background: linear-gradient(var(--grass-hi) 0 4px, var(--grass) 4px 12px, var(--grass-lo) 12px 16px, var(--dirt) 16px); position: relative; }
.h2 .ground-edge::after { content: ""; position: absolute; left: 0; right: 0; top: 16px; height: 8px; background: repeating-linear-gradient(90deg, var(--grass-lo) 0 8px, transparent 8px 20px, var(--grass) 20px 24px, transparent 24px 36px); }

/* dirt body */
.h2 .dirt {
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  background-color: var(--dirt);
  background-image: linear-gradient(45deg, var(--dirt-lo) 25%, transparent 25%), linear-gradient(-45deg, var(--dirt-hi) 25%, transparent 25%);
  background-size: 24px 24px, 32px 32px; background-position: 0 0, 12px 8px;
  min-height: calc(100% - 170px);
}

/* play block */
.h2 .play { display: block; width: 100%; border: 0; padding: 0; cursor: pointer; font: inherit; color: #fff; background: none; position: relative; transition: transform .08s steps(2); }
.h2 .play .top { background: var(--grass); position: relative; padding: 16px 16px 14px; display: flex; align-items: center; justify-content: center; gap: 14px;
  box-shadow: inset 0 6px 0 var(--grass-hi), inset 0 -6px 0 var(--grass-lo), inset 6px 0 0 var(--grass-hi), inset -6px 0 0 var(--grass-lo), 0 0 0 4px var(--ink); }
.h2 .play .side { display: block; height: 14px; background: var(--dirt-lo); margin-top: 4px; box-shadow: 0 0 0 4px var(--ink), inset 0 4px 0 #4f2f1a; }
.h2 .play:active { transform: translateY(8px); }
.h2 .play:active .side { height: 6px; }
.h2 .play .tri { width: 0; height: 0; border-left: 26px solid #fff; border-top: 16px solid transparent; border-bottom: 16px solid transparent; filter: drop-shadow(3px 3px 0 var(--grass-lo)); }
.h2 .play .label { text-align: left; }
.h2 .play .ru { font-weight: 800; font-size: 30px; letter-spacing: .5px; text-shadow: 3px 3px 0 var(--grass-lo); display: block; line-height: 1; }
.h2 .play .en { font-family: "Press Start 2P", monospace; font-size: 11px; opacity: .9; display: block; margin-top: 6px; text-shadow: 2px 2px 0 var(--grass-lo); }
.h2 .play .next { z-index: 2; position: absolute; right: 10px; top: -14px; background: var(--gold); color: var(--ink); font-family: "Press Start 2P", monospace; font-size: 9px; padding: 6px 7px; box-shadow: 0 0 0 3px var(--ink); transform: rotate(4deg); }

/* section label */
.h2 .sec { font-family: "Press Start 2P", monospace; font-size: 11px; color: var(--cream); text-shadow: 2px 2px 0 var(--ink); margin: 26px 2px 12px; display: flex; justify-content: space-between; align-items: baseline; }
.h2 .sec small { font-family: "Rubik", sans-serif; font-weight: 700; font-size: 13px; text-shadow: none; color: #f3d9b8; }

/* topic blocks */
.h2 .topics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.h2 .topic { border: 0; padding: 0; background: none; cursor: pointer; font: inherit; text-align: center; transition: transform .08s steps(2); }
.h2 .topic:active { transform: translateY(4px); }
.h2 .block { aspect-ratio: 1; position: relative; display: grid; place-items: center; background: var(--c);
  box-shadow: inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo), 0 0 0 4px var(--ink), 0 8px 0 0 var(--ink); }
.h2 .block svg { width: 58%; height: 58%; filter: drop-shadow(2px 2px 0 rgba(43,29,20,.35)); }
.h2 .topic .name { display: block; margin-top: 14px; font-weight: 800; font-size: 15px; color: var(--cream); text-shadow: 2px 2px 0 var(--ink); }
.h2 .topic .word { display: block; font-family: "Press Start 2P", monospace; font-size: 8px; color: #f3d9b8; margin-top: 4px; }
.h2 .stars { display: flex; justify-content: center; gap: 3px; margin-top: 7px; }
.h2 .stars span { width: 14px; height: 14px; display: block; }

/* village */
.h2 .village { position: relative; height: 112px; overflow: hidden;
  background: linear-gradient(var(--sky-bot), #e3f4ff 70%, var(--grass) 70% 76%, var(--grass-lo) 76% 80%, var(--dirt) 80%);
  box-shadow: 0 0 0 4px var(--ink); }
.h2 .village .row { position: absolute; left: 10px; right: 10px; bottom: 22px; display: flex; align-items: flex-end; justify-content: space-between; }
.h2 .house { width: 15%; }
.h2 .house svg { width: 100%; display: block; }
.h2 .house.plan svg { opacity: .55; }
.h2 .house.new { animation: h2pop .6s steps(4) both; animation-delay: .9s; }
@keyframes h2pop { from { transform: translateY(14px) scale(.6); opacity: 0; } }
.h2 .village .badge { position: absolute; right: 8px; top: 8px; background: var(--cream); font-weight: 800; font-size: 12px; padding: 4px 7px; box-shadow: 0 0 0 3px var(--ink); }

/* stats */
.h2 .stats { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; margin-top: 22px; }
.h2 .stat { background: var(--stone); color: #fff; padding: 10px; display: flex; align-items: center; gap: 10px; min-height: 62px;
  box-shadow: inset 4px 4px 0 #9a9aa3, inset -4px -4px 0 #5c5c63, 0 0 0 4px var(--ink); }
.h2 .stat b { font-size: 22px; font-weight: 800; display: block; line-height: 1; text-shadow: 2px 2px 0 #3a3a40; }
.h2 .stat .lbl { font-size: 12px; font-weight: 700; color: #e8e8ee; }
.h2 .torch { width: 22px; height: 38px; flex: none; }
.h2 .flame { animation: h2flick .5s steps(2) infinite; transform-origin: 50% 100%; }
@keyframes h2flick { 50% { transform: scaleY(.85) translateX(1px); } }
.h2 .quest-bar { height: 10px; background: #3a3a40; margin-top: 6px; box-shadow: 0 0 0 2px var(--ink); }
.h2 .quest-bar i { display: block; height: 100%; width: 0; background: var(--gold); box-shadow: inset 0 -3px 0 var(--gold-lo); transition: width 1s steps(8) .6s; }

/* load-in */
.h2 .rise { animation: h2rise .5s steps(5) both; }
@keyframes h2rise { from { transform: translateY(18px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .h2 *, .h2 *::before, .h2 *::after { animation: none !important; transition: none !important; } }

/* ── three modes: Учить / Играть / Повтор ───── */
.h2 .modes { display: flex; flex-direction: column; gap: 22px; padding-top: 6px; }
.h2 .mode {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; border: 0; padding: 14px 16px;
  cursor: pointer; font: inherit; color: #fff; text-align: left; background: var(--m);
  box-shadow: inset 0 6px 0 var(--mh), inset 0 -6px 0 var(--ml), 0 0 0 4px var(--ink), 0 8px 0 var(--ink);
  transition: transform .08s steps(2);
}
.h2 .mode:active { transform: translateY(6px); box-shadow: inset 0 6px 0 var(--mh), inset 0 -6px 0 var(--ml), 0 0 0 4px var(--ink), 0 2px 0 var(--ink); }
.h2 .mode .mi { width: 44px; height: 44px; flex: none; display: grid; place-items: center; filter: drop-shadow(3px 3px 0 var(--ml)); }
.h2 .mode .mi svg { width: 100%; height: 100%; }
.h2 .mode .mt { display: flex; flex-direction: column; min-width: 0; }
.h2 .mode .mt b { font-weight: 800; font-size: 28px; line-height: 1; text-shadow: 3px 3px 0 var(--ml); }
.h2 .mode .mt b em { font-family: "Press Start 2P", monospace; font-style: normal; font-size: 9px; font-weight: 400; margin-left: 6px; opacity: .85; text-shadow: 2px 2px 0 var(--ml); }
.h2 .mode .mt small { margin-top: 7px; font-weight: 700; font-size: 14px; opacity: .95; text-shadow: 1px 1px 0 var(--ml); }
.h2 .mode .done { margin-left: auto; font-weight: 800; font-size: 26px; color: #ffe066; text-shadow: 2px 2px 0 var(--ml); }
.h2 .mode.m-learn  { --m: #5fb336; --mh: #8fd65a; --ml: #3d7f22; }
.h2 .mode.m-play   { --m: #e9a23a; --mh: #ffcf6b; --ml: #a8650f; }
.h2 .mode.m-review { --m: #4a8de0; --mh: #7db4f5; --ml: #2a5aa8; }
.h2 .mode.locked   { --m: #7d7d84; --mh: #9a9aa3; --ml: #5c5c63; }
.h2 .mode.locked .mt b { opacity: .8; }
.h2 .mode .tag { position: absolute; right: 12px; top: -14px; z-index: 2; background: var(--gold); color: var(--ink); font-family: "Press Start 2P", monospace; font-size: 9px; padding: 6px 7px; box-shadow: 0 0 0 3px var(--ink); transform: rotate(3deg); }
.h2 .mode.rec { animation: h2rec 1.2s steps(2) infinite; }
@keyframes h2rec { 50% { transform: translateY(-3px); } }
.h2 .mode.shake { animation: h2shake .35s steps(4); }
@keyframes h2shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.h2 .topic.sel .block { box-shadow: inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo), 0 0 0 4px var(--ink), 0 0 0 8px var(--gold), 0 12px 0 4px var(--ink); }
.h2 .topic.sel .name { color: var(--gold); }
@media (prefers-reduced-motion: reduce) { .h2 .mode.rec { animation: none !important; } }

/* ── topic picker pop-up ────────────────────── */
.h2-pick-anchor {}
.pick { position: absolute; inset: 0; z-index: 60; display: flex; align-items: flex-end; background: rgba(43, 29, 20, .62); animation: h2dim .2s steps(3) both;
  font-family: "Rubik", system-ui, sans-serif; }
@keyframes h2dim { from { opacity: 0; } }
.pick * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.pick .pixel { image-rendering: pixelated; shape-rendering: crispEdges; }
.pick-card {
  width: 100%; max-height: 88%; overflow-y: auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  background-color: #8a5a35;
  background-image: linear-gradient(45deg, #6b4226 25%, transparent 25%), linear-gradient(-45deg, #a6704a 25%, transparent 25%);
  background-size: 24px 24px, 32px 32px; background-position: 0 0, 12px 8px;
  box-shadow: 0 -4px 0 #2b1d14, 0 -10px 0 #5fb336; animation: h2sheet .28s steps(5) both;
}
@keyframes h2sheet { from { transform: translateY(40%); } }
.pick-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.pick-head b { font-family: "Press Start 2P", monospace; font-size: 14px; line-height: 1.4; color: #fff6df; text-shadow: 2px 2px 0 #2b1d14; }
.pick-x { width: 40px; height: 40px; border: 0; cursor: pointer; font: 800 20px "Rubik", sans-serif; color: #fff; background: #7d7d84;
  box-shadow: inset 3px 3px 0 #9a9aa3, inset -3px -3px 0 #5c5c63, 0 0 0 3px #2b1d14; }
.pk {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; margin-bottom: 20px; padding: 10px 12px; border: 0; cursor: pointer; font: inherit; text-align: left;
  background: #fff6df; color: #2b1d14; box-shadow: inset 0 -6px 0 #f0dfb5, 0 0 0 4px #2b1d14, 0 6px 0 #2b1d14; transition: transform .08s steps(2);
}
.pk:active { transform: translateY(4px); box-shadow: inset 0 -6px 0 #f0dfb5, 0 0 0 4px #2b1d14, 0 2px 0 #2b1d14; }
.pk .ic { width: 62px; height: 62px; flex: none; display: grid; place-items: center; background: var(--c); box-shadow: inset 4px 4px 0 var(--hi), inset -4px -4px 0 var(--lo), 0 0 0 3px #2b1d14; }
.pk .ic svg { width: 56%; height: 56%; filter: drop-shadow(2px 2px 0 rgba(43,29,20,.35)); }
.pk .nm { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pk .nm b { font-weight: 800; font-size: 24px; line-height: 1.1; }
.pk .nm em { font-family: "Press Start 2P", monospace; font-style: normal; font-size: 8px; color: #8a6a4a; margin-top: 5px; }
.pk .nm small { font-weight: 700; font-size: 13px; color: #8a5a35; margin-top: 6px; }
.pk .st { display: flex; flex-direction: column; gap: 3px; flex: none; }
.pk .st span { width: 14px; height: 14px; display: block; }
.pk.rec { box-shadow: inset 0 -6px 0 #f0dfb5, 0 0 0 4px #2b1d14, 0 0 0 8px #ffcf3a, 0 12px 0 4px #2b1d14; }
.pk .tag { position: absolute; right: 10px; top: -16px; z-index: 2; background: #ffcf3a; color: #2b1d14; font-family: "Press Start 2P", monospace; font-size: 9px; padding: 6px 7px; box-shadow: 0 0 0 3px #2b1d14; transform: rotate(3deg); }
.pk.locked { background: #c9c9ce; box-shadow: inset 0 -6px 0 #aeaeb4, 0 0 0 4px #2b1d14, 0 6px 0 #2b1d14; }
.pk.locked .nm b, .pk.locked .nm small { color: #5c5c63; }
.pk.locked .ic { --c: #8a8a92 !important; --hi: #a8a8b0 !important; --lo: #6c6c74 !important; }
.pk.shake { animation: h2shake .35s steps(4); }
@media (prefers-reduced-motion: reduce) { .pick, .pick-card { animation: none !important; } }

/* village: two rows for 12 topics */
.h2 .village { height: 210px;
  background: linear-gradient(#bfe6ff 0, #e3f4ff 30%, #8fd65a 30% 33%, #5fb336 33% 50%, #3d7f22 50% 51.5%, #7ccc4a 51.5% 60%, #5fb336 60% 89%, #3d7f22 89% 91%, var(--dirt) 91%); }
.h2 .village .row.r1 { bottom: 24px; }
.h2 .village .row.r2 { bottom: 105px; }
.h2 .village .house { width: calc(100% / var(--per, 6) - 4px); }
.pk .ic .em { font-style: normal; font-size: 34px; line-height: 1; filter: drop-shadow(2px 2px 0 rgba(43,29,20,.3)); }

/* picker: topic groups (accordion) */
.pg {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 18px; padding: 12px 14px; border: 0; cursor: pointer; text-align: left;
  background: #6b4226; color: #fff6df; box-shadow: inset 0 -5px 0 #4f2f1a, inset 0 5px 0 #8a5a35, 0 0 0 3px #2b1d14; transition: transform .08s steps(2);
}
.pg:active { transform: translateY(3px); }
.pg .gt { font-family: "Press Start 2P", monospace; font-size: 11px; line-height: 1.4; text-shadow: 2px 2px 0 #2b1d14; flex: 1; }
.pg small { font-family: "Rubik", sans-serif; font-weight: 700; font-size: 12px; color: #f3d9b8; white-space: nowrap; }
.pg .ar { width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid #fff6df; transition: transform .15s steps(2); }
.pg.open .ar { transform: rotate(180deg); }
.pg-body { display: none; }
.pg.open + .pg-body { display: block; }

/* picker: all topics visible at once, two per row */
.pick-card { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; max-height: 92%; }
.pg.open + .pg-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 14px; margin: 0 0 14px; }
.pg-body .pk { flex-direction: column; align-items: flex-start; gap: 8px; margin: 0; padding: 10px; }
.pg-body .pk .ic { width: 54px; height: 54px; }
.pg-body .pk .ic .em { font-size: 30px; }
.pg-body .pk .nm b { font-size: 19px; }
.pg-body .pk .nm em { display: none; }
.pg-body .pk .nm small { margin-top: 4px; font-size: 12px; }
.pg-body .pk .st { flex-direction: row; }
.pg-body .pk .tag { right: 6px; top: -14px; }
.pg-body .pk.rec { box-shadow: inset 0 -6px 0 #f0dfb5, 0 0 0 4px #2b1d14, 0 0 0 7px #ffcf3a, 0 10px 0 3px #2b1d14; }

.pg-lab { font-family: "Press Start 2P", monospace; font-size: 10px; color: #f3d9b8; text-shadow: 2px 2px 0 #2b1d14; margin: 4px 2px 14px; }
.pg-cont { margin-bottom: 26px; }
.pg-cont .pk { margin-bottom: 0; }

/* game menu */
.gm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; }
.gm {
  display: flex; align-items: center; gap: 10px; border: 0; padding: 12px 10px; cursor: pointer; text-align: left; font: inherit; min-height: 84px;
  background: #fff6df; color: #2b1d14; box-shadow: inset 0 -6px 0 #f0dfb5, 0 0 0 4px #2b1d14, 0 6px 0 #2b1d14; transition: transform .08s steps(2);
}
.gm:active { transform: translateY(4px); box-shadow: inset 0 -6px 0 #f0dfb5, 0 0 0 4px #2b1d14, 0 2px 0 #2b1d14; }
.gm .gi { font-size: 34px; line-height: 1; flex: none; }
.gm .gn { display: flex; flex-direction: column; min-width: 0; }
.gm .gn b { font-weight: 800; font-size: 17px; line-height: 1.15; }
.gm .gn small { margin-top: 4px; font-weight: 700; font-size: 12px; color: #8a5a35; }
.gm.all { grid-column: 1 / -1; background: #5fb336; color: #fff; box-shadow: inset 0 6px 0 #8fd65a, inset 0 -6px 0 #3d7f22, 0 0 0 4px #2b1d14, 0 6px 0 #2b1d14; }
.gm.all .gn b { font-size: 24px; text-shadow: 2px 2px 0 #3d7f22; }
.gm.all .gn small { color: #eaffda; }

/* fourth, smaller button: choose a game */
.h2 .mode.sm { padding: 9px 14px; }
.h2 .mode.sm .mi { width: 34px; height: 34px; }
.h2 .mode.sm .mt b { font-size: 20px; }
.h2 .mode.sm .mt small { margin-top: 4px; font-size: 13px; }
.h2 .mode.m-games { --m: #9a5ad6; --mh: #c49af0; --ml: #6a3aa0; }
.h2 .mode.m-games.locked { --m: #7d7d84; --mh: #9a9aa3; --ml: #5c5c63; }
