/* ==========================================================================
   App layout, mobile first.
   <768px   : top bar + bottom nav + floating "post" button (FAB)
   768-1099 : icon rail on the left, feed in the middle
   >=1100px : left nav with labels | feed | posters column
   ========================================================================== */

.app {
  min-height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ---------- brand ----------
   Inside the app the brand is only the "posters" wordmark. The "p" tile is
   reserved for the browser tab / app icon (core/static/core/brand/). */

.brand-wordmark {
  height: 30px;
  width: auto;
  max-width: 100%;
  color: var(--text);
}

/* ---------- top bar (mobile) ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--space-2) 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
  transition: transform var(--dur-slow) var(--ease-out);
}

.topbar__brand {
  grid-column: 2;
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
}

.topbar__brand .brand-wordmark {
  height: 30px;
}

/* your avatar opens the side menu (v0.9); a dot when the Updatelog has news */
.topbar__me {
  position: relative;
  grid-column: 1;
  grid-row: 1;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--radius-full);
  transition: transform var(--dur-fast) var(--ease-out);
}

.topbar__me:active {
  transform: scale(0.92);
}

.topbar__me .avatar {
  --avatar: 32px;
}

.topbar__dot {
  top: 5px;
  right: 4px;
}

.topbar__brand {
  grid-row: 1;
}

html[data-scroll="down"] .topbar {
  transform: translateY(-100%);
}

/* ---------- side navigation (tablet & desktop) ---------- */

.sidenav {
  display: none;
}

/* ---------- main column ---------- */

.main {
  min-width: 0;
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 96px);
}

/* ---------- posters column / sheet ---------- */

.aside {
  display: none;
}

/* ---------- bottom navigation (mobile) ---------- */

.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  /* Inicio · Posters · Perfil (v0.9); Notificaciones (v0.12) and Mensajes (v0.17) join it */
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border);
}

.bottomnav__item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  color: var(--text-2);
  --icon-size: 27px;
  transition: color var(--dur-fast);
}

.bottomnav__item:active .icon {
  transform: scale(0.88);
}

.bottomnav__item .icon {
  transition: transform var(--dur-fast) var(--ease-out);
}

.bottomnav__item.is-active {
  color: var(--text);
}

.bottomnav__item[aria-disabled="true"] {
  color: var(--text-3);
}

/* "Something new" marks on navigation icons (Updatelog entries you haven't read) */
.nav-icon {
  position: relative;
  display: grid; /* a real box around the icon, so the dots sit on its top-right corner */
  place-items: center;
}

.nav-dot {
  position: absolute;
  top: -1px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--like);
  box-shadow: 0 0 0 2px var(--bg);
  animation: pop-in var(--dur-slow) var(--ease-spring);
}

/* "There are new posts" on Inicio (v0.5.1): no number, just a dot in the brand color (white in dark mode,
   black in light mode, where white wouldn't show). Pops in, then breathes once. */
.nav-dot--new {
  background: var(--accent);
  animation: pop-in var(--dur-slow) var(--ease-spring), new-dot-pulse 1.6s var(--ease-out) var(--dur-slow) 1;
}

.nav-dot[hidden] {
  display: none;
}

@keyframes new-dot-pulse {
  0% {
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 2px var(--accent);
  }
  100% {
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 9px transparent;
  }
}

.nav-count {
  display: inline-block;
  min-width: 20px;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--like);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  vertical-align: 2px;
}

/* Active/inactive icon pairs: the filled icon marks the current section */
.nav-icon .icon--on,
.is-active .nav-icon .icon--off {
  display: none;
}

.is-active .nav-icon .icon--on {
  display: block;
}

/* ---------- floating action button (mobile) ---------- */

.fab {
  position: fixed;
  right: calc(var(--space-4) + var(--safe-right));
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--space-4));
  z-index: 31;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  /* the spring easing gives the "shrink and bounce back" when you let go */
  transition: transform 360ms var(--ease-spring), opacity var(--dur-base) var(--ease-out), box-shadow var(--dur-base);
}

.fab .pencil {
  width: 32px;
  height: 32px;
}

.fab:active {
  transform: scale(0.86);
  transition-duration: var(--dur-fast);
}

/* hides while you scroll down the feed and comes back when you scroll up */
html[data-scroll="down"] .fab {
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.6);
  transition: transform 360ms var(--ease-spring), opacity var(--dur-base) var(--ease-out), visibility 0s linear var(--dur-base);
}

/* and while any sheet or the editor is open (after a beat, so its "writing" gesture is seen) */
html.is-locked .fab {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.6);
  transition: transform 360ms var(--ease-spring) 140ms, opacity var(--dur-base) var(--ease-out) 140ms,
    visibility 0s linear 340ms;
}

/* ==========================================================================
   Tablet: icon rail
   ========================================================================== */

