/* ==========================================================
   Phone layout (body.phone, set by shell/phone.js)
   Portrait: top bar + bottom tool bar + controls sheet.
   Landscape (body.phone-land): floating title pill + left rail + right drawer.
   ========================================================== */
:root {
  --m-top-h: calc(52px + env(safe-area-inset-top));
  --m-bottom-h: calc(62px + env(safe-area-inset-bottom));
  --m-rail-w: calc(64px + env(safe-area-inset-left));
  --m-ease: cubic-bezier(.2, .8, .2, 1);
}

/* Phone-only chrome is invisible on desktop. */
.m-top, .m-bottom, .m-switcher, .sheet-grab, .sheet-peek { display: none; }
body.phone .m-top, body.phone .m-bottom { display: flex; }
body.phone .sheet-grab, body.phone .sheet-peek { display: flex; }

/* ---------- Hide the desktop chrome ---------- */
body.phone .topbar,
body.phone .dock,
body.phone .statusbar,
body.phone .inspector-bar,
body.phone .project-view .board-label,
body.phone .project-view .handle,
body.phone .project-view .pv-head,
body.phone .handle { display: none !important; }

body.phone { -webkit-tap-highlight-color: transparent; }
/* The desktop's floating, rounded panels go edge to edge on a phone. */
body.phone .workspace { padding: 0; gap: 0; }
body.phone .workspace > .stage { border: 0; border-radius: 0; box-shadow: none; }
/* Rulers and grid are desktop flourishes: off on phones unless turned on from the ⋯ menu. */
body.phone:not(.m-rulers) .ruler-top, body.phone:not(.m-rulers) .ruler-left { display: none !important; }
body.phone:not(.m-grid) .viewport.grid-on { background-image: none; }
body.phone.panels-hidden .inspector { display: flex; }
body.phone .stage {
  padding-top: var(--m-top-h);
  padding-bottom: calc(var(--m-bottom-h) + var(--sheet-reserve, 0px));
  transition: padding .28s var(--m-ease);
}
body.phone.m-project .stage { padding-bottom: var(--sheet-reserve, 0px); }
body.phone.m-no-sheet .stage { padding-bottom: var(--m-bottom-h); }
body.phone .viewport { padding: 14px 12px 24px; }
body.phone .viewport.is-project { padding: 0; }
body.phone .project-view .artboard { border: 0; border-radius: 0; box-shadow: none; padding: 0; }
body.phone .project-view { padding: 0; }
body.phone .project-view .pv-frame { border-radius: 0; }
body.phone .artboard { padding: 14px; }
body.phone .board-label { font-size: 11px; }
body.phone .card-grid { grid-template-columns: 1fr; }
body.phone .intro-grid, body.phone .readme-grid { grid-template-columns: 1fr; }
body.phone .toy-frame { min-height: 44vh; }
body.phone .cat-intro { grid-template-columns: 1fr; }

/* ---------- Top bar ---------- */
.m-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: var(--m-top-h); padding: env(safe-area-inset-top) 6px 0;
  align-items: center; gap: 4px;
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--hairline);
  transition: transform .28s var(--m-ease), opacity .28s;
}
.m-btn { width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center; border-radius: 10px; color: var(--text-2); }
.m-btn:active { background: var(--surface-3); }
.m-home { border: 0; }
.m-title {
  flex: 1; min-width: 0; height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 10px; border-radius: 10px; font: 500 14px var(--sans); color: var(--text);
}
.m-title:active { background: var(--surface-3); }
.m-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--accent); }
.m-caret { color: var(--muted); font-size: 11px; }

/* ---------- Bottom bar ---------- */
.m-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: var(--m-bottom-h); padding: 4px 6px env(safe-area-inset-bottom);
  grid-template-columns: repeat(5, 1fr); align-items: stretch;
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-top: 1px solid var(--hairline);
  transition: transform .28s var(--m-ease);
}
body.phone .m-bottom { display: grid; }
.m-nav {
  position: relative; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 12px; color: var(--muted); font: 500 11px var(--sans); letter-spacing: .02em;
}
.m-nav svg { width: 22px; height: 22px; }
.m-nav.active { color: var(--accent-ink); }
.m-nav.active svg { color: var(--accent); }
.m-nav:active { background: var(--surface-3); }
.m-count {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font: 600 11px var(--sans);
}
body.phone.m-project .m-bottom { transform: translateY(110%); }

