/* Phone layout. Everything here is under body.mobile (set by js/mobile.js at <=820px wide), so desktop is untouched.
   Shape: slim top bar, the map, a bottom nav, and ONE bottom sheet that holds whichever panel is open. */

body.mobile {
  --nav-h: calc(64px + env(safe-area-inset-bottom));
  --sheet-h: 0px;
  --top-h: calc(64px + env(safe-area-inset-top));
}

/* desktop chrome that a phone replaces */
body.mobile #tools,
body.mobile #helpBtn,
body.mobile #hud,
body.mobile #coords,
body.mobile #info,
body.mobile #tip { display: none !important; }

/* larger touch targets; 16px inputs so iOS Safari never zooms the page on focus */
body.mobile input,
body.mobile select { font-size: 16px; }
body.mobile button { min-height: 36px; }
body.mobile .glass { -webkit-backdrop-filter: blur(12px) saturate(1.4); backdrop-filter: blur(12px) saturate(1.4); }

/* ---------- top: farm bar + more ---------- */
body.mobile #ui {
  z-index: 9; /* above every sheet: the farm box must always be reachable */
  left: var(--gutter); right: calc(var(--gutter) + 54px); top: calc(var(--gutter) + env(safe-area-inset-top));
  transform: none; width: auto; max-width: none;
}
body.mobile #uiRow { gap: 4px; }
body.mobile #uiRow label,
body.mobile #uiRow .div,
body.mobile #ui #worldBtn, body.mobile #ui #world3dBtn { display: none; } /* on a phone the world map is in the more menu */
body.mobile #ui #farmNo { flex: 1; min-width: 0; width: auto; height: 40px; font-size: 16px; -webkit-user-select: text; user-select: text; }
body.mobile #ui #prev, body.mobile #ui #next { width: 40px; height: 40px; }
body.mobile #ui #load { height: 40px; padding: 0 14px; }
body.mobile #status { text-align: left; }
/* routine loading chatter ("loading farm…", "up to date") is left out on a phone; errors and warnings still show */
body.mobile #status[data-kind="progress"] { display: none; }

body.mobile #moreBtn {
  display: grid; place-items: center; right: var(--gutter); top: calc(var(--gutter) + env(safe-area-inset-top));
  width: 46px; height: 52px; padding: 0; border-radius: 16px; color: var(--muted); z-index: 8; cursor: pointer;
}
body.mobile #moreBtn:active { color: #fff; }
body.mobile #moreMenu.open {
  display: flex; flex-direction: column; gap: 2px; z-index: 9; min-width: 230px; padding: 6px; border-radius: 16px;
  right: var(--gutter); top: calc(var(--gutter) + 58px + env(safe-area-inset-top));
}
body.mobile #moreMenu button {
  appearance: none; display: flex; align-items: center; gap: 10px; width: 100%; height: 46px; padding: 0 12px;
  border: 0; border-radius: 12px; background: transparent; color: var(--text); font: 500 14px var(--font); text-align: left; cursor: pointer;
}
body.mobile #moreMenu button:active { background: rgba(255, 255, 255, .1); }
body.mobile #moreMenu .kind::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
body.mobile #moreMenu .kind.on::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
body.mobile #moreMenu .kind::after { content: "hidden"; margin-left: auto; color: var(--faint); font-size: 12px; }
body.mobile #moreMenu .kind.on::after { content: "shown"; color: var(--muted); }
body.mobile #moreFilters { display: contents; }

/* ---------- bottom nav ---------- */
body.mobile #bottomNav {
  display: flex; left: 0; right: 0; bottom: 0; height: var(--nav-h); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  gap: 4px; border-radius: 0; border-width: 1px 0 0; z-index: 7;
}
body.mobile #bottomNav button {
  appearance: none; flex: 1; min-width: 0; min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 1px solid transparent; border-radius: 14px; background: transparent; color: var(--muted); font: 600 11px var(--font); cursor: pointer;
}
body.mobile #bottomNav button svg { width: 22px; height: 22px; }
body.mobile #bottomNav button.on { color: #fff; background: linear-gradient(135deg, rgba(124, 92, 255, .3), rgba(34, 211, 238, .14)); border-color: rgba(124, 92, 255, .5); }
body.mobile #bottomNav .nv-edit { display: none; }
body.mobile.editing #bottomNav .nv-view { display: none; }
body.mobile.editing #bottomNav .nv-edit { display: flex; }
body.mobile.editing #bottomNav #nvDone { color: var(--gold); }
body.mobile.shared #bottomNav { display: none; }

