/* =========================================================
   Page-specific styles — mobile-first
   ========================================================= */

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: calc(100vh - var(--topbar-h));
    display: grid; grid-template-columns: 1fr; align-items: stretch;
}
.auth-art {
    background:
      radial-gradient(circle at 30% 30%, rgba(201,162,39,.18), transparent 60%),
      linear-gradient(135deg, var(--ink) 0%, var(--ink-3) 100%);
    color: var(--ivory);
    padding: 40px 24px;
    display: flex; flex-direction: column; justify-content: center;
    position: relative; overflow: hidden;
}
.auth-art::before {
    content: ''; position: absolute; inset: 16px;
    border: 2px solid var(--gold); border-radius: 18px; pointer-events: none; opacity: .6;
}
.auth-art::after {
    content: ''; position: absolute; inset: 24px;
    border: 1px solid var(--gold-soft); border-radius: 14px; pointer-events: none; opacity: .4;
}
.auth-art h1 { color: var(--gold-soft); font-size: clamp(1.6rem, 4vw, 3.2rem); }
.auth-art .quote {
    font-style: italic; font-size: 1rem; line-height: 1.7; color: rgba(251,249,243,.85);
    border-left: 3px solid var(--gold); padding-left: 18px; margin-top: 24px;
}
.auth-art .quote .author { display: block; margin-top: 12px; font-style: normal; color: var(--gold-soft); font-family: var(--font-ui); font-size: .9rem; letter-spacing: .1em; }
.auth-art .pillars { margin-top: 32px; display: grid; grid-template-columns: repeat(2,1fr); gap: 12px; }
.auth-art .pillars div { padding: 14px; border: 1px solid rgba(201,162,39,.3); border-radius: 10px; background: rgba(255,255,255,.04); }
.auth-art .pillars i { color: var(--gold-soft); margin-bottom: 8px; }
.auth-art .pillars strong { color: var(--gold-soft); display: block; font-family: var(--font-ui); }
.auth-art .pillars span { font-size: .85rem; color: rgba(251,249,243,.7); }

.auth-form {
    background: var(--ivory);
    padding: 40px 24px;
    display: flex; flex-direction: column; justify-content: center;
}
.auth-form .form-box { max-width: 420px; width: 100%; margin: 0 auto; }
.auth-form h2 { font-size: 1.7rem; }
.auth-form .alt { font-family: var(--font-ui); font-size: .9rem; color: var(--text-muted); margin-top: 18px; text-align: center; }
.auth-form .alt a { color: var(--burgundy); font-weight: 600; }

@media (min-width: 980px) {
    .auth-wrap { grid-template-columns: 1fr 1fr; }
    .auth-art, .auth-form { padding: 60px; }
    .auth-art .quote { font-size: 1.1rem; }
}

/* ---------- Landing / hero ---------- */
.hero {
    background:
      radial-gradient(circle at 20% 10%, rgba(201,162,39,.15), transparent 50%),
      linear-gradient(135deg, var(--ink) 0%, var(--ink-2) 60%, var(--ink-3) 100%);
    color: var(--ivory);
    padding: 48px 16px 60px;
    margin: -24px -16px 36px;
    border-bottom: 4px solid var(--gold);
    position: relative; overflow: hidden;
}
.hero::after {
    content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 60px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 60'><path d='M0,30 Q150,0 300,30 T600,30 T900,30 T1200,30' stroke='%23C9A227' fill='none' stroke-width='1' opacity='.3'/></svg>") repeat-x;
    background-size: 1200px 60px;
}
.hero-inner { max-width: var(--container); margin: 0 auto; display: grid; grid-template-columns: 1fr; gap: 28px; align-items: center; }
.hero-eyebrow { color: var(--gold-soft); letter-spacing: .25em; font-family: var(--font-ui); font-size: .75rem; font-weight: 600; text-transform: uppercase; }
.hero h1 { color: var(--ivory); font-size: clamp(1.8rem, 5vw, 4rem); line-height: 1.1; margin: 12px 0 14px; }
.hero h1 .highlight { color: var(--gold-soft); font-style: italic; }
.hero p { color: rgba(251,249,243,.85); font-size: 1.02rem; max-width: 580px; }
.hero-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.hero-quote {
    background: rgba(0,0,0,.18); border: 1px solid rgba(201,162,39,.4);
    padding: 22px; border-radius: var(--r-xl);
    backdrop-filter: blur(6px); position: relative;
}
.hero-quote::before {
    content: '"'; position: absolute; top: -10px; left: 14px;
    color: var(--gold-soft); font-family: var(--font-serif); font-size: 4rem; line-height: 1; opacity: .55;
}
.hero-quote q { display: block; font-style: italic; font-size: 1rem; line-height: 1.7; color: var(--ivory); }
.hero-quote .author { margin-top: 14px; color: var(--gold-soft); font-family: var(--font-ui); font-size: .85rem; letter-spacing: .1em; }

