/* v0.22 — Phos UI system v1 (website/diffused/ui) fitted to the editor prototype: Home and editor.
   Loaded last. phos-ui.js drives --mx/--my/--gx/--gf/--eg on every element in window.PHOS_UI_GLASS (see index.html). */

/* ── 02 · one flat Frost fill. The old gradient glass variables now point at it */
:root, [data-theme=dark] {
  --ph-glass: var(--pu-frost);
  --ph-glass-dense: var(--pu-frost-dense);
  --ph-shadow: var(--pu-edge), var(--pu-drop);
  --glass-fill: linear-gradient(var(--pu-frost), var(--pu-frost));
  --glass-tint: rgba(255, 255, 255, 0.06);
  --glass-field: var(--pu-frost);
  --kelvin: var(--pu-kelvin);
  --radius-2xl: 24px;
  --radius-md: 12px;
}

/* Every glass surface and glass button: flat fill + light rising from the bottom edge (09 A) + rim light (02) */
.ph-glass, .ph-btn, .ph-icon-btn, .ph-seg, .ph-side, .ph-tagbar, .ph-drawer, .ph-modal, .ph-menu, .ph-scene-menu, .ph-banner, .ph-trash, .ph-dev,
.toolbar, .inspector, .tb-pop, .sheet, .notice, .topbar.pab .actions .primary, .pab-cta, .pab-menu, .modal .primary, .modal .ghost {
  /* each glass element starts dark: the light values never inherit from the panel around it */
  --gf: 0; --gx: 50%; --grx: initial; --gry: initial; --mx: 50%; --my: 0px; --eg: 0.55;
  /* glow size: 110% x 80% of the element (pills 90% x 130%); phos-ui.js turns it into px (--grx/--gry)
     and caps the ellipse at 2.2:1 wide and 1.2:1 tall so it never stretches on long bars or tall drawers */
  --pu-gw: 1.1; --pu-gh: 0.8;
  --pu-gsize: var(--grx, 110%) var(--gry, 80%);
  background:
    radial-gradient(var(--pu-gsize) at var(--gx) 100%, rgba(255, 150, 80, calc(var(--pu-ga, 0.42) * var(--gf))) 0%, rgba(255, 90, 31, calc(var(--pu-gb, 0.2) * var(--gf))) var(--pu-gm, 38%), rgba(255, 90, 31, 0) var(--pu-ge, 82%)),
    var(--pu-fill, var(--pu-frost)) !important;
  -webkit-backdrop-filter: var(--pu-blur) !important; backdrop-filter: var(--pu-blur) !important;
  box-shadow: var(--pu-edge), var(--pu-drop) !important;
  border: 0 !important;
  transition: background-color .2s var(--pu-ease), color .2s var(--pu-ease), transform .16s var(--pu-ease);
}
/* pills get a narrower, softer light that follows the pointer along the bottom edge; panels keep the wide one */
.ph-btn, .ph-icon-btn, .ph-seg, .ph-tagbar, .ph-dev, .toolbar, .notice, .topbar.pab .actions .primary, .pab-cta, .modal .primary, .modal .ghost {
  --pu-gw: 0.9; --pu-gh: 1.3; --pu-gsize: var(--grx, 90%) var(--gry, 130%); --pu-ga: 0.32; --pu-gb: 0.1; --pu-gm: 45%; --pu-ge: 80%;
}
/* v0.24: every panel is the same Frost as the toolbar, so each one visibly blurs what is behind it (menus, drawers,
   dialogs, the inspector, popovers). The dense glass is kept only for the reduced-transparency fallback. */
