:root { color-scheme: light; }
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background:#0b0b0f; color:#e9e9ef; }
a { color: inherit; text-decoration: none; }
.container { padding: 16px; max-width: 980px; margin: 0 auto; }
.topbar { position: sticky; top:0; display:flex; justify-content:space-between; align-items:center; padding:12px 16px; background: rgba(10,10,14,.88); backdrop-filter: blur(10px); border-bottom: 1px solid rgba(255,255,255,.08); }
.brand__title { font-weight: 700; letter-spacing:.4px; }
.nav a { margin-left: 12px; opacity:.9; }
.nav a:hover { opacity:1; }

.card { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.10); border-radius: 16px; padding: 16px; }
.h1 { font-size: 22px; margin: 0 0 12px; }
.muted { opacity: .75; }
.badge { display:inline-block; padding: 2px 10px; border-radius: 999px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.10); font-size: 12px; margin-left: 8px; }

.input { width:100%; padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,.12); background: rgba(0,0,0,.25); color: #e9e9ef; outline:none; }
.input:focus { border-color: rgba(255,255,255,.28); }
.form-row { display:flex; flex-direction:column; gap:6px; margin: 10px 0; }
.check { display:flex; gap:10px; align-items:center; margin: 10px 0; }
.actions { display:flex; gap:10px; margin-top: 14px; flex-wrap: wrap; }

.btn { padding: 10px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.16); color: #fff; cursor:pointer; }
.btn:hover { background: rgba(255,255,255,.22); }
.btn--ghost { background: transparent; }
.btn[disabled], .btn:disabled { opacity:.45; cursor:not-allowed; }

.page-head { display:flex; gap:12px; align-items:center; justify-content:space-between; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display:grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
@media (min-width: 720px){ .grid { grid-template-columns: repeat(4, minmax(0,1fr)); } }
.tile { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.10); border-radius: 16px; overflow:hidden; }
.tile__img { height: 120px; background: rgba(255,255,255,.04); display:flex; align-items:center; justify-content:center; }
.tile__img img { width:100%; height:100%; object-fit:cover; display:block; }
.tile__title { padding: 10px 12px; font-weight: 600; font-size: 14px; }

.list { display:flex; flex-direction:column; gap: 10px; }
.list__row { display:flex; gap: 12px; align-items:center; padding: 10px; border-radius: 16px; border: 1px solid rgba(255,255,255,.10); background: rgba(255,255,255,.05); }
.list__img { width: 64px; height: 48px; border-radius: 12px; overflow:hidden; background: rgba(255,255,255,.04); flex: 0 0 auto; display:flex; align-items:center; justify-content:center; }
.list__img img { width:100%; height:100%; object-fit:cover; }
.list__title { font-weight: 650; }

.ph { width: 64px; height: 48px; border-radius: 12px; background: rgba(255,255,255,.06); }
.ph--sm { width: 54px; height: 40px; }

.reader { display:flex; flex-direction:column; gap: 12px; }
.reader__meta { display:flex; justify-content:flex-start; }
.reader__text { font-size: 18px; line-height: 1.55; }
.reader__nav { display:flex; justify-content:space-between; gap: 10px; }
.media { border-radius: 16px; overflow:hidden; border: 1px solid rgba(255,255,255,.10); background: rgba(255,255,255,.04); }
.media img, .media video { width:100%; display:block; }
.note { margin-top: 14px; padding: 10px 12px; border-radius: 14px; border: 1px dashed rgba(255,255,255,.18); background: rgba(255,255,255,.04); }

.grid2 { display:grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 720px){ .grid2 { grid-template-columns: 1fr 1fr; gap: 10px; } }