/* ---------- bottom sheet: one panel at a time ---------- */
body.mobile #sheet {
  left: 0; right: 0; bottom: var(--nav-h); height: var(--sheet-h); max-height: calc(100dvh - var(--top-h) - var(--nav-h));
  display: none; flex-direction: column; border-radius: 22px 22px 0 0; border-width: 1px 0 0; z-index: 6; overflow: hidden;
  transition: height .22s cubic-bezier(.2, .8, .2, 1);
}
body.mobile #sheet.open { display: flex; }
body.mobile #sheet.dragging { transition: none; }
body.mobile #sheetGrab { flex: none; height: 20px; display: grid; place-items: center; touch-action: none; cursor: grab; }
body.mobile #sheetGrab i { width: 40px; height: 5px; border-radius: 5px; background: var(--line-strong); }
/* the panel's own header says what it is, and the nav opens/closes it: no separate title row (kept in the DOM for the dialog's accessible name) */
body.mobile #sheetBar { display: none; }
body.mobile #sheetBar b { font-size: 15px; letter-spacing: -.01em; }
body.mobile #sheetClose { appearance: none; width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer; }
body.mobile #sheetBody { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* the existing panels are moved in here, so they stop being floating boxes */
body.mobile #sheet .pane {
  position: static !important; width: auto !important; max-height: none !important; flex: 1; min-height: 0; overflow: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; border: 0; border-radius: 0; box-shadow: none; background: transparent;
  -webkit-backdrop-filter: none; backdrop-filter: none; animation: none;
}
body.mobile #sheet .pane:not(.active) { display: none !important; }
body.mobile #sheet #palette { overflow: hidden; padding: 0; }
body.mobile #sheet .lib { height: 100%; min-height: 0; }
body.mobile #sheet #palList.grid { grid-template-columns: repeat(3, 1fr); }
body.mobile #specs .specsMin { display: none; } /* the sheet has its own close */
body.mobile #editPanel .keys { display: none; } /* keyboard hints */
body.mobile .dpl button, body.mobile .dpl a, body.mobile .undoRow button { height: 40px; }

/* ---------- edit action bar ---------- */
body.mobile.editing #actionBar {
  display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 18px; z-index: 5; overflow-x: auto;
  left: var(--gutter); right: calc(var(--gutter) + 58px); width: max-content; max-width: calc(100vw - 2 * var(--gutter) - 58px);
  bottom: calc(var(--nav-h) + var(--sheet-h) + 10px); transition: bottom .22s cubic-bezier(.2, .8, .2, 1);
}
body.mobile #actionBar button {
  appearance: none; flex: none; width: 44px; height: 44px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer;
}
body.mobile #actionBar button:active { background: rgba(255, 255, 255, .12); }
body.mobile #actionBar button:disabled { opacity: .3; }
body.mobile #actionBar #abMulti.on { background: rgba(124, 92, 255, .32); color: #fff; }
body.mobile #actionBar #abDel { color: var(--danger); }
body.mobile #actionBar .ab-sep { flex: none; width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
body.mobile #actionBar .ab-sel, body.mobile #actionBar .ab-brush { display: none; align-items: center; gap: 2px; }
body.mobile #actionBar.has-sel .ab-sel { display: flex; }
body.mobile #actionBar.has-brush .ab-brush { display: flex; }
body.mobile #actionBar:not(.has-sel):not(.has-brush) .ab-sep { display: none; }
body.mobile #abCount, body.mobile #abBrush {
  flex: none; max-width: 120px; padding: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 600 12px var(--mono); color: var(--gold);
}
body.mobile #abBrush { color: var(--accent-2); max-width: 150px; }

body.mobile.sheet-drag #actionBar, body.mobile.sheet-drag #nudgePad { transition: none; }

/* a shared draft is view-only: just the map, zoom and the banner */
body.mobile.shared .sharedBanner { top: calc(var(--gutter) + env(safe-area-inset-top) + 58px); max-width: calc(100vw - 24px); }

