/* ==========================================================================
   phone.css — the in-game phone (ui/phone/*)

   Everything is sized in `u`, where 1u = 1% of the screen width, derived
   entirely in CSS from the device width:

       --sb-ph-u: dev-width * screen-width% / 10000

   That single relationship is why the UI fits the shell art at any scale —
   there is no JS layout pass, no breakpoint list, and no place for the content
   to drift out of the bezel. JS supplies exactly one measured number
   (--sb-ph-dev-w, in px); phoneLayout.js supplies the fit percentages.

   Class prefix: sb-ph-.  Tokens only, per STYLE_GUIDE.md.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Root + backdrop
   z-index 9600 sits in the free gap between .sr-toast (9500) and the crate
   ceremony (9900): above the HUD and chat, so the phone is unambiguously the
   focused device, but below ceremonies and the admin console.
   -------------------------------------------------------------------------- */
.sb-ph-root {
  position: fixed;
  inset: 0;
  z-index: 9600;
  display: block;
  pointer-events: none;
  visibility: hidden;

  /* Fallbacks; phoneLayout.applyPhoneLayout() overwrites these on open. */
  --sb-ph-scr-l: 12.19;
  --sb-ph-scr-t: 7.33;
  --sb-ph-scr-w: 75.27;
  --sb-ph-scr-h: 84.80;
  --sb-ph-scr-r: 10;
  --sb-ph-isl-w: 45;
  --sb-ph-isl-h: 6;
  --sb-ph-isl-t: 0;
  --sb-ph-isl-r: 5.5;
  --sb-ph-raise: 460ms;
  --sb-ph-lower: 320ms;
  --sb-ph-app-in: 340ms;
  --sb-ph-app-out: 280ms;
  --sb-ph-wall-dim: 0.42;
  --sb-ph-world-dim: 0.34;
  --sb-ph-glare: 0.06;
  --sb-ph-dev-w: 430px;

  /* Derived. Do not set these from JS. */
  --sb-ph-u: calc(var(--sb-ph-dev-w) * var(--sb-ph-scr-w) / 10000);
  --sb-ph-scr-rpx: calc(var(--sb-ph-dev-w) * var(--sb-ph-scr-w) * var(--sb-ph-scr-r) / 10000);
  --sb-ph-isl-rpx: calc(var(--sb-ph-dev-w) * var(--sb-ph-scr-w) * var(--sb-ph-isl-r) / 10000);
  --sb-ph-isl-hpx: calc(var(--sb-ph-dev-w) / 0.601487 * var(--sb-ph-scr-h) * var(--sb-ph-isl-h) / 10000);

  font-family: 'Exo 2', var(--font-family);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.sb-ph-root.is-open { visibility: visible; pointer-events: auto; }

/* This project does not set a global border-box, so padding would otherwise be
   added to every width below — which on a fixed-size screen means content
   bleeding past the bezel. Scoped to the phone rather than changing the global
   default, which would move a thousand other things. */
.sb-ph-root,
.sb-ph-root *,
.sb-ph-root *::before,
.sb-ph-root *::after { box-sizing: border-box; }

/* The UA's `[hidden] { display: none }` loses to any class that sets display,
   so `el.hidden = true` silently does nothing on our badges and chips. Make the
   attribute mean what it says everywhere inside the phone. */
.sb-ph-root [hidden] { display: none !important; }

.sb-ph-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 13, var(--sb-ph-world-dim));
  backdrop-filter: blur(3px) saturate(1.1);
  opacity: 0;
  transition: opacity var(--sb-ph-lower) ease;
}
.sb-ph-root.is-open .sb-ph-backdrop {
  opacity: 1;
  transition-duration: var(--sb-ph-raise);
}
/* Docked: kept in the DOM (still catches clicks so the world isn't grabbing
   pointer lock behind the phone, and tapping it still dismisses), but with
   zero visual dim/blur — the whole point of docking is an unobstructed view. */
.sb-ph-root.is-docked .sb-ph-backdrop {
  background: transparent;
  backdrop-filter: none;
}

/* --------------------------------------------------------------------------
   2. Device — the bezel box
   -------------------------------------------------------------------------- */
