/* The phone pad (src/ui/touch-controls.js) and the touch-only adjustments.

   Two root classes drive all of it:
     html.gj-touch     the phone layout is in charge (real touch input seen)
     html.gj-pad-live  ...and there is a fight on screen to drive

   Nothing here applies on a desktop that has never been touched, so the
   keyboard HUD, its hint notes and the remapping screen are exactly as they
   were. */

:root{
  --tp-safe-l:env(safe-area-inset-left,0px);
  --tp-safe-r:env(safe-area-inset-right,0px);
  --tp-safe-b:env(safe-area-inset-bottom,0px);
  --tp-safe-t:env(safe-area-inset-top,0px);
  --tp-user-scale:1;
  --tp-user-opacity:.88;
  --tp-btn:max(44px,calc(clamp(50px,14vmin,68px) * var(--tp-user-scale,1)));
  --tp-gap:clamp(6px,1.6vmin,10px);
  --tp-edge:max(12px,var(--tp-safe-b));
  --tp-stick:calc(clamp(112px,32vmin,150px) * var(--tp-user-scale,1));
}

.touch-pad{display:none}
html.gj-pad-live .touch-pad{
  display:block;position:fixed;inset:0;z-index:30;pointer-events:none;
  -webkit-user-select:none;user-select:none;-webkit-touch-callout:none;
  -webkit-tap-highlight-color:transparent;
}

/* During a fight on a phone the page itself never scrolls, zooms, selects or
   long-press-menus. Menus, the creator and settings keep their own scrolling:
   this class is only on while the pad is up. */
