/* LapKa — мини-игры, набор B (js/games-b.js). Все классы с префиксом gb-.
   Подключать после css/style.css. Цвета — только через переменные тем (кроме декоративных пастельных). */

/* ---------- общий каркас ---------- */
/* Корень игры занимает всю высоту .g-body. --gbh — высота поля: экран минус шапка игры и отступы оболочки
   (.game: 16 + 48 + 18, .g-body: 16); по ней «Тайное слово» и «Поиск слов» подгоняют размер клеток.
   Авто-отступы вместо justify-content: center — чтобы на очень низком экране верх не уезжал под шапку,
   а лишнее просто прокручивалось. */
.gb { --gbh: calc(100vh - 98px); flex: 1 1 0; min-height: 0; width: 100%; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 12px; }
@supports (height: 1dvh) { .gb { --gbh: calc(100dvh - 98px); } }
.gb > :first-child { margin-top: auto; }
.gb > :last-child { margin-bottom: auto; }
.gb button { touch-action: manipulation; -webkit-user-select: none; user-select: none; }

.gb-sorry { text-align: center; gap: 14px; }
.gb-sorry p { color: var(--muted); font-weight: 600; max-width: 360px; }
.gb-sorry-cat { animation: gb-bob 3s ease-in-out infinite; }

.gb-clue { text-align: center; max-width: 100%; }
.gb-clue b { display: block; font-size: 21px; font-weight: 900; line-height: 1.25; overflow-wrap: anywhere; }

