/*
 * B7.61 — APP SHELL for the Living Time Sphere.
 *
 * Everything here is scoped to body.sphere-app, a class added by
 * living-time-sphere-app-shell.js. Without it the page is the classic
 * document. In app mode the sphere wrapper becomes a full-viewport stage
 * that does not scroll; panels present as sheets over the living sphere;
 * the dock and the selected-day bar are always within thumb reach.
 * Palette follows the living-ui conventions: deep warm ground, teal
 * shadow, brass seams. (Nov 19, 2026: the ground and panels took
 * the cartoon Sphere's wood-and-brass warmth; the teal stays as
 * the small glyph-light accent, the way the cartoon's own glyph
 * light rides its warm wood. The daypart shades of this ground
 * live in sphere-deepening.css, under the room's warmth.)
 */

:root {
  --sphere-app-bg: #130a06;
  --sphere-app-panel: rgba(23, 13, 7, 0.97);
  --sphere-app-line: rgba(218, 164, 91, 0.38);
  --sphere-app-text: #e8e4d9;
  --sphere-app-dim: rgba(232, 228, 217, 0.62);
  --sphere-app-teal: #57b7a8;
}

/* ── Chrome exists only in app mode ─────────────────────────────── */
.sphere-app-topbar,
.sphere-app-daybar,
.sphere-app-dock,
.sphere-app-scrim {
  display: none;
}

.sphere-app-enter {
  display: none;
}

body:not(.sphere-app) .sphere-app-enter {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--sphere-app-line);
  border-radius: 999px;
  background: rgba(23, 13, 7, 0.92);
  color: var(--sphere-app-text);
  font: inherit;
  cursor: pointer;
}

/* ── Stage ──────────────────────────────────────────────────────── */
body.sphere-app {
  overflow: hidden;
}

body.sphere-app .sphere-wrapper {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  margin: 0;
  background: var(--sphere-app-bg);
  color: var(--sphere-app-text);
}

/* The app carries its own top bar: the site header (sticky, z-800) and
 * the floating Living command pill (z-11800) step aside inside the app
 * and return in Full page mode. */
body.sphere-app .site-header,
body.sphere-app #living-command-trigger {
  display: none;
}

body.sphere-app .sphere-canvas-wrap {
  order: 2;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.6rem 0;
}

body.sphere-app .sphere-alt-view {
  order: 2;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

body.sphere-app .sphere-instrument-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.sphere-app #sphere-container {
  flex: 1 1 auto;
  height: auto;
  /* Never below the renderer's own 180px minimum height: under it the
   * page refuses 3D and settles on the 2D fallback (Nov 19, 2026). */
  min-height: 200px;
  max-height: none;
  width: 100%;
}

/* The camera preset bar is superseded by the dock inside the app. */
body.sphere-app .sphere-camera-controls {
  display: none;
}

/* Status lines stay slim inside the stage. */
body.sphere-app .sphere-state-strip,
body.sphere-app .sphere-environment-bridge {
  flex: 0 0 auto;
  font-size: 0.78rem;
  margin: 0.15rem 0;
}

/* The guided intro floats over the stage instead of pushing it down. */
body.sphere-app .sphere-intro {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  width: min(30rem, calc(100% - 2rem));
  z-index: 40;
}

/* ── Top bar ────────────────────────────────────────────────────── */
body.sphere-app .sphere-app-topbar {
  order: 1;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.45rem + env(safe-area-inset-top, 0px)) 0.8rem 0.45rem;
  border-bottom: 1px solid var(--sphere-app-line);
  background: var(--sphere-app-panel);
}

.sphere-app-identity {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  white-space: nowrap;
}

.sphere-app-sigil {
  color: var(--sphere-app-teal);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.sphere-app-name {
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* The way back: a plain link home, always in the top bar, because the
 * app hides the site header. An ordinary anchor — no script, no
 * history tricks; the visitor's Back button keeps its meaning. */
.sphere-app-home {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--sphere-app-line);
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.1);
  color: var(--sphere-app-text);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 120ms ease, background 120ms ease;
}

