:root {
  --bg: #F7F5F2; --card: #FFFFFF; --border: #E4E0DA; --text: #1A1714; --label: #3D3733; --muted: #6F6966;
  --accent: #806641; --accent-hover: #74592E; --accent-soft: #F3EDE4; --danger: #A23B2A;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --radius: 10px; --max: 860px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; color: var(--text); }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.wrap { max-width: var(--max); margin: 0 auto; padding: 24px 16px 80px; }
[hidden] { display: none !important; }

/* header */
.top { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: var(--max); margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--accent); font-weight: 600; }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--label); padding: 6px 12px; border-radius: 999px; font-size: .95rem; }
nav a.on { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }

/* cards + forms */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.card.click { cursor: pointer; transition: border-color .15s; }
.card.click:hover { border-color: #CFC7BB; }
.pinned { border-left: 3px solid var(--accent); }
label { display: block; font-size: .875rem; color: var(--label); font-weight: 600; margin: 12px 0 4px; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 96px; resize: vertical; }
.btn { display: inline-block; font: inherit; font-weight: 600; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 18px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--accent-hover); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--accent-soft); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.err { color: var(--danger); font-size: .9rem; margin-top: 8px; }

/* login */
.login { max-width: 420px; margin: 10vh auto 0; }
.login .brand { font-size: 1.4rem; display: block; margin-bottom: 18px; }

/* community */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 16px; }
.chip { font: inherit; font-size: .875rem; border: 1px solid var(--border); background: var(--card); color: var(--label); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.meta { font-size: .85rem; color: var(--muted); }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; color: var(--accent-hover); background: var(--accent-soft); border-radius: 999px; padding: 2px 9px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.reacts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.react { font: inherit; font-size: .85rem; border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 2px 9px; cursor: pointer; }
.react.mine { background: var(--accent-soft); border-color: var(--accent); }
.react-add { position: relative; }
.react-menu { position: absolute; bottom: 120%; left: 0; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px; display: flex; gap: 2px; box-shadow: 0 4px 14px rgba(0,0,0,.08); z-index: 5; }
.react-menu button { background: none; border: 0; font-size: 1.15rem; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.react-menu button:hover { background: var(--accent-soft); }
.comment { border-top: 1px solid var(--border); padding: 12px 0; }
.replies { margin-left: 22px; border-left: 2px solid var(--accent-soft); padding-left: 14px; }
.replies .comment { border-top: 0; padding-bottom: 0; }
.comment-body { margin: 6px 0 0 46px; }
.composer-toggle { width: 100%; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: text; text-align: left; }

/* course */
.course { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; align-items: start; }
.course > * { min-width: 0; }
.toc { position: sticky; top: 70px; }
.toc h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.toc h3:first-child { margin-top: 0; }
.toc a { display: flex; gap: 8px; text-decoration: none; color: var(--label); padding: 6px 8px; border-radius: 6px; font-size: .92rem; }
.toc a.on { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.check { width: 16px; flex: none; color: var(--accent); }
.progress { height: 6px; background: var(--accent-soft); border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.progress > div { height: 100%; background: var(--accent); }
.video { position: relative; padding-top: 56.25%; background: #111; border-radius: 8px; overflow: hidden; margin: 10px 0 16px; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* library */
.res { display: flex; justify-content: space-between; gap: 12px; align-items: center; }

/* admin */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
details.card > summary { cursor: pointer; font-weight: 600; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: .9rem; z-index: 50; max-width: 90vw; }

/* top bar extras */
.top-right { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.bell { position: relative; text-decoration: none; font-size: 1.1rem; line-height: 1; }
.badge { position: absolute; top: -7px; right: -10px; background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700; border-radius: 999px; padding: 2px 5px; }
.me-link { display: flex; }

/* avatars, bylines */
.avatar { border-radius: 50%; object-fit: cover; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); }
.avatar.initials { color: var(--accent-hover); font-weight: 700; }
.byline { display: flex; align-items: center; gap: 12px; }
.byline-av, .me-link, .member-card, .notif { text-decoration: none; }
.byline-av { display: flex; }
.byline .meta { line-height: 1.3; }
.author { color: var(--text); font-weight: 600; text-decoration: none; }
.author:hover { text-decoration: underline; color: var(--text); }
.top-align { align-items: flex-start; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.head-row { margin-bottom: 8px; }
.head-row h1 { margin: 0; }
.search { max-width: 260px; padding: 8px 12px; }
.nudge { background: var(--accent-soft); border-color: #E6DACA; }
.check-row { display: flex; align-items: center; font-weight: 500; }

/* images */
.picker .thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: var(--accent-soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.loading { display: flex; align-items: center; justify-content: center; font-size: .72rem; color: var(--muted); }
.thumb-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(26,23,20,.75); color: #fff; font-size: .7rem; cursor: pointer; }
.small-btn { padding: 6px 12px; font-size: .9rem; }
.gallery { display: grid; gap: 6px; margin: 12px 0 4px; border-radius: 10px; overflow: hidden; }
.gallery.n1 { grid-template-columns: 1fr; }
.gallery.n2, .gallery.n4 { grid-template-columns: 1fr 1fr; }
.gallery.n3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.gallery.n3 .gal-item:first-child { grid-row: span 2; }
.gal-item { padding: 0; border: 0; background: var(--accent-soft); cursor: zoom-in; display: block; min-height: 0; }
.gal-item img { width: 100%; height: 100%; display: block; object-fit: cover; }
.gallery.n1 .gal-item img { height: auto; max-height: 520px; object-fit: contain; background: #F0ECE6; }
.gallery.compact .gal-item img, .gallery.compact.n1 .gal-item img { height: 220px; max-height: 220px; object-fit: cover; }
.gallery.n2:not(.compact) .gal-item img, .gallery.n4:not(.compact) .gal-item img { height: 260px; }
.gallery.n3:not(.compact) { height: 420px; }
.lightbox { position: fixed; inset: 0; background: rgba(20,18,16,.92); z-index: 60; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 94vw; max-height: 90vh; border-radius: 6px; }
.lightbox button { position: absolute; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 1.4rem; cursor: pointer; }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }

/* members + profile + notifications */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.member-card { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; margin: 0; }
.member-card:hover { border-color: #CFC7BB; color: inherit; }
.profile { display: flex; gap: 22px; align-items: flex-start; }
.notif { display: flex; gap: 12px; align-items: flex-start; padding: 12px 20px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--border); }
.notif:last-child { border-bottom: 0; }
.notif:hover { background: #FBFAF8; color: var(--text); }
.notif.unread { background: var(--accent-soft); }

@media (max-width: 720px) {
  .comment-body { margin-left: 0; }
  .replies { margin-left: 8px; padding-left: 10px; }
  .profile { flex-direction: column; gap: 12px; }
  .head-row { flex-direction: column; align-items: stretch; }
  .search { max-width: none; }
  .gallery.n3:not(.compact) { height: 300px; }
  .course { grid-template-columns: 1fr; }
  .toc { position: static; }
  .top-inner { gap: 10px; }
  nav { order: 3; flex-basis: 100%; }
}
.notif.unread .avatar.initials, .nudge .avatar.initials { background: #fff; }