/* ===== Theme + typography ===== */
body {
  font-size: calc(16px * var(--font-scale, 1));
}
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0f;
  --fg: #e9e9ef;
  --card: rgba(255,255,255,.06);
  --cardBorder: rgba(255,255,255,.10);
  --muted: rgba(255,255,255,.72);
  --topbarBg: rgba(10,10,14,.88);
  --topbarBorder: rgba(255,255,255,.08);
  --inputBg: rgba(0,0,0,.25);
  --inputBorder: rgba(255,255,255,.12);
  --frameBorder: rgba(255,255,255,.88);
}
body[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7fb;
  --fg: #0b0b0f;
  --card: rgba(0,0,0,.03);
  --cardBorder: rgba(0,0,0,.10);
  --muted: rgba(0,0,0,.62);
  --topbarBg: rgba(246,247,251,.88);
  --topbarBorder: rgba(0,0,0,.10);
  --inputBg: rgba(255,255,255,.78);
  --inputBorder: rgba(0,0,0,.16);
  --frameBorder: rgba(0,0,0,.88);
}

body {
  background: var(--bg);
  color: var(--fg);
}
.topbar {
  background: var(--topbarBg);
  border-bottom: 1px solid var(--topbarBorder);
}
.card {
  background: var(--card);
  border-color: var(--cardBorder);
}
.muted { opacity: 1; color: var(--muted); }
.badge { background: rgba(127,127,127,.12); border-color: var(--cardBorder); }

.input {
  background: var(--inputBg);
  border-color: var(--inputBorder);
  color: var(--fg);
}
.input:focus { border-color: color-mix(in srgb, var(--fg) 30%, transparent); }

/* ===== Topbar icons ===== */
.nav__icon {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--fg);
  border: 1px solid transparent;
}
.nav__icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav__icon:hover { background: rgba(127,127,127,.10); border-color: rgba(127,127,127,.18); }

/* ===== Page transitions ===== */
.page { animation: pageIn .18s ease-out both; }
.page.page--leave { animation: pageOut .12s ease-in both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pageOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-4px); } }

/* ===== Books: 3D cover + tilt ===== */
.grid--books { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 720px){ .grid--books { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tile--book .tile__img { height: 150px; padding: 10px; }
.book-3d {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  overflow: hidden;
  transform: perspective(900px) rotateY(-15deg);
  transform-origin: left center;
  box-shadow: 0 14px 34px rgba(0,0,0,.35);
  background: rgba(127,127,127,.10);
}
.book-3d::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 14px;
  height: 100%;
  background: rgba(0,0,0,.22);
  box-shadow: inset -1px 0 0 rgba(255,255,255,.10);
}
.book-3d::after {
  content: "";
  position: absolute;
  right: -10px;
  top: 8px;
  width: 10px;
  height: calc(100% - 16px);
  background: rgba(255,255,255,.55);
  border-radius: 0 12px 12px 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.10);
  opacity: .65;
}
.book-3d .img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display:block;
  transform: translateZ(0);
}

/* ===== Stories grid + square frames ===== */
.grid--stories { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
@media (min-width: 560px){ .grid--stories { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media (min-width: 920px){ .grid--stories { grid-template-columns: repeat(4, minmax(0,1fr)); } }

.tile__img--square { height: auto; padding: 10px; }
.frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--frameBorder);
  background: rgba(127,127,127,.10);
  position: relative;
}
.frame .img { width: 100%; height: 100%; object-fit: cover; display:block; }
.ph--square { width:100%; height:100%; border-radius: 12px; background: rgba(127,127,127,.18); }
.tile__title--center { text-align:center; }

/* ===== Skeleton + lazy image polish ===== */
.img { opacity: 0; transition: opacity .2s ease-out; }
.img.is-loaded { opacity: 1; }

.frame::before, .book-3d::before {
  /* keep pseudo elements above bg but below image */
  pointer-events: none;
}

/* Categories tag cloud */
.tag-cloud{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  justify-content:center;
  margin: 12px 0 18px;
}

.tag{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
  text-decoration:none;
  transition: transform .08s ease, opacity .12s ease;
}

/* Light mode: background 30% darker than page */
:root .tag{
  color: #111;
  background: rgba(0,0,0,.08);
}

/* Dark mode: background 30% lighter than page, font white */
.dark .tag{
  color: #fff;
  background: rgba(255,255,255,.12);
}

.tag:hover{ opacity:.9; transform: translateY(-1px); }

:root .tag.is-active{
  background: rgba(0,0,0,.16);
}
.dark .tag.is-active{
  background: rgba(255,255,255,.22);
}
