/* Phones / tablets (html.is-touch — index.html). On-screen controls (src/ui/touch-controls.js), the landscape-only
   gate (#iw-rotate) and the HUD / menu tweaks for a small landscape screen. Nothing here applies on desktop. */

/* ------------------------------------------------------------------ landscape-only gate */
#iw-rotate { display: none; }
@media (orientation: portrait) {
  html.is-touch #iw-rotate {
    position: fixed; inset: 0; z-index: 10000; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; padding: 32px; text-align: center; color: #fff; pointer-events: all; touch-action: none;
    background: radial-gradient(120% 80% at 50% 30%, #3a2a6e 0%, #1a1636 55%, #0d1020 100%);
    font-family: 'Titan One', 'Rubik', system-ui, sans-serif;
  }
  html.is-touch #iw-rotate b { font-size: 30px; letter-spacing: .02em; line-height: 1.1; text-shadow: 0 3px 0 #000; }
  html.is-touch #iw-rotate span { font: 600 15px/1.4 'Rubik', system-ui, sans-serif; opacity: .85; max-width: 280px; }
  html.is-touch #iw-rotate i {
    width: 64px; height: 110px; border: 5px solid #fff; border-radius: 14px; position: relative; margin-bottom: 18px;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .4);
    animation: iw-rot-phone 2.2s cubic-bezier(.6, 0, .3, 1) infinite;
  }
  html.is-touch #iw-rotate i::after { content: ''; position: absolute; left: 50%; bottom: 7px; width: 14px; height: 4px; margin-left: -7px; border-radius: 4px; background: #fff; }
  html.is-touch #iw-rotate i::before {
    content: ''; position: absolute; inset: 10px 8px 18px; border-radius: 6px;
    background: linear-gradient(135deg, #ff4fa3, #7b5cff 55%, #2fe0c2);
  }
  /* nothing behind the card takes taps or keeps the GPU busy for nothing */
  html.is-touch #app, html.is-touch #ui-root, html.is-touch .iw-touch { visibility: hidden; }
}
@keyframes iw-rot-phone { 0%, 20% { rotate: 0deg; } 55%, 85% { rotate: -90deg; } 100% { rotate: 0deg; } }

/* ------------------------------------------------------------------ on-screen controls */
.iw-touch { position: fixed; inset: 0; z-index: 12; pointer-events: none; display: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  --tb-bg: rgba(14, 16, 32, .42); --tb-line: rgba(255, 255, 255, .62); --tb-hot: #2fe0c2;
  --sr: env(safe-area-inset-right, 0px); --sl: env(safe-area-inset-left, 0px); }
.iw-touch.is-on { display: block; }
.iw-touch__zone { position: absolute; inset: 0; pointer-events: auto; touch-action: none; }

/* floating stick: sits where the thumb lands; a faint ghost marks the default spot */
.iw-touch__stick { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none;
  transform: translate3d(calc(var(--sl) + 196px), calc(100vh - 116px), 0); opacity: max(.24, calc(var(--top, 1) * .42)); transition: opacity .18s; }
/* --bs = this control's size (layout editor); sizes, not `scale`, so the knob's travel stays in screen px */
.iw-touch__stick::before { content: ''; position: absolute; left: calc(-62px * var(--bs, 1)); top: calc(-62px * var(--bs, 1)); width: calc(124px * var(--bs, 1)); height: calc(124px * var(--bs, 1)); border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .06) 0 55%, rgba(255, 255, 255, .14) 56% 100%);
  border: 2px solid var(--tb-line); box-sizing: border-box; }
.iw-touch__knob { position: absolute; left: calc(-27px * var(--bs, 1)); top: calc(-27px * var(--bs, 1)); width: calc(54px * var(--bs, 1)); height: calc(54px * var(--bs, 1)); border-radius: 50%;
  background: rgba(255, 255, 255, .82); box-shadow: 0 3px 10px rgba(0, 0, 0, .35), inset 0 -4px 0 rgba(0, 0, 0, .14); }
.iw-touch__stick.is-active { opacity: max(.7, var(--top, 1)); transition: none; }
.iw-touch__lbl { display: none; }