/* ---------- Controls sheet (the inspector, restyled) ---------- */
body.phone .inspector {
  position: fixed; left: 0; right: 0; top: auto; width: auto; z-index: 55;
  bottom: var(--m-bottom-h);
  height: var(--sheet-h, 96px); max-height: calc(100% - var(--m-top-h));
  transform: none; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--hairline); border-bottom: 0; border-radius: 16px 16px 0 0;
  box-shadow: 0 -12px 36px rgba(0, 0, 0, .25);
}
body.phone.m-project .inspector { bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
body.phone .inspector.sheet-anim { transition: height .3s var(--m-ease), transform .28s var(--m-ease); }
body.phone.m-no-sheet .inspector { display: none; }

.sheet-grab {
  flex-shrink: 0; height: 44px; align-items: center; justify-content: center; gap: 10px; position: relative;
  cursor: grab; touch-action: none; user-select: none;
}
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.sheet-label { position: absolute; right: 14px; font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.sheet-peek {
  flex-shrink: 0; gap: 8px; padding: 0 12px 12px; overflow-x: auto; scrollbar-width: none;
}
.sheet-peek::-webkit-scrollbar { display: none; }
.q-btn {
  flex-shrink: 0; min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; gap: 7px;
  border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font: 500 13px var(--sans); white-space: nowrap;
}
.q-btn:active { background: var(--surface-4); }
.q-btn.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.q-btn.q-icon { padding: 0 12px; }
.q-btn svg { flex-shrink: 0; }

body.phone .panel-dock { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.panel-dock.compact .compact-tabs {
  flex: none; align-items: flex-end; height: auto; display: flex; gap: 4px; padding: 8px 10px 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line);
}
.panel-dock.compact .compact-tabs::-webkit-scrollbar { display: none; }
.panel-dock.compact .pg-tab {
  flex: none; height: 44px; min-height: 44px; display: inline-flex; align-items: center; padding: 0 14px; border-radius: 10px 10px 0 0; font: 500 13px var(--sans);
  color: var(--muted); border-bottom: 2px solid transparent;
}
.panel-dock.compact .pg-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel-dock.compact .compact-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px 20px; -webkit-overflow-scrolling: touch; }
body.phone .xywh { display: none; }

/* Touch-sized controls inside the sheet */
body.phone .lc-btn, body.phone .lc-select, body.phone .layer-row { min-height: 44px; }
body.phone .lc-btn { border-radius: 10px; font-size: 13px; }
body.phone .lc-line { min-height: 36px; font-size: 13px; }
body.phone label.lc-line { min-height: 44px; }
body.phone .lc-check { width: 22px; height: 22px; }
body.phone .lc-select { padding: 0 8px; font-size: 13px; }
body.phone input[type=range].pro-slider { height: 44px; margin: 0; background: transparent; border: 0; }
body.phone input[type=range].pro-slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--surface-3); border: 0; }
body.phone input[type=range].pro-slider::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -11px; border-radius: 50%; border: 2px solid var(--accent); background: var(--surface); }
body.phone input[type=range].pro-slider::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; }
body.phone .lc-btn-row { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
body.phone .layers-tools button, body.phone .link-btn { min-height: 44px; display: inline-flex; align-items: center; }

/* Touch-sized page content */
body.phone .jump-grid button, body.phone .console-chips button { min-height: 44px; }
body.phone .console-chips { gap: 6px; }
body.phone .console-input { height: 52px; }
body.phone .console-input input { font-size: 16px; } /* 16px stops iOS zooming into the field */

/* ---------- Tab switcher ---------- */
body.phone .m-switcher:not([hidden]) { display: flex; }
.m-switcher {
  position: fixed; inset: 0; z-index: 90; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--canvas); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  animation: m-fade .18s ease-out;
}
@keyframes m-fade { from { opacity: 0; } }
.m-switch-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 16px; min-height: 56px; }
.m-switch-title { flex: 1; font: 600 16px var(--sans); }
.m-link { min-height: 44px; padding: 0 10px; color: var(--muted); font-size: 13px; }
.m-done { min-height: 40px; padding: 0 16px; border-radius: 20px; background: var(--accent); color: var(--on-accent); font: 600 13px var(--sans); }
.m-switch-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 8px 14px 24px; align-content: start; }
.m-tabcard {
  position: relative; min-height: 104px; padding: 14px 44px 14px 14px; border-radius: 14px; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
}
.m-tabcard.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.m-tabcard-label { font: 500 14px var(--sans); color: var(--text); word-break: break-word; }
.m-tabcard-kind { margin-top: auto; font: 11px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.m-tabcard-close { position: absolute; top: 4px; right: 4px; width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); border-radius: 10px; }
.m-tabcard-close:disabled { opacity: .25; }