.sb-ph-device {
  position: absolute;
  left: 50%;
  bottom: max(1.5vh, env(safe-area-inset-bottom));
  width: var(--sb-ph-dev-w);
  height: calc(var(--sb-ph-dev-w) / 0.601487);
  /* Resting pose is authored on .is-open so the default state is the one we
     animate *from* — the phone is off-screen until it's asked for. */
  transform: translate(-50%, 108%) rotate(3deg) scale(0.94);
  opacity: 0;
  transition:
    transform var(--sb-ph-lower) cubic-bezier(0.4, 0, 0.9, 0.35),
    opacity calc(var(--sb-ph-lower) * 0.55) ease;
  will-change: transform;
  filter: drop-shadow(0 calc(var(--sb-ph-u) * 3) calc(var(--sb-ph-u) * 7) rgba(0, 0, 0, 0.55));
}
.sb-ph-root.is-open .sb-ph-device {
  transform: translate(-50%, 0) rotate(0deg) scale(1);
  opacity: 1;
  transition:
    transform var(--sb-ph-raise) var(--ease-enter),
    opacity calc(var(--sb-ph-raise) * 0.4) ease;
}

/* Docked: opened while actively skiing (desktop only — see phoneShell.js
   _shouldDock). Anchored to the right edge instead of centered, and the
   backdrop below goes fully transparent, so the mountain stays visible next
   to the phone rather than behind a dimmed, blurred modal. Same size — the
   ask was to stop blocking the view, not to shrink the device. */
.sb-ph-root.is-docked .sb-ph-device {
  left: auto;
  right: 6vw;
  transform: translate(0, 108%) rotate(3deg) scale(0.94);
}
.sb-ph-root.is-docked.is-open .sb-ph-device {
  transform: translate(0, 0) rotate(0deg) scale(1);
}

.sb-ph-shell {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   3. Screen
   -------------------------------------------------------------------------- */
.sb-ph-screen {
  position: absolute;
  left: calc(var(--sb-ph-scr-l) * 1%);
  top: calc(var(--sb-ph-scr-t) * 1%);
  width: calc(var(--sb-ph-scr-w) * 1%);
  height: calc(var(--sb-ph-scr-h) * 1%);
  border-radius: var(--sb-ph-scr-rpx);
  overflow: hidden;
  background: #02070f;
  font-size: calc(var(--sb-ph-u) * 4);
  isolation: isolate;
}

/* The authored wallpaper is intentionally wider than this portrait screen.
   `cover` crops its sides without stretching it, and the screen's overflow
   clip keeps every pixel inside the measured bezel. */
.sb-ph-wallpaper {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #0a1424;
  background-image:
    url('images/ui/phone_bg.webp'),
    linear-gradient(180deg, #12243d 0%, #0a1424 55%, #060d18 100%);
  image-rendering: auto;
  transition: opacity 420ms ease;
}
.sb-ph-wallpaper::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(3, 7, 14, calc(var(--sb-ph-wall-dim) * 0.7)) 0%,
    rgba(3, 7, 14, var(--sb-ph-wall-dim)) 45%,
    rgba(3, 7, 14, calc(var(--sb-ph-wall-dim) + 0.2)) 100%);
}

/* Sleep layer — the screen stays dark for a beat while the device rises, so it
   reads as waking rather than as a div appearing. */
.sb-ph-sleep {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: #02070f;
  opacity: 1;
  pointer-events: none;
  transition: opacity 260ms ease;
}
.sb-ph-root.is-awake .sb-ph-sleep { opacity: 0; }

/* Diagonal specular sheen. Desktop only — one fewer composited layer on mobile,
   where --sb-ph-glare is 0 anyway. */
.sb-ph-glare {
  position: absolute;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  background: linear-gradient(118deg,
    rgba(255, 255, 255, 0) 38%,
    rgba(255, 255, 255, var(--sb-ph-glare)) 46%,
    rgba(255, 255, 255, 0) 58%);
}

/* --------------------------------------------------------------------------
   4. Status bar + camera island
   The island is redrawn in CSS because our content composites *over* the shell
   art, covering the painted camera module. Redrawing it means it can also carry
   notifications, which the painted one never could.
   -------------------------------------------------------------------------- */
.sb-ph-statusbar {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--sb-ph-isl-t) * 1%);
  height: calc(var(--sb-ph-isl-h) * 1%);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 calc(var(--sb-ph-u) * 6);
  font-family: 'Oxanium', var(--font-family);
  font-size: calc(var(--sb-ph-u) * 3.6);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  pointer-events: none;
}
.sb-ph-clock { font-variant-numeric: tabular-nums; }
.sb-ph-status-right {
  display: flex;
  align-items: center;
  gap: calc(var(--sb-ph-u) * 1.6);
  opacity: 0.9;
}
.sb-ph-status-right svg { display: block; }

/* Idle shape traces the ACTUAL camera-housing silhouette painted into
   phone_wrapper.webp, sampled at 2px increments (flat ~196px-wide top,
   tapering to a point ~48px down — not a rounded-rect pill, which is why a
   border-radius approximation never sat flush against the bezel). Fill colour
   is the housing's own measured tone (~#26292e, a neutral charcoal — the art
   is NOT pure black there). Points are % of the island's own box, so they
   track --sb-ph-isl-w/-h automatically if those are ever retuned. */