/* ================= Items sheet: the item library, redone for a thumb ================= */
body.mobile #sheet #palette .lib { min-height: 0; }
body.mobile .lib-head { padding: 4px 12px 8px; gap: 8px; }
body.mobile .lib .qrow { gap: 8px; }
body.mobile #palQ { height: 44px; border-radius: 12px; padding-left: 38px; padding-right: 40px; }
body.mobile .lib .search svg { left: 13px; width: 16px; height: 16px; }
body.mobile .lib .x { width: 36px; height: 36px; right: 4px; }
body.mobile .lib .x svg { width: 14px; height: 14px; }

/* filters live behind one button, with a badge when any are narrowing the list */
body.mobile .lib .fbtn {
  appearance: none; position: relative; flex: none; width: 44px; height: 44px; padding: 0; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); color: var(--muted); cursor: pointer;
}
body.mobile .lib .fbtn svg { width: 20px; height: 20px; }
body.mobile .lib .fbtn[aria-expanded="true"] { color: #fff; background: rgba(124, 92, 255, .28); border-color: rgba(124, 92, 255, .6); }
body.mobile .lib .fbtn b { display: none; position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--grad); color: #fff; font: 700 11px/18px var(--font); text-align: center; }
body.mobile .lib .fbtn[data-n]:not([data-n=""]) b { display: block; }
body.mobile .lib .fbtn[data-n]:not([data-n=""]) b::before { content: attr(data-n); }
body.mobile .lib .filters, body.mobile .lib .lib-count .sort { display: none; }
body.mobile .lib.show-filters .filters { display: flex; gap: 8px; }
body.mobile .lib.show-filters .lib-count .sort { display: flex; }
body.mobile .lib .filters select { height: 44px; font-size: 16px; padding: 0 8px; border-radius: 12px; }
body.mobile .lib .sort select { height: 36px; font-size: 14px; color: var(--text); border-color: var(--line); }
body.mobile .lib .views { padding: 3px; border-radius: 12px; }
body.mobile .lib .views button { width: 40px; height: 38px; border-radius: 9px; }
body.mobile .lib .views button svg { width: 18px; height: 18px; }

/* tabs and categories: ONE line each that you swipe sideways, instead of wrapping into a wall of chips */
body.mobile .lib .tabs, body.mobile .lib .cats {
  display: flex; flex-wrap: nowrap; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  margin: 0 -12px; padding: 0 12px;
}
body.mobile .lib .tabs::-webkit-scrollbar, body.mobile .lib .cats::-webkit-scrollbar { display: none; }
body.mobile .lib .tabs { background: transparent; border-radius: 0; }
body.mobile .lib .tabs button { flex: none; height: 38px; padding: 0 14px; border-radius: 19px; font-size: 13.5px; background: rgba(255, 255, 255, .05); }
body.mobile .lib .tabs button.on { background: rgba(124, 92, 255, .32); }
body.mobile .lib .cats button { height: 34px; padding: 0 13px; font-size: 13px; }

/* count / reset line */
body.mobile .lib-count { min-height: 26px; font-size: 12.5px; }
body.mobile .lib-count button { font-size: 12.5px; min-height: 32px; padding: 0 4px; }

/* while browsing, tabs and categories slide away so the items get the room; scroll up a little to get them back */
body.mobile .lib.slim .tabs, body.mobile .lib.slim .cats { display: none; }

/* the grid: 3 across, big tiles, names on two lines, star always there */
body.mobile #palList { padding: 8px 12px 16px; gap: 8px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
body.mobile #palList.grid { grid-template-columns: repeat(3, 1fr); }
body.mobile #palList.compact { grid-template-columns: repeat(4, 1fr); gap: 6px; }
body.mobile .pal { padding: 6px 6px 8px; -webkit-tap-highlight-color: transparent; }
body.mobile .pal:active { background: rgba(124, 92, 255, .25); transform: scale(.97); }
body.mobile .pal .thumb { height: 84px; }
body.mobile #palList.compact .thumb { height: 60px; }
body.mobile .pal .nm { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; font-size: 12px; min-height: 2.5em; }
body.mobile #palList.compact .nm { min-height: 0; -webkit-line-clamp: 1; text-align: left; }
body.mobile .pal .sub { font-size: 10.5px; }
body.mobile #palList.list .pal { min-height: 60px; padding: 6px 10px 6px 6px; }
body.mobile #palList.list .thumb { width: 52px; height: 52px; }
body.mobile #palList.list .star { opacity: 1; }

/* what you are placing: a proper bar with a big stop button */
body.mobile #palBrush { padding: 8px 12px calc(8px); }
body.mobile #palBrush .cur .thumb { width: 48px; height: 48px; }
body.mobile #palBrush .who b { font-size: 14px; }
body.mobile #palBrush #palStop { width: 44px; height: 44px; border-radius: 12px; }
body.mobile #palBrush #palStop svg { width: 16px; height: 16px; }
body.mobile #palBrush .hint { font-size: 12.5px; padding: 4px 0; }

/* peeking sheet: just the item being placed, nothing to scroll */
body.mobile #sheet[data-pane="items"][data-snap="peek"] .lib-head,
body.mobile #sheet[data-pane="items"][data-snap="peek"] #palList { display: none; }
body.mobile #sheet[data-pane="items"][data-snap="peek"] #palBrush { border-top: 0; background: transparent; padding-top: 0; }

/* keyboard open: nav steps aside and the sheet sits right on top of the keyboard, using the height that is left */
body.mobile.kb #bottomNav { display: none; }
body.mobile.kb #sheet { bottom: var(--kb-h, 0px); height: calc(var(--vvh, 100dvh) - var(--top-h)); max-height: none; }
body.mobile.kb #actionBar { display: none; }

/* ================= placing: line the map up under a cross-hair, then press Place ================= */
body.mobile #reticle { position: fixed; z-index: 4; width: 0; height: 0; pointer-events: none; display: none; }
body.mobile.placing #reticle { display: block; }
/* a ring with a gap in each side: precise, but never hides what is under it */
body.mobile #reticle::before, body.mobile #reticle::after { content: ""; position: absolute; background: rgba(255, 255, 255, .9); box-shadow: 0 0 0 1px rgba(0, 0, 0, .55); }
body.mobile #reticle::before { left: -18px; top: -1px; width: 36px; height: 2px; -webkit-mask: linear-gradient(90deg, #000 0 35%, transparent 35% 65%, #000 65%); mask: linear-gradient(90deg, #000 0 35%, transparent 35% 65%, #000 65%); }
body.mobile #reticle::after { top: -18px; left: -1px; height: 36px; width: 2px; -webkit-mask: linear-gradient(180deg, #000 0 35%, transparent 35% 65%, #000 65%); mask: linear-gradient(180deg, #000 0 35%, transparent 35% 65%, #000 65%); }
body.mobile #reticle i { position: absolute; left: -11px; top: -11px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--gold); box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), 0 0 12px rgba(255, 212, 59, .6); }

body.mobile #abPlace {
  width: auto; padding: 0 16px 0 12px; gap: 6px; grid-auto-flow: column; border-radius: 22px; margin: 0 4px;
  background: linear-gradient(135deg, #7c5cff, #4f8cff); color: #fff; font: 700 14px var(--font);
}
body.mobile #abPlace:active { filter: brightness(1.15); }
body.mobile.placing #actionBar .ab-brush { gap: 0; }

/* one-step arrows: move the selected items, or the ghost, one grid square at a time */
body.mobile.editing #nudgePad.show {
  display: flex; left: var(--gutter); z-index: 5; gap: 2px; padding: 4px; border-radius: 16px;
  bottom: calc(var(--nav-h) + var(--sheet-h) + 10px + 56px); transition: bottom .22s cubic-bezier(.2, .8, .2, 1);
}
body.mobile #nudgePad button { appearance: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 12px; background: transparent; color: var(--text); font: 500 22px/1 var(--font); cursor: pointer; }
body.mobile #nudgePad button:active { background: rgba(255, 255, 255, .14); }
body.mobile.kb #nudgePad { display: none !important; }

/* Farm sheet: name and value visible straight away */
body.mobile #specs.pane { padding: 4px 14px 12px; }
body.mobile #specs .hero { margin-bottom: 8px; }

/* the heart lives in the More menu on a phone, where the farm bar has no room */
body.mobile #likeBtn { display: none !important; }
