/* ═══════════════════════════════════════════════════════════════════════════
   CHIKARA OS · home.css
   The home screen: identity header, paged application grid, canonical-vector
   tiles, page dots, dock, gesture hint. Nothing here hard-codes an app.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── 1 · HOME LAYOUT ───────────────────────────────────────────────────── */

.home {
  padding:
    calc(var(--shell-status-h) + .5rem)
    0
    calc(env(safe-area-inset-bottom, 0px) + 6.5rem);
  background: transparent;
  /* The Gamazine atmosphere from materials.css shows through the home — home
     is the only surface that lets the environment fully speak. */
}

/* ─── 2 · HEADER ────────────────────────────────────────────────────────── */

.home__header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: .5rem calc(var(--shell-edge) + var(--safe-right)) 1rem calc(var(--shell-edge) + var(--safe-left));
}

.home__lead { min-width: 0; }

.home__date {
  font-family: var(--font-mono);
  font-size: var(--t-nano);
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: .35rem;
}

.home__greeting {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 5.2vw, 2.15rem);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -.014em;
  color: var(--text-primary);
}

.home__searchbtn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--glass-bg);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--glass-brd);
  color: var(--text-secondary);
  box-shadow: var(--shadow-1);
  transition:
    color var(--dur-fast) var(--ease-material),
    transform var(--dur-fast) var(--ease-material),
    box-shadow var(--dur-fast) var(--ease-material);
}
.home__searchbtn:hover {
  color: var(--text-primary);
  box-shadow: var(--shadow-2);
}
.home__searchbtn:active { transform: scale(.92); }
.home__searchbtn svg { display: block; }

/* ─── 3 · PAGES ─────────────────────────────────────────────────────────── */

.home__pages {
  flex: 1 1 auto;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  padding: 0 calc(var(--shell-edge) + var(--safe-right)) 0 calc(var(--shell-edge) + var(--safe-left));
  gap: 0;
}
.home__pages::-webkit-scrollbar { display: none; }

.home__page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: min-content;
  column-gap: 1rem;
  row-gap: 1.35rem;
  align-content: start;
  padding: .5rem 0 1rem;
}

/* App Library is always the final page. It occupies the same grid as a page
   but is visually distinguished by a plinth card that spans the whole row. */
.home__page--library {
  grid-template-columns: 1fr;
  align-content: start;
}

.library-plinth {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.15rem 1.2rem;
  border-radius: var(--r-lg);
  background-color: var(--surface-lift);
  background-image:
    linear-gradient(180deg, rgba(255,255,255,.55), rgba(255,255,255,0)),
    var(--tex-vel-grain);
  background-size: auto, 340px 340px;
  background-blend-mode: normal, soft-light;
  border: 1px solid var(--hairline);
  box-shadow: var(--sh-inset), var(--shadow-2);
  text-align: left;
  transition: transform var(--dur-base) var(--ease-material),
              box-shadow var(--dur-base) var(--ease-material);
}
html[data-theme="obsidian"] .library-plinth {
  background-image:
    linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,0)),
    var(--tex-obs-grain);
  background-size: auto, 380px 380px;
  box-shadow: var(--sh-inset-d), var(--shadow-2);
}
.library-plinth:active { transform: scale(.985); }
.library-plinth:hover  { box-shadow: var(--sh-inset), var(--shadow-3); }

.library-plinth__art {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  color: var(--accent);
}
.library-plinth__art svg { width: 26px; height: 26px; }

.library-plinth__text { flex: 1 1 auto; min-width: 0; }
.library-plinth__title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text-primary);
}
.library-plinth__sub {
  display: block;
  margin-top: 2px;
  font-size: var(--t-tiny);
  color: var(--text-muted);
}
.library-plinth__chev {
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-size: 1.55rem;
  line-height: 1;
  color: var(--accent);
  opacity: .8;
}

/* ─── 4 · TILES ─────────────────────────────────────────────────────────── */

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .55rem;
  min-width: 0;
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  transition: transform var(--dur-fast) var(--ease-material);
  -webkit-user-select: none;
  user-select: none;
}
.tile:active .tile__art { transform: scale(.88); }
.tile:active .tile__name { opacity: .8; }

.tile__art {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 76px;
  border-radius: 22%; /* squircle-ish, iOS-adjacent but not iOS */
  display: grid;
  place-items: center;
  isolation: isolate;
  overflow: hidden;
  /* Canonical plinth: vellum for the default theme, obsidian for dark. The
     vector is placed above this plinth, unchanged. */
  background-color: var(--surface-lift);
  background-image:
    radial-gradient(70% 60% at 30% 18%,
      rgba(255,255,255,.95) 0%, rgba(255,255,255,0) 62%),
    linear-gradient(180deg, rgba(255,255,255,.35), rgba(255,255,255,0)),
    var(--tex-vel-grain);
  background-size: auto, auto, 340px 340px;
  background-blend-mode: normal, normal, soft-light;
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.6),
    inset 0 -1px 0 rgba(31,26,22,.05),
    var(--shadow-1);
  transition:
    transform 240ms var(--ease-spring),
    box-shadow 240ms var(--ease-material);
}
html[data-theme="obsidian"] .tile__art {
  background-color: var(--surface-lift);
  background-image:
    radial-gradient(70% 60% at 30% 18%,
      rgba(255,255,255,.06) 0%, rgba(255,255,255,0) 62%),
    linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,0)),
    var(--tex-obs-grain);
  background-size: auto, auto, 380px 380px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.05),
    inset 0 0 0 1px rgba(246,240,226,.06),
    var(--shadow-1);
}