/* клетки для слогов собираемого слова */
.gb-slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.gb-slot { min-width: 46px; height: 52px; padding: 0 6px; border-radius: 14px; border: 2.5px dashed var(--line); background: var(--soft); color: var(--ink); display: grid; place-items: center; font-size: 26px; line-height: 1; }
.gb-slot.gb-wide { min-width: 58px; }
.gb-slot.gb-on { border-style: solid; border-color: var(--edge); background: var(--card); box-shadow: 0 3px 0 var(--edge); animation: gb-pop .25s ease; }
.gb-slot.gb-ok { background: var(--ok); color: #123524; }
.gb-slot.gb-no { background: var(--bad-bg); border-color: var(--bad); box-shadow: 0 3px 0 var(--bad); }

/* плитки-кнопки */
.gb-zone { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.gb-bank { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; width: 100%; max-width: 420px; }
.gb-bank.gb-flex { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 520px; }
.gb-t { display: inline-grid; place-items: center; min-height: 50px; padding: 4px 2px; border-radius: 14px; border: 2.5px solid var(--edge); background: var(--card); color: var(--ink); box-shadow: 0 4px 0 var(--edge); font-size: 24px; font-weight: 700; line-height: 1.1; transition: transform .08s, box-shadow .08s, opacity .15s, background .15s; }
.gb-bank.gb-flex .gb-t, .gb-tl-line .gb-t { min-width: 54px; padding: 4px 12px; }
.gb-t:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.gb-t:disabled { cursor: default; }
.gb-t.gb-on { background: var(--pri-2); }
.gb-t.gb-used { opacity: .25; box-shadow: none; transform: translateY(4px); }
.gb-t.gb-good { background: var(--ok); color: #123524; box-shadow: 0 1px 0 var(--edge); transform: translateY(3px); }
.gb-t.gb-bad { background: var(--bad-bg); border-color: var(--bad); color: var(--muted); box-shadow: none; transform: translateY(4px); }
.gb-t.gb-ctl { background: var(--pri-2); font-size: 20px; }
.gb-t.gb-go { background: var(--pri); color: var(--pri-ink); font-weight: 900; }

.gb-next { min-height: 54px; display: flex; justify-content: center; align-items: center; width: 100%; }
.gb-after { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; animation: gb-rise .25s ease both; }
.gb-after-t { font-size: 18px; font-weight: 900; }
.gb-after-w { font-weight: 700; }
.gb-after-w .jp { font-size: 22px; }
.gb-plus { color: var(--ok); font-weight: 900; font-size: 20px; animation: gb-pop .3s ease; display: inline-block; }
.gb-minus { color: var(--bad); font-weight: 900; font-size: 16px; }
.gb-shake { animation: gb-shake .32s ease; }

/* компактные варианты ответа (эмодзи, касса) */
.gb .opts.gb-opts { gap: 10px; max-width: 520px; }
.gb .opts.gb-opts .opt { min-height: 52px; padding: 8px 14px; font-size: 16px; line-height: 1.25; text-align: center; box-shadow: 0 4px 0 var(--edge); }
.gb .opts.gb-opts .opt .jp { font-size: 23px; }

/* ---------- 1. Тайное слово ---------- */
.gb-secret { gap: 6px; --k: clamp(23px, calc((var(--gbh) - 130px) / 14), 46px); } /* 14 рядов: 6 попыток + 8 рядов клавиатуры */
.gb-sc-top { min-height: 36px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; text-align: center; font-weight: 700; font-size: 14px; }
.gb-sc-top > b { font-size: 17px; font-weight: 900; }
.gb-sc-clue { font-weight: 800; background: var(--acc); color: #3b2a3f; padding: 3px 12px; border-radius: 12px; border: 2px solid var(--edge); animation: gb-pop .25s ease; }
.gb-sc-board { display: grid; grid-template-rows: repeat(6, var(--k)); gap: 4px; }
.gb-sc-row { display: grid; grid-auto-flow: column; grid-auto-columns: calc(var(--k) * 1.12); gap: 5px; justify-content: center; }
.gb-cell { position: relative; display: grid; place-items: center; border: 2.5px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font-size: calc(var(--k) * .56); line-height: 1; }
.gb-cell.gb-cur { border-color: var(--pri); border-style: dashed; }
.gb-cell.gb-fill { border-color: var(--edge); animation: gb-pop .16s ease; }
.gb-cell.gb-hit, .gb-key.gb-hit, .gb-lg.gb-hit { background: var(--ok); color: #123524; border-color: var(--edge); }
.gb-cell.gb-near, .gb-key.gb-near, .gb-lg.gb-near { background: var(--acc); color: #3b2a3f; border-color: var(--edge); }
.gb-cell.gb-miss, .gb-key.gb-miss, .gb-lg.gb-miss { background: var(--soft); color: var(--muted); border-color: var(--line); }
.gb-key.gb-miss { box-shadow: none; transform: translateY(2px); }
.gb-cell.gb-hit::after, .gb-key.gb-hit::after { content: "◯"; }
.gb-cell.gb-near::after, .gb-key.gb-near::after { content: "△"; }
.gb-cell.gb-miss::after, .gb-key.gb-miss::after { content: "✕"; }
.gb-cell::after, .gb-key::after { position: absolute; right: 2px; top: 1px; font-size: 8px; font-weight: 900; line-height: 1; font-family: sans-serif; opacity: .85; }
.gb-key::after { font-size: 7px; right: 1px; }
.gb-flip { animation: gb-flip .34s ease both; }
.gb-sc-info { min-height: 20px; display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; font-size: 11px; font-weight: 800; }
.gb-lg { padding: 1px 7px; border-radius: 8px; border: 1.5px solid var(--line); white-space: nowrap; }
.gb-sc-warn { color: var(--bad); font-size: 13px; }
.gb-sc-kb { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) 2px repeat(5, minmax(0, 1fr)); grid-auto-rows: var(--k); gap: 4px; width: calc(100% + 16px); max-width: 470px; flex: none; }
.gb-key { position: relative; display: grid; place-items: center; padding: 0; min-width: 0; border: 2px solid var(--edge); border-radius: 9px; background: var(--card); color: var(--ink); box-shadow: 0 2px 0 var(--edge); font-size: clamp(15px, calc(var(--k) * .54), 23px); line-height: 1; transition: transform .06s, box-shadow .06s, background .2s; }
.gb-key:active { transform: translateY(2px); box-shadow: none; background: var(--pri-2); }
.gb-key.gb-ctl { background: var(--pri-2); font-family: inherit; font-size: 13px; font-weight: 800; }
.gb-key.gb-del { grid-column: span 2; font-size: 17px; }
.gb-key.gb-go { grid-column: span 3; background: var(--pri); color: var(--pri-ink); }
.gb-sc-end { width: 100%; max-width: 420px; padding: 14px 18px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; animation: gb-rise .3s ease both; }
.gb-sc-word { display: flex; align-items: center; gap: 12px; }
.gb-sc-word .jp { font-size: 34px; line-height: 1.3; }
.gb-ru { font-size: 18px; font-weight: 800; }
.gb-sc-end .btn { margin-top: 6px; }

/* ---------- 2. Спаси онигири ---------- */
.gb-oni-stage { display: flex; align-items: flex-end; justify-content: center; gap: 2px; min-height: 112px; }
.gb-oni-cat { transform-origin: 50% 90%; }
.gb-oni-cat.gb-chomp { animation: gb-chomp .5s ease; }
.gb-oni-plate { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.gb-oni-rice { line-height: 0; }
.gb-oni-rice.gb-hurt { animation: gb-wobble .45s ease; }
.gb-onigiri { display: block; }
.gb-oni-hp { display: flex; gap: 5px; }
.gb-oni-hp i { width: 12px; height: 12px; border-radius: 50% 50% 45% 45%; background: var(--pri); border: 2px solid var(--edge); transition: transform .2s, opacity .2s, background .2s; }
.gb-oni-hp i.gb-off { background: var(--soft); border-color: var(--line); transform: scale(.7); }

/* ---------- 3. Перепутанные слоги ---------- */
.gb-scr { gap: 16px; }
.gb-scr .q-timer i.gb-low { background: var(--bad); }
.gb-scr-msg { min-height: 34px; display: flex; align-items: center; gap: 10px; font-weight: 800; }
.gb-scr-msg .jp { font-size: 24px; }

/* ---------- 4. Поиск слов ---------- */
.gb-ws { gap: 10px; }
.gb-ws-tip { font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; }
.gb-ws-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; width: min(100%, 372px, max(238px, calc(var(--gbh) - 226px))); flex: none; padding: 7px; border-radius: 22px; border: 2.5px solid var(--edge); background: var(--card); box-shadow: 0 5px 0 var(--edge); touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.gb-ws-c { display: grid; place-items: center; min-width: 0; aspect-ratio: 1; border-radius: 10px; background: var(--soft); color: var(--ink); font-size: 20px; line-height: 1; transition: transform .1s, background .12s; }
.gb-ws-c.gb-found { font-weight: 800; }
.gb-f0 { background: #ffd6a5; color: #3b2a3f; }
.gb-f1 { background: #caffbf; color: #3b2a3f; }
.gb-f2 { background: #9bf6ff; color: #3b2a3f; }
.gb-f3 { background: #ffc6ff; color: #3b2a3f; }
.gb-f4 { background: #fdffb6; color: #3b2a3f; }
.gb-ws-c.gb-sel { background: var(--pri); color: var(--pri-ink); transform: scale(1.07); }
.gb-ws-c.gb-bad { background: var(--bad); color: #3f1010; animation: gb-shake .32s ease; }
.gb-ws-c.gb-hint { box-shadow: 0 0 0 3px var(--acc), 0 0 0 5px var(--edge); animation: gb-pulse .65s ease 4; z-index: 1; }
.gb-ws-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; width: 100%; }
.gb-ws-w { display: inline-flex; align-items: baseline; gap: 6px; min-height: 34px; padding: 4px 11px; border-radius: 12px; border: 2px solid var(--edge); background: var(--card); color: var(--ink); box-shadow: 0 2px 0 var(--edge); font-weight: 800; font-size: 14px; line-height: 1.3; text-align: left; }
.gb-ws-w .jp { font-size: 15px; color: var(--muted); }
.gb-ws-w .jp:empty { display: none; }
.gb-ws-w.gb-done { box-shadow: none; transform: translateY(2px); cursor: default; }
.gb-ws-w.gb-done b { text-decoration: line-through; text-decoration-thickness: 2px; }
.gb-ws-w.gb-done .jp { color: inherit; }
.gb-ws-w.gb-f0 { background: #ffd6a5; color: #3b2a3f; }
.gb-ws-w.gb-f1 { background: #caffbf; color: #3b2a3f; }
.gb-ws-w.gb-f2 { background: #9bf6ff; color: #3b2a3f; }
.gb-ws-w.gb-f3 { background: #ffc6ff; color: #3b2a3f; }
.gb-ws-w.gb-f4 { background: #fdffb6; color: #3b2a3f; }

/* ---------- 5. Угадай по эмодзи ---------- */
.gb-emo-card { width: 100%; max-width: 520px; padding: 12px 16px; text-align: center; }
.gb-emo-e { font-size: 44px; line-height: 1.3; letter-spacing: .08em; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; animation: gb-pop .3s ease; }
.gb-emo-jp { min-height: 58px; display: flex; flex-direction: column; justify-content: center; }
.gb-emo-name { font-size: 26px; line-height: 1.3; animation: gb-rise .25s ease both; }
.gb-emo-name.gb-long { font-size: 18px; }
.gb-emo-jp .q-sub { margin-top: 0; font-size: 14px; }

/* ---------- 6. Собери название ---------- */
.gb-tl-card { width: 100%; max-width: 520px; padding: 12px 14px 12px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gb-tl-ru { font-size: 21px; font-weight: 900; line-height: 1.2; }
.gb-tl-line { min-height: 66px; width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; padding: 6px 0 10px; border-bottom: 3px dashed var(--line); }
.gb-tl-line.gb-no .gb-t { background: var(--bad); color: #3f1010; }
.gb-tl-line span.gb-t { animation: gb-pop .25s ease; }
.gb-tl-line.gb-done { min-height: 0; gap: 4px; padding: 0 0 8px; }
.gb-tl-line.gb-done .gb-t { min-width: 0; min-height: 36px; padding: 2px 7px; font-size: 17px; border-radius: 11px; }
.gb-tl-note { min-height: 22px; font-size: 13px; font-weight: 800; color: var(--muted); text-align: center; letter-spacing: .02em; }
.gb-tl-parts { display: flex; flex-direction: column; gap: 5px; width: 100%; max-width: 440px; animation: gb-rise .25s ease both; }
.gb-tl-p { display: flex; align-items: baseline; gap: 10px; padding: 4px 10px; border-radius: 12px; background: var(--soft); border: 2px solid var(--line); font-weight: 700; font-size: 13px; line-height: 1.3; }
.gb-tl-p .jp { font-size: 18px; flex: none; color: var(--ink); }
.gb-tl .gb-zone .q-sub { margin-top: 0; }

/* ---------- 7. Касса ---------- */
.gb-cash { gap: 10px; }
.gb-cash-hello { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 480px; }
.gb-cash-hello .bubble { flex: 1; font-size: 15px; }
.gb-cash-sheet { width: 100%; max-width: 480px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.gb-cash-units { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.gb-cash-units > div { display: flex; flex-direction: column; align-items: center; padding: 6px 2px; border-radius: 14px; border: 2.5px solid var(--edge); background: var(--pri-2); color: var(--ink); box-shadow: 0 3px 0 var(--edge); }
.gb-cash-units .jp { font-size: 30px; line-height: 1.2; }
.gb-cash-units b { font-size: 15px; font-weight: 900; }
.gb-cash-units small { font-size: 11px; opacity: .8; }
.gb-cash-digits { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.gb-cash-digits > div { display: flex; flex-direction: column; align-items: center; padding: 3px 0; border-radius: 9px; background: var(--soft); border: 2px solid var(--line); }
.gb-cash-digits .jp { font-size: 19px; line-height: 1.2; }
.gb-cash-digits small { font-size: 12px; font-weight: 800; color: var(--muted); }
.gb-cash-ex { text-align: center; font-weight: 700; font-size: 15px; }
.gb-cash-ex .jp { font-size: 20px; }
.gb-cash-tag { position: relative; width: 100%; max-width: 420px; padding: 12px 16px; text-align: center; }
.gb-cash-tag::before { content: ""; position: absolute; left: 12px; top: 50%; width: 12px; height: 12px; margin-top: -6px; border-radius: 50%; background: var(--bg); border: 2.5px solid var(--edge); }
.gb-cash-kj { font-size: 34px; line-height: 1.3; letter-spacing: .02em; animation: gb-pop .25s ease; }
.gb-cash-num { font-size: 40px; font-weight: 900; line-height: 1.2; letter-spacing: .02em; animation: gb-pop .25s ease; }
.gb-cash-disp { display: flex; align-items: baseline; justify-content: center; gap: 6px; min-width: 200px; min-height: 52px; padding: 4px 18px; border-radius: 16px; border: 2.5px solid var(--edge); background: var(--card); font-weight: 900; font-size: 30px; line-height: 1.35; }
.gb-cash-disp span { color: var(--muted); font-size: 22px; }
.gb-cash-disp.gb-empty b::after { content: "…"; color: var(--line); }
.gb-cash-disp.gb-ok { background: var(--ok-bg); border-color: var(--ok); }
.gb-cash-disp.gb-no { background: var(--bad-bg); border-color: var(--bad); }
.gb-cash-disp.gb-no b { text-decoration: line-through; }
.gb-pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; max-width: 300px; }
.gb-pad .gb-t { min-height: 48px; font-size: 24px; font-weight: 900; }
.gb-pad .gb-t.gb-ctl { font-size: 20px; }
.gb-cash-mini { font-size: 12px; font-weight: 800; color: var(--muted); text-align: center; }
.gb-cash-mini .jp { font-size: 15px; color: var(--ink); }
.gb-cash-fb { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 14px; border-radius: 20px; border: 2.5px solid var(--ok); background: var(--ok-bg); text-align: center; animation: gb-rise .25s ease both; }
.gb-cash-fb.gb-no { border-color: var(--bad); background: var(--bad-bg); }
.gb-cash-fbt { font-weight: 800; font-size: 16px; }
.gb-cash-fbt .jp { font-size: 20px; }
.gb-cash-mine { font-size: 13px; font-weight: 700; color: var(--muted); }
.gb-cash-mine .jp { font-size: 16px; }
.gb-cash-bd { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 6px; font-weight: 800; font-size: 14px; }
.gb-cash-bd > span { padding: 2px 9px; border-radius: 10px; background: var(--card); border: 2px solid var(--line); white-space: nowrap; }
.gb-cash-bd .jp { font-size: 17px; }
.gb-cash-bd i { font-style: normal; color: var(--muted); }
.gb-cash-read { display: flex; align-items: center; gap: 10px; }
.gb-cash-read .jp { font-size: 17px; overflow-wrap: anywhere; }
.gb-cash-read .iconbtn { width: 40px; height: 40px; }

/* ---------- анимации ---------- */
@keyframes gb-pop { from { transform: scale(.82); opacity: .4; } 60% { transform: scale(1.08); } to { transform: none; opacity: 1; } }
@keyframes gb-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes gb-flip { from { transform: scaleY(.1); } 60% { transform: scaleY(1.08); } to { transform: none; } }
@keyframes gb-shake { 20% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 80% { transform: translateX(-3px); } }
@keyframes gb-bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
@keyframes gb-chomp { 30% { transform: translateX(30px) rotate(12deg) scale(1.08); } 55% { transform: translateX(24px) rotate(6deg) scale(1.02); } }
@keyframes gb-wobble { 25% { transform: rotate(-7deg) scale(.95); } 60% { transform: rotate(5deg); } }
@keyframes gb-pulse { 50% { transform: scale(1.18); } }

/* ---------- маленькие экраны и широкие экраны ---------- */
@media (max-width: 380px) {
  .gb-slot { min-width: 42px; height: 48px; font-size: 24px; }
  .gb-clue b, .gb-tl-ru { font-size: 19px; }
  .gb-emo-e { font-size: 40px; }
  .gb-cash-kj { font-size: 30px; }
}
@media (max-height: 640px) {
  .gb { gap: 8px; }
  .gb-oni-stage { min-height: 96px; }
  .gb-oni-cat .mascot, .gb-onigiri { width: 84px; height: 84px; }
  .gb-pad .gb-t { min-height: 42px; }
  .gb .opts.gb-opts .opt { min-height: 46px; }
  .gb-emo-jp { min-height: 50px; }
  .gb-cash-hello .mascot { width: 64px; height: 64px; }
}
@media (min-width: 821px) {
  .gb { gap: 16px; }
  .gb-secret { gap: 8px; }
  .gb-ws-c { font-size: 23px; }
  .gb-emo-e { font-size: 56px; }
  .gb-t:hover:not(:disabled):not(.gb-on):not(.gb-ctl) { background: var(--soft); }
}
@media (prefers-reduced-motion: reduce) {
  .gb *, .gb *::before, .gb *::after { animation: none !important; transition: none !important; }
}