.sb-ph-island {
  position: absolute;
  left: 50%;
  top: calc(var(--sb-ph-isl-t) * 1%);
  transform: translateX(-50%);
  width: calc(var(--sb-ph-isl-w) * 1%);
  height: calc(var(--sb-ph-isl-h) * 1%);
  z-index: 32;
  background: #26292e;
  clip-path: polygon(
    0% 0%, 100% 0%,
    99% 20.8%, 96% 41.7%, 94% 54.2%, 93% 62.5%, 91% 70.8%, 91% 79.2%, 90% 87.5%, 85% 95.8%, 70% 98.5%,
    50% 100%,
    30% 98.5%, 15% 95.8%, 10% 87.5%, 9% 79.2%, 9% 70.8%, 7% 62.5%, 6% 54.2%, 4% 41.7%, 1% 20.8%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--sb-ph-u) * 2);
  padding: 0 calc(var(--sb-ph-u) * 3) calc(var(--sb-ph-u) * 2);
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
  transition: width 380ms var(--ease-enter), height 380ms var(--ease-enter), clip-path 260ms ease;
}
/* Expanded for a notification: real Dynamic-Island behaviour — grows out of
   the housing silhouette into a plain rounded pill, since at this size it
   reads as a UI element, not as "the camera cutout" anymore. */
.sb-ph-island.has-toast {
  width: calc(var(--sb-ph-isl-w) * 1.85%);
  height: calc(var(--sb-ph-isl-h) * 1.35%);
  clip-path: none;
  border-radius: calc(var(--sb-ph-isl-rpx) * 2);
  padding: 0 calc(var(--sb-ph-u) * 3);
}
.sb-ph-island-msg {
  font-size: calc(var(--sb-ph-u) * 3.3);
  font-weight: 600;
  color: var(--accent-light);
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 200ms ease 120ms, max-width 340ms var(--ease-enter);
}
.sb-ph-island.has-toast .sb-ph-island-msg { opacity: 1; max-width: calc(var(--sb-ph-u) * 60); }
.sb-ph-island-icon { display: none; color: var(--accent); }
.sb-ph-island.has-toast .sb-ph-island-icon { display: block; }
.sb-ph-island-icon svg { width: calc(var(--sb-ph-u) * 4.4); height: calc(var(--sb-ph-u) * 4.4); }

/* Home indicator */
.sb-ph-homebar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--sb-ph-u) * 1.8);
  transform: translateX(-50%);
  width: calc(var(--sb-ph-u) * 34);
  height: calc(var(--sb-ph-u) * 1.1);
  border-radius: var(--radius-pill);
  background: rgba(236, 243, 251, 0.55);
  z-index: 34;
  cursor: pointer;
  pointer-events: auto;
  transition: background var(--ease-fast), transform var(--ease-fast);
}
.sb-ph-homebar:hover { background: rgba(236, 243, 251, 0.85); }
.sb-ph-homebar:active { transform: translateX(-50%) scaleY(0.7); }

/* --------------------------------------------------------------------------
   5. Stage — home screen and the app on top of it
   -------------------------------------------------------------------------- */
.sb-ph-stage {
  position: absolute;
  inset: 0;
  z-index: 20;
}

.sb-ph-home {
  position: absolute;
  inset: 0;
  top: var(--sb-ph-isl-hpx);
  padding: calc(var(--sb-ph-u) * 5) calc(var(--sb-ph-u) * 6) calc(var(--sb-ph-u) * 8);
  display: flex;
  flex-direction: column;
  transform-origin: 50% 45%;
  transition:
    transform var(--sb-ph-app-in) cubic-bezier(0.2, 0.9, 0.25, 1),
    opacity calc(var(--sb-ph-app-in) * 0.7) ease,
    filter var(--sb-ph-app-in) ease;
}
.sb-ph-stage.has-app .sb-ph-home {
  transform: scale(0.92);
  opacity: 0.35;
  filter: blur(2px);
  pointer-events: none;
}

/* The app window grows out of the icon that launched it — transform-origin is
   set from the icon's centre by phoneShell.js. That single detail is most of
   what makes this read as an OS rather than as a tab switch. */