/* Specular highlight — a soft diagonal sheen across the top-left. */
.tile__gloss {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(135deg,
    rgba(255,255,255,.45) 0%,
    rgba(255,255,255,.08) 22%,
    rgba(255,255,255,0) 50%);
  mix-blend-mode: screen;
  opacity: .55;
}
html[data-theme="obsidian"] .tile__gloss { opacity: .18; }

.tile__icon {
  position: relative;
  z-index: 1;
  width: 62%;
  height: 62%;
  object-fit: contain;
  pointer-events: none;
  /* Guard against crude substitute icons: force vector SVG to scale cleanly. */
  image-rendering: -webkit-optimize-contrast;
}

.tile__name {
  display: block;
  max-width: 88%;
  font-family: var(--font-body);
  font-size: var(--t-tiny);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -.004em;
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(255,255,255,.55);
  transition: opacity var(--dur-fast) var(--ease-material);
}
html[data-theme="obsidian"] .tile__name {
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

.tile__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--gold-spec);
  background-size: 340% 100%;
  animation: gold-sweep 12s ease-in-out infinite;
  color: #241A0A;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0;
  display: grid;
  place-items: center;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(94,68,22,.5);
}

/* Featured tile — slightly larger presence via a top plinth ribbon. */
.tile--featured .tile__art::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1px solid rgba(201,151,58,.42);
  pointer-events: none;
}

/* Inactive / unavailable application */
.tile--muted { opacity: .5; filter: saturate(.6); }

/* ─── 5 · PAGE DOTS ─────────────────────────────────────────────────────── */

.home__dots {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .35rem;
  padding: .65rem 1rem .35rem;
}
.home__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  background: var(--text-muted);
  opacity: .35;
  transition:
    width 260ms var(--ease-architect),
    opacity 220ms var(--ease-material),
    background-color 220ms var(--ease-material);
}
.home__dot.is-active {
  width: 18px;
  border-radius: 999px;
  opacity: 1;
  background: var(--gold-spec);
  background-size: 340% 100%;
  animation: gold-sweep 16s ease-in-out infinite;
}

/* ─── 6 · DOCK ──────────────────────────────────────────────────────────── */

.dock {
  flex: 0 0 auto;
  margin: .35rem auto 0;
  padding: .7rem .85rem;
  display: flex;
  align-items: center;
  gap: .35rem;
  width: fit-content;
  max-width: calc(100% - 2 * (var(--shell-edge) + var(--safe-left)));
  border-radius: calc(var(--r-lg) + 6px);
  background-color: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  backdrop-filter: blur(22px) saturate(1.5);
  border: 1px solid var(--glass-brd);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.4),
    0 2px 10px rgba(31,26,22,.10),
    0 22px 48px rgba(31,26,22,.12);
}
html[data-theme="obsidian"] .dock {
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.06),
    0 2px 10px rgba(0,0,0,.4),
    0 22px 48px rgba(0,0,0,.55);
}

.dock__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: .3rem .45rem;
  border-radius: var(--r-md);
  transition: transform 220ms var(--ease-spring);
}
.dock__item:active { transform: scale(.9); }

.dock__icon {
  width: 44px;
  height: 44px;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  transition: transform 260ms var(--ease-spring);
}
.dock__item:hover .dock__icon { transform: translateY(-2px); }

.dock__name {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-muted);
  max-width: 52px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Active indicator — a small gold underline */
.dock__item.is-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold-spec);
  background-size: 300% 100%;
  animation: gold-sweep 8s ease-in-out infinite;
}

/* ─── 7 · GESTURE HINT ──────────────────────────────────────────────────── */

.home__gesture {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: var(--t-nano);
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms var(--ease-material);
}
.home__gesture.is-visible { opacity: .55; }

/* ─── 8 · LANDSCAPE / WIDE HOME ─────────────────────────────────────────── */

@media (min-width: 720px) {
  .home__page {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    column-gap: 1.15rem;
    row-gap: 1.5rem;
  }
  .tile__art { max-width: 84px; }
}
@media (min-width: 1024px) {
  .home__page {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    column-gap: 1.25rem;
  }
  .tile__art { max-width: 88px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .home { padding-top: calc(var(--shell-status-h) + .25rem); }
  .home__header { padding-bottom: .5rem; }
  .home__greeting { font-size: clamp(1.15rem, 3vw, 1.5rem); }
  .home__page { row-gap: 1rem; }
  .tile__art { max-width: 60px; }
  .tile__name { font-size: 10px; }
  .home__dots { padding-top: .35rem; }
  .dock { padding: .5rem .7rem; }
  .dock__icon { width: 38px; height: 38px; }
  .home__gesture { display: none; }
}

/* ─── 9 · REDUCED MOTION ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .home__pages { scroll-behavior: auto; }
  .tile__art,
  .tile__icon,
  .dock__icon,
  .home__dot,
  .dock__item {
    transition-duration: .001ms !important;
    animation: none !important;
  }
}
html[data-reduced-motion="true"] .home__pages { scroll-behavior: auto; }
html[data-reduced-motion="true"] .tile__art,
html[data-reduced-motion="true"] .tile__icon,
html[data-reduced-motion="true"] .dock__icon,
html[data-reduced-motion="true"] .home__dot,
html[data-reduced-motion="true"] .dock__item {
  transition-duration: .001ms !important;
  animation: none !important;
}
