/* ── TOWER-SIGIL MOBILE · TOUCH-FIRST UI LAYER ───────────────────────────
 * Loaded by index.html. Activates when body has .is-touch (set by
 * tower-sigil-mobile.js). Desktop is unaffected unless explicitly opted in
 * via the floating ⚙ button.
 * ──────────────────────────────────────────────────────────────────── */

html, body { -webkit-text-size-adjust: 100%; }
body.is-touch {
  user-select: none; -webkit-user-select: none;
  /* respect iOS safe area for the bottom drawer */
  --ts-safe-bot: env(safe-area-inset-bottom, 0px);
}

/* ── FLOATING ⚙ SETTINGS BUTTON (top-right under header) ─────────────── */
.ts-fmenu{
  position:fixed; top:54px; right:10px; z-index:120;
  display:flex; flex-direction:column; gap:8px;
  pointer-events:none;
}
.ts-fbtn{
  pointer-events:auto;
  width:42px; height:42px; border-radius:50%;
  background:rgba(20,10,31,0.86);
  border:1px solid rgba(245,158,11,0.55);
  color:#fde047; font-size:18px; line-height:1;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; padding:0;
  box-shadow:0 4px 14px rgba(0,0,0,0.45), inset 0 0 8px rgba(245,158,11,0.18);
  transition:transform .12s ease, background .12s ease;
}
.ts-fbtn:active{ transform:scale(0.92); background:rgba(124,58,237,0.35); }