.sb-ph-app {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(9, 14, 24, 0.94), rgba(6, 10, 18, 0.97));
  transform-origin: var(--sb-ph-ox, 50%) var(--sb-ph-oy, 50%);
  transform: scale(0.28);
  opacity: 0;
  border-radius: 24%;
  overflow: hidden;
  transition:
    transform var(--sb-ph-app-in) cubic-bezier(0.2, 0.9, 0.25, 1),
    opacity calc(var(--sb-ph-app-in) * 0.55) ease,
    border-radius var(--sb-ph-app-in) ease;
  will-change: transform;
}
.sb-ph-app.is-in { transform: scale(1); opacity: 1; border-radius: 0; }
.sb-ph-app.is-out {
  transform: scale(0.28);
  opacity: 0;
  border-radius: 24%;
  transition-duration: var(--sb-ph-app-out), calc(var(--sb-ph-app-out) * 0.6), var(--sb-ph-app-out);
}

/* --------------------------------------------------------------------------
   6. Home screen
   -------------------------------------------------------------------------- */
.sb-ph-greeting {
  font-family: 'Oxanium', var(--font-family);
  font-size: calc(var(--sb-ph-u) * 3.4);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
  opacity: 0.75;
  margin-bottom: calc(var(--sb-ph-u) * 1);
}
.sb-ph-place {
  font-size: calc(var(--sb-ph-u) * 6.6);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: calc(var(--sb-ph-u) * 7);
  text-shadow: 0 calc(var(--sb-ph-u) * 0.4) calc(var(--sb-ph-u) * 2) rgba(0, 0, 0, 0.6);
}

.sb-ph-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: calc(var(--sb-ph-u) * 7) calc(var(--sb-ph-u) * 5);
  align-content: start;
  /* Grid items default to align-items:stretch on the block axis, which forces
     each .sb-ph-appicon down to the row track's computed height BEFORE its own
     flex column gets to lay out tile+label — and since the tile is the one
     flexible child, it silently shrank to a non-square sliver to absorb the
     deficit. `start` lets each icon size to its own natural content instead,
     which is what the row's auto-height should have been measuring anyway. */
  align-items: start;
}
.sb-ph-appicon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--sb-ph-u) * 2);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  /* Staggered wake-up; --i is the icon index. */
  opacity: 0;
  transform: translateY(calc(var(--sb-ph-u) * 3)) scale(0.86);
  transition:
    opacity 260ms ease,
    transform 380ms var(--ease-enter);
  transition-delay: calc(var(--i, 0) * 24ms + 150ms);
}
.sb-ph-root.is-awake .sb-ph-appicon { opacity: 1; transform: none; }

