/* ============================================================
 * EMOJI UNIVERSE - LEFT RAIL
 * Desktop: vertical fixed sidebar (Slack/Discord pattern).
 * Mobile:  bottom tab bar + slim topbar.
 * ============================================================ */

:root {
  --rail-w: 72px;
  --rail-w-expanded: 220px;
  --topbar-h: 56px;
  --bottombar-h: 64px;
}

/* -------------------- DESKTOP RAIL -------------------- */

.rail {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 max(12px, var(--safe-bottom, 0px));
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  border-right: 1px solid var(--color-border);
  z-index: var(--layer-header);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  transition: width var(--t-base) var(--ease-out-quart);
}
.rail::-webkit-scrollbar { display: none; }

.rail__brand {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--grad-accent);
  box-shadow: 0 8px 24px var(--color-accent-soft);
  margin-bottom: 14px;
  flex-shrink: 0;
  text-decoration: none;
  transition: transform var(--t-fast) var(--ease-out-back);
}
.rail__brand:hover { transform: scale(1.06) rotate(-2deg); }
.rail__brand-emoji {
  font-size: 22px;
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.5));
}

.rail__nav,
.rail__tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0 8px;
}

.rail__tools { margin-top: auto; }

.rail__item,
.rail__tool {
  position: relative;
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  width: 100%;
  padding: 8px 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--color-fg-dim);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast) ease, color var(--t-fast) ease,
              transform var(--t-fast) var(--ease-out-back);
  overflow: hidden;
  white-space: nowrap;
}

.rail__item:hover,
.rail__tool:hover {
  background: var(--color-surface-2);
  color: var(--color-fg);
}

.rail__item:active,
.rail__tool:active { transform: scale(0.96); }

.rail__item.is-active {
  background: var(--grad-accent);
  color: #000;
  font-weight: 700;
  box-shadow: 0 6px 18px var(--color-accent-soft);
}

.rail__item.is-active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 22%;
  bottom: 22%;
  width: 3px;
  border-radius: 3px;
  background: var(--color-accent);
  box-shadow: 0 0 12px var(--color-accent);
}

.rail__icon {
  font-size: 20px;
  line-height: 1;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.rail__label {
  font-size: 12.5px;
  letter-spacing: 0.01em;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity var(--t-base) ease, transform var(--t-base) ease;
  pointer-events: none;
}

.rail__divider {
  width: 36px;
  height: 1px;
  background: var(--color-border-strong);
  margin: 12px 0 12px;
  opacity: 0.7;
  flex-shrink: 0;
}

.rail__tool--accent {
  background: var(--color-surface-2);
  color: var(--color-fg);
  font-weight: 700;
}
.rail__tool--accent:hover {
  background: var(--grad-accent);
  color: #000;
}

/* Expand-on-hover for desktop */
@media (hover: hover) and (min-width: 1024px) {
  .rail:hover {
    width: var(--rail-w-expanded);
  }
  .rail:hover .rail__label {
    opacity: 1;
    transform: translateX(0);
  }
  .rail:hover .rail__divider {
    width: calc(100% - 24px);
  }
}

/* -------------------- TOOLTIPS for icon-only state -------------------- */

@media (min-width: 1024px) {
  .rail:not(:hover) .rail__item::after,
  .rail:not(:hover) .rail__tool::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 10px;
    background: var(--color-bg-2);
    border: 1px solid var(--color-border-strong);
    border-radius: 8px;
    font-size: 12px;
    color: var(--color-fg);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-fast) ease 100ms;
    box-shadow: var(--shadow-md);
    z-index: 5;
  }
  .rail:not(:hover) .rail__item:hover::after,
  .rail:not(:hover) .rail__tool:hover::after {
    opacity: 1;
  }
}

/* -------------------- BODY OFFSET -------------------- */

@media (min-width: 768px) {
  body {
    padding-left: var(--rail-w);
  }

  /* Hide the old top header + the new topbar on desktop */
  .app-header,
  .topbar { display: none; }

  /* Sticky toolbar sits at top of viewport (no header on desktop) */
  .sticky-toolbar { top: 0; }

  /* Hero takes full height (no header to subtract) */
  .hero { min-height: 100vh; }
  @supports (height: 100dvh) {
    .hero { min-height: 100dvh; }
  }
}