.sphere-app-home:active {
  transform: scale(0.95);
  background: rgba(212, 175, 55, 0.2);
}

/* Narrow screens: the name yields so the way back, today's coordinate
 * and the top actions all stay on the bar. */
@media (max-width: 720px) {
  body.sphere-app .sphere-app-topbar {
    gap: 0.5rem;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
  }

  .sphere-app-name {
    display: none;
  }
}

@media (max-width: 480px) {
  .sphere-app-home {
    padding: 0.4rem 0.65rem;
  }

  .sphere-app-top-btn {
    padding: 0.4rem 0.6rem;
  }

  body.sphere-app .sphere-app-coordinate {
    font-size: 0.78rem;
  }
}

body.sphere-app .sphere-app-coordinate {
  flex: 1 1 auto;
  margin: 0;
  text-align: center;
  color: var(--sphere-app-dim);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sphere-app-top-actions {
  display: flex;
  gap: 0.4rem;
}

.sphere-app-top-btn {
  min-height: 40px;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--sphere-app-line);
  border-radius: 999px;
  background: transparent;
  color: var(--sphere-app-text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, background 120ms ease;
}

.sphere-app-top-btn:active {
  transform: scale(0.95);
  background: rgba(212, 175, 55, 0.16);
}

/* ── Selected-day bar (the "now playing" bar) ───────────────────── */
body.sphere-app .sphere-app-daybar {
  order: 3;
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border-top: 1px solid var(--sphere-app-line);
  background: var(--sphere-app-panel);
}

.sphere-app-day-nav {
  flex: 0 0 52px;
  min-height: 52px;
  border: 1px solid var(--sphere-app-line);
  border-radius: 0.8rem;
  background: transparent;
  color: var(--sphere-app-text);
  font-size: 1.3rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, background 120ms ease;
}

.sphere-app-day-main {
  flex: 1 1 auto;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid transparent;
  border-radius: 0.8rem;
  background: rgba(218, 164, 91, 0.10);
  color: var(--sphere-app-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, background 120ms ease;
}

.sphere-app-day-nav:active,
.sphere-app-day-main:active {
  transform: scale(0.97);
  background: rgba(212, 175, 55, 0.16);
}

.sphere-app-day-label {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.25;
}

.sphere-app-day-sub {
  color: var(--sphere-app-dim);
  font-size: 0.74rem;
  letter-spacing: 0.03em;
}

/* ── Dock ───────────────────────────────────────────────────────── */
body.sphere-app .sphere-app-dock {
  order: 4;
  flex: 0 0 auto;
  display: flex;
  gap: 0.35rem;
  padding: 0.45rem 0.6rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(212, 175, 55, 0.18);
  background: var(--sphere-app-panel);
}

.sphere-dock-btn {
  flex: 1 1 0;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border: 1px solid transparent;
  border-radius: 0.85rem;
  background: transparent;
  color: var(--sphere-app-dim);
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease;
}

.sphere-dock-btn span {
  font-size: 1.15rem;
  line-height: 1;
  color: var(--sphere-app-teal);
}

/* The fullscreen button stays hidden where the browser offers no
 * fullscreen (the shell only unhides it when the API exists). */
.sphere-dock-btn[hidden] {
  display: none;
}

/* Fullscreen: the stage keeps its deep ground edge to edge. */
:fullscreen {
  background: var(--sphere-app-bg);
}

.sphere-dock-btn:active {
  transform: scale(0.94);
  background: rgba(212, 175, 55, 0.16);
  color: var(--sphere-app-text);
}

.sphere-dock-btn[aria-pressed="true"] {
  background: rgba(87, 183, 168, 0.16);
  color: var(--sphere-app-text);
  border-color: var(--sphere-app-line);
}

/* ── Sheets ─────────────────────────────────────────────────────── */
body.sphere-app .sphere-app-scrim {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(12, 6, 2, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 0s linear 200ms;
}

body.sphere-app .sphere-app-scrim.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease;
}

body.sphere-app .sphere-sheet {
  position: fixed;
  z-index: 120;
  background: #170d07;
  color: var(--sphere-app-text);
  box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  overscroll-behavior: contain;
  visibility: hidden;
  transition: transform 260ms ease, visibility 0s linear 260ms;
}

/* Phone: bottom sheets. */
@media (max-width: 899px) {
  body.sphere-app .sphere-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 84dvh;
    border-top: 1px solid var(--sphere-app-line);
    border-radius: 1.1rem 1.1rem 0 0;
    padding: 0.9rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translateY(105%);
  }
}

/* Desktop: right side sheets; the sphere stays alive beside them. */
@media (min-width: 900px) {
  body.sphere-app .sphere-sheet {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(430px, 94vw);
    border-left: 1px solid var(--sphere-app-line);
    padding: 1rem 1.1rem;
    transform: translateX(105%);
  }

  body.sphere-app .sphere-sheet--planner,
  body.sphere-app .sphere-sheet--atlas {
    width: min(680px, 96vw);
  }
}

body.sphere-app .sphere-sheet.is-open {
  transform: none;
  visibility: visible;
  transition: transform 260ms ease;
}

.sphere-sheet-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 2;
  min-height: 40px;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--sphere-app-line);
  border-radius: 999px;
  background: rgba(23, 13, 7, 0.92);
  color: var(--sphere-app-text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  touch-action: manipulation;
}