@media (min-width: 900px) {
    .hero { padding: 80px 24px 100px; margin: -32px -24px 48px; }
    .hero-inner { grid-template-columns: 1.3fr 1fr; gap: 48px; }
    .hero p { font-size: 1.15rem; }
    .hero-quote q { font-size: 1.1rem; }
}

/* ---------- Sections ---------- */
.section-title {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
    margin-bottom: 20px;
}
.section-title h2 { margin: 0; }
.section-title h2 small {
    display: block; font-family: var(--font-ui); font-size: .75rem;
    color: var(--text-muted); font-weight: 500;
    letter-spacing: .15em; text-transform: uppercase; margin-bottom: 4px;
}

/* ---------- Book grid ---------- */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
}
.book-card {
    background: var(--surface);
    border-radius: var(--r-lg);
    overflow: hidden;
    transition: transform .2s, box-shadow .2s, border-color .2s;
    text-decoration: none;
    color: var(--text);
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--line);
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--gold); }
.book-cover {
    aspect-ratio: 2/3; background: var(--ink); position: relative; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .badge-views {
    position: absolute; bottom: 8px; right: 8px;
    background: rgba(11,27,43,.85); color: var(--gold-soft);
    font-family: var(--font-ui); font-size: .7rem; padding: 3px 8px; border-radius: 999px;
    display: flex; align-items: center; gap: 4px;
}
.book-cover .badge-views i { width: 12px; height: 12px; }
.book-info { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; }
.book-info .title { font-family: var(--font-serif); font-weight: 700; font-size: .95rem; line-height: 1.3; margin-bottom: 4px; color: var(--ink);
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-info .author { font-family: var(--font-ui); font-size: .78rem; color: var(--text-muted); margin-bottom: 8px; }
.book-info .meta { display: flex; justify-content: space-between; font-family: var(--font-ui); font-size: .72rem; color: var(--text-muted); margin-top: auto; gap: 6px; flex-wrap: wrap; }
.book-info .meta .stars i { width: 12px; height: 12px; }
@media (min-width: 720px) {
    .book-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }
}

/* ---------- Filter bar ---------- */
.filter-bar {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    margin-bottom: 20px;
}
.filter-bar .input, .filter-bar .select { padding: 8px 12px; font-size: .9rem; }
.filter-chip {
    padding: 6px 14px; border-radius: 999px; background: var(--parchment); color: var(--ink);
    font-family: var(--font-ui); font-size: .82rem; border: 1px solid var(--line);
    transition: all .15s; white-space: nowrap;
}
.filter-chip:hover { border-color: var(--gold); background: var(--ivory); }
.filter-chip.active { background: var(--ink); color: var(--ivory); border-color: var(--ink); }

/* ---------- Book detail ---------- */
.book-detail {
    display: grid; grid-template-columns: 1fr; gap: 24px;
    align-items: flex-start;
}
.book-detail-cover {
    aspect-ratio: 2/3; border-radius: var(--r-lg); overflow: hidden;
    box-shadow: 0 30px 60px rgba(11,27,43,.3); border: 1px solid var(--gold);
    max-width: 220px; margin: 0 auto;
}
.book-detail h1 { font-size: clamp(1.5rem, 3.6vw, 2.4rem); margin-bottom: 6px; }
.book-detail .author { font-family: var(--font-body); font-style: italic; font-size: 1.1rem; color: var(--burgundy); margin-bottom: 14px; }
.book-detail .meta-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }
.book-detail .description { font-size: 1rem; line-height: 1.8; color: var(--text-soft); }