@media (max-width: 767px) {
  .sticky-toolbar {
    top: calc(var(--topbar-h) + var(--safe-top, 0px));
  }
  .hero {
    min-height: calc(100vh - var(--topbar-h));
  }
  @supports (height: 100dvh) {
    .hero { min-height: calc(100dvh - var(--topbar-h)); }
  }
}

/* -------------------- MOBILE: rail becomes bottom bar -------------------- */

.topbar {
  display: none;
}

@media (max-width: 767px) {
  body {
    padding-left: 0;
    padding-top: var(--topbar-h);
    padding-bottom: calc(var(--bottombar-h) + var(--safe-bottom, 0px));
  }

  /* Hide the old app-header completely - the topbar replaces it */
  .app-header { display: none !important; }

  /* TOPBAR */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--topbar-h) + var(--safe-top, 0px));
    padding-top: var(--safe-top, 0px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-inline: max(12px, var(--safe-left)) max(12px, var(--safe-right));
    background: color-mix(in oklab, var(--color-bg) 86%, transparent);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    border-bottom: 1px solid var(--color-border);
    z-index: var(--layer-header);
  }

  .topbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-fg);
    text-decoration: none;
    font-size: 15px;
  }
  .topbar__brand-icon {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 9px;
    background: var(--grad-accent);
    font-size: 17px;
    box-shadow: 0 4px 12px var(--color-accent-soft);
  }
  .topbar__brand-text strong {
    background: var(--grad-accent);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-left: 1px;
  }

  .topbar__actions {
    display: flex;
    gap: 6px;
  }
  .topbar__btn {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border-radius: 10px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-fg);
    font-size: 16px;
  }
  .topbar__btn:active { transform: scale(0.92); }

  /* RAIL → BOTTOM BAR */
  .rail {
    flex-direction: row;
    width: 100%;
    height: calc(var(--bottombar-h) + var(--safe-bottom, 0px));
    top: auto;
    bottom: 0;
    left: 0;
    padding: 8px max(8px, var(--safe-left)) calc(8px + var(--safe-bottom, 0px)) max(8px, var(--safe-right));
    border-right: none;
    border-top: 1px solid var(--color-border);
    align-items: stretch;
    overflow-x: auto;
    gap: 0;
  }

  .rail__brand,
  .rail__divider,
  .rail__tools {
    display: none;
  }

  .rail__nav {
    flex-direction: row;
    gap: 2px;
    justify-content: space-around;
    width: 100%;
    padding: 0;
  }

  .rail__item {
    flex: 1 1 0;
    min-width: 44px;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    justify-items: center;
    padding: 6px 4px;
    border-radius: 12px;
    text-align: center;
    color: var(--color-fg-dim);
    background: transparent;
    gap: 2px;
  }

  .rail__item.is-active {
    background: var(--color-surface-2);
    color: var(--color-fg);
    font-weight: 700;
    box-shadow: none;
  }
  .rail__item.is-active::before { display: none; }
  .rail__item.is-active .rail__icon {
    transform: translateY(-1px);
    filter: drop-shadow(0 2px 8px var(--color-accent-soft));
  }

  .rail__icon {
    width: 24px;
    height: 24px;
    font-size: 18px;
  }
  .rail__label {
    opacity: 1;
    transform: none;
    font-size: 9.5px;
    letter-spacing: 0.03em;
    pointer-events: none;
    color: inherit;
  }

  /* Indicator pip above active tab */
  .rail__item.is-active::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 18px;
    height: 3px;
    border-radius: 2px;
    background: var(--color-accent);
    box-shadow: 0 0 8px var(--color-accent);
  }
}

/* -------------------- TINY ROOM: super-narrow phones -------------------- */

@media (max-width: 380px) {
  .rail__item { padding: 6px 2px; }
  .rail__icon { font-size: 16px; }
  .rail__label { font-size: 9px; }
}

/* -------------------- DARK BG / FIRE up the colors -------------------- */

[data-theme="paper"] .rail,
[data-theme="solar"] .rail {
  background: color-mix(in oklab, var(--color-bg) 92%, transparent);
}
