/* PunkRecords — native mobile UI (phones only).
   Loaded with media="(max-width: 640px)", so nothing here can touch desktop.
   Concept from a Gemini Argon (high thinking) review, 2026-11-08: "pocket monograph":
   glass top bar, bottom tab bar, hairline list feed, swipe shelves, floating reading dock. */

:root {
  --mob-header-h: 52px;
  --mob-tab-h: 58px;
  --mob-px: 16px;
  --mob-read-px: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --glass: color-mix(in srgb, var(--bg) 86%, transparent);
  --glass-float: color-mix(in srgb, var(--surface) 92%, transparent);
  --shadow-float: 0 10px 30px -6px rgba(40, 28, 16, .18), 0 2px 8px rgba(40, 28, 16, .07);
  --spring: cubic-bezier(.2, .8, .2, 1);
}
[data-theme="dark"] { --shadow-float: 0 12px 32px -4px rgba(0, 0, 0, .55), 0 2px 10px rgba(0, 0, 0, .35); }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--mob-header-h) + 64px); }
body { -webkit-tap-highlight-color: transparent; overflow-x: hidden; padding-bottom: calc(var(--mob-tab-h) + var(--safe-bottom)); }
html[data-page="admin"] body { padding-bottom: 0; }
a, button { touch-action: manipulation; }

/* ---------- 1. Top bar: brand + two tools, nothing else ---------- */
.site-header {
  padding-top: var(--safe-top);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
}
.header-inner { height: var(--mob-header-h); min-height: 0; padding: 0 var(--mob-px) !important; gap: 8px; }
.top-nav, .mob-tabs, .header-tools .show-sm { display: none !important; }
html:not([data-page="admin"]) .auth-box { display: none !important; }
.brand { gap: 8px; min-height: 44px; }
.brand-mark { width: 26px; height: 26px; }
.brand-name { font-size: 18px !important; }
.header-tools { gap: 6px; }
.header-tools .icon-btn {
  width: 38px; height: 38px; min-width: 38px; padding: 0;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  transition: transform .12s var(--spring), background-color .12s ease;
}
.header-tools .icon-btn:active { transform: scale(.92); background: var(--surface-2); }
.lang-menu { right: 0; }

/* ---------- 2. Bottom tab bar ---------- */
.app-tabbar {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr);
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: calc(var(--mob-tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
html[data-page="admin"] .app-tabbar { display: none !important; }
.app-tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--mob-tab-h); color: var(--faint);
  font: 600 11px var(--sans); letter-spacing: .02em;
  transition: color .15s ease, transform .12s var(--spring);
}
.app-tab svg { width: 22px; height: 22px; }
.app-tab:active { transform: scale(.9); }
.app-tab::before {
  content: ''; position: absolute; top: 0; width: 26px; height: 3px; border-radius: 0 0 4px 4px;
  background: currentColor; opacity: 0; transform: scaleX(.3); transition: opacity .2s ease, transform .25s var(--spring);
}
/* which tab is lit: driven by the page, no JS needed */
html[data-page="home"] .app-tab[data-tab="sci"],
html[data-page="post"]:not([data-section="fiction"]) .app-tab[data-tab="sci"] { color: var(--sci); }
html[data-page="worlds"] .app-tab[data-tab="fic"],
html[data-section="fiction"] .app-tab[data-tab="fic"] { color: var(--fic); }
html[data-page="chat"] .app-tab[data-tab="chat"],
html[data-page="account"] .app-tab[data-tab="me"],
html[data-page="auth"] .app-tab[data-tab="me"],
html[data-page="reset"] .app-tab[data-tab="me"] { color: var(--ink); }
html[data-page="home"] .app-tab[data-tab="sci"]::before,
html[data-page="post"]:not([data-section="fiction"]) .app-tab[data-tab="sci"]::before,
html[data-page="worlds"] .app-tab[data-tab="fic"]::before,
html[data-section="fiction"] .app-tab[data-tab="fic"]::before,
html[data-page="chat"] .app-tab[data-tab="chat"]::before,
html[data-page="account"] .app-tab[data-tab="me"]::before,
html[data-page="auth"] .app-tab[data-tab="me"]::before,
html[data-page="reset"] .app-tab[data-tab="me"]::before { opacity: 1; transform: none; }
.app-tab[data-tab="fic"] .app-tab-label { font-style: italic; }