html.gj-pad-live,html.gj-pad-live body{overscroll-behavior:none;touch-action:none;
  -webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
html.gj-touch #scene{touch-action:none}
html.gj-touch button,html.gj-touch input,html.gj-touch select{touch-action:manipulation}

/* The keyboard notes are a wall of key caps on a phone. The pad speaks for
   itself; the touch help lives in Settings › Controls. */
html.gj-touch #hintP1,html.gj-touch #hintP2{display:none!important}

.tp-zone,.tp-cluster,.tp-quick,.tp-mode{opacity:var(--tp-user-opacity,.88)}

/* ---------------- the stick ---------------- */
.tp-zone{
  position:absolute;left:0;bottom:0;width:48%;height:68%;
  pointer-events:auto;touch-action:none;
}
.tp-stick{
  position:absolute;width:var(--tp-stick);height:var(--tp-stick);border-radius:50%;
  left:calc(var(--tp-safe-l) + 18px);bottom:calc(var(--tp-edge) + 6px);
  background:radial-gradient(circle,rgba(232,225,211,.06) 0 55%,rgba(232,225,211,.12) 56% 100%);
  border:2px solid rgba(232,225,211,.28);
  box-shadow:0 2px 14px rgba(0,0,0,.35);
  display:grid;place-items:center;opacity:.72;transition:opacity .12s;
}
.tp-stick.on{opacity:1;left:0;right:auto;bottom:auto;top:0;transition:none}
.tp-stick::before{content:'';position:absolute;inset:16%;border-radius:50%;
  border:1px dashed rgba(232,225,211,.18)}
.tp-knob{
  width:44%;height:44%;border-radius:50%;
  background:radial-gradient(circle at 40% 35%,#f4d48a,#c88a22 70%);
  border:2px solid rgba(16,14,12,.6);box-shadow:0 3px 10px rgba(0,0,0,.45);
  will-change:transform;
}

/* ---------------- the buttons ---------------- */
.tp-btn{
  position:relative;pointer-events:auto;touch-action:none;
  font:600 12.5px/1 var(--ui);letter-spacing:.02em;text-transform:uppercase;color:var(--bone,#e8e1d3);
  background:rgba(16,14,12,.62);border:2px solid rgba(232,225,211,.34);border-radius:50%;
  min-width:44px;min-height:44px;padding:0;margin:0;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
  box-shadow:0 2px 10px rgba(0,0,0,.35);
  -webkit-tap-highlight-color:transparent;transition:transform .05s,background .05s,box-shadow .08s;
}
.tp-btn small{font-size:8.2px;letter-spacing:.1em;opacity:.7;font-weight:600;min-height:9px}
.tp-btn.on{background:rgba(242,179,61,.88);color:#16120e;border-color:#f2b33d;transform:scale(.94)}
.tp-btn:focus{outline:none}
.tp-btn:focus-visible{outline:2px solid #f2b33d;outline-offset:2px}

.tp-ring{
  position:absolute;inset:-4px;width:calc(100% + 8px);height:calc(100% + 8px);
  pointer-events:none;transform:rotate(-90deg);opacity:0;transition:opacity .08s;
}
.tp-ring circle{
  fill:none;stroke:#f2b33d;stroke-width:3.4;stroke-linecap:round;
  stroke-dasharray:100;stroke-dashoffset:calc(100 * (1 - var(--tp-charge,0)));
}
.tp-btn.charging .tp-ring{opacity:1}
.tp-btn.charged .tp-ring circle{stroke:#ff5c3a;stroke-width:4.4}
.tp-btn.charged{box-shadow:0 0 18px rgba(255,92,58,.65),0 2px 10px rgba(0,0,0,.35)}

.tp-cluster{
  position:absolute;right:calc(var(--tp-safe-r) + 14px);bottom:var(--tp-edge);
  display:grid;gap:var(--tp-gap);
  grid-template-columns:repeat(4,var(--tp-btn));grid-template-rows:repeat(3,var(--tp-btn));
  grid-template-areas:
    "more  hook upper kickL"
    "slip  jab  cross kick"
    "body  duck guard legKick";
  pointer-events:none;
}
.tp-cluster .tp-btn{width:100%;height:100%}
.tp-jab,.tp-cross{border-color:rgba(242,179,61,.65)}
.tp-jab .tp-l,.tp-cross .tp-l{font-size:14px}
.tp-kick,.tp-kickL,.tp-legKick{border-color:rgba(212,74,52,.7)}
.tp-kickL .tp-l,.tp-kick .tp-l{font-size:11.5px}
.tp-guard{border-radius:calc(var(--tp-btn) / 2);border-color:rgba(84,140,200,.75);background:rgba(20,32,48,.66)}
.tp-duck,.tp-slip{border-color:rgba(84,140,200,.55)}
.tp-body.on{background:rgba(212,74,52,.9);border-color:#e05a40;color:#fff;transform:none}
.tp-more-btn{opacity:.88;font-size:11px}
.tp-more-btn.on{transform:none}
.tp-special{border-color:rgba(242,179,61,.68);color:#ffe2a6}
.tp-btn.tp-teach{border-color:#f2b33d!important;box-shadow:0 0 0 3px rgba(242,179,61,.45),0 2px 12px rgba(0,0,0,.5)}

/* Secondary moves & Quick Specials: anchored above the right pad, never over the middle of the ring. */
.tp-more,.tp-mode,.tp-quick{
  position:absolute;display:grid;gap:6px;pointer-events:none;
}
.tp-more[hidden],.tp-quick[hidden]{display:none}
.tp-more,.tp-quick{
  right:calc(var(--tp-safe-r) + 14px);
  bottom:calc(var(--tp-edge) + 3 * var(--tp-btn) + 2 * var(--tp-gap) + 8px);
}
.tp-more{grid-template-columns:repeat(3,minmax(78px,auto));}
.tp-quick{grid-auto-flow:column;align-items:center}
.tp-quick .tp-pill{min-height:44px;padding:0 11px;font-size:11px;background:rgba(16,14,12,.72)}
.tp-mode{
  left:calc(var(--tp-safe-l) + 18px);
  bottom:calc(var(--tp-edge) + var(--tp-stick) + 14px);
  grid-auto-flow:column;
}
.tp-mode:empty{display:none}
.tp-pill{border-radius:22px;min-height:44px;padding:0 12px;font-size:11.5px;background:rgba(16,14,12,.76)}
.tp-mode .tp-pill{border-color:rgba(242,179,61,.6);padding:0 11px}

/* Left-handed layout: swap stick to the right, strike cluster to the left. */
html.gj-touch-left .tp-zone{left:auto;right:0}
html.gj-touch-left .tp-stick{left:auto;right:calc(var(--tp-safe-r) + 18px)}
html.gj-touch-left .tp-stick.on{left:0;right:auto}
html.gj-touch-left .tp-cluster,
html.gj-touch-left .tp-more,
html.gj-touch-left .tp-quick{right:auto;left:calc(var(--tp-safe-l) + 14px)}
html.gj-touch-left .tp-mode{left:auto;right:calc(var(--tp-safe-r) + 18px)}

/* ---------------- pause ---------------- */
.tp-pause{
  position:absolute;top:calc(var(--tp-safe-t) + 6px);left:calc(50% + 54px);
  width:44px;height:44px;border-radius:50%;pointer-events:auto;touch-action:manipulation;
  background:rgba(16,14,12,.6);border:2px solid rgba(232,225,211,.34);
  display:flex;align-items:center;justify-content:center;gap:5px;padding:0;
  -webkit-tap-highlight-color:transparent;
}
.tp-pause i{display:block;width:4px;height:15px;background:var(--bone,#e8e1d3);border-radius:1px}

/* A suggestion, never a gate: fades by itself, cannot be tapped. */
.tp-rotate{display:none}
@media (orientation:portrait){
  html.gj-pad-live .tp-rotate{
    display:block;position:absolute;left:50%;transform:translateX(-50%);
    top:calc(var(--tp-safe-t) + 50%);margin:0;padding:6px 12px;border-radius:14px;
    font:500 11px/1.2 var(--ui);letter-spacing:.08em;text-transform:uppercase;white-space:nowrap;
    color:rgba(232,225,211,.8);background:rgba(16,14,12,.5);pointer-events:none;
    animation:tp-fade 5s ease-in forwards;
  }
  /* Taller than wide: the hands stack one more row and give the stick room. */
  .tp-cluster{
    grid-template-columns:repeat(3,var(--tp-btn));grid-template-rows:repeat(4,var(--tp-btn));
    grid-template-areas:
      "more   hook   upper"
      "slip   jab    cross"
      "kickL  kick   legKick"
      "body   duck   guard";
    bottom:calc(var(--tp-edge) + 8px);
  }
  .tp-zone{width:52%;height:46%}
  .tp-stick{bottom:calc(var(--tp-edge) + 28px)}
  .tp-more,.tp-quick{
    right:calc(var(--tp-safe-r) + 14px);
    bottom:calc(var(--tp-edge) + 8px + 4 * var(--tp-btn) + 3 * var(--tp-gap) + 8px);
  }
  .tp-more{grid-template-columns:repeat(3,minmax(84px,auto));}
  .tp-mode{
    left:calc(var(--tp-safe-l) + 14px);right:auto;
    bottom:calc(var(--tp-edge) + 28px + var(--tp-stick) + 14px);
    grid-auto-flow:row;grid-template-columns:repeat(2,auto);
  }
  html.gj-touch-left .tp-mode{left:auto;right:calc(var(--tp-safe-r) + 14px)}
  /* Centered right below the round clock, clear of side bars, drunk meters, and center ring. */
  .tp-pause{left:50%;right:auto;transform:translateX(-50%);top:calc(var(--tp-safe-t) + 74px)}
}
@keyframes tp-fade{0%,70%{opacity:1}100%{opacity:0;visibility:hidden}}
@media (prefers-reduced-motion:reduce){.tp-btn,.tp-stick,.tp-ring{transition:none}}

/* Menu back buttons are thumb targets too. */
html.gj-touch .nav-back{min-height:46px;min-width:88px}

/* ---------------- touch help & preferences (Settings › Controls) ---------------- */
.ctl-touch{display:none}
html.gj-touch .ctl-touch{
  display:block;width:min(900px,94vw);text-align:left;
  border:1px solid rgba(232,225,211,.16);background:rgba(232,225,211,.03);padding:12px 14px;
}
.ctl-touch h2{font-family:var(--display);font-size:20px;letter-spacing:.04em;margin:0 0 6px}
.ctl-touch ul{margin:0;padding-left:18px;font-size:13px;line-height:1.5}
.ctl-touch li b{color:var(--amber,#f2b33d);font-weight:600}
.ctl-touch-prefs{
  display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:10px 16px;
  margin:10px 0 12px;padding:10px 12px;background:rgba(16,14,12,.55);border:1px solid rgba(232,225,211,.14);
}
.ctl-touch-pref{display:flex;flex-direction:column;gap:4px;font-size:12px;color:#d6cbb9}
.ctl-touch-pref span{display:flex;justify-content:space-between;gap:8px;font-weight:600;color:var(--bone)}
.ctl-touch-pref input[type=range]{width:100%;accent-color:var(--amber);min-height:28px}
.ctl-touch-seg{display:flex;gap:6px}
.ctl-touch-seg button{
  flex:1;min-height:38px;padding:6px 10px;border:1px solid rgba(232,225,211,.24);
  background:var(--dark2);color:var(--bone);font:600 11.5px var(--ui);text-transform:uppercase;letter-spacing:.06em;
}
.ctl-touch-seg button[aria-pressed="true"]{background:var(--amber);color:#16120e;border-color:var(--amber)}
.ctl-touch-toggle{
  display:flex;align-items:center;gap:8px;min-height:38px;font-size:12.5px;color:var(--bone);cursor:pointer;
}
.ctl-touch-toggle input{width:18px;height:18px;accent-color:var(--amber)}
.ctl-touch-keys{margin-top:10px;min-height:44px;padding:0 14px;font:600 12px var(--ui);letter-spacing:.06em;
  text-transform:uppercase;background:var(--dark2,#1c1915);color:var(--bone,#e8e1d3);border:1px solid rgba(232,225,211,.28)}
html.gj-touch:not(.gj-show-keys) #controlsScreen .ctl-wrap,
html.gj-touch:not(.gj-show-keys) #controlsScreen #ctlNote,
html.gj-touch:not(.gj-show-keys) #controlsScreen #ctlResetBtn{display:none}
html.gj-touch #controlsScreen .screen-main{overflow-y:auto;-webkit-overflow-scrolling:touch;
  padding-left:max(16px,var(--tp-safe-l));padding-right:max(16px,var(--tp-safe-r))}
/* Unfolded on a phone: the screen scrolls as one page instead of two
   independently scrolling columns squeezed to nothing. */
html.gj-touch #controlsScreen .ctl-wrap{flex:0 0 auto}
html.gj-touch #controlsScreen .ctl-col{overflow:visible}
@media (max-width:640px){html.gj-touch #controlsScreen .ctl-wrap{grid-template-columns:1fr}}
html.gj-touch #controlsScreen .screen-main{min-height:0;justify-content:flex-start}
html.gj-touch #controlsScreen .screen-main>*{flex-shrink:0}