.sb-ph-tile {
  position: relative;
  width: calc(var(--sb-ph-u) * 20);
  height: calc(var(--sb-ph-u) * 20);
  /* Defensive: even with the grid fix above, this must never be the child
     that gives up its size to make something else fit. A squished tile is a
     silent, ugly failure; better to let something else overflow visibly. */
  flex-shrink: 0;
  border-radius: 24%;
  background: var(--sb-ph-tile, linear-gradient(158deg, #6fb8ff, #2f6ed4));
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow:
    0 calc(var(--sb-ph-u) * 1.2) calc(var(--sb-ph-u) * 2.6) rgba(0, 0, 0, 0.45),
    inset 0 calc(var(--sb-ph-u) * 0.35) 0 rgba(255, 255, 255, 0.28);
  transition: transform 180ms var(--ease-enter), box-shadow var(--ease-fast);
}
.sb-ph-tile svg {
  width: 58%;
  height: 58%;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}
.sb-ph-applabel {
  font-size: calc(var(--sb-ph-u) * 3.4);
  font-weight: 600;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.sb-ph-badge {
  position: absolute;
  top: calc(var(--sb-ph-u) * -1.4);
  right: calc(var(--sb-ph-u) * -1.4);
  min-width: calc(var(--sb-ph-u) * 6);
  height: calc(var(--sb-ph-u) * 6);
  padding: 0 calc(var(--sb-ph-u) * 1.4);
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #2a0808;
  font-family: 'Oxanium', var(--font-family);
  font-size: calc(var(--sb-ph-u) * 3.4);
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 calc(var(--sb-ph-u) * 0.5) rgba(3, 7, 14, 0.8);
}

/* --------------------------------------------------------------------------
   7. Focus — one ring, every app, driven by phoneNav
   -------------------------------------------------------------------------- */
.sb-ph-screen [data-nav] { outline: none; }
.sb-ph-screen [data-nav].is-focus { position: relative; z-index: 1; }
.sb-ph-screen [data-nav].is-focus .sb-ph-tile {
  transform: scale(1.09);
  box-shadow:
    0 0 0 calc(var(--sb-ph-u) * 0.7) var(--accent),
    0 calc(var(--sb-ph-u) * 2) calc(var(--sb-ph-u) * 4) rgba(0, 0, 0, 0.5),
    0 0 calc(var(--sb-ph-u) * 5) var(--accent-glow),
    inset 0 calc(var(--sb-ph-u) * 0.35) 0 rgba(255, 255, 255, 0.28);
}
.sb-ph-screen [data-nav].is-focus .sb-ph-applabel { color: var(--accent-light); }

/* Generic focus treatment for rows, chips and buttons. */
.sb-ph-row.is-focus,
.sb-ph-btn.is-focus,
.sb-ph-chip.is-focus,
.sb-ph-thumb.is-focus {
  box-shadow: 0 0 0 calc(var(--sb-ph-u) * 0.6) var(--accent), 0 0 calc(var(--sb-ph-u) * 4) var(--accent-glow);
  border-color: transparent;
}

/* --------------------------------------------------------------------------
   8. Shared app chrome
   -------------------------------------------------------------------------- */
.sb-ph-appbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: calc(var(--sb-ph-u) * 2.5);
  padding:
    calc(var(--sb-ph-isl-hpx) + var(--sb-ph-u) * 3)
    calc(var(--sb-ph-u) * 4)
    calc(var(--sb-ph-u) * 3);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(10, 15, 25, 0.7);
}
.sb-ph-appbar h2 {
  margin: 0;
  font-size: calc(var(--sb-ph-u) * 4.6);
  font-weight: 700;
  letter-spacing: 0.01em;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-ph-appbar-sub {
  font-size: calc(var(--sb-ph-u) * 3.2);
  color: var(--text-muted);
  font-weight: 500;
}
.sb-ph-iconbtn {
  flex: 0 0 auto;
  width: calc(var(--sb-ph-u) * 8.5);
  height: calc(var(--sb-ph-u) * 8.5);
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background var(--ease-fast), border-color var(--ease-fast), transform var(--ease-fast);
}
.sb-ph-iconbtn:hover { background: rgba(255, 255, 255, 0.11); border-color: var(--border-prominent); }
.sb-ph-iconbtn:active { transform: scale(0.94); }
.sb-ph-iconbtn svg { width: calc(var(--sb-ph-u) * 5); height: calc(var(--sb-ph-u) * 5); }

.sb-ph-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: calc(var(--sb-ph-u) * 3) calc(var(--sb-ph-u) * 4) calc(var(--sb-ph-u) * 9);
  scrollbar-width: none;
}
.sb-ph-body::-webkit-scrollbar { width: 0; height: 0; }

.sb-ph-section {
  font-family: 'Oxanium', var(--font-family);
  font-size: calc(var(--sb-ph-u) * 3.1);
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: calc(var(--sb-ph-u) * 4) 0 calc(var(--sb-ph-u) * 2);
}
.sb-ph-section:first-child { margin-top: calc(var(--sb-ph-u) * 1); }

.sb-ph-row {
  display: flex;
  align-items: center;
  gap: calc(var(--sb-ph-u) * 3);
  width: 100%;
  padding: calc(var(--sb-ph-u) * 3);
  margin-bottom: calc(var(--sb-ph-u) * 2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--ease-fast), border-color var(--ease-fast);
}
.sb-ph-row:hover { background: rgba(255, 255, 255, 0.085); }
.sb-ph-row-ico {
  flex: 0 0 auto;
  width: calc(var(--sb-ph-u) * 9);
  height: calc(var(--sb-ph-u) * 9);
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: rgba(103, 180, 255, 0.14);
  color: var(--accent);
  overflow: hidden;
}
.sb-ph-row-ico svg { width: 55%; height: 55%; }
.sb-ph-row-ico img { width: 100%; height: 100%; object-fit: cover; }
.sb-ph-row-main { flex: 1 1 auto; min-width: 0; }
.sb-ph-row-title {
  font-size: calc(var(--sb-ph-u) * 3.9);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-ph-row-sub {
  font-size: calc(var(--sb-ph-u) * 3.2);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: calc(var(--sb-ph-u) * 0.5);
}
.sb-ph-row-meta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: calc(var(--sb-ph-u) * 1);
  font-size: calc(var(--sb-ph-u) * 3);
  color: var(--text-muted);
}
.sb-ph-pill {
  min-width: calc(var(--sb-ph-u) * 5);
  padding: 0 calc(var(--sb-ph-u) * 1.5);
  height: calc(var(--sb-ph-u) * 5);
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #04121f;
  font-weight: 800;
  font-size: calc(var(--sb-ph-u) * 3);
  display: grid;
  place-items: center;
}
.sb-ph-dot {
  width: calc(var(--sb-ph-u) * 2.2);
  height: calc(var(--sb-ph-u) * 2.2);
  border-radius: var(--radius-round);
  background: var(--success);
  box-shadow: 0 0 calc(var(--sb-ph-u) * 2) var(--success);
}
.sb-ph-dot.is-off { background: var(--text-muted); box-shadow: none; }

.sb-ph-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--sb-ph-u) * 1.8);
  padding: 0 calc(var(--sb-ph-u) * 4);
  height: calc(var(--sb-ph-u) * 10);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: calc(var(--sb-ph-u) * 3.7);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--ease-fast), border-color var(--ease-fast), transform var(--ease-fast);
}
.sb-ph-btn:hover { background: rgba(255, 255, 255, 0.11); }
.sb-ph-btn:active { transform: scale(0.97); }
.sb-ph-btn svg { width: calc(var(--sb-ph-u) * 4.4); height: calc(var(--sb-ph-u) * 4.4); }
.sb-ph-btn-primary {
  background: linear-gradient(180deg, rgba(103, 180, 255, 0.28), rgba(103, 180, 255, 0.16));
  border-color: rgba(103, 180, 255, 0.45);
  color: var(--accent-light);
}
.sb-ph-btn-danger {
  background: rgba(255, 111, 111, 0.12);
  border-color: rgba(255, 111, 111, 0.35);
  color: var(--danger);
}
.sb-ph-btn-wide { width: 100%; }
.sb-ph-btn[disabled] { opacity: 0.45; pointer-events: none; }