/* ── TUTORIAL OVERLAY (first launch, gated on localStorage) ──────────── */
.ts-tut{
  position:fixed; inset:0; z-index:600;
  background:rgba(5,3,12,0.94);
  display:none; flex-direction:column; align-items:center; justify-content:center;
  padding:24px; text-align:center; gap:14px;
  backdrop-filter:blur(4px); -webkit-backdrop-filter:blur(4px);
}
.ts-tut.open{ display:flex; }
.ts-tut .icn{ font-size:54px; line-height:1; filter:drop-shadow(0 0 14px rgba(245,158,11,0.6)); }
.ts-tut .ttl{ font-family:'Cinzel',serif; font-size:18px; letter-spacing:4px; color:#fde047; text-transform:uppercase; text-shadow:0 0 10px rgba(245,158,11,0.55); }
.ts-tut .bdy{ font-size:13px; color:#cbd5e1; line-height:1.55; max-width:340px; }
.ts-tut .dots{ display:flex; gap:6px; }
.ts-tut .dots i{ width:7px; height:7px; border-radius:50%; background:rgba(124,58,237,0.3); }
.ts-tut .dots i.on{ background:#c084fc; box-shadow:0 0 8px #c084fc; }
.ts-tut .row{ display:flex; gap:10px; margin-top:6px; }
.ts-tut button{ border:0; padding:10px 18px; border-radius:8px; font-family:'Cinzel',serif; font-size:11px; letter-spacing:2px; text-transform:uppercase; font-weight:700; cursor:pointer; }
.ts-tut .next{ background:linear-gradient(90deg,#7c3aed,#f59e0b); color:#fff; box-shadow:0 4px 14px rgba(245,158,11,0.35); }
.ts-tut .skip{ background:transparent; color:#94a3b8; border:1px solid rgba(124,58,237,0.4); }

/* ── SETTINGS PANEL ──────────────────────────────────────────────────── */
.ts-set{
  position:fixed; inset:0; z-index:550;
  background:rgba(5,3,12,0.96);
  display:none; flex-direction:column; padding:18px; gap:14px;
  overflow-y:auto;
}
.ts-set.open{ display:flex; }
.ts-set .hdr{ display:flex; justify-content:space-between; align-items:center; padding-bottom:8px; border-bottom:1px solid rgba(245,158,11,0.35); }
.ts-set .ttl{ font-family:'Cinzel',serif; font-size:14px; color:#fde047; letter-spacing:3px; text-transform:uppercase; }
.ts-set .x{ width:34px; height:34px; border-radius:8px; border:1px solid #f59e0b; background:rgba(245,158,11,0.18); color:#fde047; font-size:16px; font-weight:700; cursor:pointer; }
.ts-set .row{ display:flex; flex-direction:column; gap:6px; padding:10px 0; border-bottom:1px dashed rgba(124,58,237,0.18); }
.ts-set .lab{ font-family:'Cinzel',serif; font-size:11px; color:#c084fc; letter-spacing:2px; text-transform:uppercase; }
.ts-set .val{ font-size:10px; color:#fde047; font-weight:700; }
.ts-set input[type=range]{ width:100%; accent-color:#f59e0b; height:24px; }
.ts-set .tog{ display:inline-block; width:44px; height:24px; border-radius:12px; background:rgba(124,58,237,0.25); border:1px solid rgba(124,58,237,0.45); position:relative; cursor:pointer; }
.ts-set .tog::after{ content:''; position:absolute; top:1px; left:1px; width:20px; height:20px; border-radius:50%; background:#c084fc; transition:left .15s; }
.ts-set .tog.on{ background:rgba(124,58,237,0.55); }
.ts-set .tog.on::after{ left:21px; background:#fde047; }
.ts-set .note{ font-size:10px; color:#64748b; letter-spacing:1px; }
.ts-set .ts-reset{
  font-family:'Cinzel',serif; font-size:11px; letter-spacing:2px; text-transform:uppercase;
  padding:10px 14px; border-radius:6px; border:1px solid rgba(124,58,237,0.45);
  background:rgba(124,58,237,0.18); color:#c084fc; cursor:pointer; font-weight:700;
}
.ts-set .ts-reset:active{ background:rgba(124,58,237,0.32); }

/* ── PORTRAIT REFLOW ────────────────────────────────────────────────────
 * The base CSS already collapses #rail into a horizontal bottom strip at
 * max-width:760px. We tighten that for portrait phones (390x844), give the
 * board more vertical room, and respect the iOS home indicator.
 * ──────────────────────────────────────────────────────────────────── */
@media (max-width:760px) and (orientation:portrait){
  body.is-touch #board-wrap{ height:62vh; }
  body.is-touch #rail{
    max-height:calc(38vh - env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background:linear-gradient(180deg,rgba(20,10,31,0.96),rgba(10,6,18,0.98));
    box-shadow:0 -4px 18px rgba(0,0,0,0.55);
  }
  body.is-touch .rail-section{ width:220px; padding:10px 12px; }
  body.is-touch .rail-section h3{ font-size:0.68rem; margin-bottom:6px; }
  body.is-touch .wave-btn{ padding:10px 6px; font-size:0.78rem; }
  /* enlarge tower picks for fat-finger taps */
  body.is-touch .tower-pick{ padding:10px 6px; min-height:74px; }
  body.is-touch .tower-pick .glyph{ width:34px; height:34px; }
  /* speed buttons & sigil nodes — touch targets ≥ 36px */
  body.is-touch .speed-btn{ min-height:36px; min-width:38px; }
  body.is-touch .sigil-node{ padding:8px; min-height:60px; }
  /* keep the floating ⚙ above the drawer */
  body.is-touch .ts-fmenu{ top:46px; right:8px; }
}

/* Landscape phones / tablets: keep side rail visible but ensure pickable */
@media (max-width:900px) and (orientation:landscape){
  body.is-touch #rail{ width:240px; }
  body.is-touch .tower-pick{ min-height:64px; }
  body.is-touch .speed-btn{ min-height:34px; }
}

/* ── CANVAS TRANSFORM POLISH ─────────────────────────────────────────────
 * The mobile JS sets transform via inline style on the canvas during pan
 * and pinch. We just make sure transitions don't fight the gesture, and
 * the canvas never bleeds outside the wrap.
 * ──────────────────────────────────────────────────────────────────── */
body.is-touch #board-wrap{ overflow:hidden; }
body.is-touch #gameCanvas{
  transform-origin:center center;
  transition:none;
  will-change:transform;
  touch-action:none;
}

/* ── EARN-POPUP HOOK (commercial) ───────────────────────────────────────
 * The shared OnyxWallet popup is a fixed overlay; we just ensure it stacks
 * above our tutorial & settings on touch.
 * ──────────────────────────────────────────────────────────────────── */
.onyx-earn-popup, .onyx-wallet-popup{ z-index:700 !important; }

/* ╔═══════════════════════════════════════════════════════════════════╗
   ║  DEEP-PASS LAYER (tower-sigil-deep.js)                            ║
   ║  Sigil Rune Forge · Daily Ribbon · FX overlay polish              ║
   ╚═══════════════════════════════════════════════════════════════════╝ */

/* Rune-glow rising float (drop from killed enemy) */
@keyframes ts-rune-rise{
  0%   { transform:translateY(0)    scale(0.9); opacity:0; }
  20%  { transform:translateY(-6px) scale(1.1); opacity:1; }
  100% { transform:translateY(-28px) scale(0.85); opacity:0; }
}

/* Daily-challenge ribbon (top of viewport, under header) */
.ts-daily{
  position:fixed; top:54px; left:60px; right:60px; z-index:115;
  display:flex; align-items:center; gap:10px;
  padding:6px 10px; border-radius:10px;
  background:linear-gradient(90deg, rgba(124,58,237,0.30), rgba(245,158,11,0.18));
  border:1px solid rgba(245,158,11,0.55);
  box-shadow:0 4px 16px rgba(0,0,0,0.55), inset 0 0 12px rgba(124,58,237,0.20);
  color:#fde047;
  pointer-events:auto;
}
.ts-daily .ico{ font-size:18px; line-height:1; filter:drop-shadow(0 0 8px rgba(245,158,11,0.7)); }
.ts-daily .meta{ flex:1; min-width:0; }
.ts-daily .ttl{ font-family:'Cinzel',serif; font-size:10px; letter-spacing:2px; color:#fde047; text-transform:uppercase; }
.ts-daily .dsc{ font-size:10px; color:#cbd5e1; line-height:1.3; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ts-daily.done{ background:linear-gradient(90deg, rgba(34,197,94,0.22), rgba(245,158,11,0.16)); border-color:rgba(34,197,94,0.55); }
.ts-daily-toggle{
  flex-shrink:0; font-family:'Cinzel',serif; font-size:10px; letter-spacing:2px; text-transform:uppercase; font-weight:700;
  padding:6px 10px; border-radius:6px;
  background:rgba(20,10,31,0.78); border:1px solid rgba(124,58,237,0.55);
  color:#c084fc; cursor:pointer;
}
.ts-daily-toggle.on{ background:linear-gradient(90deg,#7c3aed,#f59e0b); color:#fff; border-color:#fde047; box-shadow:0 0 12px rgba(245,158,11,0.45); }
.ts-daily-toggle.done{ background:rgba(34,197,94,0.40); color:#fff; border-color:#22c55e; cursor:default; }
@media (max-width:500px){
  .ts-daily{ left:8px; right:60px; top:52px; padding:4px 8px; }
  .ts-daily .ttl{ font-size:9px; }
  .ts-daily .dsc{ font-size:9px; }
}

/* Sigil Rune Forge panel */
.ts-runes{
  position:fixed; inset:0; z-index:560;
  display:none; flex-direction:column;
  background:radial-gradient(ellipse at top, rgba(20,10,31,0.98), rgba(5,3,12,0.99));
  overflow-y:auto;
  color:#cbd5e1;
}
.ts-runes.open{ display:flex; }
.ts-runes .hdr{
  display:flex; justify-content:space-between; align-items:center;
  padding:14px 18px; border-bottom:1px solid rgba(245,158,11,0.35);
  position:sticky; top:0; background:rgba(5,3,12,0.96); z-index:2;
}
.ts-runes .ttl{ font-family:'Cinzel',serif; font-size:16px; color:#fde047; letter-spacing:3px; text-transform:uppercase; text-shadow:0 0 10px rgba(245,158,11,0.45); }
.ts-runes .x{
  width:34px; height:34px; border-radius:8px;
  border:1px solid #f59e0b; background:rgba(245,158,11,0.18);
  color:#fde047; font-size:16px; font-weight:700; cursor:pointer;
}
.ts-runes .body{ padding:14px 18px; display:flex; flex-direction:column; gap:18px; max-width:560px; margin:0 auto; width:100%; }
.ts-runes .sect{ border:1px dashed rgba(124,58,237,0.25); border-radius:10px; padding:12px; background:rgba(20,10,31,0.45); }
.ts-runes .lbl{
  font-family:'Cinzel',serif; font-size:10px; letter-spacing:2.5px;
  text-transform:uppercase; color:#c084fc; margin-bottom:8px;
}

/* Rune fragment pills */
.ts-runes .frags{ display:grid; grid-template-columns:repeat(auto-fill, minmax(96px,1fr)); gap:8px; }
.ts-runes .frag{
  display:flex; flex-direction:column; align-items:center; gap:3px;
  padding:10px 6px; border-radius:8px;
  background:rgba(8,4,15,0.65);
  border:1px solid var(--c, #7c3aed);
  color:var(--c, #fde047);
  font-family:'Cinzel',serif; cursor:pointer;
  transition:transform .12s ease, background .12s ease;
}
.ts-runes .frag:active{ transform:scale(0.95); }
.ts-runes .frag.empty{ opacity:0.34; filter:grayscale(0.6); }
.ts-runes .frag .g{ font-size:24px; text-shadow:0 0 8px var(--c, #fde047); }
.ts-runes .frag .n{ font-size:9px; letter-spacing:1.5px; text-transform:uppercase; color:#cbd5e1; }
.ts-runes .frag .ct{ font-size:11px; color:#fde047; font-weight:700; }

/* Forge slots */
.ts-runes .slots{ display:flex; gap:10px; justify-content:center; margin:8px 0; }
.ts-runes .slot{
  width:64px; height:64px; border-radius:12px;
  border:2px dashed rgba(124,58,237,0.45);
  display:flex; align-items:center; justify-content:center;
  background:rgba(8,4,15,0.65);
  cursor:pointer; transition:border-color .15s, background .15s;
}
.ts-runes .slot.filled{ border-color:#fde047; background:rgba(245,158,11,0.10); border-style:solid; }
.ts-runes .slot .g{ font-size:32px; }
.ts-runes .slot .g.empty{ color:rgba(124,58,237,0.45); font-size:24px; }
.ts-runes .forge-row{ display:flex; gap:8px; }
.ts-runes .ts-btn{
  flex:1; font-family:'Cinzel',serif; font-size:11px; letter-spacing:2.5px; text-transform:uppercase; font-weight:700;
  padding:10px 14px; border-radius:8px; border:0; cursor:pointer;
}
.ts-runes .ts-btn.forge{ background:linear-gradient(90deg,#7c3aed,#f59e0b); color:#fff; box-shadow:0 4px 14px rgba(245,158,11,0.35); }
.ts-runes .ts-btn.ghost{ background:transparent; border:1px solid rgba(124,58,237,0.45); color:#c084fc; flex:0 0 90px; }
.ts-runes .preview{ margin-top:10px; }
.ts-runes .pv{
  padding:10px 12px; border-radius:8px;
  border:1px solid var(--c, rgba(124,58,237,0.45));
  background:rgba(8,4,15,0.65); color:#cbd5e1; display:flex; flex-direction:column; gap:3px;
}
.ts-runes .pv b{ font-family:'Cinzel',serif; letter-spacing:2px; color:var(--c, #fde047); text-shadow:0 0 8px var(--c, #fde047); font-size:13px; text-transform:uppercase; }
.ts-runes .pv span{ font-size:11px; color:#94a3b8; }
.ts-runes .pv.blank{ font-style:italic; color:#64748b; text-align:center; font-size:11px; }
.ts-runes .pv.unknown{ color:#fda4af; text-align:center; font-size:11px; }

/* Crafted active toggles */
.ts-runes .crafted{ display:flex; flex-direction:column; gap:6px; }
.ts-runes .crafted-pill{
  display:flex; flex-direction:column; gap:2px; text-align:left;
  padding:10px 12px; border-radius:8px;
  background:rgba(8,4,15,0.65);
  border:1px solid var(--c, rgba(124,58,237,0.45));
  cursor:pointer; transition:background .12s, border-color .12s;
}
.ts-runes .crafted-pill.on{ background:linear-gradient(90deg, rgba(124,58,237,0.30), rgba(245,158,11,0.18)); border-color:#fde047; box-shadow:0 0 12px var(--c, #fde047); }
.ts-runes .crafted-pill b{ font-family:'Cinzel',serif; font-size:12px; letter-spacing:2px; color:var(--c, #fde047); text-transform:uppercase; }
.ts-runes .crafted-pill span{ font-size:10px; color:#94a3b8; }
.ts-runes .empty{ font-size:11px; color:#64748b; font-style:italic; text-align:center; padding:8px; }

/* Combo Codex */
.ts-runes .codex{ display:flex; flex-direction:column; gap:6px; }
.ts-runes .codex-row{
  display:grid; grid-template-columns:auto 1fr; gap:4px 10px;
  padding:8px 10px; border-radius:6px;
  background:rgba(8,4,15,0.4); border:1px solid rgba(124,58,237,0.18);
}
.ts-runes .codex-row.found{ border-color:var(--c, #fde047); }
.ts-runes .codex-row.locked{ opacity:0.55; filter:grayscale(0.4); }
.ts-runes .codex-row .recipe{ grid-row:1 / span 2; font-size:14px; letter-spacing:2px; align-self:center; }
.ts-runes .codex-row .recipe i{ font-style:normal; padding:0 1px; text-shadow:0 0 6px currentColor; }
.ts-runes .codex-row .name{ font-family:'Cinzel',serif; font-size:11px; letter-spacing:2px; color:var(--c, #fde047); text-transform:uppercase; }
.ts-runes .codex-row .desc{ font-size:10px; color:#94a3b8; line-height:1.3; }