.review-item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.review-item:last-child { border-bottom: 0; }
.review-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.review-head .name { font-weight: 600; font-family: var(--font-ui); }
.review-head .when { color: var(--text-muted); font-size: .85rem; font-family: var(--font-ui); }

@media (min-width: 800px) {
    .book-detail { grid-template-columns: 280px 1fr; gap: 40px; }
    .book-detail-cover { max-width: none; margin: 0; }
}

/* ---------- Reader (FULL IMMERSIVE) ---------- */
body.reader-mode { background: var(--ink); }
body.reader-mode .topbar,
body.reader-mode .footer { display: none; }
body.reader-mode .main { max-width: 100%; margin: 0; padding: 0; min-height: 100vh; }
body.reader-mode .flash-wrap { max-width: 100%; padding: 8px 12px; margin: 0; }

.reader-wrap {
    min-height: 100vh;
    background: var(--ink);
    display: flex; flex-direction: column;
}
.reader-toolbar {
    position: sticky; top: 0; z-index: 50;
    background: rgba(11,27,43,.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(201,162,39,.25);
    color: var(--ivory);
    padding: 10px 12px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    font-family: var(--font-ui);
}
.reader-toolbar .reader-back {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px; border-radius: var(--r);
    background: rgba(255,255,255,.06);
    color: var(--ivory); text-decoration: none;
    font-size: .85rem; border: 1px solid rgba(201,162,39,.25);
}
.reader-toolbar .reader-back:hover { background: rgba(201,162,39,.18); color: var(--gold-soft); }
.reader-toolbar .reader-back i { width: 16px; height: 16px; }
.reader-toolbar .reader-title {
    min-width: 0; text-align: center; padding: 0 8px;
}
.reader-toolbar .reader-title .t {
    font-family: var(--font-serif); color: var(--gold-soft);
    font-size: 1.05rem; font-weight: 700; line-height: 1.1;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-toolbar .reader-title .a {
    font-size: .78rem; opacity: .7;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-controls {
    display: flex; gap: 4px; align-items: center; flex-wrap: nowrap;
}
.reader-btn {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(201,162,39,.25);
    color: var(--ivory);
    padding: 8px;
    width: 38px; height: 38px;
    border-radius: var(--r);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s;
}
.reader-btn:hover { background: rgba(201,162,39,.18); border-color: var(--gold); color: var(--gold-soft); }
.reader-btn:disabled { opacity: .4; cursor: not-allowed; }
.reader-btn i { width: 18px; height: 18px; }
.reader-page-info {
    color: var(--gold-soft);
    font-family: var(--font-ui); font-size: .82rem;
    padding: 0 8px;
    white-space: nowrap;
}

.reader-canvas-wrap {
    flex: 1;
    padding: 16px 8px 32px;
    overflow: auto;
    text-align: center;
    background: var(--ink);
}
.reader-canvas-wrap canvas {
    box-shadow: 0 30px 80px rgba(0,0,0,.5);
    border-radius: 4px;
    max-width: 100%; height: auto;
    background: white;
}

/* Mobile reader */
@media (max-width: 720px) {
    .reader-toolbar {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .reader-toolbar .reader-title { text-align: left; padding: 0; }
    .reader-toolbar .reader-title .t { font-size: .95rem; }
    .reader-controls { justify-content: center; flex-wrap: wrap; }
    .reader-btn { width: 36px; height: 36px; }
    .reader-canvas-wrap { padding: 8px; }
}

/* ---------- Profile ---------- */
.profile-header {
    background: linear-gradient(135deg, var(--ink) 0%, var(--ink-3) 100%);
    color: var(--ivory);
    padding: 28px 20px;
    border-radius: var(--r-xl);
    border: 1px solid var(--gold);
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; gap: 18px; align-items: center;
    text-align: center;
    margin-bottom: 24px;
    position: relative; overflow: hidden;
}
.profile-header::before {
    content: ''; position: absolute; top: -40px; right: -40px;
    width: 200px; height: 200px; border: 1px solid var(--gold-soft); border-radius: 50%; opacity: .25;
}
.profile-header::after {
    content: ''; position: absolute; bottom: -60px; right: 60px;
    width: 280px; height: 280px; border: 1px solid var(--gold); border-radius: 50%; opacity: .15;
}
.profile-header h1 { color: var(--ivory); margin-bottom: 4px; font-size: clamp(1.5rem, 4vw, 2.4rem); }
.profile-header .username { color: var(--gold-soft); font-family: var(--font-ui); }
.profile-header .bio {
    color: rgba(251,249,243,.85); font-style: italic;
    max-width: 600px; margin-top: 12px; line-height: 1.6;
}
.profile-stats { display: flex; gap: 18px; margin-top: 14px; justify-content: center; flex-wrap: wrap; }
.profile-stats div { font-family: var(--font-ui); }
.profile-stats strong {
    display: block; font-family: var(--font-serif); font-size: 1.4rem;
    color: var(--gold-soft);
}
.profile-stats span {
    font-size: .75rem; color: rgba(251,249,243,.6);
    text-transform: uppercase; letter-spacing: .1em;
}
.profile-actions {
    display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}

.profile-grid { display: grid; grid-template-columns: 1fr; gap: 24px; }

@media (min-width: 800px) {
    .profile-header {
        flex-direction: row;
        align-items: flex-start;
        text-align: left;
        padding: 36px 32px;
        gap: 24px;
    }
    .profile-header > div:first-of-type,
    .profile-header > div:nth-of-type(1) { flex: 1; }
    .profile-stats { justify-content: flex-start; }
    .profile-actions { flex-direction: column; align-items: flex-end; }
}
@media (min-width: 1000px) {
    .profile-grid { grid-template-columns: 280px 1fr; }
}

/* Tabs (used on profile/friends/notif) */
.tabs {
    display: flex; gap: 4px; flex-wrap: wrap;
    border-bottom: 1px solid var(--line);
    margin-bottom: 18px;
    overflow-x: auto;
}
.tabs a {
    padding: 10px 16px;
    color: var(--text-muted);
    font-family: var(--font-ui); font-size: .9rem; font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.tabs a.active {
    color: var(--ink); border-bottom-color: var(--gold);
}
.tabs a:hover { color: var(--ink); }

/* ---------- Feed / Posts ---------- */
.feed-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: flex-start;
}
.feed-side { display: none; }
@media (min-width: 900px) {
    .feed-layout { grid-template-columns: 220px 1fr; gap: 20px; }
    .feed-side { display: block; position: sticky; top: calc(var(--topbar-h) + 16px); }
}
@media (min-width: 1180px) {
    .feed-layout { grid-template-columns: 220px 1fr 280px; gap: 24px; }
    .feed-side.feed-right { display: block; }
}

.side-card { padding: 16px; }
.side-card h4 { font-family: var(--font-ui); font-size: .75rem; letter-spacing: .15em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r); color: var(--text); font-family: var(--font-ui); font-size: .9rem; }
.side-link:hover { background: var(--parchment); }
.side-link i { width: 16px; height: 16px; color: var(--ink-3); }
.side-link.active { background: var(--ink); color: var(--ivory); }
.side-link.active i { color: var(--gold-soft); }

.composer {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 14px; margin-bottom: 16px;
}
.composer textarea { width: 100%; min-height: 70px; resize: vertical; border: 0; outline: none; font-family: var(--font-body); font-size: 1rem; background: transparent; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.composer-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.composer-tools button, .composer-tools .check {
    background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
    padding: 6px 10px; border-radius: var(--r); display: inline-flex; align-items: center; gap: 6px;
    font-family: var(--font-ui); font-size: .85rem;
}
.composer-tools button:hover, .composer-tools .check:hover { background: var(--parchment); color: var(--ink); }

.post {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 16px; margin-bottom: 14px;
    transition: border-color .15s;
}
.post:hover { border-color: var(--gold-soft); }
.post-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.post-head .meta { flex: 1; min-width: 0; }
.post-head .name { font-weight: 600; color: var(--ink); }
.post-head .when { font-family: var(--font-ui); font-size: .78rem; color: var(--text-muted); }
.post-content { font-size: .98rem; line-height: 1.7; white-space: pre-wrap; word-wrap: break-word; }
.post-image { margin-top: 10px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); max-height: 460px; }
.post-image img { width: 100%; object-fit: cover; }
.post-book {
    margin-top: 10px;
    display: flex; gap: 12px; padding: 10px;
    border: 1px dashed var(--gold); border-radius: var(--r);
    background: var(--ivory);
}
.post-book img { width: 50px; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.post-book .t { font-family: var(--font-serif); font-weight: 700; }
.post-book .a { font-size: .85rem; color: var(--text-muted); font-family: var(--font-ui); }
.post-actions {
    display: flex; gap: 4px; margin-top: 12px; padding-top: 10px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}
.post-actions button, .post-actions a {
    background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
    padding: 8px 12px; border-radius: var(--r); display: inline-flex; align-items: center; gap: 6px;
    font-family: var(--font-ui); font-size: .85rem; font-weight: 500;
    text-decoration: none;
}
.post-actions button:hover, .post-actions a:hover { background: var(--parchment); color: var(--ink); }
.post-actions .liked { color: var(--burgundy); }
.post-actions .liked i { fill: var(--burgundy); }

.post-comments { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.comment { display: flex; gap: 10px; margin-bottom: 10px; }
.comment .bubble { background: var(--parchment); padding: 8px 14px; border-radius: 14px; flex: 1; min-width: 0; word-wrap: break-word; }
.comment .bubble .n { font-weight: 600; font-family: var(--font-ui); font-size: .85rem; }
.comment-form { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.comment-form input { flex: 1; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); font-family: var(--font-body); }
.comment-form input:focus { outline: none; border-color: var(--gold); }

/* ---------- Chat (DM) ---------- */
.chat-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    overflow: hidden;
    height: calc(100vh - var(--topbar-h) - 60px);
    min-height: 480px;
}
.chat-sidebar {
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    background: var(--ivory);
    min-width: 0;
}
.chat-sidebar .head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 8px;
}
.chat-sidebar .head h3 { margin: 0; font-size: 1.15rem; }
.chat-sidebar .list { flex: 1; overflow-y: auto; }
.chat-thread {
    display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; align-items: center;
    border-bottom: 1px solid var(--line);
    text-decoration: none; color: var(--text);
    min-width: 0;
}
.chat-thread:hover, .chat-thread.active { background: var(--parchment); }
.chat-thread.active { border-left: 3px solid var(--gold); }
.chat-thread img { flex-shrink: 0; }
.chat-thread .info { flex: 1; min-width: 0; }
.chat-thread .n { font-weight: 600; font-family: var(--font-ui); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread .last { color: var(--text-muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread .badge-unread {
    background: var(--burgundy); color: white; font-size: .7rem; padding: 1px 7px;
    border-radius: 999px; font-family: var(--font-ui); flex-shrink: 0;
}

.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    display: flex; gap: 10px; align-items: center;
}
.chat-header .name { font-family: var(--font-ui); font-weight: 600; }
.chat-header .role { font-size: .72rem; }
.chat-header .icon-btn { color: var(--text); width: 36px; height: 36px; }
.chat-header .icon-btn:hover { background: var(--parchment); color: var(--ink); }

.chat-body {
    flex: 1; overflow-y: auto; padding: 16px;
    background:
      radial-gradient(circle at 20% 20%, rgba(201,162,39,.05), transparent 40%),
      var(--ivory);
}
.chat-msg { display: flex; gap: 8px; margin-bottom: 12px; max-width: 85%; }
.chat-msg .bubble {
    padding: 10px 14px; border-radius: 16px;
    background: var(--parchment); color: var(--ink);
    box-shadow: var(--shadow-sm); font-size: .95rem;
    word-wrap: break-word; min-width: 0;
}
.chat-msg .when {
    font-size: .7rem; color: var(--text-muted);
    margin-top: 4px; font-family: var(--font-ui);
}
.chat-msg.mine { margin-left: auto; flex-direction: row-reverse; }
.chat-msg.mine .bubble { background: var(--ink); color: var(--ivory); }
.chat-msg.mine .when { text-align: right; }

.chat-input {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--line); background: var(--surface);
    align-items: center;
}
.chat-input input {
    flex: 1; padding: 10px 16px; border-radius: 999px;
    border: 1px solid var(--line); font-family: var(--font-body);
    font-size: .95rem; min-width: 0;
}
.chat-input input:focus { outline: none; border-color: var(--gold); }
.chat-input .btn { flex-shrink: 0; }

.chat-empty {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-muted); padding: 32px 20px; text-align: center;
}
.chat-empty i { width: 56px; height: 56px; color: var(--gold); margin-bottom: 12px; }
.chat-empty h3 { color: var(--ink); margin-bottom: 8px; }
.chat-empty p { max-width: 360px; }
.chat-empty .actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }

/* Mobile chat: switch view between sidebar (list) and main (conversation) */
.chat-back-btn { display: none; }
@media (max-width: 760px) {
    .chat-layout { height: calc(100vh - var(--topbar-h) - 24px); border-radius: 0; margin: -16px -12px; border-left: 0; border-right: 0; }
    .chat-layout.has-peer .chat-sidebar { display: none; }
    .chat-layout:not(.has-peer) .chat-main { display: none; }
    .chat-back-btn { display: inline-flex; }
    .chat-msg { max-width: 90%; }
}
@media (min-width: 760px) {
    .chat-layout { grid-template-columns: 300px 1fr; }
}
@media (min-width: 1000px) {
    .chat-layout { grid-template-columns: 340px 1fr; }
}

/* ---------- Public chat (rooms) ---------- */
.rooms-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 24px; }
.room-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 18px; transition: all .2s; text-decoration: none; color: var(--text);
    display: flex; flex-direction: column; gap: 8px;
}
.room-card:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: var(--shadow); }
.room-card .icon { width: 44px; height: 44px; border-radius: 12px; background: var(--ink); color: var(--gold-soft); display: inline-flex; align-items: center; justify-content: center; }
.room-card h3 { margin: 0; font-size: 1.15rem; }
.room-card .desc { color: var(--text-muted); font-size: .9rem; }
@media (min-width: 600px) {
    .rooms-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* ---------- Reading list ---------- */
.rl-cols { display: grid; grid-template-columns: 1fr; gap: 14px; }
.rl-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px; }
.rl-col h3 { display: flex; align-items: center; gap: 8px; padding-bottom: 10px; border-bottom: 2px solid var(--gold); margin-bottom: 10px; font-size: 1.1rem; }
.rl-col h3 i { color: var(--gold); }
.rl-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rl-item:last-child { border-bottom: 0; }
.rl-item img { width: 50px; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.rl-item .info { flex: 1; min-width: 0; }
.rl-item .info .t { font-family: var(--font-serif); font-weight: 700; font-size: .95rem; line-height: 1.3; }
.rl-item .info .a { font-size: .8rem; color: var(--text-muted); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--gold); }
@media (min-width: 760px) { .rl-cols { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Notifications ---------- */
.notif-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.notif-item {
    display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line);
    text-decoration: none; color: var(--text);
    transition: background .15s;
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--parchment); }
.notif-item.unread { background: rgba(201,162,39,.06); border-left: 3px solid var(--gold); }
.notif-item .icon { width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; background: var(--ink); color: var(--gold-soft); display: inline-flex; align-items: center; justify-content: center; }
.notif-item .msg { flex: 1; min-width: 0; }
.notif-item .when { font-size: .78rem; color: var(--text-muted); font-family: var(--font-ui); }