@media (min-width: 768px) {
  .app {
    display: grid;
    grid-template-columns: 76px minmax(0, 600px);
    justify-content: center;
    column-gap: var(--space-6);
  }

  .topbar,
  .bottomnav,
  .fab {
    display: none;
  }

  .main {
    padding-top: var(--space-4);
    padding-bottom: var(--space-10);
  }

  .sidenav {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    height: 100dvh;
    padding: var(--space-4) 0;
  }

  .sidenav__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    margin-bottom: var(--space-3);
    border-radius: var(--radius-md);
  }

  .sidenav__brand {
    min-height: 52px;
  }

  .sidenav__brand .brand-wordmark {
    height: 18px; /* fits the 76px icon rail */
  }

  .sidenav__list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    width: 100%;
    align-items: center;
  }

  .sidenav__item {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-height: 52px;
    min-width: 52px;
    justify-content: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    color: var(--text-2);
    font-size: var(--fs-lg);
    font-weight: 500;
    --icon-size: 27px;
    transition: background-color var(--dur-fast), color var(--dur-fast);
  }

  .sidenav__item:hover {
    background: var(--accent-soft);
    color: var(--text);
  }

  .sidenav__item.is-active {
    color: var(--text);
    font-weight: 700;
  }

  .sidenav__item[aria-disabled="true"] {
    color: var(--text-3);
  }

  .sidenav__label {
    display: none;
  }

  .sidenav .sidenav__compose {
    margin-top: var(--space-3);
    width: 52px;
    height: 52px;
    padding: 0;
    box-shadow: 0 0 0 1px var(--border);
    transition: transform 360ms var(--ease-spring), box-shadow var(--dur-fast), opacity var(--dur-fast);
  }

  .sidenav .sidenav__compose:active:not(:disabled) {
    transform: scale(0.9);
    transition-duration: var(--dur-fast);
  }

  .sidenav .sidenav__compose .sidenav__label {
    display: none;
  }

  .sidenav__footer {
    margin-top: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
  }

  /* the side menu is for phones; tablets and PC have the side nav */
  .drawer {
    display: none !important;
  }
}

/* ==========================================================================
   Desktop: three columns
   ========================================================================== */

@media (min-width: 1100px) {
  .app {
    grid-template-columns: 248px minmax(0, 600px) 320px;
    column-gap: var(--space-8);
  }

  .sidenav {
    align-items: stretch;
    padding: var(--space-5) 0 var(--space-4);
  }

  .sidenav__brand {
    padding: var(--space-1) var(--space-4) var(--space-2);
  }

  .sidenav__brand .brand-wordmark {
    height: 40px;
  }

  .sidenav__list {
    align-items: stretch;
  }

  .sidenav__item {
    justify-content: flex-start;
    padding: var(--space-2) var(--space-4);
  }

  .sidenav__label {
    display: inline;
  }

  /* with labels visible the count says it; the dot is for the icon-only rail */
  .sidenav .nav-dot {
    display: none;
  }

  /* ...except "new posts", which has no count */
  .sidenav .nav-dot--new:not([hidden]) {
    display: block;
  }

  .sidenav .sidenav__compose {
    width: 100%;
    height: 52px;
    font-size: var(--fs-lg);
  }

  .sidenav .sidenav__compose .sidenav__label {
    display: inline;
  }

  .sidenav .sidenav__compose .pencil {
    width: 24px;
    height: 24px;
    margin-left: -6px;
  }

  .sidenav__footer {
    align-items: stretch;
  }

  .sidenav__item--posters {
    display: none;
  }

  .aside {
    display: block;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: var(--space-5) 0;
    overflow-y: auto;
  }

  .aside .aside__close,
  .aside .aside__grabber {
    display: none;
  }
}

/* ---------- side menu on phones (v0.9, the roadmap's "drawer") ---------- */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 55;
}

.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.drawer__panel {
  position: absolute;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: min(320px, 84vw);
  padding: calc(var(--safe-top) + var(--space-3)) var(--space-3) calc(var(--safe-bottom) + var(--space-3));
  padding-left: calc(var(--safe-left) + var(--space-3));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
  box-shadow: var(--shadow-lg);
  transition: transform var(--dur-fast) var(--ease-out);
}

/* opening / closing (Alpine x-transition classes; the root's opacity sets the duration) */
.drawer-anim {
  transition: opacity 280ms var(--ease-out);
}

.drawer-anim .drawer__panel {
  transition: transform 280ms var(--ease-spring);
}

.drawer-out {
  opacity: 0;
}

.drawer-out .drawer__panel {
  transform: translateX(-104%);
}

.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.drawer__me {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-1);
  border-radius: var(--radius-md);
}

.drawer__name {
  overflow: hidden;
  font-size: var(--fs-xl);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-4);
  padding: 0 var(--space-1) var(--space-3);
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.drawer__stats a {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-height: var(--tap);
  padding-top: 12px;
}

.drawer__stats strong {
  color: var(--text);
}

.drawer__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.drawer__item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  min-height: 52px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: 600;
  text-align: left;
  --icon-size: 24px;
  transition: background-color var(--dur-fast);
}

.drawer__item:active,
.drawer__item:hover {
  background: var(--accent-soft);
}

.drawer__item.is-active {
  font-weight: 800;
}

.drawer__item.is-danger {
  color: var(--danger);
}

.drawer__item .nav-count {
  margin-left: auto;
}

.drawer__sep {
  height: 1px;
  margin: var(--space-2) var(--space-3);
  background: var(--border);
}

.drawer__foot {
  margin-top: auto;
  padding-top: var(--space-3);
}
/* v0.11: the Posters column lives in the shell; on the /posters/ page (which already is the list) it steps aside */
html[data-nav="people"] .aside .people {
  display: none;
}
/* v0.11, the installed app on iPhone: the status bar is see-through (white clock); the strip under it is always
   black, so the clock reads in the light theme too */
html.is-app .app::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  height: var(--safe-top);
  background: #000;
  pointer-events: none;
}