/* Phones / tablets (touch.js sets body.touch). Touch layer + phone-sized overrides of ui.css. */
body.touch {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; touch-action: none;
}
body.touch #modal .sw-body, body.touch #modal .sh-list { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
/* iOS will not type into a field that inherits user-select: none; 16px stops focus auto-zoom */
body.touch input[type=text], body.touch input:not([type]), body.touch textarea { -webkit-user-select: text; user-select: text; touch-action: manipulation; font-size: max(16px, 1em); }

/* ------------------------------------------------ touch layer */
/* under #ui (z 10, pointer-events none except its buttons/windows): any button ui.js shows in play
   (e.g. the debug panel) still gets the tap; everything else falls through to this layer */
#touch { position: fixed; inset: 0; z-index: 5; display: none; touch-action: none; font-family: var(--font); --k: 1; }
#touch.on { display: block; }
@media (max-height: 360px) { #touch { --k: 0.88; } }
@media (max-height: 400px) { #touch .tc-stick { top: calc(100% - env(safe-area-inset-bottom, 0px) - 84px); } }
@media (min-height: 560px) { #touch { --k: 1.2; } }

/* floating joystick: rests bottom-left, jumps under the thumb */
.tc-stick { position: absolute; width: 0; height: 0; left: calc(env(safe-area-inset-left, 0px) + 100px); top: calc(100% - env(safe-area-inset-bottom, 0px) - 92px); pointer-events: none; }
.tc-stick::before {
  content: ''; position: absolute; width: 124px; height: 124px; left: -62px; top: -62px; border-radius: 50%;
  border: 2px solid rgba(79, 195, 255, 0.5); background: radial-gradient(circle, rgba(8, 16, 32, 0.1), rgba(8, 16, 32, 0.5));
  box-shadow: 0 0 14px rgba(79, 195, 255, 0.25), inset 0 0 18px rgba(79, 195, 255, 0.15); opacity: 0.6; transition: opacity 0.15s;
}
.tc-stick::after {
  content: 'MOVE'; position: absolute; left: -40px; width: 80px; top: 66px; text-align: center; font-size: 11px; font-weight: 700;
  letter-spacing: 0.3em; color: rgba(217, 241, 255, 0.7); text-shadow: 0 1px 2px #000;
}
.tc-stick.on::after { display: none; }
.tc-knob {
  position: absolute; width: 56px; height: 56px; left: -28px; top: -28px; border-radius: 50%; opacity: 0.65;
  background: radial-gradient(circle at 40% 35%, rgba(170, 230, 255, 0.6), rgba(40, 110, 180, 0.6)); border: 2px solid #8fe0ff; box-shadow: 0 0 12px var(--sys-glow);
}
.tc-stick.on::before, .tc-stick.on .tc-knob { opacity: 1; }

.tc-lookhint { /* above the skill cluster, left of the Arise button */
  position: absolute; left: 50%; top: 28%; pointer-events: none; text-align: center;
  font-size: 13px; font-weight: 700; letter-spacing: 0.24em; color: rgba(217, 241, 255, 0.85); text-shadow: 0 1px 3px #000; animation: tcHint 2.4s ease-in-out infinite;
}
.tc-lookhint i { display: block; font-style: normal; font-size: 22px; letter-spacing: 0.6em; padding-left: 0.6em; color: var(--sys-border); }
@keyframes tcHint { 0%, 100% { opacity: 0.35; transform: translateX(-10px); } 50% { opacity: 1; transform: translateX(10px); } }

/* action buttons: --x/--y = centre offset from the bottom-right corner, --s = size */
.tc-btn {
  position: absolute; width: calc(var(--s) * var(--k)); height: calc(var(--s) * var(--k)); border-radius: 50%;
  right: calc(env(safe-area-inset-right, 0px) + (var(--x) - var(--s) / 2) * var(--k));
  bottom: calc(env(safe-area-inset-bottom, 0px) + (var(--y) - var(--s) / 2) * var(--k));
  display: flex; align-items: center; justify-content: center; color: #d9f1ff;
  background: radial-gradient(circle at 50% 38%, rgba(24, 58, 100, 0.74), rgba(8, 16, 32, 0.84));
  border: 2px solid var(--sys-border); box-shadow: 0 0 12px var(--sys-glow), inset 0 0 14px rgba(79, 195, 255, 0.2);
  transition: transform 0.06s, box-shadow 0.12s;
}
.tc-btn .ico { width: 46%; height: 46%; filter: drop-shadow(0 0 4px #4fc3ff); }
.tc-btn svg { width: 100%; height: 100%; display: block; }
.tc-btn .cd { position: absolute; inset: 0; border-radius: 50%; pointer-events: none; }
.tc-btn .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; text-shadow: 0 0 6px #000, 0 1px 2px #000; }
.tc-btn .nm {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 1px; font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; white-space: nowrap; color: #e6f6ff; text-shadow: 0 0 3px #000, 0 1px 2px #000, 0 0 8px #000;
}
.tc-btn .mp {
  position: absolute; bottom: -3px; right: -4px; font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 6px;
  background: rgba(10, 30, 70, 0.92); border: 1px solid #6aa0ff; color: #b8d4ff;
}
.tc-btn .mp:empty, .tc-btn .lv:empty, .tc-btn .cnt:empty { display: none; }
.tc-btn .mp::after { content: ' MP'; font-size: 8px; }
.tc-btn .lv {
  position: absolute; top: -4px; right: -6px; font-style: normal; font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 6px;
  background: rgba(40, 30, 0, 0.92); border: 1px solid var(--gold); color: var(--gold);
}
.tc-btn .cnt { position: absolute; top: -4px; left: -4px; font-size: 13px; line-height: 1; padding: 2px 5px; border-radius: 8px; background: rgba(20, 8, 40, 0.92); color: #e6d0ff; border: 1px solid var(--monarch); }
.tc-btn.off, .tc-mini.off { display: none; }
.tc-btn.dim .ico { opacity: 0.4; filter: grayscale(1); }
.tc-btn.dim .mp { border-color: var(--danger); color: #ffb0b0; }
.tc-btn.down { transform: scale(0.9); background: radial-gradient(circle at 50% 38%, rgba(60, 140, 220, 0.85), rgba(16, 40, 80, 0.9)); box-shadow: 0 0 22px #8fe0ff, inset 0 0 18px rgba(143, 224, 255, 0.5); }
.tc-btn.ready { border-color: var(--gold); animation: tcReady 0.9s ease-in-out infinite alternate; }
.tc-btn.ready .ico { opacity: 1; filter: drop-shadow(0 0 6px var(--gold)); color: #fff3c0; }
.tc-btn.active { border-color: var(--monarch); box-shadow: 0 0 22px var(--monarch), inset 0 0 18px rgba(181, 108, 255, 0.5); }
@keyframes tcReady { from { box-shadow: 0 0 8px rgba(255, 207, 90, 0.5); } to { box-shadow: 0 0 24px rgba(255, 207, 90, 1), inset 0 0 14px rgba(255, 207, 90, 0.4); } }
.tc-attack { border-width: 3px; }
.tc-attack .ico { width: 44%; height: 44%; color: #fff; }
.tc-attack .nm { font-size: 11px; }
.tc-arise, .tc-summon, .tc-domain { border-color: var(--monarch); box-shadow: 0 0 12px rgba(181, 108, 255, 0.55), inset 0 0 14px rgba(181, 108, 255, 0.2); }
.tc-arise .ico, .tc-summon .ico, .tc-domain .ico { color: #e6d0ff; filter: drop-shadow(0 0 5px var(--monarch)); }
.tc-arise.ready { border-color: var(--monarch); animation: tcArise 0.8s ease-in-out infinite alternate; }
.tc-arise.ready .ico { filter: drop-shadow(0 0 8px var(--monarch)); color: #fff; }
@keyframes tcArise { from { box-shadow: 0 0 10px rgba(181, 108, 255, 0.6); } to { box-shadow: 0 0 30px rgba(181, 108, 255, 1), inset 0 0 18px rgba(181, 108, 255, 0.5); } }
.tc-bloodlust { border-color: #ff5a64; box-shadow: 0 0 12px rgba(255, 60, 70, 0.5), inset 0 0 14px rgba(255, 60, 70, 0.18); }
.tc-bloodlust .ico { color: #ffd0d4; filter: drop-shadow(0 0 4px #ff3040); }
.tc-fatal { border-color: #ff2a3a; box-shadow: 0 0 14px rgba(255, 30, 50, 0.6), inset 0 0 14px rgba(255, 30, 50, 0.22); }
.tc-fatal .ico { color: #ffc0c6; filter: drop-shadow(0 0 5px #ff1a2a); }
/* quick-use potions: red / blue flasks with the bag count */
.tc-hp { border-color: #ff5a64; box-shadow: 0 0 10px rgba(255, 60, 70, 0.45); }
.tc-hp .ico { color: #ffb8be; filter: drop-shadow(0 0 4px #ff3040); }
.tc-mp { border-color: #5a8cff; box-shadow: 0 0 10px rgba(80, 130, 255, 0.5); }
.tc-mp .ico { color: #c0d4ff; filter: drop-shadow(0 0 4px #4a7aff); }
.tc-hp .ico, .tc-mp .ico { width: 56%; height: 56%; }
.tc-hp .cnt, .tc-mp .cnt { left: auto; right: -6px; top: auto; bottom: -4px; font-size: 11px; background: rgba(8, 16, 32, 0.92); color: #fff; border-color: currentColor; }
.tc-hp .nm, .tc-mp .nm { display: none; }

/* system buttons, top-right */
.tc-sys { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 8px); right: calc(env(safe-area-inset-right, 0px) + 8px); display: flex; gap: 6px; }
.tc-mini {
  position: relative; width: max(44px, calc(44px * var(--k))); height: max(44px, calc(44px * var(--k))); display: flex; align-items: center; justify-content: center; color: #d9f1ff;
  background: var(--sys-bg); border: 1px solid var(--sys-border); box-shadow: 0 0 10px var(--sys-glow), inset 0 0 12px rgba(79, 195, 255, 0.15);
}
.tc-mini svg { width: 56%; height: 56%; }
.tc-mini.down { background: rgba(40, 110, 180, 0.7); transform: scale(0.92); }
.tc-mini em { position: absolute; top: -6px; right: -6px; font-style: normal; font-size: 11px; font-weight: 700; line-height: 1; padding: 2px 4px; border-radius: 6px; background: #3a2800; border: 1px solid var(--gold); color: var(--gold); animation: flicker 2s infinite; }
.tc-mini em:empty { display: none; }
.tc-party em { background: #082038; border-color: var(--sys-border); color: #bfe9ff; animation: none; } /* party size, not an alert */

/* title extras: Fullscreen (Android) / Add to Home Screen tip (iPhone) */
#touch-title { position: fixed; inset: 0; z-index: 20; display: none; pointer-events: none; font-family: var(--font); }
#touch-title.on { display: block; }
#touch-title > * { pointer-events: auto; }
.tc-fs-big { position: absolute; right: calc(env(safe-area-inset-right, 0px) + 14px); bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); display: flex; align-items: center; gap: 8px; font-size: 15px; padding: 8px 16px; }
.tc-fs-big svg { width: 20px; height: 20px; }
#touch-title.fs .tc-fs-big { display: none; }
.tc-tip {
  position: absolute; left: calc(env(safe-area-inset-left, 0px) + 14px); bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); width: min(250px, 30vw);
  padding: 9px 30px 9px 12px; font-size: 13px; line-height: 1.35; color: var(--sys-text); background: var(--sys-bg); border: 1px solid var(--gold);
  box-shadow: 0 0 12px rgba(255, 207, 90, 0.35);
}
.tc-tip b { color: #fff3c0; }
.tc-tip button { position: absolute; top: 2px; right: 2px; width: 28px; height: 28px; font-size: 20px; line-height: 1; color: var(--sys-dim); background: none; border: 0; }

/* portrait: ask for landscape */
#rotate { display: none; position: fixed; inset: 0; z-index: 100; background: radial-gradient(ellipse at center, #0c1830, #05070c 70%); flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; font-family: var(--font); color: var(--sys-text); padding: 24px; }
@media (orientation: portrait) { body.touch #rotate { display: flex; } }
.rot-ico { width: 74px; height: 74px; color: var(--sys-border); filter: drop-shadow(0 0 8px var(--sys-border)); animation: tcRot 2.2s ease-in-out infinite; }
.rot-ico svg { width: 100%; height: 100%; }
.rot-t { font-size: 22px; font-weight: 700; letter-spacing: 0.3em; color: #fff; text-shadow: 0 0 10px var(--sys-border); }
.rot-s { font-size: 15px; letter-spacing: 0.08em; color: var(--sys-dim); }
@keyframes tcRot { 0%, 25% { transform: rotate(0); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }

/* ------------------------------------------------ phone-sized HUD (ui.css ids/classes) */
body.touch #skillbar, body.touch #controls-hint, body.touch .title-foot { display: none !important; }
body.touch #hud-stats { top: calc(env(safe-area-inset-top, 0px) + 6px); left: calc(env(safe-area-inset-left, 0px) + 8px); transform: scale(0.74); transform-origin: 0 0; }
/* the gold line shares the XP row so the HUD stays as short as before (the quest panel sits right under it) */
body.touch .gold-row { position: absolute; left: 14px; bottom: 7px; margin: 0; }
body.touch .gold-row small { display: none; }
body.touch .xp-row { padding-left: 86px; }
body.touch #quest { top: calc(env(safe-area-inset-top, 0px) + 104px); left: calc(env(safe-area-inset-left, 0px) + 8px); right: auto; width: 290px; transform: scale(0.68); transform-origin: 0 0; }
body.touch #quest::after { content: '\2013'; position: absolute; top: 3px; right: 9px; font-size: 16px; font-weight: 700; color: var(--sys-dim); }
body.touch #quest.tc-folded::after { content: '+'; }
body.touch #quest.tc-folded .ql { display: none; }
@media (max-height: 400px) { body.touch #quest { transform: scale(0.6); } } /* clear of the joystick */
/* the objective line is the first-timer's "what next": readable even scaled down (~11px on screen) */
body.touch #quest .qo { font-size: 18px; line-height: 1.25; }
body.touch #h-xp { font-size: 14px; }
/* boss bar fits between the HUD stats (~252px) and the top-right buttons (~202px: 4 of them in a gate,
   the Shop button is city-only and so is no boss) */
/* buttons pinned to the top middle (potions): x from the centre, y from the top; below the boss bar while it shows */
.tc-btn.tc-top { right: auto; bottom: auto; left: calc(50% + (var(--x) - var(--s) / 2) * var(--k)); top: calc(env(safe-area-inset-top, 0px) + (var(--y) - var(--s) / 2) * var(--k)); }
body.touch:has(#bossbar:not(.hidden)) .tc-btn.tc-top { top: calc(env(safe-area-inset-top, 0px) + 52px + (var(--y) - var(--s) / 2) * var(--k)); }
@media (max-width: 720px) { .tc-btn.tc-top { margin-left: -30px; } } /* small phones: clear of the top-right buttons */
body.touch #bossbar {
  top: calc(env(safe-area-inset-top, 0px) + 6px); padding: 3px 8px 2px;
  left: calc(50% + 32px + (env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) / 2);
  width: min(380px, calc(100% - 478px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
}
body.touch .boss-name { font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { /* narrow: the full name on two lines, without the "— Gate Boss" tag */
  body.touch .boss-name { white-space: normal; font-size: 12px; line-height: 1.1; }
  body.touch .boss-name small { display: none; }
}
body.touch .boss-name small { font-size: 11px; }
body.touch .boss-track { height: 10px; }
body.touch .boss-hp { font-size: 10px; }
body.touch #prompts { bottom: calc(env(safe-area-inset-bottom, 0px) + 112px); gap: 4px; }
@media (max-width: 700px) { body.touch #prompts { bottom: calc(env(safe-area-inset-bottom, 0px) + 132px); } } /* clear of Bloodlust */
body.touch .prompt { font-size: 14px; padding: 5px 12px; gap: 8px; }
body.touch .prompt kbd { font-size: 11px; height: 19px; min-width: 20px; }
body.touch #notifs { top: calc(env(safe-area-inset-top, 0px) + 88px); width: min(560px, 62vw); zoom: 0.66; } /* zoom scales top + width too */
body.touch #ui:has(#bossbar:not(.hidden)) #notifs { top: calc(env(safe-area-inset-top, 0px) + 168px); } /* below the boss bar and the potions (zoomed: ~110 px) */
/* short screens show one message at a time (ui.js); capped so it ends above the skill buttons */
@media (max-height: 420px) { body.touch .notif { max-height: 170px; overflow: hidden; } }
body.touch #banner .bt { font-size: 38px; }
body.touch #banner .bl { font-size: 14px; }
body.touch #levelup::before { top: -20px; height: 120px; }
body.touch #levelup .lu-line { top: 30px; }
body.touch #levelup .lu-t { font-size: 54px; }
body.touch #levelup .lu-s { font-size: 18px; margin-top: 6px; }
body.touch .dn { font-size: 17px; }
body.touch .dn.crit { font-size: 24px; }
body.touch .dn.shadow.crit-s { font-size: 21px; }
body.touch .dn.poison { font-size: 13px; }
body.touch .dn.player { font-size: 16px; }
body.touch .dn.blocked, body.touch .dn.dodge { font-size: 14px; }
body.touch .mk { font-size: 11px; }

/* System windows: scaled down, two columns again (ui.css stacks them under 900px wide), finger-sized targets */
/* zoom also scales vh, so max-height is divided back to ~97% of the screen. --t = a 44px finger target
   before the zoom (44 / 0.8, 44 / 0.7) */
body.touch #modal .sys-window { zoom: 0.8; max-height: calc(var(--vh) * 97 / 0.8); --t: 55px; }
@media (max-height: 440px) { body.touch #modal .sys-window { zoom: 0.7; max-height: calc(var(--vh) * 97 / 0.7); --t: 63px; } }
/* small phones (iPhone XS / SE / mini in landscape with Safari's bars): smaller again, targets still 44 px */
@media (max-height: 380px) { body.touch #modal .sys-window { zoom: 0.6; max-height: calc(var(--vh) * 97 / 0.6); --t: 74px; } }
body.touch #modal .tab-body { min-height: 0; } /* the fixed frame height only on big screens */
body.touch #modal .sys-btn, body.touch #modal .tab, body.touch #modal .tab-close, body.touch #modal .name-input { min-height: var(--t); }
body.touch #modal .plus { width: var(--t); height: var(--t); }
body.touch #modal .set input[type=range] { height: var(--t); }
body.touch #modal .set input[type=checkbox] { width: var(--t); height: var(--t); }
body.touch #modal .stat { grid-template-columns: 44px 1fr 44px var(--t); }
/* small print stays >= ~11px on screen */
body.touch #modal .job-opt, body.touch #modal .stat .sn small, body.touch #modal .st-preview { font-size: 16px; }
body.touch .menu .sys-btn { min-height: 44px; }
body.touch .pause-grid { grid-template-columns: 1.15fr 1fr; }
body.touch .st-stats, body.touch .st-id { grid-template-columns: 1fr 1fr; }
body.touch .st-derived, body.touch .sh-head { grid-template-columns: repeat(3, 1fr); }
body.touch .plus { font-size: 26px; }
body.touch .tab { padding: 10px 18px; }
body.touch .sys-btn { padding: 12px 26px; }
body.touch .tab-close { pointer-events: auto; font-size: 0; padding: 9px 14px; border: 1px solid var(--sys-border); background: rgba(10, 30, 60, 0.75); cursor: pointer; }
body.touch .tab-close kbd { display: none; }
body.touch .tab-close::after { content: '\2715  CLOSE'; font-size: 15px; font-weight: 700; letter-spacing: 0.14em; color: #fff; }

/* title on a short landscape screen */
body.touch .title-corner { top: calc(env(safe-area-inset-top, 0px) + 8px); font-size: 10px; }
body.touch .title-corner.tl { left: calc(env(safe-area-inset-left, 0px) + 14px); }
body.touch .title-corner.tr { right: calc(env(safe-area-inset-right, 0px) + 14px); }
@media (max-height: 560px) {
  body.touch .kicker { font-size: 11px; margin-bottom: 4px; }
  body.touch .logo-top { font-size: clamp(30px, 12vh, 112px); }
  body.touch .logo-craft { font-size: clamp(26px, 10vh, 86px); margin-top: 2px; }
  body.touch .tagline { font-size: 12px; margin-top: 6px; }
  body.touch .menu { margin-top: 14px; gap: 8px; }
  body.touch .menu .sys-btn { width: 290px; padding: 8px 18px; font-size: 16px; }
}
/* Block (shield) */
.tc-block.active { border-color: #ffe680; box-shadow: 0 0 22px #ffc020, inset 0 0 18px rgba(255, 210, 90, 0.45); }