/* ---------- 3. Home / Ether masthead ---------- */
html[data-page="home"] main.shell, html[data-page="worlds"] main.shell { padding-left: 0; padding-right: 0; }
.home-intro, .ether-intro { padding: 22px var(--mob-px) 18px !important; max-width: none; }
.home-kicker, .ether-kicker { font-size: 11px; margin-bottom: 8px; }
.home-title { font-size: 31px; line-height: 1.08; }
.ether-title { font-size: 36px; }
.home-dek, .ether-dek { font-size: 16px; line-height: 1.45; margin-top: 10px; }
.home-doors { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.door { min-height: 60px; padding: 10px 26px 10px 12px; border-radius: 14px; box-shadow: none; }
.door:hover { transform: none; box-shadow: none; }
.door:active { transform: scale(.97); }
.door-label { font-size: 16px; }
.door-sub { font-size: 12px; line-height: 1.3; }
.door-arrow { right: 10px; font-size: 16px; }

/* ---------- 4. Featured story ---------- */
.hero { margin: 4px var(--mob-px) 6px !important; border-radius: 20px; }
.hero-card { min-height: 0; padding: 22px 18px 18px; border-radius: 20px; transition: transform .14s var(--spring); }
.hero-card.has-cover { min-height: 340px; }
.hero-card:active { transform: scale(.985); }
.hero-title { font-size: 24px; line-height: 1.18; }
.hero-excerpt { font-size: 15px; line-height: 1.5; margin-bottom: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hero-card .chip { margin-bottom: 12px; }

/* ---------- 5. Sticky search + chips, hairline list feed ---------- */
.feed-layout { display: flex !important; flex-direction: column; gap: 0; margin-top: 10px; }
.feed-main { min-width: 0; }
.feed-main > .section-head { padding: 14px var(--mob-px) 0; margin: 0; }
.feed-tools {
  position: sticky; top: calc(var(--mob-header-h) + var(--safe-top)); z-index: 30;
  display: flex; flex-direction: column; gap: 8px; margin: 0;
  padding: 10px var(--mob-px);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.search-box { width: 100%; max-width: none; height: 42px; border-radius: 999px; }
.search-box input { font-size: 16px; }
.topic-chips {
  display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px;
  margin: 0 calc(var(--mob-px) * -1); padding: 0 var(--mob-px);
  scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
}
.topic-chips::-webkit-scrollbar { display: none; }
.topic-chips > * { flex: none; min-height: 34px; white-space: nowrap; scroll-snap-align: start; }

.post-card {
  grid-template-columns: minmax(0, 1fr) 84px;
  grid-template-areas: "chip thumb" "body thumb" "meta meta";
  gap: 6px 14px;
  padding: 16px var(--mob-px);
  border-bottom: 1px solid var(--border);
}
.post-card:active { background: var(--surface-2); }
.post-card > .chip { grid-area: chip; margin-left: 0 !important; align-self: start; }
.post-card > div { grid-area: body; min-width: 0; }
.post-card > .thumb {
  grid-area: thumb; display: grid !important; grid-row: auto;
  width: 84px; height: 84px; min-height: 0; border-radius: 14px; align-self: start;
}
.post-card > .card-meta { grid-area: meta; margin-top: 6px; font-size: 12.5px; gap: 7px; }
.post-card h3 { font-size: 18px; line-height: 1.28; font-weight: 700; }
.post-card .dek { font-size: 14px; line-height: 1.45; margin-top: 4px; }
.card-actions { margin-left: auto; gap: 2px; }
.card-actions > * { min-height: 36px; min-width: 36px; }

/* ---------- 6. Most Read and side cards as swipe shelves ---------- */
.feed-side { display: block !important; padding: 22px 0 6px; margin-top: 8px; background: var(--surface-2); border-top: 1px solid var(--border); }
.feed-side .side-card { background: transparent; border: 0; box-shadow: none; padding: 0; margin: 0 0 18px; }
.feed-side .side-card:not(#popular) { margin: 0 var(--mob-px) 18px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
#popular .section-head { padding: 0 var(--mob-px); margin-bottom: 10px; }
.popular-list {
  display: flex; gap: 10px; overflow-x: auto; margin: 0; padding: 2px var(--mob-px) 8px;
  scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.popular-list::-webkit-scrollbar { display: none; }
.popular-list > li {
  flex: 0 0 74%; scroll-snap-align: start; margin: 0; padding: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.popular-list > li:active { transform: scale(.98); }

/* ---------- 7. Article: book-like reading + floating dock ---------- */
.post-shell { padding: 14px var(--mob-read-px) 120px; }
.crumbs { display: inline-flex; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); font-size: 12.5px; margin-bottom: 14px; }
.post-title { font-size: 31px; line-height: 1.12; }
.post-dek { font-size: 18px; line-height: 1.45; }
.post-meta { font-size: 13px; gap: 8px; padding: 12px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.post-band { margin: 16px calc(var(--mob-read-px) * -1) 22px !important; border-radius: 0 !important; }
.article-body { font-size: 19px; line-height: 1.72; }
.article-body img, .article-body figure { max-width: none; width: calc(100% + var(--mob-read-px) * 2); margin-left: calc(var(--mob-read-px) * -1); margin-right: calc(var(--mob-read-px) * -1); border-radius: 0; }
.article-body pre, .article-body table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: 14px; }
.toc { border-radius: 14px; }

/* the top action row becomes a floating glass dock above the tab bar */
.post-actions.top {
  position: fixed; left: 50%; bottom: calc(var(--mob-tab-h) + var(--safe-bottom) + 12px); z-index: 55;
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 5px 8px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--glass-float);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow-float);
  max-width: calc(100vw - 32px);
  animation: dock-in .35s var(--spring) both;
}
@keyframes dock-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
.post-actions.top > *, .post-actions.top .share-row > * { min-height: 40px; min-width: 40px; }
.post-actions.top .share-row { display: inline-flex; gap: 2px; }
.post-actions:not(.top) { flex-wrap: wrap; gap: 10px; }

.related { margin-top: 30px; }
.related-grid {
  display: flex !important; gap: 10px; overflow-x: auto;
  margin: 0 calc(var(--mob-read-px) * -1); padding: 2px var(--mob-read-px) 8px;
  scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.related-grid::-webkit-scrollbar { display: none; }
.related-card { flex: 0 0 76%; scroll-snap-align: start; }
.comments textarea, .comments input, .form input, .form textarea { font-size: 16px; }

/* ---------- 8. Chat fills the space between the bars ---------- */
html[data-page="chat"] body { overflow: hidden; }
.chat-shell { height: calc(100dvh - var(--mob-header-h) - var(--safe-top) - var(--mob-tab-h) - var(--safe-bottom)) !important; }
.chat-app input, .chat-app textarea { font-size: 16px; }
html[data-page="chat"] .site-footer { display: none; }

/* ---------- 9. Footer: a short colophon ---------- */
.site-footer { margin-top: 36px; }
.footer-inner { padding: 30px var(--mob-px) 24px !important; }
.footer-top { flex-direction: column; gap: 22px; margin-bottom: 22px; }
.site-footer .footer-tag { font-size: 16px; }
.site-footer .footer-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; }
.site-footer .footer-cols a { padding: 6px 0; }
.site-footer .footer-note { font-size: 12px; }

/* ---------- 10. Feel ---------- */
.btn, .chip { transition: transform .12s var(--spring); }
.btn:active, .chip:active { transform: scale(.96); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