.sb-ph-empty {
  padding: calc(var(--sb-ph-u) * 12) calc(var(--sb-ph-u) * 6);
  text-align: center;
  color: var(--text-muted);
  font-size: calc(var(--sb-ph-u) * 3.6);
  line-height: 1.5;
}
.sb-ph-empty svg {
  width: calc(var(--sb-ph-u) * 12);
  height: calc(var(--sb-ph-u) * 12);
  opacity: 0.4;
  margin-bottom: calc(var(--sb-ph-u) * 3);
}

.sb-ph-spinner {
  width: calc(var(--sb-ph-u) * 7);
  height: calc(var(--sb-ph-u) * 7);
  margin: calc(var(--sb-ph-u) * 10) auto;
  border-radius: var(--radius-round);
  border: calc(var(--sb-ph-u) * 0.8) solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: sbPhSpin 720ms linear infinite;
}
@keyframes sbPhSpin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   9. Camera app
   -------------------------------------------------------------------------- */
.sb-ph-shots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: calc(var(--sb-ph-u) * 1.6);
}
/* Rendered as a div with role="button", NOT a <button>: Chromium sizes form
   controls from their content and ignores aspect-ratio for the block height,
   which collapses a button thumbnail to a sliver. `width: 100%` is also
   required — a grid item does not stretch on its own here. */
.sb-ph-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  padding: 0;
}
.sb-ph-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sb-ph-thumb-badge {
  position: absolute;
  right: calc(var(--sb-ph-u) * 0.8);
  bottom: calc(var(--sb-ph-u) * 0.8);
  width: calc(var(--sb-ph-u) * 4.4);
  height: calc(var(--sb-ph-u) * 4.4);
  border-radius: var(--radius-round);
  background: rgba(68, 221, 136, 0.9);
  color: #052; display: grid; place-items: center;
}
.sb-ph-thumb-badge svg { width: 70%; height: 70%; }

.sb-ph-viewer {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(3, 6, 12, 0.96);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity 200ms ease;
}
.sb-ph-viewer.is-in { opacity: 1; }
.sb-ph-viewer-img {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--sb-ph-u) * 3);
}
.sb-ph-viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); }
.sb-ph-viewer-actions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: calc(var(--sb-ph-u) * 2);
  padding: calc(var(--sb-ph-u) * 3) calc(var(--sb-ph-u) * 4) calc(var(--sb-ph-u) * 8);
}
/* Same shrink-wrap problem as the thumbnails — these must fill their tracks. */
.sb-ph-viewer-actions .sb-ph-btn { width: 100%; }

/* --------------------------------------------------------------------------
   10. Waypoints app
   -------------------------------------------------------------------------- */
.sb-ph-map {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-default);
  background: #081018;
  margin-bottom: calc(var(--sb-ph-u) * 3);
}
/* The "you are here" marker is drawn by renderSkiInfoBoardMapSnapshot itself —
   we pass the player position as the board position — so there is no overlay
   dot to style here. */
.sb-ph-map canvas { width: 100%; height: 100%; display: block; }

/* --------------------------------------------------------------------------
   11. Messages app
   -------------------------------------------------------------------------- */