/* ---------- Events ---------- */
.event-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 16px; margin-bottom: 12px;
    display: grid; grid-template-columns: 70px 1fr; gap: 14px; align-items: flex-start;
}
.event-date {
    background: var(--ink); color: var(--gold-soft); border-radius: var(--r); text-align: center;
    padding: 10px 6px; font-family: var(--font-ui);
}
.event-date .d { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 800; line-height: 1; color: var(--ivory); }
.event-date .m { font-size: .68rem; letter-spacing: .15em; text-transform: uppercase; }
.event-card h3 { margin: 0 0 4px; font-size: 1.1rem; }
.event-card .meta { font-family: var(--font-ui); font-size: .82rem; color: var(--text-muted); line-height: 1.6; }
.event-card > form { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
@media (min-width: 760px) {
    .event-card { grid-template-columns: 80px 1fr auto; gap: 18px; align-items: center; }
    .event-card > form { grid-column: auto; }
}

/* ---------- Admin ---------- */
.admin-layout { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: flex-start; }
.admin-side {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 12px;
}
.admin-side h4 { margin-bottom: 10px; }
.admin-side .side-link { width: 100%; }
.admin-side hr { margin: 10px 0; }
@media (min-width: 900px) {
    .admin-layout { grid-template-columns: 240px 1fr; gap: 24px; }
    .admin-side { position: sticky; top: calc(var(--topbar-h) + 16px); }
}

.admin-stats {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 16px;
    position: relative; overflow: hidden;
}
.stat-card::after {
    content: ''; position: absolute; top: -20px; right: -20px;
    width: 80px; height: 80px; border: 1px solid var(--gold); border-radius: 50%; opacity: .25;
}
.stat-card h5 { font-family: var(--font-ui); font-size: .72rem; text-transform: uppercase; letter-spacing: .15em; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .num { font-family: var(--font-serif); font-size: 1.9rem; font-weight: 800; color: var(--ink); line-height: 1; }
.stat-card .sub { font-family: var(--font-ui); font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
.stat-card .icon { position: absolute; right: 12px; top: 12px; color: var(--gold); }
@media (min-width: 720px) { .admin-stats { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .admin-stats { grid-template-columns: repeat(4, 1fr); } }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-lg); border: 1px solid var(--line); }
/* Auto-wrap admin tables for horizontal scroll on mobile */
.admin-layout .table:not(.table-wrap .table) {
    display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap;
}
@media (min-width: 1100px) {
    .admin-layout .table:not(.table-wrap .table) { display: table; white-space: normal; }
}
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-family: var(--font-ui); font-size: .88rem; vertical-align: middle; }
.table th { background: var(--parchment); font-weight: 700; color: var(--ink); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--ivory); }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table code { font-size: .8rem; }