.ph-drawer, .ph-modal, .ph-menu, .ph-scene-menu, .ph-dev, .tb-pop, .sheet, .inspector, .notice, .pab-menu { --pu-fill: var(--pu-frost); }
/* glass that holds glass (the toolbar and its popovers): its blur moves to ::before so the popover can blur the canvas */
.toolbar { isolation: isolate; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
.toolbar::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none; -webkit-backdrop-filter: var(--pu-blur); backdrop-filter: var(--pu-blur); }
.ph-seg, .ph-banner, .ph-trash, .ph-icon-btn { position: relative; isolation: isolate; }
.ph-glass::after, .ph-btn::after, .ph-icon-btn::after, .ph-seg::after, .ph-side::after, .ph-tagbar::after, .ph-drawer::after, .ph-modal::after, .ph-menu::after,
.ph-scene-menu::after, .ph-banner::after, .ph-trash::after, .ph-dev::after, .toolbar::after, .inspector::after, .tb-pop::after, .sheet::after, .notice::after,
.topbar.pab .actions .primary::after, .pab-cta::after, .pab-menu::after, .modal .primary::after, .modal .ghost::after {
  content: "" !important; position: absolute !important; inset: 0 !important; border-radius: inherit !important; pointer-events: none !important; padding: 1px !important; z-index: auto !important;
  background: radial-gradient(var(--pu-rim-r, 240px) circle at var(--mx, 50%) var(--my, 0px), rgba(255, 242, 228, 0.95), rgba(255, 150, 90, 0.5) 38%, rgba(255, 255, 255, 0) 72%) !important;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0) !important; -webkit-mask-composite: xor !important; mask-composite: exclude !important;
  opacity: var(--eg, 0.55) !important; filter: none !important; transform: none !important;
}
.ph-btn, .ph-icon-btn, .topbar.pab .actions .primary, .pab-cta, .modal .primary, .modal .ghost { --pu-rim-r: 90px; position: relative; isolation: isolate; }
.modal .primary, .modal .ghost { height: 40px; padding: 0 18px; border-radius: var(--pu-r-pill) !important; color: #fff !important; }
.modal .primary:hover, .modal .primary:active { background: var(--pu-key) !important; color: var(--pu-on-key) !important; }
/* the old glow layers are replaced by the one above */
.ph-btn::before, .topbar .actions .ghost::before, .primary::before, .ghost::before { content: none !important; }

/* ── 03 · buttons: primary = Frost turning Key with black text on hover, rim stays; secondary = Frost; quiet = text */
.ph-btn { height: 44px; min-height: 44px; padding: 0 20px; border-radius: var(--pu-r-pill) !important; color: #fff !important; font: 500 14px/1 var(--pu-sans); }
.ph-btn-sm { height: 36px; min-height: 36px; padding: 0 14px; font-size: 13px; }
.ph-btn-primary:hover, .ph-btn-primary:active, .topbar.pab .actions .primary:hover, .topbar.pab .actions .primary:active, .pab-cta:hover, .pab-cta:active {
  background: var(--pu-key) !important; color: var(--pu-on-key) !important;
}
.ph-btn-primary:hover::after, .primary:hover::after { opacity: var(--eg, 0.55) !important; }
.ph-btn.ph-quiet { background: transparent !important; box-shadow: none !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; color: var(--pu-ink-sub) !important; }
.ph-btn.ph-quiet::after { content: none !important; }
.ph-btn.ph-quiet:hover { background: var(--pu-wash-hover) !important; color: #fff !important; }
.ph-icon-btn { border-radius: var(--pu-r-pill) !important; --pu-rim-r: 60px; }

/* ── accent: Key-tinted pills (Upgrade, Pro tags, badges, active chips) */
.ph-pill-sm, .ph-tag { border-radius: var(--pu-r-pill) !important; }
.ph-chip { background: rgba(255, 255, 255, 0.06); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); color: #E4E4E7; }
.ph-chip.on { background: var(--pu-tint-on) !important; box-shadow: inset 0 0 0 1px var(--pu-tint-on-edge) !important; color: #fff !important; }

/* ── 04 · segmented: Frost track, selected tab a grey pill */
.ph-seg { border-radius: var(--pu-r-pill) !important; }
.ph-seg-btn { border-radius: var(--pu-r-pill) !important; height: 40px; padding: 0 16px; }
.ph-seg-btn.on { background: var(--pu-wash) !important; color: #fff !important; box-shadow: none !important; }

/* ── 08 · fields: Frost pill, Key rim + halo on focus */
.ph-tagbar { border-radius: var(--pu-r-pill) !important; }
.ph-tagbar:focus-within { box-shadow: var(--pu-focus), var(--pu-drop) !important; }
.ph-field input, #ph-rename { width: 100%; height: 48px; padding: 0 20px; border: 0; border-radius: var(--pu-r-pill); outline: 0;
  background: var(--pu-frost); -webkit-backdrop-filter: var(--pu-blur); backdrop-filter: var(--pu-blur); box-shadow: var(--pu-edge); color: #fff; font: 400 15px var(--pu-sans); }
.ph-field input:focus, #ph-rename:focus { box-shadow: var(--pu-focus); }
.field input, .field select { border-radius: var(--pu-r-pill) !important; background: var(--pu-frost) !important; }
.field input:focus, .field select:focus { box-shadow: var(--pu-focus) !important; }

/* ── 01 · surfaces 24, rows inside them 12 */
.ph-side, .ph-drawer, .ph-modal, .ph-menu, .ph-scene-menu, .ph-banner, .ph-trash, .ph-card, .ph-card-main, .ph-newtile, .ph-frame, .ph-thumb-inner,
.inspector, .tb-pop, .sheet, .pab-menu { border-radius: var(--pu-r-panel) !important; }
.ph-menu, .ph-scene-menu, .tb-pop, .pab-menu { padding: 12px !important; }
.ph-plan, .ph-plan-opt, .ph-nav, .ph-menu-item, .ph-scene-item, .ph-scene-row, .tb-item, .pab-mi, .readout, .cam-icon, .insp-icon { border-radius: var(--pu-r-row) !important; }
.ph-dev, .ph-dev button, .notice, .ph-toast { border-radius: var(--pu-r-pill) !important; }
@media (width <= 640px) { .ph-tagbar { border-radius: var(--pu-r-panel) !important; } }

/* ── 06 · toolbar: Frost pill, the selected tool a grey pill (no white) */
.toolbar { border-radius: var(--pu-r-pill) !important; --pu-rim-r: 280px; }
.tb-btn { border-radius: var(--pu-r-pill) !important; }
.tb-btn.active, .tb-btn.active:hover { background: rgba(255, 255, 255, 0.12) !important; color: #fff !important; box-shadow: none !important; }
.tb-btn.open { background: var(--pu-wash-hover) !important; }
.tb-btn.toggle.on, .tb-item.on { background: var(--pu-tint-on) !important; box-shadow: inset 0 0 0 1px var(--pu-tint-on-edge) !important; }
@media (max-height: 520px) and (orientation: landscape) { .toolbar { border-radius: var(--pu-r-panel) !important; } }

/* ── 07 · Kelvin bar B: the Kelvin gradient as a hairline on the top edge that fades in and out at both ends,
   with a spill of the same colours below it, fading out within 30 px so it never reaches the text */
.sheet::before, .ph-kelvin {
  content: "" !important; position: absolute !important; z-index: 1 !important; left: 16px !important; right: 16px !important; top: 0 !important; height: 30px !important;
  border-radius: 0 !important; background: var(--pu-kelvin) !important; opacity: 1 !important; box-shadow: none !important; pointer-events: none !important;
  -webkit-mask: linear-gradient(180deg, #000 0, #000 1.5px, rgba(0, 0, 0, 0.2) 1.5px, rgba(0, 0, 0, 0.07) 12px, rgba(0, 0, 0, 0) 30px), linear-gradient(90deg, rgba(0, 0, 0, 0) 0, #000 16%, #000 84%, rgba(0, 0, 0, 0) 100%) !important;
  -webkit-mask-composite: source-in !important;
  mask: linear-gradient(180deg, #000 0, #000 1.5px, rgba(0, 0, 0, 0.2) 1.5px, rgba(0, 0, 0, 0.07) 12px, rgba(0, 0, 0, 0) 30px), linear-gradient(90deg, rgba(0, 0, 0, 0) 0, #000 16%, #000 84%, rgba(0, 0, 0, 0) 100%) !important;
  mask-composite: intersect !important;
}
/* the Kelvin line is the top light of these panels: no white rim resting on top of it */
.sheet, .ph-modal:has(.ph-kelvin) { --pu-fill: var(--pu-frost-dense); --eg: 0; }
.sheet { padding-top: 28px !important; }
.ph-modal-glow { display: none !important; }

/* ── plans and other dialogs: mark + label + close on one line, then title, text, options, actions */
.ph-modal { gap: 18px !important; padding: 24px !important; }
.ph-modal-head { position: relative; display: flex; align-items: center; gap: 10px; }
.ph-modal-head > svg { flex: none; }
.ph-modal-head .ph-mono { font-size: 11px; }
.ph-modal-head .ph-modal-x { position: relative !important; top: auto !important; right: auto !important; margin-left: auto; width: 36px; height: 36px; }
.ph-modal-text { gap: 8px !important; }
.ph-modal-text h2 { margin: 0 !important; font-size: 26px !important; line-height: 30px !important; font-weight: 600 !important; letter-spacing: -0.02em !important; }
.ph-modal-text p { margin: 0 !important; font-size: 15px !important; line-height: 22px !important; color: var(--pu-ink-sub) !important; max-width: 40ch; }
.ph-plans { gap: 8px !important; }
.ph-plan-opt { display: flex !important; align-items: center !important; justify-content: space-between !important; gap: 16px !important; min-height: 64px; padding: 12px 16px !important; }
.ph-plan-l { display: flex; flex-direction: column; gap: 4px; min-width: 0; text-align: left; }
.ph-plan-l b { font-size: 16px; font-weight: 600; color: #fff; }
.ph-plan-l small { font-size: 13px; line-height: 18px; color: var(--pu-ink-sub); }
.ph-price { display: flex; align-items: baseline; gap: 2px; flex: none; white-space: nowrap; }
.ph-price b { font: 600 18px/1 var(--pu-sans); letter-spacing: -0.02em; color: #fff; }
.ph-price small { font: 400 12px/1 var(--pu-mono); color: var(--pu-ink-sub); }
.ph-modal-acts { justify-content: flex-end; }
.ph-modal-foot { color: var(--pu-ink-faint) !important; }

/* ── the logo is a link, not a button: no hover wash */
.ph-home-btn:hover, .topbar.pab .ph-home-btn:hover, .pab-brand:hover { background: transparent !important; }

/* ── the editor bar's actions (Plot icons: list, export) */
.topbar.pab .actions .ghost { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' fill='none' stroke='black' stroke-width='4' stroke-linecap='round'%3E%3Cpath d='M18 12h22M18 24h22M18 36h22'/%3E%3Ccircle cx='9' cy='12' r='3' fill='black' stroke='none'/%3E%3Ccircle cx='9' cy='24' r='3' fill='black' stroke='none'/%3E%3Ccircle cx='9' cy='36' r='3' fill='black' stroke='none'/%3E%3C/svg%3E"); }
.topbar.pab .actions .primary { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' fill='none' stroke='black' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M24 7v23M14 21l10 10 10-10M9 41h30'/%3E%3C/svg%3E"); border-radius: var(--pu-r-pill) !important; padding: 0 16px !important; }
/* the icon sits in a span-free button, so the rim takes ::after and the icon moves to a background mask on ::before */
.topbar.pab .actions .primary::before, .topbar.pab .actions .ghost::before {
  content: "" !important; position: static !important; width: 15px; height: 15px; flex: none; background: currentColor !important; opacity: 1 !important;
  -webkit-mask: var(--ic) center / contain no-repeat !important; mask: var(--ic) center / contain no-repeat !important;
}

/* Excalidraw chrome that remains: pills */
.canvas .excalidraw .main-menu-trigger, .canvas .excalidraw .zoom-actions, .canvas .excalidraw .undo-redo-buttons, .canvas .excalidraw .zoom-actions button, .canvas .excalidraw .undo-redo-buttons button { border-radius: var(--pu-r-pill) !important; }
.canvas .excalidraw .dropdown-menu-container, .canvas .excalidraw .context-menu { border-radius: var(--pu-r-panel) !important; }
.canvas .excalidraw .dropdown-menu-item, .canvas .excalidraw .context-menu-item { border-radius: var(--pu-r-row) !important; }

/* ── secondary hover = the glass with its light, as on the consistency board (Buttons A): no lighter fill.
   The old v0.20 hover (a white top-to-bottom gradient) in home.css is overridden here. */
.ph-btn:not(.ph-btn-primary):not(.ph-quiet):hover, .ph-btn-ghost:hover, .ph-icon-btn:hover, .modal .ghost:hover {
  background: radial-gradient(var(--pu-gsize) at var(--gx) 100%, rgba(255, 150, 80, calc(var(--pu-ga, 0.42) * var(--gf))) 0%, rgba(255, 90, 31, calc(var(--pu-gb, 0.2) * var(--gf))) var(--pu-gm, 38%), rgba(255, 90, 31, 0) var(--pu-ge, 82%)), var(--pu-fill, var(--pu-frost)) !important;
}

/* ── v0.23 · Home on phones and tablets
   - the sidebar is no longer sticky below 900 px, so it no longer keeps the 80 px offset (it slid over "Projects")
   - below 900 px the projects come first; Folders and the plan follow them, side by side on tablets
   - the tag chips scroll sideways in one row; the search field takes the full width above them */
.ph-chiprow { display: contents; }
@media (width <= 900px) {
  .ph-body { gap: 20px; }
  .ph-side { position: relative; top: 0; order: 2; flex-direction: row; align-items: flex-start; }
  .ph-main { order: 1; }
  .ph-side .ph-side-group { flex: 1 1 220px; }
  .ph-side .ph-plan { flex: 1 1 300px; }
  .ph-tagbar { flex-direction: column; align-items: stretch; gap: 6px; padding: 6px; }
  .ph-tag-input { order: -1; flex: none; min-height: 44px; }
  .ph-tagcount { display: none; }
  .ph-chiprow { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 0 2px 2px;
    -webkit-mask: linear-gradient(90deg, #000 88%, transparent); mask: linear-gradient(90deg, #000 88%, transparent); }
  .ph-chiprow::-webkit-scrollbar { display: none; }
  .ph-chiprow .ph-chip { flex: none; }
}
@media (width <= 640px) {
  .ph-side { flex-direction: column; align-items: stretch; }
  .ph-side .ph-side-group, .ph-side .ph-plan { flex: none; }
  .ph-head { align-items: center; }
  .ph-head h1 { font-size: 30px; line-height: 34px; }
  .ph-row { gap: 10px; }
  .ph-seg { width: 100%; }
  .ph-seg-btn { flex: 1 1 0; justify-content: center; padding: 0 10px; font-size: 13px; min-width: 0; }
  .ph-newtile { min-height: 96px; aspect-ratio: auto; flex-direction: row; gap: 10px; }
  .ph-dev { bottom: calc(8px + env(safe-area-inset-bottom)); }
}

/* ── v0.24 · comments from the v0.23 review
   - Folders open and close (closed at first); the head is a row button with a chevron
   - search and tags are two separate things: a search field pill, then a row of tag pills (no shared panel)
   - tag pills are the system's 40 px chips on every screen; "New" is an accent badge; no Kelvin badge on cards */
.ph-side .ph-side-group:first-child { display: flex !important; flex-direction: column; gap: 2px; }
.ph-fold-btn { width: 100%; height: 36px; padding: 0 8px 0 10px !important; border: 0; border-radius: var(--pu-r-row); display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: transparent; color: inherit; cursor: pointer; transition: background-color .15s var(--pu-ease); }
.ph-fold-btn:hover { background: var(--pu-wash-hover); }
.ph-fold-btn:focus-visible { outline: 2px solid var(--pu-key); outline-offset: 2px; }
.ph-fold-r { display: inline-flex; align-items: center; gap: 8px; color: var(--pu-ink-sub); }
.ph-fold-chev { transition: transform .2s var(--pu-ease); }
.ph-fold-btn[aria-expanded="true"] .ph-fold-chev { transform: rotate(180deg); }
.ph-folders { display: flex; flex-direction: column; gap: 2px; animation: ph-fade .18s var(--pu-ease) both; }
.ph-folders[hidden] { display: none !important; }

.ph-tagtools { display: flex; align-items: center; gap: 14px; }
.ph-searchpill { flex: 1 1 auto; max-width: 560px; height: 48px; color: var(--pu-ink-sub); cursor: text; }
.ph-searchpill svg { width: 16px; height: 16px; flex: none; }
.ph-searchpill input { font: 400 15px var(--pu-sans); letter-spacing: 0; text-transform: none; }
.ph-searchpill input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
.ph-tagtools .ph-tagcount { display: inline; margin-left: auto; color: var(--pu-ink-sub); white-space: nowrap; }
.ph-chiprow { display: flex !important; flex-wrap: wrap; gap: 8px; margin-top: -8px; -webkit-mask: none !important; mask: none !important; overflow: visible; padding: 0; }
.ph-chip { height: 40px !important; min-height: 40px !important; padding: 0 16px !important; font-size: 12px !important; flex: none; }
.ph-badge.is-new { background: var(--pu-tint-on) !important; box-shadow: inset 0 0 0 1px var(--pu-tint-on-edge) !important; color: var(--pu-key) !important; }
@media (width <= 900px) {
  .ph-chiprow { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: -8px -12px 0; padding: 0 12px;
    -webkit-mask: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 28px), transparent) !important; mask: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 28px), transparent) !important; }
  .ph-chiprow::-webkit-scrollbar { display: none; }
  .ph-searchpill { max-width: none; }
}
@media (width <= 640px) {
  .ph-tagtools .ph-tagcount { display: none; }
  .ph-folders { display: grid; grid-template-columns: 1fr 1fr; }
}

/* v0.24 · editor: the canvas menu (☰) is gone; its actions live in the toolbar's More (···), shown at every width.
   The More menu holds the Plan actions; on phones (toolbar cut short) the Draw and Grid sections join them. */
.canvas .excalidraw .main-menu-trigger, .canvas .excalidraw .App-menu_top__left .dropdown-menu-container { display: none !important; }
.tb-more { display: block !important; }
.tb-more .tb-pop { width: 280px; }
.tb-more .tb-narrow { display: none !important; }
@media (width <= 640px), (max-height: 520px) and (orientation: landscape) { .tb-more .tb-narrow { display: grid !important; } .tb-more .tb-pop-head.tb-narrow { display: block !important; } }
.tb-pop-list { display: flex; flex-direction: column; gap: 2px; }
.tb-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 40px; padding: 0 12px; border: 0; border-radius: var(--pu-r-row);
  background: transparent; color: var(--pu-ink-soft); font: 400 14px/1.2 var(--pu-sans); text-align: left; cursor: pointer; transition: background-color .15s var(--pu-ease), color .15s var(--pu-ease); }
.tb-row:hover, .tb-row:focus-visible { background: var(--pu-wash-hover); color: var(--pu-ink); outline: none; }
.tb-row-meta { font: 500 10.5px/1 var(--pu-mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--pu-ink-sub); }
.tb-row.tb-danger { color: #F87171; }
/* every floating panel in the editor is the same Frost as the toolbar */
.sel-bar, .pen-bar { background: var(--pu-frost) !important; -webkit-backdrop-filter: var(--pu-blur) !important; backdrop-filter: var(--pu-blur) !important; box-shadow: var(--pu-edge), var(--pu-drop) !important; }