.sphere-sheet-close:active {
  transform: scale(0.95);
}

body.sphere-app .sphere-sheet-tools {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Sheets must not inherit document-flow widths from their old layout. */
body.sphere-app .sphere-controls-bar,
body.sphere-app .calendar-workbench,
body.sphere-app .sphere-sidebar,
body.sphere-app .living-planner-shell {
  max-height: none;
  margin: 0;
}

/* ── Portrait phones: the Sphere owns the screen (Nov 19, 2026) ────
 * On Aaron's Galaxy A16 the app column gave the stage what was left
 * after every bar took its share — about 153px of an 844px screen,
 * under the renderer's 180px minimum, so the phone got the 2D
 * fallback and a letterbox stage. Here the bars go slim and the
 * stage takes the screen: environment and Interact become one row
 * each, the top bar and selected-day bar tighten, and the container
 * carries a floor sized to the phone's own height. The guide bar's
 * share is handled by its slim default in sphere-deepening.css. */
@media (max-width: 720px) and (orientation: portrait) {
  body.sphere-app #sphere-container {
    min-height: clamp(300px, 45dvh, 520px);
  }

  body.sphere-app .sphere-app-topbar {
    padding-top: calc(0.3rem + env(safe-area-inset-top, 0px));
    padding-bottom: 0.3rem;
  }

  .sphere-app-top-btn {
    white-space: nowrap;
    min-height: 44px;
  }

  body.sphere-app .sphere-state-strip {
    margin: 0;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
  }

  /* Environment: one row — the reading, then its button beside it. */
  body.sphere-app .sphere-environment-bridge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
  }

  body.sphere-app .sphere-environment-bridge-text {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.sphere-app .sphere-environment-bridge .sphere-btn {
    flex: 0 0 auto;
    min-height: 32px;
  }

  /* Interact: one row — the button, then its hint beside it. */
  body.sphere-app .sphere-interact-bar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }

  body.sphere-app .sphere-interact-hint {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.72rem;
  }

  body.sphere-app .sphere-app-daybar {
    padding: 0.3rem 0.5rem;
  }

  .sphere-app-day-nav,
  .sphere-app-day-main {
    min-height: 44px;
  }

  .sphere-dock-btn {
    min-height: 48px;
  }
}

/* ── Reduced motion: tactile answers stay instant, travel stops ── */
@media (prefers-reduced-motion: reduce) {
  .sphere-app-home,
  .sphere-app-top-btn,
  .sphere-app-day-nav,
  .sphere-app-day-main,
  .sphere-dock-btn,
  body.sphere-app .sphere-sheet,
  body.sphere-app .sphere-app-scrim {
    transition: none;
  }
}
