:root { --bg:#FAF9F6; --card:#fff; --text:#111827; --muted:#5b6678; --line:#e2e8f0; --navy:#0F2537; --accent:#0F6470; }
html.dark { --bg:#000000; --card:#16181c; --text:#e7e9ea; --muted:#71767b; --line:#2f3336; --accent:#5cc8c4; }
* { box-sizing:border-box; margin:0; padding:0; }
[hidden] { display:none !important; }
body { background:var(--bg); color:var(--text); font-family:Inter,'Noto Sans Sinhala',sans-serif; line-height:1.6; -webkit-font-smoothing:antialiased; overflow-wrap:anywhere; }
a { color:inherit; }
button, input { font:inherit; color:inherit; }
button { cursor:pointer; }
.wrap { width:100%; max-width:1180px; margin:0 auto; padding-left:16px; padding-right:16px; }
.narrow { max-width:820px; }
h1, h2, h3 { line-height:1.3; }

#read-progress { position:fixed; top:0; left:0; height:3px; width:0; background:#2fb3ad; z-index:60; }

.topbar { position:sticky; top:0; z-index:40; background:var(--card); border-bottom:2px solid var(--accent); }
.topbar-row { display:flex; align-items:center; gap:12px; height:70px; }
.icon-btn { width:42px; height:42px; flex-shrink:0; border:1px solid var(--line); border-radius:10px; background:transparent; font-size:1.25rem; }
.brand { display:flex; align-items:center; gap:10px; text-decoration:none; flex:1; min-width:0; }
.brand img, footer img { width:48px; height:48px; border-radius:12px; background:#fff; object-fit:contain; padding:3px; flex-shrink:0; }
.brand strong { display:block; font-size:1.6rem; font-weight:800; line-height:1.1; color:var(--accent); }
.brand small { display:block; font-size:.68rem; line-height:1.3; color:var(--muted); }

#overlay { position:fixed; inset:0; background:rgba(0,0,0,.6); z-index:50; }
#drawer { position:fixed; top:0; bottom:0; left:0; width:min(320px,86vw); background:var(--card); z-index:55; padding:16px; overflow-y:auto; transform:translateX(-105%); transition:transform .25s; }
#drawer.open { transform:none; box-shadow:8px 0 30px rgba(0,0,0,.25); }
.drawer-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.drawer-link { display:flex; justify-content:space-between; gap:10px; padding:11px 12px; border-radius:10px; text-decoration:none; font-weight:600; }
.drawer-link:hover, .drawer-link[aria-current] { background:var(--bg); color:var(--accent); }
.drawer-link small { color:var(--muted); }
.label { display:block; font-size:.7rem; font-weight:700; letter-spacing:.08em; text-transform:uppercase; color:var(--accent); }
#drawer .label { margin:16px 12px 6px; }

.hero { display:flex; align-items:center; gap:36px; margin-top:28px; padding:44px; border-radius:24px; color:#fff; background:linear-gradient(135deg,#0B2E4A,#0F6470); }
.hero img { width:180px; height:180px; border-radius:50%; background:#fff; padding:16px; object-fit:contain; flex-shrink:0; }
.hero h1 { font-size:clamp(1.8rem,4.5vw,3rem); font-weight:800; }
.hero .tagline { margin:10px 0 14px; font-family:Merriweather,serif; font-style:italic; font-size:clamp(1rem,2.4vw,1.4rem); color:#A7E3E0; }

.section-head { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:center; gap:12px; margin:40px 0 20px; }
.section-head h2 { font-size:1.5rem; font-weight:800; border-left:6px solid var(--accent); padding-left:12px; }
input[type=search], input[type=email] { padding:10px 14px; border:1px solid var(--line); border-radius:10px; background:var(--card); min-width:0; }
.grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(min(100%,320px),1fr)); gap:24px; }
.card { display:flex; flex-direction:column; background:var(--card); border:1px solid var(--line); border-radius:16px; overflow:hidden; text-decoration:none; transition:transform .2s,box-shadow .2s; }
.card:hover { transform:translateY(-3px); box-shadow:0 10px 25px rgba(15,37,55,.14); }
.card-img { width:100%; aspect-ratio:16/9; object-fit:cover; display:block; }
.no-banner { object-fit:contain; background:#fff; padding:16px; }
.card-body { display:flex; flex-direction:column; gap:8px; padding:18px 20px; flex:1; }
.card h3 { font-family:Merriweather,'Noto Sans Sinhala',serif; font-size:1.15rem; }
.card p { font-size:.9rem; color:var(--muted); display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.meta { font-size:.8rem; color:var(--muted); }
.card .meta { margin-top:auto; }
.empty { color:var(--muted); }

/* Category and topic cards: small picture tiles, 2 per row, name on top of the picture */
.cat-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.cat-card { display:flex; flex-direction:column; justify-content:flex-end; aspect-ratio:4/3; padding:12px; border-radius:14px; color:#fff; text-decoration:none; text-shadow:0 1px 6px rgba(0,0,0,.6);
    background:linear-gradient(180deg,rgba(2,12,24,.05) 30%,rgba(2,12,24,.85)), var(--cover,none) center/cover, linear-gradient(135deg,#0B2E4A,#148089); transition:transform .2s,box-shadow .2s; }
.cat-card:hover { transform:translateY(-3px); box-shadow:0 14px 30px rgba(15,37,55,.28); }
.cat-name { font-size:1rem; font-weight:800; line-height:1.25; }
.cat-count { font-size:.72rem; font-weight:600; color:#c9f1ee; }
@media (min-width:720px) { .cat-grid { grid-template-columns:repeat(auto-fill,minmax(180px,210px)); } }
#category-topics { margin:14px 0 12px; row-gap:20px; }

/* Category page tiles: folder and post share one size, different look */
.tile { aspect-ratio:1/1; min-width:0; text-decoration:none; border-radius:14px; transition:transform .2s,box-shadow .2s; }
.tile:hover { transform:translateY(-3px); }
.folder-tile { position:relative; display:flex; flex-direction:column; justify-content:flex-end; padding:12px; color:#fff; text-shadow:0 1px 6px rgba(0,0,0,.6);
    border-top-left-radius:4px;
    background:linear-gradient(180deg,rgba(2,12,24,.05) 30%,rgba(2,12,24,.85)), var(--cover,none) center/cover, linear-gradient(135deg,#0B2E4A,#148089);
    box-shadow:0 0 0 2px var(--accent), 5px 5px 0 -1px var(--card), 5px 5px 0 1px var(--accent); }
.folder-tile::before { content:""; position:absolute; left:-2px; top:-12px; width:46%; height:14px; background:var(--accent); border-radius:8px 8px 0 0; }
.folder-tile:hover { box-shadow:0 0 0 2px var(--accent), 5px 5px 0 -1px var(--card), 5px 5px 0 1px var(--accent), 0 14px 30px rgba(15,37,55,.28); }
.tile-badge { position:absolute; top:10px; right:10px; padding:2px 8px; border-radius:99px; background:rgba(2,12,24,.65); color:#c9f1ee; font-size:.62rem; font-weight:700; letter-spacing:.06em; text-transform:uppercase; text-shadow:none; }
.post-tile { display:flex; flex-direction:column; overflow:hidden; background:var(--card); border:1px solid var(--line); }
.post-tile:hover { box-shadow:0 10px 25px rgba(15,37,55,.14); border-color:var(--accent); }
.tile-img { width:100%; aspect-ratio:2/1; object-fit:cover; display:block; }
.tile-body { display:flex; flex-direction:column; gap:4px; padding:8px 10px 10px; flex:1; min-height:0; }
.tile-kind { display:none; font-size:.62rem; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--accent); }
.tile-body h3 { font-family:Merriweather,'Noto Sans Sinhala',serif; font-size:.82rem; line-height:1.35; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.tile-body .meta { margin-top:auto; font-size:.68rem; }

/* Home front page: lead post (picture, then text under it) and plain rows with a thumbnail */
.front { display:grid; grid-template-columns:1fr; gap:8px; }
.lead { display:flex; flex-direction:column; gap:10px; text-decoration:none; padding-bottom:18px; border-bottom:1px solid var(--line); }
.lead-img { display:block; width:100%; aspect-ratio:16/10; object-fit:cover; }
.lead-body { display:flex; flex-direction:column; gap:8px; }
.lead-kind { font-size:.7rem; font-weight:800; letter-spacing:.08em; text-transform:uppercase; color:var(--accent); }
.lead h3 { font-family:Merriweather,'Noto Sans Sinhala',serif; font-size:clamp(1.5rem,6vw,2.2rem); line-height:1.25; }
.lead:hover h3 { color:var(--accent); }
.lead p { font-size:1rem; color:var(--muted); }
.rows { display:flex; flex-direction:column; }
.row { display:grid; grid-template-columns:minmax(0,1fr) 110px; align-items:center; gap:14px; padding:14px 0; border-bottom:1px solid var(--line); text-decoration:none; }
.rows .row:last-child { border-bottom:0; }
.row:hover h3 { color:var(--accent); }
.row-text { display:flex; flex-direction:column; gap:4px; min-width:0; }
.row h3 { font-family:Merriweather,'Noto Sans Sinhala',serif; font-size:1.05rem; line-height:1.35; display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden; transition:color .2s; }
.row-img { width:110px; height:84px; border-radius:6px; object-fit:cover; }
@media (min-width:820px) {
    .front { grid-template-columns:1.5fr 1fr; gap:28px; align-items:start; }
    .lead { border-bottom:0; padding-bottom:0; }
    .rows .row:first-child { padding-top:0; }
}

/* Tags */
.tag-bar { display:flex; flex-wrap:wrap; gap:8px; margin:0 0 16px; }
.tag-bar.scroll { flex-wrap:nowrap; overflow-x:auto; padding-bottom:6px; scrollbar-width:none; }
.tag-bar.scroll::-webkit-scrollbar { display:none; }
.tag-chip { flex-shrink:0; padding:5px 13px; border:1px solid var(--line); border-radius:99px; background:var(--card); color:var(--muted); font-size:.82rem; font-weight:600; text-decoration:none; transition:color .2s,border-color .2s; }
.tag-chip:hover, .tag-chip[aria-current] { color:var(--accent); border-color:var(--accent); }
.tag-chip[aria-current] { background:rgba(92,200,196,.12); }
#art-tags { margin:12px 0 0; }

/* Mini cards: sideways scroll */
.scroll-buttons { display:flex; gap:8px; }
.icon-btn:disabled { opacity:.35; cursor:default; }
.mini-row { display:flex; gap:14px; overflow-x:auto; scroll-snap-type:x mandatory; padding-bottom:12px; }
.mini-card { flex:0 0 230px; display:flex; flex-direction:column; gap:6px; padding:10px; background:var(--card); border:1px solid var(--line); border-radius:14px; text-decoration:none; scroll-snap-align:start; }
.mini-card:hover { border-color:var(--accent); }
.mini-img { width:100%; aspect-ratio:16/9; object-fit:cover; border-radius:9px; }
.mini-card h3 { font-size:.92rem; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.mini-card .meta { margin-top:auto; }
#more { margin-bottom:48px; }

/* Category / topic page: thin banner strip */
.cat-hero { margin:20px 0; padding:12px 18px 14px; border-radius:16px; color:#fff; text-shadow:0 1px 6px rgba(0,0,0,.6);
    background:linear-gradient(180deg,rgba(2,12,24,.25),rgba(2,12,24,.85)), var(--cover,none) center/cover, linear-gradient(135deg,#0B2E4A,#148089); }
.cat-hero a { font-size:.8rem; font-weight:600; text-decoration:none; }
.cat-hero h1 { margin-top:8px; font-size:clamp(1.25rem,4vw,1.7rem); }
.cat-hero p { font-size:.8rem; }
#category-view { padding-bottom:48px; }
.pagination { display:flex; flex-wrap:wrap; justify-content:center; align-items:center; gap:8px; margin-top:32px; }
.page-btn { min-width:42px; padding:8px 14px; text-align:center; background:var(--card); border:1px solid var(--line); border-radius:10px; text-decoration:none; font-weight:600; }
.page-btn[aria-current] { background:#0F6470; border-color:#0F6470; color:#fff; }

/* Social links */
.links { padding:30px 0; background:var(--card); border-top:1px solid var(--line); text-align:center; }
.links h2 { font-size:1.1rem; margin-bottom:14px; }
.link-list { display:flex; flex-wrap:wrap; justify-content:center; gap:10px; }
.link-btn { padding:10px 20px; border-radius:99px; background:#0F6470; color:#fff; font-weight:600; font-size:.9rem; text-decoration:none; }
.link-btn[data-name=reddit] { background:#c23a00; }
.link-btn[data-name=telegram] { background:#17719f; }
.link-btn:hover { filter:brightness(1.12); }

.subscribe { background:#16181c; border:1px solid #2f3336; color:#fff; border-radius:18px; padding:28px; margin-bottom:48px; }
.subscribe form { display:flex; flex-wrap:wrap; gap:10px; margin-top:16px; }
.subscribe input { flex:1 1 220px; background:#fff; color:#111827; }
.subscribe button, .sources-btn { display:inline-block; padding:10px 20px; border:0; border-radius:10px; background:#0F6470; color:#fff; font-weight:600; text-decoration:none; }

#article-bar { position:sticky; z-index:30; background:var(--card); border-bottom:1px solid var(--line); }
.bar-row { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:center; gap:8px; padding-top:10px; padding-bottom:10px; }
#back-link { font-size:.9rem; font-weight:600; text-decoration:none; color:var(--accent); }
.tools { display:flex; flex-wrap:wrap; gap:6px; }
.tool { display:inline-flex; align-items:center; justify-content:center; min-width:38px; height:38px; padding:0 10px; border:1px solid var(--line); border-radius:8px; background:var(--card); font-size:.8rem; font-weight:700; }
.tool svg { width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
.tool:hover { border-color:var(--accent); color:var(--accent); }
.tool[aria-pressed=true], .tool[aria-expanded=true] { background:#0F6470; border-color:#0F6470; color:#fff; }
.tool:not([aria-pressed=true]) .i-stop, .tool[aria-pressed=true] .i-play { display:none; }
#save-btn[aria-pressed=true] svg { fill:currentColor; }

/* Contents panel */
.toc { padding-top:4px; padding-bottom:14px; max-height:50vh; overflow-y:auto; }
.toc ol { list-style:none; counter-reset:toc; display:flex; flex-direction:column; gap:2px; margin-top:6px; }
.toc li { counter-increment:toc; }
.toc a { display:flex; gap:10px; padding:8px 10px; border-radius:8px; text-decoration:none; font-size:.92rem; font-weight:600; }
.toc a::before { content:counter(toc); min-width:1.2em; color:var(--accent); font-weight:700; }
.toc a:hover { background:var(--bg); color:var(--accent); }
#reader { padding-top:36px; padding-bottom:36px; }
.chip { display:inline-block; padding:4px 12px; border-radius:6px; background:#0F6470; color:#fff; font-size:.72rem; font-weight:700; text-transform:uppercase; text-decoration:none; }
#reader > h1 { margin:16px 0; font-family:Merriweather,'Noto Sans Sinhala',serif; font-size:clamp(1.7rem,5vw,2.7rem); }
.standfirst { font-size:1.15rem; color:var(--muted); margin-bottom:12px; }
.banner { display:block; width:100%; height:auto; border-radius:16px; margin:24px 0; }
.prose { line-height:1.85; margin-bottom:28px; }
.prose > * + * { margin-top:1.1em; }
.prose h1, .prose h2, .prose h3 { margin-top:1.8em; }
.prose img { display:block; max-width:100%; height:auto; margin-left:auto; margin-right:auto; border-radius:12px; }
.prose ul, .prose ol { padding-left:1.5em; }
.prose a { color:var(--accent); }
.prose blockquote { border-left:4px solid var(--accent); padding-left:1em; font-style:italic; color:var(--muted); }
.prose pre { overflow-x:auto; padding:14px; border-radius:10px; background:#16181c; color:#e7e9ea; line-height:1.5; }
.prose h2, .prose h3 { scroll-margin-top:var(--sticky-h,150px); }

/* Collapsible deep sections */
.prose details { border:1px solid var(--line); border-radius:12px; background:var(--card); }
.prose summary { display:flex; align-items:center; gap:10px; padding:14px 16px; cursor:pointer; list-style:none; font-weight:700; color:var(--accent); }
.prose summary::-webkit-details-marker { display:none; }
.prose summary::before { content:''; flex-shrink:0; width:8px; height:8px; border-right:2px solid currentColor; border-bottom:2px solid currentColor; transform:rotate(-45deg); transition:transform .2s; }
.prose details[open] > summary { border-bottom:1px solid var(--line); }
.prose details[open] > summary::before { transform:rotate(45deg); }
.prose details > :not(summary) { margin-left:16px; margin-right:16px; }
.prose details > * + * { margin-top:1em; }
.prose details > :last-child:not(summary) { margin-bottom:16px; }
.prose table { display:block; overflow-x:auto; border-collapse:collapse; }
.prose th, .prose td { border:1px solid var(--line); padding:8px 12px; }
html:not(.dark) #article-view.sepia { background:#F4ECD8; --bg:#F4ECD8; }

/* Previous / Next part buttons */
.part-nav { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:center; gap:12px; margin:8px 0 28px; padding-top:20px; border-top:1px solid var(--line); }
.part-status { order:2; flex:1 1 100%; text-align:center; font-size:.85rem; color:var(--muted); }
.part-btn { padding:12px 22px; border:1px solid var(--line); border-radius:10px; background:var(--card); font-weight:700; text-decoration:none; }
.part-btn.primary { margin-left:auto; border-color:#0F6470; background:#0F6470; color:#fff; }
@media (min-width:600px) { .part-status { order:0; flex:0 1 auto; } }
#related { padding-bottom:48px; }

#message-view { padding-top:70px; padding-bottom:90px; text-align:center; }
#message-view p { margin:14px 0 24px; }

footer { background:#000; color:#cbd5e1; padding:32px 0; font-size:.9rem; }
footer .wrap { display:flex; flex-wrap:wrap; align-items:center; gap:16px; }
footer p:last-child { margin-left:auto; }

#toast { position:fixed; right:16px; bottom:16px; z-index:70; padding:12px 18px; border-radius:12px; background:#16181c; border:1px solid #2f3336; color:#fff; opacity:0; pointer-events:none; transition:opacity .3s; }
#toast.show { opacity:1; }

@media (max-width:700px) {
    .hero { flex-direction:column; text-align:center; gap:20px; padding:28px 20px; }
    .hero img { width:130px; height:130px; }
    input[type=search] { width:100%; }
    footer p:last-child { margin-left:0; }
}

@media print {
    #read-progress, .topbar, #overlay, #drawer, #article-bar, #related, .part-nav, .sources-btn, #links, footer, #toast { display:none !important; }
    html, body, #article-view { background:#fff !important; color:#000 !important; }
    .prose details { background:none !important; break-inside:avoid; }
    .prose a { color:#000; }
}
