/* ─────────────────────────────────────────
   LAYOUT  —  app shell, sidebar, bottom nav,
              page routing, detail layout
───────────────────────────────────────── */

/* ── App shell ── */
.app-shell    { display: flex; min-height: 100vh; }

.main-content {
  margin-left: var(--nav);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Page routing ── */
.page { display: none; flex-direction: column; flex: 1; min-height: 0; animation: fadeUp 320ms var(--ease-out); }
.page.active { display: flex; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Scroll-reveal (progressive enhancement, see js/motion.js) ──
   The hidden starting state below only applies once <html> carries
   .js-reveal, which motion.js adds itself — and only when
   IntersectionObserver is supported. If that script fails to load or
   errors for any reason, .js-reveal is never added and every
   [data-reveal] element just displays normally, immediately, with no
   animation. Content can never end up permanently invisible because of
   this feature — it can only ever be enhanced, never broken, by it.
   Staggering is driven by --reveal-delay, set per-element by motion.js. */
.js-reveal [data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .7s var(--ease-out), transform .7s var(--ease-out);
  transition-delay: var(--reveal-delay, 0ms);
  will-change: opacity, transform;
}
.js-reveal [data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Icon sidebar (desktop) ── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--nav);
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
  z-index: 200;
  transition: background .25s;
}

.sidebar-logo {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-2);
  letter-spacing: .06em;
  margin-bottom: 20px;
  user-select: none;
}

.nav-icons {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
}

.nav-icon-btn {
  position: relative;
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-3);
  cursor: pointer;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
  /* Make li elements behave like buttons for keyboard nav */
  list-style: none;
}
.nav-icon-btn:hover  { background: var(--bg-hover); color: var(--fg-2); }
.nav-icon-btn.active { background: var(--bg-card);  color: var(--fg); }
.nav-icon-btn svg { pointer-events: none; }

/* Tooltip */
.nav-tip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1a1a1a;
  color: #f0f0f0;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 7px 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t) var(--ease);
  z-index: 999;
}
.nav-icon-btn:hover .nav-tip { opacity: 1; }

body.dark .nav-tip { background: #e8e6e2; color: #111; }

.nav-tip-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  background: rgba(255,255,255,0.14);
  color: #f0f0f0;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 4px;
  padding: 1px 5px;
  min-width: 18px;
  line-height: 16px;
}
body.dark .nav-tip-key {
  background: rgba(0,0,0,0.12);
  color: #111;
  border-color: rgba(0,0,0,0.18);
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

/* ── Detail layout (work / writing / store case pages) ── */
.detail-layout { display: flex; flex: 1; min-height: 0; }

.detail-side {
  width: 260px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
  display: flex; flex-direction: column;
}

.detail-side-top {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  --progress: 0;
}
.detail-side-top::before {
  content: '';
  position: absolute; inset: 0;
  width: calc(var(--progress) * 100%);
  background: var(--bg-hover);
  transition: width 0.1s linear;
  pointer-events: none;
  z-index: 0;
}
.detail-side-top > * { position: relative; z-index: 1; }

.ds-label { font-size: 10px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--fg-3); margin-bottom: 6px; }
.ds-title { font-size: 14px; font-weight: 600; color: var(--fg); line-height: 1.3; margin-bottom: 4px; }
.ds-sub   { font-size: 12px; color: var(--fg-2); line-height: 1.4; }

.detail-side-next   { padding: 16px 0 0; flex: 1; }
.ds-next-label      { font-size: 10px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--fg-3); padding: 0 20px; margin-bottom: 8px; }
.ds-next-item       { padding: 12px 20px; cursor: pointer; transition: background var(--t); }
.ds-next-item:hover { background: var(--bg-card); }
.ds-next-title      { font-size: 13px; font-weight: 500; color: var(--fg); margin-bottom: 2px; }
.ds-next-sub        { font-size: 12px; color: var(--fg-3); line-height: 1.4; }

.detail-main {
  flex: 1;
  padding: 40px 48px;
  max-width: 700px;
  min-height: 0;
  overflow-y: auto;
}