.sb-ph-thread {
  display: flex;
  flex-direction: column;
  gap: calc(var(--sb-ph-u) * 1.2);
  padding-bottom: calc(var(--sb-ph-u) * 2);
}
.sb-ph-daydiv {
  align-self: center;
  margin: calc(var(--sb-ph-u) * 3) 0 calc(var(--sb-ph-u) * 1.5);
  padding: calc(var(--sb-ph-u) * 0.8) calc(var(--sb-ph-u) * 2.5);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
  font-size: calc(var(--sb-ph-u) * 2.9);
  font-weight: 600;
}
.sb-ph-bubble {
  max-width: 78%;
  padding: calc(var(--sb-ph-u) * 2.2) calc(var(--sb-ph-u) * 3);
  border-radius: calc(var(--sb-ph-u) * 4.5);
  font-size: calc(var(--sb-ph-u) * 3.7);
  line-height: 1.35;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.sb-ph-bubble.is-them {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.09);
  border-bottom-left-radius: calc(var(--sb-ph-u) * 1.2);
}
.sb-ph-bubble.is-me {
  align-self: flex-end;
  background: linear-gradient(180deg, #4a9df0, #2f6ed4);
  color: #f4faff;
  border-bottom-right-radius: calc(var(--sb-ph-u) * 1.2);
}
.sb-ph-bubble.is-grouped { margin-top: calc(var(--sb-ph-u) * -0.6); }
.sb-ph-bubble.is-pending { opacity: 0.55; }

.sb-ph-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: calc(var(--sb-ph-u) * 2);
  padding: calc(var(--sb-ph-u) * 2.5) calc(var(--sb-ph-u) * 3) calc(var(--sb-ph-u) * 6);
  border-top: 1px solid var(--border-subtle);
  background: rgba(8, 12, 20, 0.85);
}
.sb-ph-composer input {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--sb-ph-u) * 9);
  padding: 0 calc(var(--sb-ph-u) * 3.5);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font: inherit;
  font-size: calc(var(--sb-ph-u) * 3.6);
  outline: none;
}
.sb-ph-composer input::placeholder { color: var(--text-muted); }
.sb-ph-composer input:focus { border-color: var(--accent); background: rgba(255, 255, 255, 0.1); }
.sb-ph-send {
  flex: 0 0 auto;
  width: calc(var(--sb-ph-u) * 9);
  height: calc(var(--sb-ph-u) * 9);
  border-radius: var(--radius-round);
  border: 0;
  background: linear-gradient(180deg, #4a9df0, #2f6ed4);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform var(--ease-fast), filter var(--ease-fast);
}
.sb-ph-send:hover { filter: brightness(1.12); }
.sb-ph-send:active { transform: scale(0.92); }
.sb-ph-send svg { width: 55%; height: 55%; }

/* --------------------------------------------------------------------------
   12. Reels app
   -------------------------------------------------------------------------- */
.sb-ph-reels {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}
.sb-ph-reel {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: translateY(100%);
  transition: transform 320ms var(--ease-enter), opacity 200ms ease;
}
.sb-ph-reel.is-current { opacity: 1; transform: translateY(0); }
.sb-ph-reel.is-prev { opacity: 0; transform: translateY(-100%); }
.sb-ph-reel video,
.sb-ph-reel .sb-ph-reel-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.sb-ph-reel-poster { background-size: cover; background-position: center; transition: opacity 260ms ease; }
.sb-ph-reel.is-playing .sb-ph-reel-poster { opacity: 0; }

.sb-ph-reel-info {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: calc(var(--sb-ph-u) * 12) calc(var(--sb-ph-u) * 4) calc(var(--sb-ph-u) * 7);
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.78));
  pointer-events: none;
}
.sb-ph-reel-author {
  font-size: calc(var(--sb-ph-u) * 3.9);
  font-weight: 700;
  margin-bottom: calc(var(--sb-ph-u) * 0.8);
}
.sb-ph-reel-caption {
  font-size: calc(var(--sb-ph-u) * 3.4);
  color: rgba(236, 243, 251, 0.86);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sb-ph-reel-mtn {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--sb-ph-u) * 1.2);
  margin-top: calc(var(--sb-ph-u) * 1.6);
  padding: calc(var(--sb-ph-u) * 0.8) calc(var(--sb-ph-u) * 2.2);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.16);
  font-size: calc(var(--sb-ph-u) * 2.9);
  font-weight: 600;
}
.sb-ph-reel-mtn svg { width: calc(var(--sb-ph-u) * 3.4); height: calc(var(--sb-ph-u) * 3.4); }