.iw-tbtn { position: absolute; width: 60px; height: 60px; margin: 0; border-radius: 50%; pointer-events: auto; touch-action: none;
  display: grid; place-items: center; box-sizing: border-box; color: #fff; background: var(--tb-bg); border: 2px solid var(--tb-line);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  transition: scale .12s, background-color .12s, opacity .2s; --k: #15121c; scale: var(--bs, 1); opacity: var(--top, 1); }
.iw-tbtn__i { width: 52%; height: 52%; display: grid; place-items: center; pointer-events: none; }
.iw-tbtn__i svg { width: 100%; height: 100%; display: block; }
.iw-tbtn__l { position: absolute; left: 50%; top: 100%; translate: -50% 1px; font: 800 9.5px/1 'Rubik', system-ui, sans-serif; letter-spacing: .06em;
  text-transform: uppercase; color: #fff; text-shadow: 0 1px 2px #000, 0 0 3px #000; white-space: nowrap; pointer-events: none; }
.iw-tbtn.is-down { scale: calc(var(--bs, 1) * .9); background: rgba(255, 255, 255, .3); }

/* thumb arc around FIRE (bottom right) */
.iw-tbtn.is-fire { width: 86px; height: 86px; right: calc(var(--sr) + 30px); bottom: 34px; background: rgba(47, 224, 194, .3); border-color: var(--tb-hot); border-width: 3px; }
.iw-tbtn.is-fire.is-down { background: rgba(47, 224, 194, .62); }
.iw-tbtn.is-jump { right: calc(var(--sr) + 146px); bottom: 26px; }
.iw-tbtn.is-swim { right: calc(var(--sr) + 128px); bottom: 112px; }
.iw-tbtn.is-swim.is-down { background: rgba(47, 224, 194, .5); border-color: var(--tb-hot); }
.iw-tbtn.is-sub { width: 54px; height: 54px; right: calc(var(--sr) + 46px); bottom: 142px; }
.iw-tbtn.is-sub.is-low { opacity: calc(var(--top, 1) * .45); }
.iw-tbtn.is-special { width: 64px; height: 64px; right: calc(var(--sr) + 118px); bottom: 196px; }
.iw-tbtn__ring { position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(#ffd23f calc(var(--k, 0) * 360deg), rgba(255, 255, 255, .12) 0);
  -webkit-mask: radial-gradient(circle, transparent 0 calc(50% - 4px), #000 calc(50% - 3px)); mask: radial-gradient(circle, transparent 0 calc(50% - 4px), #000 calc(50% - 3px)); }
.iw-tbtn.is-special:not(.is-ready) .iw-tbtn__i { opacity: .55; }
.iw-tbtn.is-special.is-ready { background: rgba(255, 210, 63, .38); border-color: #ffd23f; animation: iw-tsp 1s ease-in-out infinite; }
.iw-tbtn.is-special.is-active { animation: none; opacity: calc(var(--top, 1) * .5); }
@keyframes iw-tsp { 50% { box-shadow: 0 0 0 6px rgba(255, 210, 63, .35), 0 0 22px rgba(255, 210, 63, .7); } }

/* top-left: pause + map */
.iw-tbtn.is-pause { width: 42px; height: 42px; left: calc(var(--sl) + 12px); top: 12px; }
.iw-tbtn.is-map { width: 50px; height: 50px; left: calc(var(--sl) + 10px); top: 66px; }
.iw-tbtn.is-chat { width: 40px; height: 40px; right: calc(var(--sr) + 14px); top: 46px; }
.iw-touch.is-map .iw-tbtn.is-map { background: rgba(47, 224, 194, .55); border-color: var(--tb-hot); }

/* map open: a tap picks the Super Jump pin under it (diorama.js); dead: only the map (plan the jump) and pause */
.iw-touch.is-dead:not(.is-map) .iw-touch__zone { pointer-events: none; }
.iw-touch.is-map .iw-touch__stick, .iw-touch.is-dead .iw-touch__stick,
.iw-touch.is-map .iw-tbtn:not(.is-map):not(.is-pause):not(.is-chat), .iw-touch.is-dead .iw-tbtn:not(.is-map):not(.is-pause):not(.is-chat) { display: none; }

/* small phones (≤ 360 px tall): tighten the arc */
@media (max-height: 360px) {
  .iw-tbtn { width: 54px; height: 54px; }
  .iw-tbtn.is-fire { width: 76px; height: 76px; bottom: 24px; }
  .iw-tbtn.is-jump { right: calc(var(--sr) + 130px); bottom: 16px; }
  .iw-tbtn.is-swim { right: calc(var(--sr) + 114px); bottom: 92px; }
  .iw-tbtn.is-sub { width: 48px; height: 48px; bottom: 120px; right: calc(var(--sr) + 40px); }
  .iw-tbtn.is-special { width: 56px; height: 56px; bottom: 164px; right: calc(var(--sr) + 104px); }
}

/* ------------------------------------------------------------------ HUD on a phone */
/* keyboard keycaps mean nothing on glass: the touch buttons carry those actions */
html.is-touch .iw-hud kbd.iw-key, html.is-touch .iw-map__label > span:first-child { display: none; }
html.is-touch .iw-fps { left: calc(env(safe-area-inset-left, 0px) + 62px); top: 22px; }

/* ------------------------------------------------------------------ menus on a phone */
/* the keyboard prompt bar: keep only the chat button (without its T keycap) */
html.is-touch .iw-prompts .iw-hint:not(.iw-chat-hint) { display: none; }
html.is-touch .iw-chat-hint .iw-kbm, html.is-touch .iw-backbtn .iw-hint { display: none; }
/* phones: the menus are laid out as if the screen were 620 px tall, then scaled to fit (--tz = height / 620, set by
   index.html). Keeps the desktop proportions — the px minimum font sizes otherwise outgrow their boxes and overlap. */
html.is-touch .iw-ui { zoom: var(--tz, 1); --u: min(calc(1vw / var(--tz, 1)), calc(1.7778vh / var(--tz, 1))); }
/* the floating keyboard-focus ring has nothing to follow on a touch screen */
html.is-touch .iw-cursor { display: none !important; }
/* title: a tap anywhere starts — the logo (which recolours the UI on click) must not swallow the first tap */
html.is-touch .iw-title .iw-brandbutton { pointer-events: none; }
/* keycaps on buttons / tab bars (Enter, Esc, Q / E…) — kept only in the keyboard list of How to play */
html.is-touch #ui-root kbd.iw-key:not(.iw-key--touch):not(.iw-ctl__keys kbd) { display: none; }

/* ------------------------------------------------------------------ layout editor (openEditor) */
.iw-touch.is-edit { display: block; z-index: 40; pointer-events: auto; touch-action: none; background: rgba(8, 10, 24, .62); }
.iw-touch.is-edit .iw-touch__zone { display: none; }
.iw-touch.is-edit .iw-touch__stick { pointer-events: auto; opacity: max(.75, var(--top, 1)); }
.iw-touch.is-edit .iw-touch__lbl { display: block; position: absolute; left: 0; top: calc(66px * var(--bs, 1)); translate: -50% 0; white-space: nowrap;
  font: 800 10px/1 'Rubik', system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: #fff; text-shadow: 0 1px 2px #000; }
.iw-touch.is-edit .iw-tbtn { display: grid !important; }
.iw-touch.is-edit .iw-tbtn.is-sel { box-shadow: 0 0 0 3px #ffd23f, 0 0 18px rgba(255, 210, 63, .7); }
.iw-touch.is-edit .iw-touch__stick.is-sel::before { box-shadow: 0 0 0 3px #ffd23f, 0 0 18px rgba(255, 210, 63, .7); }
.iw-tedit { position: absolute; left: 50%; top: 8px; translate: -50% 0; width: min(560px, calc(100vw - 150px)); padding: 8px 12px 10px; border-radius: 14px;
  background: rgba(21, 18, 28, .94); border: 2px solid rgba(255, 255, 255, .22); color: #fff; font: 600 11px/1.2 'Rubik', system-ui, sans-serif;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45); touch-action: auto; z-index: 2; }
.iw-tedit__t { display: block; font: 400 15px/1.1 'Titan One', 'Rubik', sans-serif; letter-spacing: .02em; }
.iw-tedit__h { display: block; margin-top: 2px; opacity: .7; font-size: 10px; }
.iw-tedit__row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 7px; }
.iw-tedit__sel { min-width: 64px; padding: 4px 8px; border-radius: 8px; background: #ffd23f; color: #15121c; font: 900 10px/1 'Rubik', sans-serif; font-style: normal; text-transform: uppercase; text-align: center; }
.iw-tedit__r { display: flex; align-items: center; gap: 6px; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.iw-tedit__r input { width: 92px; accent-color: #2fe0c2; }
.iw-tedit__r output { min-width: 34px; font-variant-numeric: tabular-nums; }
.iw-tedit__b { margin-left: auto; padding: 8px 12px; border: 0; border-radius: 9px; font: 900 11px/1 'Rubik', sans-serif; text-transform: uppercase; letter-spacing: .05em; color: #15121c; background: #fff; }
.iw-tedit__b + .iw-tedit__b { margin-left: 0; }
.iw-tedit__b.is-done { background: #2fe0c2; }