/* Admin grid responsive on dashboard */
.admin-twocol { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 1000px) { .admin-twocol { grid-template-columns: 1fr 1fr; gap: 24px; } }

/* ---------- Search ---------- */
.search-section { margin-bottom: 28px; }
.search-section h3 { padding-bottom: 8px; border-bottom: 2px solid var(--gold); margin-bottom: 14px; }

/* ---------- Friends ---------- */
.friend-grid {
    display: grid; gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.friend-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 14px; text-align: center; transition: border-color .15s;
}
.friend-card:hover { border-color: var(--gold); }
.friend-card .name { font-weight: 700; font-family: var(--font-ui); margin-top: 8px; line-height: 1.2; }
.friend-card .uname { color: var(--text-muted); font-size: .82rem; font-family: var(--font-ui); margin-bottom: 8px; }
.friend-card .actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
@media (min-width: 600px) {
    .friend-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
}

/* ---------- Error pages ---------- */
.err-page {
    text-align: center; padding: 60px 16px; max-width: 600px; margin: 0 auto;
}
.err-page .code {
    font-family: var(--font-serif); font-size: clamp(5rem, 18vw, 8rem);
    font-weight: 900; color: var(--gold); line-height: 1;
}
.err-page h2 { font-size: clamp(1.4rem, 4vw, 2rem); margin: 12px 0; }
.err-page p { color: var(--text-muted); }

/* ---------- Feature grid (home dashboard) ---------- */
.feature-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px; margin: 28px 0;
}
.feature-card {
    padding: 20px; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); text-align: center; transition: all .2s;
}
.feature-card:hover { border-color: var(--gold); transform: translateY(-3px); box-shadow: var(--shadow); }
.feature-card .icon {
    width: 52px; height: 52px; margin: 0 auto 12px;
    border-radius: 14px; background: var(--ink); color: var(--gold-soft);
    display: inline-flex; align-items: center; justify-content: center;
}
.feature-card .icon i { width: 26px; height: 26px; }
.feature-card h3 { margin-bottom: 6px; font-size: 1.05rem; }
.feature-card p { color: var(--text-muted); font-size: .88rem; margin: 0; }
