/* Phone layout (max-width 700px): the board fills the screen, the side panel becomes a bottom sheet
   opened from a bottom tab bar (Map, Chat, Sheet, Journal, Party: built in importers.js), windows go
   full-width and touch targets grow. Desktop is untouched: everything sits inside the media query. */

@media (max-width: 700px) {
  :root { --m-tabs: 58px; --m-top: 44px; }

  html, body { overscroll-behavior: none; }
  #table { height: 100vh; height: 100dvh; }
  body.m-phone #main { margin-bottom: calc(var(--m-tabs) + env(safe-area-inset-bottom, 0px)); }

  /* iOS zooms into inputs smaller than 16px */
  input, select, textarea { font-size: 16px; }
  input[type=checkbox] { width: 18px; height: 18px; }

  /* top bar: brand, page name, clock, connection */
  #topbar { height: var(--m-top); gap: 8px; padding: 0 8px 0 6px; }
  .camp-name { display: none; }
  #pagebar { gap: 2px; }
  .top-right { gap: 6px; }
  #people { display: none; }
  .top-right > .icon-btn { display: none; }
  .clock-chip { height: 28px; padding: 3px 8px; }
  .clock-day { display: none; }

  /* tools: a slim rail on the left */
  #toolbar { width: 46px; gap: 2px; padding: 6px 0; }
  .tool { width: 40px; height: 40px; }
  .layer { width: 38px; }

  /* side panel → bottom sheet */
  #side-grip { display: none; }
  #side {
    position: fixed; left: 0; right: 0; bottom: calc(var(--m-tabs) + env(safe-area-inset-bottom, 0px)); width: auto !important;
    height: min(66dvh, 600px); z-index: 30; border-top: 1px solid var(--accent-dim); border-radius: 14px 14px 0 0;
    box-shadow: 0 -20px 44px rgba(0, 0, 0, .65); transform: translateY(calc(100% + var(--m-tabs) + 20px)); visibility: hidden;
    transition: transform .28s var(--ease), visibility 0s linear .28s;
  }
  body.side-hidden #side { display: flex; }
  body.m-sheet #side { transform: none; visibility: visible; transition: transform .28s var(--ease), visibility 0s; }
  #side::before { content: ""; position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: var(--rule-2); }
  .side-tabs { padding-top: 10px; overflow-x: auto; scrollbar-width: none; }
  .side-tabs::-webkit-scrollbar { display: none; }
  .side-tab { flex: 1 0 auto; min-width: 62px; padding: 10px 10px 11px; }
  .side-panel { padding: 10px 12px; }

  /* bottom tab bar */
  #m-tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; height: calc(var(--m-tabs) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px); background: linear-gradient(180deg, #0d121d, #070a11); border-top: 1px solid var(--rule);
  }
  #m-tabs::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 35%, transparent), transparent); }
  .m-tab {
    position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0;
    border: 0; border-radius: 0; background: transparent; color: var(--dim); font: 700 8.5px var(--mono); letter-spacing: .14em; text-transform: uppercase; box-shadow: none !important;
  }
  .m-tab .ico { width: 22px; height: 22px; }
  .m-tab:active:not(:disabled) { transform: none; background: rgba(255, 255, 255, .03); }
  .m-tab.on { color: var(--accent); }
  .m-tab.on::before { content: ""; position: absolute; top: 0; left: 26%; right: 26%; height: 2px; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
  .m-badge { position: absolute; top: 5px; left: calc(50% + 7px); min-width: 17px; padding: 1px 5px; border-radius: 9px; background: var(--blood); color: #fff; font: 700 9px var(--sans); letter-spacing: 0; }
  .m-badge[hidden] { display: none; }
  #side .badge { display: none; }

  /* chat: big dice buttons and input */
  .chat-foot { padding: 8px 10px 10px; gap: 8px; }
  .quick-dice { gap: 4px; flex-wrap: wrap; }
  .quick-dice button { min-width: 38px; min-height: 36px; padding: 6px 8px; font-size: 11px; }
  .chat-input { min-height: 48px; }
  .chat-as { max-width: 130px; font-size: 14px; }

  /* windows: full width between the top bar and the tab bar */
  #windows .win {
    left: 0 !important; top: var(--m-top) !important; width: 100vw !important; height: auto !important; max-width: 100vw; min-width: 0;
    bottom: calc(var(--m-tabs) + env(safe-area-inset-bottom, 0px)); max-height: none; border-radius: 0; border-left: 0; border-right: 0; resize: none;
  }
  .win-head { cursor: default; padding: 6px 6px 6px 14px; }
  .win-title { font-size: 17px; }
  .win-x { width: 42px; height: 42px; font-size: 26px; }
  .win-scroll { padding: 12px; }
  .tabs { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; padding: 11px 13px; }

  /* sheets: one column, touch-sized rows */
  .sh-abil { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sh-cols { grid-template-columns: minmax(0, 1fr); }
  .rollable { min-height: 34px; }
  .line { min-height: 34px; }

  /* token HUD */
  #hud { flex-wrap: wrap; max-width: calc(100vw - 60px); gap: 6px; padding: 6px 8px; }
  #hud button { min-width: 38px; min-height: 38px; padding: 6px 9px; font-size: 13px; }
  .hud-cond { width: 38px; }
  .hud-group { gap: 4px; flex-wrap: wrap; max-width: 100%; }
  .hud-group:has(.hud-cond) { border-right: 0; padding-right: 0; }
  .hud-hp { font-size: 14px; }

  /* menus, dialogs and the rest of the floating things */
  .ctx { min-width: 230px; max-width: calc(100vw - 16px); }
  .ctx-item { padding: 11px 14px 11px 10px; font-size: 14px; }
  .modal { width: calc(100vw - 24px); max-width: none; }
  #toasts { bottom: calc(var(--m-tabs) + 14px + env(safe-area-inset-bottom, 0px)); width: calc(100vw - 24px); }
  #hand-tray { left: 54px; }
  body.m-phone #hand-tray { position: fixed; bottom: calc(var(--m-tabs) + 10px + env(safe-area-inset-bottom, 0px)); }
  #macrobar { bottom: 8px; }
  #turnbanner { top: 12px; padding: 8px 18px; max-width: calc(100% - 24px); }
  #turnbanner b { font-size: 18px; }
  #stagehint { bottom: 12px; width: calc(100% - 24px); text-align: center; }
  #toolopts { top: 6px; max-width: calc(100% - 12px); }
  .hover-card { display: none; }
}
