  /* Розкладка: поле + бічна колонка фіксованої ширини = один блок по центру; кнопки знизу лише на тачскрінах */
  :root{
    --bg:#F3F5F8; --surface:#FFFFFF; --line:#E4E8EE; --ink:#1F2A3C; --muted:#6B7486;
    --yellow:#FFD12E; --yellow-soft:#FFF8DF; --on-yellow:#1F2A3C; --yellow-edge:#D9AE10;
    --btn:#FFFFFF; --overlay:rgba(255,255,255,.93); --shadow:rgba(31,42,60,.08);
    --pad:#FFFFFF; --pad-edge:#D5DBE5; --pad-hi:rgba(255,255,255,.9); --yellow-ink:#B98F00;
    --neon:#16A34A; --neon-soft:rgba(22,163,74,.22); --neon-glow:rgba(22,163,74,.35);
    --notify:#3B82F6;
    --side-w:140px;
    color-scheme:light;
  }
  @media (prefers-color-scheme:dark){
    :root:not([data-theme="light"]){
      --bg:#0F141C; --surface:#171E29; --line:#273142; --ink:#E6EBF2; --muted:#8D97A8;
      --yellow-soft:#2A2B22; --btn:#1F2735; --overlay:rgba(15,20,28,.93); --shadow:rgba(0,0,0,.35);
      --pad:#1A2130; --pad-edge:#2C3647; --pad-hi:rgba(255,255,255,.05); --yellow-ink:#FFD12E;
      --neon:#3BE07A; --neon-soft:rgba(59,224,122,.25); --neon-glow:rgba(59,224,122,.6);
      color-scheme:dark;
    }
  }
  :root[data-theme="dark"]{
    --bg:#0F141C; --surface:#171E29; --line:#273142; --ink:#E6EBF2; --muted:#8D97A8;
    --yellow-soft:#2A2B22; --btn:#1F2735; --overlay:rgba(15,20,28,.93); --shadow:rgba(0,0,0,.35);
    --pad:#1A2130; --pad-edge:#2C3647; --pad-hi:rgba(255,255,255,.05); --yellow-ink:#FFD12E;
    --neon:#3BE07A; --neon-soft:rgba(59,224,122,.25); --neon-glow:rgba(59,224,122,.6);
    color-scheme:dark;
  }
  *{box-sizing:border-box;margin:0;padding:0}
  html,body{height:100%}
  body{
    font-family:"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
    background:var(--bg);color:var(--ink);
    display:flex;flex-direction:column;overflow:hidden;
    user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent;
    touch-action:manipulation;   /* pinch-zoom дозволено, подвійний тап не масштабує сторінку */
    transition:background .2s,color .2s;
  }
  main{
    flex:1;min-height:0;display:flex;gap:12px;justify-content:center;width:100%;
    padding:calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  #boardWrap{flex:0 0 auto;min-height:0;display:flex;align-items:center;justify-content:center;overflow:hidden}
  #boardCard{
    position:relative;background:var(--surface);border:1px solid var(--line);border-radius:12px;
    padding:6px;box-shadow:0 4px 18px var(--shadow);
  }
  /* поле без жестів гри; pinch-zoom лишається там, де браузер підтримує pinch-zoom (інакше — none) */
  canvas#board{display:block;border-radius:8px;touch-action:none;touch-action:pinch-zoom}
  #boardCard.glitch{animation:glitch .52s steps(2, end)}
  @keyframes glitch{
    0%  {transform:translate(0,0);   filter:drop-shadow(4px 0 rgba(255,0,80,.75)) drop-shadow(-4px 0 rgba(0,200,255,.75))}
    20% {transform:translate(-5px,1px);filter:drop-shadow(-5px 0 rgba(255,0,80,.75)) drop-shadow(5px 0 rgba(0,200,255,.75))}
    40% {transform:translate(4px,-2px);filter:drop-shadow(3px 0 rgba(255,0,80,.6)) drop-shadow(-3px 0 rgba(0,200,255,.6)) hue-rotate(25deg)}
    60% {transform:translate(-3px,0);  filter:drop-shadow(-2px 0 rgba(255,0,80,.5)) drop-shadow(2px 0 rgba(0,200,255,.5))}
    80% {transform:translate(2px,1px); filter:none}
    100%{transform:translate(0,0);   filter:none}
  }
  @media (prefers-reduced-motion:reduce){
    #boardCard.glitch{animation:none}
    .toast{transition:none}            /* сповіщення з'являється без «виїзду» з пружиною */
    body{transition:none}
  }

  /* ---------- Бічна колонка: одна фіксована ширина, усе розтягнуто по ній ---------- */
  .side{
    width:var(--side-w);flex:0 0 var(--side-w);display:flex;flex-direction:column;gap:8px;
    overflow-y:auto;overflow-x:hidden;align-self:center;max-height:100%;
  }
  .card{background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:10px;width:100%}
  .brand-top{display:flex;align-items:center;gap:8px;margin-bottom:8px}
  /* логотип: темна блискавка на жовтому квадраті — завжди контрастна */
  .logo{background:var(--yellow);color:#1F2A3C;border-radius:8px;width:28px;height:28px;flex:0 0 28px;display:flex;align-items:center;justify-content:center}
  .logo svg,.overlay .badge svg{fill:currentColor;stroke:none;width:62%;height:62%}
  .title{font-weight:800;font-size:15px}
  .tools{display:grid;grid-template-columns:repeat(4,1fr);gap:4px}
  .icon-btn{
    width:100%;height:32px;border:1px solid var(--line);background:var(--btn);border-radius:8px;cursor:pointer;color:var(--ink);
    display:flex;align-items:center;justify-content:center;
  }
  .icon-btn:hover{background:var(--yellow-soft)}
  .icon-btn svg{width:17px;height:17px}
  .icon-btn:focus-visible,.btn:focus-visible{outline:2px solid var(--yellow);outline-offset:2px}

  .stat .lbl{font-size:11px;color:var(--muted);font-weight:700;text-transform:uppercase;letter-spacing:.3px}
  .stat .sub{font-size:11px;color:var(--muted);margin-top:1px}
  .stat .val{font-size:22px;font-weight:800;margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-variant-numeric:tabular-nums}
  .stat.accent{background:var(--yellow);border-color:var(--yellow);color:var(--on-yellow)}
  .stat.accent .lbl,.stat.accent .sub{color:var(--on-yellow);opacity:.75}
  #next{width:100%;max-width:84px;aspect-ratio:1/1;margin:4px auto 0;display:block}

  /* ---------- Оверлеї на полі ---------- */
  .overlay{
    --ov-gap:10px;
    position:absolute;inset:6px;border-radius:8px;background:var(--overlay);
    backdrop-filter:blur(3px);-webkit-backdrop-filter:blur(3px);
    display:flex;flex-direction:column;align-items:center;justify-content:flex-start;text-align:center;
    padding:14px;gap:var(--ov-gap);z-index:5;overflow:auto;overscroll-behavior:contain;
  }
  /* центрування розпірками: коли вміст вищий за поле, верх не обрізається і все доступне прокруткою */
  .overlay::before,.overlay::after{content:"";flex:1 0 0}
  .overlay::before{margin-bottom:calc(-1 * var(--ov-gap))}
  .overlay::after{margin-top:calc(-1 * var(--ov-gap))}
  .overlay > *{flex-shrink:0}
  .overlay.hidden{display:none}
  .overlay .badge{background:var(--yellow);color:#1F2A3C;border-radius:12px;width:48px;height:48px;display:flex;align-items:center;justify-content:center}
  .overlay h2{font-size:clamp(18px,4.5vw,26px);line-height:1.2;text-wrap:balance}
  .overlay p{font-size:clamp(12px,3.4vw,15px);color:var(--muted);line-height:1.4;max-width:290px}
  .overlay.dark{background:rgba(20,26,38,.95)}
  .overlay.dark h2{color:#FFD12E}
  .overlay.dark p{color:#C9D0DC}
  .phrase{color:#fff!important;font-weight:700}
  .sumcard{
    background:#FFD12E;color:#1F2A3C;border-radius:12px;padding:12px 14px;max-width:270px;
    font-size:14px;line-height:1.45;box-shadow:0 6px 20px rgba(255,209,46,.25);
  }
  .sumcard b{font-size:17px;font-weight:900;white-space:nowrap}
  .result-meta{display:flex;gap:10px;justify-content:center;color:#C9D0DC;font-size:12px}
  .result-meta b{color:#fff}
  .btn{
    background:var(--yellow);color:var(--on-yellow);border:none;border-radius:10px;padding:12px 20px;
    font-size:15px;font-weight:800;cursor:pointer;font-family:inherit;box-shadow:0 3px 0 var(--yellow-edge);
  }
  .btn:active{transform:translateY(2px);box-shadow:0 1px 0 var(--yellow-edge)}
  .btn.ghost{background:transparent;color:#fff;border:1.5px solid rgba(255,255,255,.35);box-shadow:none}
  .btns{display:flex;flex-direction:column;gap:8px;width:100%;max-width:250px}
  /* 16px — iOS не масштабує сторінку при фокусі; виділення тексту тут дозволене */
  #copyText{width:100%;max-width:260px;height:84px;border-radius:8px;border:1px solid #445;padding:6px;font-family:inherit;font-size:16px;line-height:1.3;background:#0F141C;color:#fff;resize:none;
    user-select:text;-webkit-user-select:text;-webkit-touch-callout:default}
  .tip{font-size:12px!important}
  .tip.touch{display:none}
  .touch-only{display:none}

  /* ---------- Посилання на Telegram-канал (звичайна навігація, без віджетів і зовнішніх ресурсів) ---------- */
  .tg-link{
    display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:36px;padding:7px 14px;
    border-radius:999px;border:1px solid var(--line);background:var(--btn);color:var(--ink);
    font-size:13px;font-weight:700;text-decoration:none;line-height:1.2;
  }
  .tg-link:hover{background:var(--yellow-soft)}
  .tg-link:focus-visible{outline:2px solid var(--yellow);outline-offset:2px}
  .tg-ic{display:inline-flex;width:18px;height:18px;flex:0 0 18px;color:#229ED9}
  .tg-ic svg{width:100%;height:100%}
  .overlay.dark .tg-link{background:transparent;color:#fff;border-color:rgba(255,255,255,.35)}
  .modal .tg-link{align-self:center}
  .tg-link.small{min-height:34px;padding:6px 12px;font-size:12.5px}
  .modal.info .ob-controls{display:none!important}   /* «Особливості блоків»: лише блоки й механіки */

  /* ---------- Стартове меню: окремий повноекранний шар над усією грою (не оверлей поля) ----------
     position:fixed + inset:0 — завжди точно видима область (iOS Safari з панелями теж); вміст центрується
     через margin:auto, тож на низьких екранах верх НЕ обрізається, а все доступне прокруткою самого шару. */
  .start-screen{
    position:fixed;inset:0;z-index:30;display:flex;flex-direction:column;align-items:center;
    overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
    background:radial-gradient(120% 60% at 50% 0%, rgba(255,209,46,.13), rgba(255,209,46,0) 60%), var(--bg);
    padding:calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  .start-screen.hidden{display:none}
  .menu-card{margin:auto 0;width:100%;max-width:340px;display:flex;flex-direction:column;align-items:center;gap:22px;text-align:center;flex-shrink:0}
  .menu-brand{display:flex;flex-direction:column;align-items:center;gap:10px}
  .start-screen .badge{background:var(--yellow);color:#1F2A3C;width:68px;height:68px;border-radius:18px;display:flex;align-items:center;justify-content:center;box-shadow:0 8px 24px rgba(255,209,46,.3)}
  .start-screen .badge svg{fill:currentColor;stroke:none;width:62%;height:62%}
  .menu-title{font-size:clamp(34px,10vw,44px);font-weight:900;letter-spacing:.3px;line-height:1.05;color:var(--ink)}
  .menu-sub{font-size:14px;color:var(--muted);line-height:1.4;max-width:260px}
  .menu-actions{display:flex;flex-direction:column;gap:12px;width:100%;max-width:280px}
  .btn.menu-play{font-size:20px;padding:16px 20px;letter-spacing:.3px}
  .menu-hint{font-size:12.5px;color:var(--muted);line-height:1.45;max-width:290px}
  .menu-hint.touch{display:none}
  .tg-btn{
    display:inline-flex;align-items:center;justify-content:center;gap:10px;min-height:48px;padding:10px 20px 10px 12px;
    border-radius:999px;border:1px solid var(--line);background:var(--surface);color:var(--ink);
    font-size:15px;font-weight:800;text-decoration:none;box-shadow:0 4px 14px var(--shadow);
  }
  .tg-btn:hover{border-color:#229ED9}
  .tg-btn:focus-visible{outline:2px solid var(--yellow);outline-offset:2px}
  .tg-logo{display:inline-flex;width:28px;height:28px;flex:0 0 28px}
  .tg-logo svg{width:100%;height:100%}
  .tg-link .tg-logo{width:20px;height:20px;flex-basis:20px}
  /* низька видима висота (iOS Safari з панелями, альбом): компактніше, без порожнього простору */
  @media (max-height:640px){
    .menu-card{gap:14px}
    .start-screen .badge{width:52px;height:52px;border-radius:14px}
    .menu-title{font-size:32px}
    .btn.menu-play{padding:13px 18px;font-size:18px}
    .menu-actions{gap:10px}
  }
  @media (max-height:440px){
    .menu-card{gap:10px}
    .menu-brand{gap:4px}
    .start-screen .badge{width:40px;height:40px;border-radius:11px}
    .menu-title{font-size:26px}
    .menu-sub{font-size:12.5px}
    .btn.menu-play{padding:10px 18px;font-size:17px}
    .btn.alt{padding:8px 14px}
    .tg-btn{min-height:42px;padding:6px 16px 6px 10px}
  }
  .btn.alt{background:transparent;color:var(--ink);border:2px solid var(--yellow);box-shadow:none;padding:11px 16px;font-size:14.5px}
  .btn.alt:hover{background:var(--yellow-soft)}
  .btn.alt:active{transform:translateY(1px)}
  .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
  /* поле — поверхня жестів: без виноски й виділення при довгому дотику */
  canvas#board{-webkit-touch-callout:none;-webkit-user-select:none;user-select:none}

  /* ---------- Навчання (онбординг) ---------- */
  .modal{
    position:fixed;inset:0;z-index:40;background:rgba(8,12,18,.62);
    backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);
    display:flex;align-items:center;justify-content:center;
    padding:calc(14px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
  }
  .modal.hidden{display:none}
  .modal-card{
    background:var(--surface);color:var(--ink);border:1px solid var(--line);border-radius:16px;
    width:100%;max-width:440px;max-height:100%;overflow:auto;padding:18px;overscroll-behavior:contain;
    display:flex;flex-direction:column;gap:12px;box-shadow:0 24px 60px rgba(0,0,0,.35);
  }
  .modal-card > *{flex-shrink:0}
  .modal-card:focus{outline:none}   /* фокус контейнера діалогу — лише точка старту; кнопки мають власну рамку фокусу */
  .ob-head{display:flex;align-items:center;gap:10px}
  .ob-head h2{font-size:21px;line-height:1.2}
  .ob-lead{font-size:14px;color:var(--muted);line-height:1.45}
  .ob-row{display:flex;gap:12px;align-items:flex-start}
  .ob-row .ics{display:flex;gap:4px;flex:0 0 64px;justify-content:flex-start}
  .ob-row canvas{width:30px;height:30px}
  .ob-row b{display:block;font-size:14px;margin-bottom:1px}
  .ob-row span{font-size:13px;color:var(--muted);line-height:1.35}
  .ob-sub{font-size:12px;text-transform:uppercase;letter-spacing:.4px;color:var(--muted);margin-top:4px}
  .surge-ic{width:30px;height:30px;border-radius:7px;background:var(--bg);position:relative;overflow:hidden;border:1px solid var(--line)}
  .surge-ic::after{content:"";position:absolute;left:3px;right:3px;top:13px;height:3px;border-radius:2px;background:#FF3B3B;box-shadow:0 0 8px 2px rgba(255,59,59,.7)}
  .restore-ic{width:30px;height:30px;border-radius:7px;background:var(--bg);position:relative;overflow:hidden;border:1px solid var(--line)}
  .restore-ic::before{content:"";position:absolute;left:0;right:0;top:0;height:15px;background:linear-gradient(rgba(59,224,122,0),rgba(59,224,122,.45))}
  .restore-ic::after{content:"";position:absolute;left:3px;right:3px;top:14px;height:3px;border-radius:2px;background:#3BE07A;box-shadow:0 0 8px 2px rgba(59,224,122,.7)}
  .notify-ic{width:30px;height:30px;border-radius:50%;background:var(--notify);color:#fff;display:flex;align-items:center;justify-content:center}
  .notify-ic svg{width:17px;height:17px}
  .ob-ctl{display:flex;flex-wrap:wrap;gap:8px 16px}
  .ob-ctl.touch{display:none}
  .ctl-item{display:flex;align-items:center;gap:5px;font-size:13px}
  .ctl-item em{font-style:normal;color:var(--muted);margin-left:2px}
  .mini{
    width:30px;height:30px;border-radius:50%;border:1.5px solid var(--pad-edge);background:var(--pad);color:var(--ink);
    display:inline-flex;align-items:center;justify-content:center;
  }
  .mini svg{width:52%;height:52%}
  .mini.rot{border:2px solid var(--yellow);color:var(--yellow-ink)}
  .mini.drop{background:var(--yellow);border-color:var(--yellow);color:#1F2A3C}
  .mini.drop svg{stroke-width:3}
  kbd svg{width:13px;height:13px;margin:3px 0}
  kbd{
    display:inline-block;min-width:22px;text-align:center;padding:0 5px;border:1px solid var(--line);
    border-bottom-width:2px;border-radius:6px;background:var(--bg);font-family:inherit;font-size:11.5px;font-weight:700;color:var(--ink);
  }
  .modal .btn{align-self:stretch;padding:14px}

  /* ---------- Сповіщення «Графіки оновлено!» ---------- */
  .toast{
    position:fixed;left:50%;top:calc(10px + env(safe-area-inset-top, 0px));z-index:50;
    width:min(92vw, 360px);display:flex;gap:10px;align-items:center;
    background:var(--surface);color:var(--ink);border:1px solid var(--line);border-radius:14px;
    padding:10px 14px;box-shadow:0 12px 30px rgba(0,0,0,.25);
    transform:translate(-50%, -160%);transition:transform .35s cubic-bezier(.2,.9,.3,1.2);pointer-events:none;
  }
  .toast.show{transform:translate(-50%, 0)}
  .toast-ic{flex:0 0 38px;height:38px;border-radius:50%;background:var(--notify);color:#fff;display:flex;align-items:center;justify-content:center}
  .toast-ic svg{width:20px;height:20px}
  .toast b{display:block;font-size:14px}
  .toast span{font-size:12px;color:var(--muted)}

  /* ---------- Сенсорні кнопки: ◄ ►  |  ↻ ⬇ ---------- */
  #controls{
    --ctl-pad:16px;   /* бічний відступ; збільшена зона «скинути» доходить рівно до краю екрана, не далі */
    display:none;flex:0 0 auto;align-items:center;justify-content:space-between;
    padding:4px max(var(--ctl-pad), env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(var(--ctl-pad), env(safe-area-inset-left, 0px));
    touch-action:manipulation;
  }
  #controls .grp{display:flex;gap:14px;align-items:center}
  #controls .grp + .grp{gap:16px}
  #controls button{
    width:66px;height:66px;border-radius:50%;
    border:1.5px solid var(--pad-edge);background:var(--pad);color:var(--ink);
    touch-action:none;display:flex;align-items:center;justify-content:center;
    -webkit-touch-callout:none;user-select:none;-webkit-user-select:none;
    box-shadow:inset 0 1px 0 var(--pad-hi), 0 4px 12px var(--shadow);
    transition:transform .08s, box-shadow .15s, border-color .15s, color .15s;
  }
  #controls button svg{width:46%;height:46%}
  #controls button.pressed{
    transform:scale(.93);border-color:var(--neon);color:var(--neon);
    box-shadow:0 0 0 3px var(--neon-soft), 0 0 22px var(--neon-glow);
  }
  #controls .rot{width:68px;height:68px;border:2px solid var(--yellow);color:var(--yellow-ink)}
  #controls .rot svg{width:50%;height:50%}
  #controls .drop{
    position:relative;width:66px;height:66px;
    background:var(--yellow);border-color:var(--yellow);color:var(--on-yellow);
    box-shadow:0 4px 0 var(--yellow-edge), 0 6px 14px var(--shadow);
  }
  #controls .drop svg{width:50%;height:50%;stroke-width:3}
  #controls .drop::after{content:"";position:absolute;inset:-14px calc(-1 * max(var(--ctl-pad), env(safe-area-inset-right, 0px))) calc(-10px - env(safe-area-inset-bottom, 0px)) -8px;border-radius:24px}
  #controls .drop.pressed{border-color:var(--yellow);color:var(--on-yellow);transform:scale(.93) translateY(2px);box-shadow:0 0 0 3px rgba(255,209,46,.3), 0 0 24px rgba(255,209,46,.65)}

  svg.ic{fill:none;stroke:currentColor;stroke-width:2.4;stroke-linecap:round;stroke-linejoin:round;display:block}

  @media (pointer:coarse), (hover:none){
    #controls{display:flex}
    .tip.keys-tip,.ob-ctl.keys{display:none}
    .tip.touch{display:block}
    .menu-hint.touch{display:block}
    .menu-hint.keys-tip{display:none}
    .ob-ctl.touch{display:flex}
    .touch-only{display:block}
  }
  /* на тачскрінах кнопки керування самі тримають нижній safe-area */
  @media (pointer:coarse), (hover:none){
    main{padding-bottom:10px}
  }
  @media (max-width:760px){
    main{gap:6px;padding:calc(6px + env(safe-area-inset-top, 0px)) max(6px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px))}
    #boardCard{padding:3px;border-radius:10px}
    .overlay{inset:3px}
  }
  @media (max-width:760px) and (pointer:coarse), (max-width:760px) and (hover:none){
    main{padding-bottom:4px}
  }
  /* телефони: колонка вужча, щоб полю лишилась ширина */
  @media (max-width:600px){
    :root{--side-w:80px}
    .side{gap:6px}
    .card{padding:7px 6px;border-radius:10px}
    .card.brand{padding:4px}
    .brand-top,.stat .sub,.stat.best{display:none}
    .tools{grid-template-columns:repeat(2,1fr)}
    .icon-btn{height:44px}
    .stat{text-align:center}
    .stat .lbl{font-size:9.5px;letter-spacing:0}
    .stat .val{font-size:16px}
    #next{max-width:56px}
  }
  /* досить висоти — кнопки теми/звуку/паузи/довідки в один стовпчик на всю ширину колонки (≈72×44) */
  @media (max-width:600px) and (min-height:640px){
    .tools{grid-template-columns:1fr}
  }
  /* вузькі телефони (320–350px): кнопки трохи менші, щоб між усіма зонами дотику був зазор і не було горизонтального переповнення */
  @media (max-width:350px){
    #controls{--ctl-pad:10px}
    #controls .grp{gap:10px}
    #controls .grp + .grp{gap:12px}
    #controls button,#controls .drop{width:58px;height:58px}
    #controls .rot{width:60px;height:60px}
    #controls .drop::after{left:-4px}
    .sumcard b{font-size:15px}
  }

  /* ---------- DT-008.2: HUD над полем (портретний телефон). Клас body.hud-top ставить resize(),
     лише коли квадратна клітинка поля від цього не зменшується; інакше лишається бічна колонка. ---------- */
  body.hud-top main{flex-direction:column;align-items:center;justify-content:center;gap:4px}
  body.hud-top .side{
    order:-1;width:100%;flex:0 0 auto;max-height:none;overflow:visible;align-self:center;
    display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px;
  }
  body.hud-top .card{padding:3px 4px;border-radius:10px}
  body.hud-top .card.brand{grid-column:1 / -1;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 4px 4px 8px}
  body.hud-top .brand-top{display:flex;margin:0;min-width:0}
  body.hud-top .logo{width:26px;height:26px;flex:0 0 26px}
  body.hud-top .title{font-size:16px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
  body.hud-top .tools{display:grid;grid-template-columns:repeat(4,42px);gap:4px;flex:0 0 auto}
  body.hud-top .icon-btn{height:40px}
  body.hud-top .stat{display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;min-width:0}
  body.hud-top .stat .lbl{font-size:9.5px;letter-spacing:0}
  body.hud-top .stat .sub{display:none}
  body.hud-top .stat .val{font-size:17px;margin-top:1px;max-width:100%}
  body.hud-top .stat.next{order:5}
  body.hud-top .stat.next{flex-direction:row;gap:3px;padding:2px 3px}
  body.hud-top #next{width:36px;max-width:36px;margin:0;flex:0 0 36px}
  body.hud-top .stat.best{display:none;order:4}
  @media (min-width:400px) and (min-height:821px){
    body.hud-top .side{grid-template-columns:repeat(5,minmax(0,1fr))}
    body.hud-top .stat.best{display:flex}
  }
  /* DT-009.2: на нижчих портретних екранах (iOS Safari з панелями) — компактніші кнопки внизу (56 px ≥ 44 px),
     лише в режимі HUD над полем. resize() оцінює HUD уже з ними й вмикає його, тільки якщо клітинка не менша. */
  @media (max-height:820px){
    body.hud-top #controls{padding-top:2px;padding-bottom:calc(8px + env(safe-area-inset-bottom, 0px))}
    body.hud-top #controls button,body.hud-top #controls .drop{width:56px;height:56px}
    body.hud-top #controls .rot{width:58px;height:58px}
    body.hud-top #controls .drop::after{bottom:calc(-8px - env(safe-area-inset-bottom, 0px))}
  }

  /* ---------- Низький альбомний екран: колонка-сітка, оверлеї компактніші ---------- */
  @media (orientation:landscape) and (max-height:500px){
    :root{--side-w:150px}
    .side{display:grid;grid-template-columns:1fr 1fr;gap:6px;align-content:center}
    .card{padding:6px;border-radius:10px}
    .card.brand{grid-column:1 / -1;padding:4px}
    .brand-top,.stat .sub{display:none}
    .stat.best{display:block;grid-column:1 / -1}
    .tools{grid-template-columns:repeat(2,1fr)}
    .icon-btn{height:44px}
    .stat{text-align:center}
    .stat .lbl{font-size:9.5px;letter-spacing:0}
    .stat .val{font-size:16px}
    #next{max-width:48px}
    .overlay{--ov-gap:6px;padding:10px}
    .overlay .badge{width:38px;height:38px;border-radius:10px}
    .btn{padding:10px 16px}
  }
  /* альбомний тачскрін: кнопки керування — у нижніх кутах, поле займає всю висоту.
     Бічні відступи main гарантовано резервують місце під групи кнопок (без перекриття з полем/колонкою). */
  @media (orientation:landscape) and (max-height:500px) and (min-width:620px) and (pointer:coarse),
         (orientation:landscape) and (max-height:500px) and (min-width:620px) and (hover:none){
    #controls{
      --ctl-pad:12px;
      position:fixed;left:0;right:0;bottom:0;z-index:10;pointer-events:none;align-items:flex-end;
      padding-top:0;padding-bottom:calc(10px + env(safe-area-inset-bottom, 0px));
    }
    #controls .grp{pointer-events:auto;gap:12px}
    #controls .grp + .grp{gap:14px}
    #controls button,#controls .drop{width:60px;height:60px}
    #controls .rot{width:62px;height:62px}
    main{
      gap:8px;
      padding:calc(6px + env(safe-area-inset-top, 0px)) calc(max(12px, env(safe-area-inset-right, 0px)) + 148px) calc(6px + env(safe-area-inset-bottom, 0px)) calc(max(12px, env(safe-area-inset-left, 0px)) + 140px);
    }
  }

  /* ---------- DT-010: режими керування на сенсорних пристроях ----------
     body.touch-ui — сенсорний пристрій (визначає game.js); body.ctl-gestures / body.ctl-buttons — обраний режим.
     Без цих класів (звичайний ПК) розкладка не змінюється. */
  [hidden]{display:none!important}
  .ctl-change{display:none}
  body.touch-ui .ctl-change{display:block}
  .menu-hint.btn-hint,.gest-only,.btn-only{display:none}
  body.ctl-buttons .menu-hint.btn-hint{display:block}
  body.ctl-buttons .menu-hint.touch{display:none}
  body.ctl-gestures .gest-only,body.ctl-buttons .btn-only{display:block}
  body.ctl-gestures .ob-ctl.touch,body.ctl-gestures .touch-only,body.ctl-buttons .touch-only{display:none}
  .modal .ctl-change{align-self:center;padding:10px 18px}
  .overlay .ctl-change{padding:9px 16px;font-size:14px}

  /* «Жести»: нижніх кнопок немає зовсім, і місце під них не резервується — нижній safe-area тримає main */
  body.ctl-gestures #controls{display:none}
  body.ctl-gestures main{padding-bottom:calc(10px + env(safe-area-inset-bottom, 0px))}
  @media (max-width:760px){
    body.ctl-gestures main{padding-bottom:calc(4px + env(safe-area-inset-bottom, 0px))}
  }
  @media (orientation:landscape) and (max-height:500px) and (min-width:620px){
    body.ctl-gestures main{
      padding:calc(6px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    }
  }

  /* Бічна колонка на сенсорному пристрої (обидва режими): компактний бренд «⚡ Дтетріс» над панеллю інструментів (ширина колонки та сама).
     Якщо resize() обрав HUD згори (body.hud-top), бренд уже є в рядку інструментів — тут нічого не додаємо. */
  @media (max-width:600px), (orientation:landscape) and (max-height:500px){
    body.touch-ui:not(.hud-top) .brand-top{display:flex;justify-content:center;gap:4px;margin:2px 0 4px;min-width:0}
    body.touch-ui:not(.hud-top) .brand-top .logo{width:18px;height:18px;flex:0 0 18px;border-radius:5px}
    body.touch-ui:not(.hud-top) .brand-top .title{font-size:12.5px;line-height:1;white-space:nowrap}
  }

  /* ---------- Екран «Оберіть керування» (повноекранний шар, як стартове меню) ---------- */
  .ctl-screen{
    position:fixed;inset:0;z-index:35;display:flex;flex-direction:column;
    overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
    background:radial-gradient(120% 60% at 50% 0%, rgba(255,209,46,.13), rgba(255,209,46,0) 60%), var(--bg);
    padding:calc(14px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  }
  .ctl-screen.hidden{display:none}
  .ctl-body{margin:auto;width:100%;max-width:460px;display:flex;flex-direction:column;align-items:center;gap:10px;text-align:center;flex-shrink:0;padding-bottom:12px}
  .ctl-title{font-size:clamp(22px,7vw,30px);font-weight:900;line-height:1.1}
  .ctl-lead{font-size:13px;color:var(--muted);line-height:1.4;max-width:340px}
  .ctl-opts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;width:100%}
  .ctl-opt{
    position:relative;display:flex;flex-direction:column;align-items:center;gap:6px;min-width:0;
    padding:26px 8px 12px;border-radius:16px;border:2px solid var(--line);background:var(--surface);color:var(--ink);
    font-family:inherit;text-align:center;cursor:pointer;box-shadow:0 4px 14px var(--shadow);
    transition:border-color .15s, box-shadow .15s, background .15s;
  }
  .ctl-opt:focus-visible{outline:3px solid var(--yellow);outline-offset:2px}
  .ctl-opt[aria-checked="true"]{border-color:var(--yellow);background:var(--yellow-soft);box-shadow:0 0 0 3px rgba(255,209,46,.35), 0 6px 18px var(--shadow)}
  .ctl-opt[aria-checked="true"]::after{
    content:"✓";position:absolute;top:6px;right:8px;width:20px;height:20px;border-radius:50%;
    background:var(--yellow);color:#1F2A3C;font-size:13px;font-weight:900;line-height:20px;
  }
  .ctl-rec{position:absolute;top:6px;left:8px;padding:2px 7px;border-radius:999px;background:var(--yellow);color:#1F2A3C;font-size:10.5px;font-weight:800;line-height:1.4;white-space:nowrap}
  .ctl-rec.ghost{background:transparent;color:var(--muted);border:1px solid var(--line)}
  .ctl-demo{
    display:block;width:100%;height:auto;aspect-ratio:3/4;border-radius:10px;border:1px solid var(--line);
    max-width:150px;max-width:min(150px, calc(40vh * .75));max-width:min(150px, calc(40dvh * .75));
  }
  .ctl-name{font-size:17px;font-weight:900;line-height:1.1}
  .ctl-desc{font-size:12px;color:var(--muted);line-height:1.35}
  /* підтвердження завжди під рукою: футер прилипає до низу навіть на низьких екранах */
  .ctl-foot{
    position:sticky;bottom:0;margin:0 calc(-1 * max(12px, env(safe-area-inset-right, 0px))) 0 calc(-1 * max(12px, env(safe-area-inset-left, 0px)));
    display:flex;flex-direction:column;align-items:center;gap:8px;flex-shrink:0;
    padding:10px max(12px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    background:var(--bg);border-top:1px solid var(--line);
  }
  .ctl-foot .btn{width:100%;max-width:320px}
  .ctl-foot .btn:disabled{opacity:.55;cursor:default;box-shadow:none;transform:none}
  .ctl-foot .btn.alt{padding:9px 16px}
  @media (orientation:landscape) and (max-height:500px){
    .ctl-body{gap:6px}
    .ctl-title{font-size:22px}
    .ctl-lead{display:none}
    .ctl-opts{max-width:440px}
    .ctl-opt{padding-top:24px}
    .ctl-foot{flex-direction:row;justify-content:center}
    .ctl-foot .btn{max-width:240px;padding:10px 14px}
  }
  @media (max-height:600px) and (orientation:portrait){
    .ctl-lead{font-size:12px}
    .ctl-desc{font-size:11.5px}
  }
  @media (prefers-reduced-motion:reduce){
    .ctl-opt{transition:none}
  }