.sb-ph-reel-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: calc(var(--sb-ph-u) * 0.7);
  background: var(--accent);
  width: 0;
  z-index: 3;
}
.sb-ph-reel-controls {
  position: absolute;
  top: calc(var(--sb-ph-isl-hpx) + var(--sb-ph-u) * 3);
  left: calc(var(--sb-ph-u) * 4);
  right: calc(var(--sb-ph-u) * 4);
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.sb-ph-reel-sound,
.sb-ph-reel-back {
  position: static;
  flex: 0 0 auto;
  width: calc(var(--sb-ph-u) * 9);
  height: calc(var(--sb-ph-u) * 9);
  border-radius: var(--radius-round);
  border: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  transition: background var(--ease-fast);
}
.sb-ph-reel-sound:hover,
.sb-ph-reel-back:hover { background: rgba(0, 0, 0, 0.75); }
.sb-ph-reel-sound svg,
.sb-ph-reel-back svg { width: 52%; height: 52%; }

.sb-ph-reel-hint {
  position: absolute;
  top: calc(var(--sb-ph-isl-hpx) + var(--sb-ph-u) * 14);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  padding: calc(var(--sb-ph-u) * 1) calc(var(--sb-ph-u) * 2.4);
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.5);
  font-size: calc(var(--sb-ph-u) * 2.9);
  font-weight: 600;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.82);
  transition: opacity 400ms ease;
}
.sb-ph-reel-hint.is-gone { opacity: 0; }

/* --------------------------------------------------------------------------
   13. Mobile
   The phone reuses the same shell art, scaled up. Two hard rules:
   no backdrop-filter (documented as the single most expensive thing on screen
   there), and no glass sheen — both are extra full-screen composited layers.
   -------------------------------------------------------------------------- */
html.is-mobile .sb-ph-backdrop { backdrop-filter: none; }
html.is-mobile .sb-ph-glare { display: none; }
html.is-mobile .sb-ph-device { filter: none; }
html.is-mobile .sb-ph-stage.has-app .sb-ph-home { filter: none; }
html.is-mobile .sb-ph-row { padding: calc(var(--sb-ph-u) * 3.4) calc(var(--sb-ph-u) * 3); }

/* Reels on mobile: a decoding video plus a live WebGL canvas is exactly the GPU
   pressure that kills the tab during the crate ceremony. phoneShell.js sets
   this class and G._renderSuspended together. `visibility`, never `display`, so
   the renderer never sees a resize and reallocates buffers. */
body.sb-phone-lite canvas#scene { visibility: hidden; }

/* --------------------------------------------------------------------------
   14. `/phone layout` admin panel (ui/phone/phoneTunePanel.js)
   Lives here rather than in an injected <style> block, per STYLE_GUIDE.md.
   z-index above the phone itself so you can see what you're dialling in.
   -------------------------------------------------------------------------- */
.sb-pht,
.sb-pht * { box-sizing: border-box; }
.sb-pht {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: 9700;
  display: none;
  flex-direction: column;
  width: 290px;
  max-height: 78vh;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  background: var(--bg-base);
  box-shadow: var(--shadow-high);
  font-family: var(--font-family);
  color: var(--text);
  overflow: hidden;
}
.sb-pht-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-raised);
}
.sb-pht-title { flex: 1 1 auto; font-size: var(--font-md); font-weight: 700; }
.sb-pht-plat {
  font-family: 'Oxanium', var(--font-family);
  font-size: var(--font-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-pill);
  background: var(--accent-glow);
}
.sb-pht-x {
  border: 0; background: none; color: var(--text-secondary);
  font-size: var(--font-lg); line-height: 1; cursor: pointer; padding: 0 var(--sp-1);
}
.sb-pht-x:hover { color: var(--text); }
.sb-pht-body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-2) var(--sp-3); }
.sb-pht-group {
  font-family: 'Oxanium', var(--font-family);
  font-size: var(--font-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: var(--sp-3) 0 var(--sp-1);
}
.sb-pht-row {
  display: grid;
  grid-template-columns: 88px 1fr 54px;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-1);
}
.sb-pht-label { font-size: var(--font-sm); color: var(--text-secondary); }
.sb-pht-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.sb-pht-num {
  width: 100%;
  padding: 2px var(--sp-1);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: var(--font-xs);
  font-family: var(--font-family-mono);
}
.sb-pht-actions {
  display: flex; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border-subtle);
}
.sb-pht-btn {
  flex: 1 1 0;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
}
.sb-pht-btn:hover { background: rgba(255, 255, 255, 0.12); }

/* --------------------------------------------------------------------------
   15. Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .sb-ph-device,
  .sb-ph-app,
  .sb-ph-home,
  .sb-ph-appicon,
  .sb-ph-island,
  .sb-ph-reel,
  .sb-ph-tile {
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
    animation-duration: 1ms !important;
  }
  .sb-ph-device { transform: translate(-50%, 0) !important; }
  .sb-ph-app.is-in { transform: none !important; }
  .sb-ph-spinner { animation: none; }
}