/* ---------- Floating pills: restore (Hide UI) and exit full screen ---------- */
.float-pill {
  position: fixed; z-index: 120; top: calc(env(safe-area-inset-top) + 10px); right: calc(env(safe-area-inset-right) + 10px);
  width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center;
  background: var(--glass); border: 1px solid var(--line-strong); color: var(--text);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity .4s;
}
.float-pill[hidden] { display: none; }
.float-pill.faded { opacity: .3; }

/* ---------- Hide UI ---------- */
body.phone.ui-hidden .m-top { transform: translateY(-110%); }
body.phone.ui-hidden .m-bottom { transform: translateY(110%); }
body.phone.ui-hidden .inspector { transform: translateY(110%); }
body.phone.ui-hidden .stage { padding: 0; }

/* Context menu: touch-sized on phones */
body.phone .ctx-menu { min-width: 240px; padding: 6px; border-radius: 14px; }
body.phone .ctx-item { min-height: 44px; font-size: 14px; border-radius: 8px; }

/* ==========================================================
   Landscape phone
   ========================================================== */
body.phone-land .m-top {
  top: calc(env(safe-area-inset-top) + 8px); left: auto; right: calc(var(--m-drawer-reserve, 0px) + env(safe-area-inset-right) + 8px); width: max-content;
  height: 44px; padding: 0 2px; border: 1px solid var(--hairline); border-radius: 14px; max-width: 46vw;
}
body.phone-land .m-home { display: none; }
body.phone-land .m-bottom {
  top: 0; bottom: 0; right: auto; width: var(--m-rail-w); height: auto;
  grid-template-columns: 1fr; grid-template-rows: repeat(5, 1fr);
  padding: env(safe-area-inset-top) 4px env(safe-area-inset-bottom) calc(env(safe-area-inset-left) + 4px);
  border-top: 0; border-right: 1px solid var(--hairline);
}
body.phone-land .m-nav { min-height: 44px; }
body.phone-land .m-nav span:not(.m-count) { display: none; }
body.phone-land.m-project .m-bottom { transform: translateX(-110%); }
body.phone.phone-land .stage { padding: 0 var(--m-drawer-reserve, 0px) 0 var(--m-rail-w); }
body.phone.phone-land.m-project .stage { padding: 0 var(--m-drawer-reserve, 0px) 0 0; }
body.phone.phone-land.ui-hidden .stage { padding: 0; }
body.phone-land .viewport { padding-top: 64px; }
body.phone-land .viewport.is-project { padding: 0; }

/* Drawer: a slim strip of quick actions (peek) or a full panel (half/full). */
body.phone-land .inspector {
  top: 0; bottom: 0; left: auto; right: 0; height: auto; max-height: none;
  width: 92px; padding-right: env(safe-area-inset-right);
  border-radius: 16px 0 0 16px; border: 1px solid var(--hairline); border-right: 0;
  transition: width .3s var(--m-ease), transform .28s var(--m-ease);
}
body.phone-land.m-project .inspector { padding-bottom: 0; }
body.phone-land .inspector[data-sheet="half"], body.phone-land .inspector[data-sheet="full"] { width: min(360px, 52vw); }
body.phone-land .inspector[data-sheet="closed"] { width: 92px; }
body.phone-land { --m-drawer-reserve: 92px; }
body.phone-land.m-no-sheet { --m-drawer-reserve: 0px; }
body.phone-land .sheet-grab { height: 44px; }
body.phone-land .sheet-label { display: none; }
body.phone-land .sheet-handle { width: 5px; height: 26px; }
body.phone-land .sheet-peek { flex-direction: column; padding: 0 8px 10px; overflow: visible; }
body.phone-land .inspector[data-sheet="half"] .sheet-peek, body.phone-land .inspector[data-sheet="full"] .sheet-peek { flex-direction: row; flex-wrap: wrap; }
body.phone-land .q-btn { justify-content: center; padding: 0 8px; font-size: 12px; white-space: normal; text-align: center; }
body.phone-land .inspector:not([data-sheet="half"]):not([data-sheet="full"]) .panel-dock { display: none; }
body.phone-land.ui-hidden .m-top { transform: translateY(-160%); }
body.phone-land.ui-hidden .m-bottom { transform: translateX(-110%); }
body.phone-land.ui-hidden .inspector { transform: translateX(110%); }
