/* =========================================================
   MOBILE / TOUCH  — phone par khelne layak layout
   ========================================================= */

:root {
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html, body { overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#game { -webkit-tap-highlight-color: transparent; }

.touch-device button:hover { filter: none; }
.touch-device .char-card:hover { transform: none; }

/* ---- floating joystick: appears where the thumb lands ---- */
#stick {
  left: calc(18px + var(--safe-l));
  bottom: calc(20px + var(--safe-b));
  opacity: 0.55;
  transition: opacity 0.18s ease;
}
#stick.floating {
  position: fixed;
  opacity: 1;
  margin: 0;
  transition: none;
}
#stick.active { opacity: 1; }

.touch-actions {
  right: calc(16px + var(--safe-r));
  bottom: calc(22px + var(--safe-b));
}
.touch-actions button { -webkit-user-select: none; }
#btn-act { font-family: inherit; }

.touch-device .hud-top-left { top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); }
.touch-device .hud-top-right { top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); }
.touch-device #prompt { bottom: calc(210px + var(--safe-b)); }
.touch-device #toasts { bottom: calc(196px + var(--safe-b)); }
.touch-device #dialog { bottom: calc(12px + var(--safe-b)); }
.touch-device .hud-hint { display: none; }

/* ---------------- phones (portrait) ---------------- */
@media (max-width: 700px) and (pointer: coarse) {
  .char-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; max-height: none; }
  .char-card { padding: 4px; border-radius: 10px; }
  .char-card .char-name { font-size: 8.5px; padding: 3px 2px 2px; }
  .play-btn { padding: 15px; font-size: 16px; border-radius: 14px; }
  .start-hint { display: none; }

  .brand { padding: 5px 9px; gap: 6px; }
  .brand-mark { width: 26px; height: 26px; font-size: 13px; }
  .brand-text h1 { font-size: 11.5px; letter-spacing: 0.06em; }
  .brand-text p { display: none; }
  .status-pill { padding: 4px 8px; font-size: 10.5px; }
  .clock-pill span:last-child { font-size: 7.5px; padding: 0 4px; }
  .hud-top-left { width: auto; max-width: 62vw; gap: 5px; }
  #quest-list.quest-panel { max-width: 62vw; padding: 6px 7px 5px; }
  .quest-head { font-size: 7.5px; letter-spacing: 0.1em; padding-bottom: 4px; }
  .quest-row { padding: 4px 1px; gap: 5px; }
  .quest-name { font-size: 9px; }
  .quest-sub { font-size: 7.5px; }
  .quest-right { font-size: 8.5px; }
  .quest-ping { width: 14px; height: 14px; font-size: 10px; }

  #minimap-wrap { width: 92px; padding: 3px; border-radius: 11px; }
  #minimap { width: 86px; height: 86px; border-radius: 7px; }
  .minimap-label { font-size: 5px; padding: 3px 2px 0; }
  .minimap-label b { font-size: 6px; padding: 0 2px; }
  .top-buttons button { width: 30px; height: 30px; font-size: 13px; }

  #dialog { width: calc(100vw - 20px); }
  .dialog-card { flex-direction: column; gap: 8px; padding: 10px; border-radius: 16px; }
  .portrait-wrap { width: 54px; height: 54px; border-radius: 10px; }
  .dialog-head { align-items: center; }
  .dialog-head h3 { font-size: 15px; }
  .dialog-head p { font-size: 8.5px; }
  #dialog-text { font-size: 12.5px; min-height: 42px; margin: 6px 0 4px; }
  .next-btn { padding: 9px 16px; font-size: 12.5px; border-radius: 10px; }
  .choice-btn { padding: 11px 16px; font-size: 12.5px; flex: 1; }
  .choices { gap: 7px; }

  #stick { width: 118px; height: 118px; }
  #knob { width: 52px; height: 52px; margin: -26px 0 0 -26px; }
  .touch-actions { gap: 9px; }
  .touch-actions button { width: 56px; height: 56px; font-size: 19px; }
  #btn-act { width: 68px; height: 68px; font-size: 20px; }
  #btn-run { width: 46px; height: 46px; font-size: 15px; }

  .map-card { padding: 10px; border-radius: 16px; gap: 8px; width: 100%; max-height: 94vh; }
  #big-map-canvas { width: 100%; }
  .map-head h2 { font-size: 17px; }
  .map-head p { font-size: 8.5px; }
  .map-legend { font-size: 8px; gap: 6px 10px; }
  .map-legend-tip { display: none; }
}

/* landscape phone: keep controls out of the way */
@media (max-height: 500px) and (pointer: coarse) {
  .touch-device .hud-top-left { gap: 4px; }
  #quest-list.quest-panel { display: none; }
  .brand-text p { display: none; }
  #stick { width: 100px; height: 100px; bottom: calc(12px + var(--safe-b)); }
  #knob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .touch-actions { bottom: calc(14px + var(--safe-b)); }
  .touch-actions button { width: 48px; height: 48px; font-size: 16px; }
  #btn-act { width: 58px; height: 58px; }
  #btn-run { width: 40px; height: 40px; }
  .touch-device #prompt { bottom: calc(120px + var(--safe-b)); }
  .touch-device #toasts { bottom: calc(110px + var(--safe-b)); }
  #dialog { width: min(720px, 96vw); bottom: calc(8px + var(--safe-b)); }
  .dialog-card { flex-direction: row; padding: 8px 10px; }
  .portrait-wrap { width: 56px; height: 56px; }
  #dialog-text { font-size: 12px; min-height: 34px; margin: 4px 0 3px; }
  .next-btn { padding: 6px 12px; font-size: 11.5px; }
}

@media (max-width: 700px) {
  .start-panel { padding-bottom: calc(28px + var(--safe-b)); }
  #start-screen { -webkit-overflow-scrolling: touch; }
}