/* ── Bottom nav (mobile) ── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bnav-h);
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 300;
  align-items: stretch;
  justify-content: space-around;
  padding: 0 4px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.bnav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  border-radius: var(--r-sm);
  padding: 6px 4px;
  color: var(--fg-3);
  transition: color var(--t) var(--ease), background var(--t) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.bnav-btn:hover  { background: var(--bg-hover); color: var(--fg-2); }
.bnav-btn.active { color: var(--fg); }
.bnav-btn.active .bnav-icon-wrap { background: var(--bg-card); }

.bnav-icon-wrap {
  width: 32px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t) var(--ease);
}

.bnav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .01em;
  line-height: 1;
  white-space: nowrap;
}

/* ── Bottom nav sheets ── */
.bnav-sheet-backdrop {
  display: none;
  position: fixed; inset: 0;
  z-index: 290;
  background: rgba(0,0,0,.18);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: opacity .2s var(--ease);
}
.bnav-sheet-backdrop.open { display: block; }

.bnav-sheet,
.bnav-content-sheet {
  position: fixed;
  left: 8px; right: 8px;
  bottom: calc(var(--bnav-h) + 10px);
  background: var(--bg);
  border: 1px solid var(--border-s);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.06);
  z-index: 310;
  overflow: hidden;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s var(--ease), opacity .18s var(--ease);
}
.bnav-sheet.open,
.bnav-content-sheet.open { transform: translateY(0); opacity: 1; pointer-events: auto; }

.bnav-sheet-head {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.bnav-sheet-title { font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-3); }

.bnav-sheet-item {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 18px;
  cursor: pointer;
  transition: background var(--t) var(--ease);
  border-bottom: 1px solid var(--border);
}
.bnav-sheet-item:last-child { border-bottom: none; }
.bnav-sheet-item:hover { background: var(--bg-card); }

.bnav-sheet-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-2); flex-shrink: 0;
  transition: background var(--t), border-color var(--t);
}
.bnav-sheet-item:hover .bnav-sheet-icon { background: var(--bg-hover); border-color: var(--border-s); }

.bnav-sheet-info  { flex: 1; min-width: 0; }
.bnav-sheet-name  { font-size: 14px; font-weight: 500; color: var(--fg); }
.bnav-sheet-sub   { font-size: 12px; color: var(--fg-3); margin-top: 1px; }

.bnav-sheet-divider {
  padding: 10px 18px 4px;
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--fg-3);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.bnav-sheet-utils {
  display: flex; align-items: center;
  padding: 10px 18px; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.bnav-sheet-util-btn {
  flex: 1;
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--fg-2);
  transition: background var(--t), color var(--t), border-color var(--t);
}
.bnav-sheet-util-btn:hover { background: var(--bg-hover); color: var(--fg); border-color: var(--border-s); }
.bnav-sheet-util-btn svg { flex-shrink: 0; }

/* ── Responsive breakpoints ── */
@media (max-width: 860px) {
  .sidebar       { display: none; }
  .main-content  {
    margin-left: 0;
    padding-bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav    { display: flex; padding-bottom: env(safe-area-inset-bottom, 0px); }
  /* Detail pages: the whole layout scrolls (not .detail-main), so Up Next
     can follow the article. Order: Now Viewing bar (sticky, with
     progress) → [Store: buy block] → content → Up Next. */
  .detail-layout { flex-direction: column; overflow-y: auto; position: relative; }
  .detail-side   { display: contents; }
  .detail-side-top {
    order: 0; flex-shrink: 0;
    position: sticky; top: 0; z-index: 5;
    background: var(--bg);
  }
  .store-buy-block  { order: 1; flex-shrink: 0; }
  .detail-main   { order: 2; flex: none; overflow: visible; padding: 24px 20px; }
  .detail-side-next {
    order: 3; flex: none;
    border-top: 1px solid var(--border);
    padding: 16px 0 32px;
  }
  .site-footer   { display: none; }
  .toast         { bottom: calc(var(--bnav-h) + 12px); }
  .search-overlay { padding-top: 48px; padding-left: 12px; padding-right: 12px; align-items: flex-start; }
}
