/*
Theme Name: OnStory Clean
Theme URI: https://example.com/
Author: OpenAI
Description: Lightweight mobile-first WordPress story/news theme with chapter reader and AdSense-ready placements.
Version: 3.0.0
Requires at least: 6.2
Requires PHP: 8.0
Text Domain: onstory
*/

:root{
  --os-bg:#fff;--os-surface:#fff;--os-text:#171717;--os-muted:#6f6f6f;--os-border:#e9e9e9;
  --os-accent:#111;--os-link:#171717;--os-max:1120px;--os-reading:760px;
  --os-radius:8px;--os-mobile-pad:14px;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--os-bg);color:var(--os-text);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;-webkit-font-smoothing:antialiased;line-height:1.5;overflow-wrap:anywhere}
a{color:var(--os-link);text-decoration:none}
a:hover{text-decoration:none}
a:focus-visible,button:focus-visible,input:focus-visible{outline:2px solid #111;outline-offset:3px}
img{max-width:100%;height:auto;display:block}
button,input{font:inherit}
.os-wrap{width:min(calc(100% - 32px),var(--os-max));margin-inline:auto}
.screen-reader-text{position:absolute!important;clip:rect(1px,1px,1px,1px);clip-path:inset(50%);height:1px;width:1px;overflow:hidden;white-space:nowrap}

/* Header */
.site-header{height:70px;border-bottom:1px solid var(--os-border);background:rgba(255,255,255,.98);display:flex;align-items:center;position:relative;z-index:100}
.site-header-inner{display:flex;align-items:center;gap:24px;min-width:0}
.site-branding{font-size:22px;font-weight:800;line-height:1.1;white-space:nowrap;min-width:0}
.site-branding>a{display:block;overflow:hidden;text-overflow:ellipsis}
.site-branding img{max-height:38px;width:auto}
.header-search-toggle{display:none;border:0;background:transparent;width:42px;height:42px;border-radius:50%;font-size:21px;cursor:pointer;margin-left:auto}
.header-search{margin-left:auto;width:min(420px,48vw);position:relative}
.header-search input{width:100%;height:42px;border:1px solid #e5e5e5;border-radius:8px;padding:0 42px 0 14px;font-size:14px;background:#fafafa;outline:none}
.header-search input:focus{border-color:#bdbdbd;background:#fff}
.header-search button{position:absolute;right:6px;top:6px;width:30px;height:30px;border:0;background:transparent;cursor:pointer;font-size:17px}

/* Shared */
.main-space{padding:36px 0 64px}
.section-title{font-size:24px;line-height:1.2;margin:0 0 20px;font-weight:800;letter-spacing:-.01em}
.post-cat{display:inline-block;margin-top:10px;font-size:12px;line-height:1.2;font-weight:700;color:var(--os-muted)}
.post-meta{font-size:12px;color:#888;display:flex;gap:7px;align-items:center;margin-top:4px}
.os-thumb-placeholder{display:grid;place-items:center;width:100%;height:100%;background:#f1f1f1;color:#aaa;font-size:12px;font-weight:800;text-transform:uppercase;letter-spacing:.08em}

/* Home featured */
.featured-grid{display:grid;grid-template-columns:minmax(0,1.65fr) minmax(0,1fr) minmax(0,1fr);gap:22px;margin-bottom:44px;align-items:start}
.featured-card{min-width:0;overflow:hidden}
.featured-card .thumb{display:block;aspect-ratio:16/10;overflow:hidden;border-radius:var(--os-radius);background:#eee}
.featured-card .thumb img{width:100%;height:100%;object-fit:cover;transition:transform .2s ease}
@media(hover:hover){.featured-card:hover .thumb img{transform:scale(1.015)}}
.featured-card h2{font-size:24px;line-height:1.18;margin:6px 0 6px;letter-spacing:-.015em}
.featured-card.small h2{font-size:17px;line-height:1.28;margin-top:5px}

/* Feed */
.news-list{display:flex;flex-direction:column;min-width:0}
.news-card{display:grid;grid-template-columns:240px minmax(0,1fr);gap:20px;padding:20px 0;border-bottom:1px solid var(--os-border);min-width:0}
.news-card:first-child{padding-top:0}
.news-thumb{display:block;aspect-ratio:16/10;overflow:hidden;border-radius:var(--os-radius);background:#eee}
.news-thumb img{width:100%;height:100%;object-fit:cover}
.news-body{min-width:0}
.news-body h2{font-size:20px;line-height:1.26;margin:5px 0 8px;letter-spacing:-.01em}
.news-excerpt{font-size:14px;line-height:1.62;color:#666;margin:0;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
.news-card:nth-of-type(n+7){content-visibility:auto;contain-intrinsic-size:180px}
.load-more-wrap{text-align:center;padding:28px 0 8px}
.os-load-more{min-height:44px;padding:0 22px;border:1px solid #dcdcdc;border-radius:8px;background:#fff;font-weight:750;cursor:pointer}
.os-load-more:hover{background:#f7f7f7}

/* Viewed */
.viewed-section{margin-top:44px;padding-top:26px;border-top:1px solid var(--os-border)}
.viewed-list{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:18px}
.viewed-empty{color:#777;font-size:14px}
.viewed-item{font-size:14px;font-weight:700;line-height:1.4}

/* Archives */
.archive-head{margin-bottom:24px}
.archive-head h1{font-size:30px;line-height:1.15;margin:0;letter-spacing:-.02em}
.os-pagination{display:flex;justify-content:center;gap:8px;margin-top:32px;flex-wrap:wrap}
.os-pagination .page-numbers{display:inline-grid;place-items:center;min-width:40px;min-height:40px;padding:7px 10px;border:1px solid #e1e1e1;border-radius:7px}
.os-pagination .current{background:#111;color:#fff;border-color:#111}

/* Story */
.story-shell{width:min(calc(100% - 32px),980px);margin:0 auto;padding:34px 0 66px}
.story-head{width:min(100%,var(--os-reading));margin:0 auto}
.story-breadcrumb{font-size:13px;font-weight:700;color:#666;margin-bottom:9px}
.story-title{font-size:38px;line-height:1.14;letter-spacing:-.025em;margin:0 0 13px}
.chapter-kicker{font-size:22px;line-height:1.25;margin:0 0 19px}
.reader-tools{display:flex;flex-wrap:wrap;gap:22px;align-items:flex-end;padding:14px 0 17px;border-top:1px solid var(--os-border);border-bottom:1px solid var(--os-border);margin-bottom:26px}
.reader-group-label{font-size:12px;color:#777;margin-bottom:6px}
.reader-buttons{display:flex;gap:7px;align-items:center}
.reader-button{width:36px;height:34px;border:1px solid #ddd;border-radius:6px;background:#fff;cursor:pointer;font-weight:700}
.reader-button[data-theme="light"]{background:#fff}
.reader-button[data-theme="sepia"]{background:#f5eddb}
.reader-button[data-theme="dark"]{background:#242424;color:#fff}
.font-value{min-width:42px;text-align:center;font-size:13px}
.story-content{width:min(100%,var(--os-reading));margin:0 auto;font-family:Georgia,"Times New Roman",serif;font-size:22px;line-height:1.72;overflow-wrap:break-word}
.story-content p{margin:0 0 1.15em}
.story-content img{margin:1.35em auto;border-radius:4px}
.story-content figure{margin:1.35em 0}
.story-content h2,.story-content h3{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;line-height:1.25;letter-spacing:-.015em}
.story-content iframe,.story-content video{max-width:100%}
.chapter-nav{width:min(100%,var(--os-reading));margin:32px auto 0;display:grid;grid-template-columns:1fr 1fr;gap:12px}
.chapter-nav>div:last-child{text-align:right}
.chapter-nav a{display:inline-flex;align-items:center;justify-content:center;min-height:46px;border:1px solid #d9d9d9;border-radius:8px;padding:0 17px;font-weight:800;font-size:13px}
.toc-box{width:min(100%,var(--os-reading));margin:32px auto 0;border-top:1px solid var(--os-border);padding-top:23px}
.toc-title{display:flex;justify-content:space-between;gap:15px;align-items:flex-start}
.toc-title h3{font-size:19px;line-height:1.3;margin:0}
.toc-count{font-size:12px;color:#777;white-space:nowrap}
.toc-list{list-style:none;padding:0;margin:14px 0 0}
.toc-list li{border-top:1px solid #f0f0f0}
.toc-list a{display:flex;gap:12px;padding:12px 0;font-weight:700;font-size:14px;align-items:center}
.toc-list .num{color:#999;width:24px;flex:0 0 24px}
.same-category{width:min(100%,var(--os-max));margin:50px auto 0;padding-top:30px;border-top:1px solid var(--os-border)}
.same-category-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:20px}
.same-card{min-width:0}
.same-card .thumb{display:block;aspect-ratio:16/10;overflow:hidden;background:#eee;border-radius:var(--os-radius)}
.same-card .thumb img{width:100%;height:100%;object-fit:cover}
.same-card h3{font-size:16px;line-height:1.34;margin:7px 0 0}

/* Ads: rendered only if the corresponding widget area contains code. */
.os-ad-slot{width:min(100%,var(--os-reading));margin:24px auto;text-align:center;overflow:hidden}
.os-ad-label{font-size:9px;line-height:1;text-transform:uppercase;letter-spacing:.09em;color:#aaa;margin-bottom:6px}
.os-ad-widget{width:100%;text-align:center}
.os-ad-widget ins{max-width:100%}
.news-list>.os-ad-slot{width:100%;margin:18px 0;padding-bottom:18px;border-bottom:1px solid var(--os-border)}

/* Footer */
.site-footer{border-top:1px solid var(--os-border);padding:28px 0 38px;background:var(--os-surface)}
.footer-top{display:flex;justify-content:space-between;gap:28px;align-items:center}
.footer-title{font-weight:800;font-size:18px}
.footer-nav{display:flex;flex-wrap:wrap;gap:16px;font-size:13px;list-style:none;padding:0;margin:0}
.footer-nav li{margin:0}
.copyright{font-size:12px;color:#888;margin-top:14px}

/* Reader themes */
.reader-sepia{--os-bg:#f6f0e3;--os-surface:#f6f0e3;--os-text:#29251e;--os-border:#ded5c4;--os-link:#29251e}
.reader-dark{--os-bg:#1c1c1c;--os-surface:#1c1c1c;--os-text:#e8e8e8;--os-border:#353535;--os-link:#f2f2f2}
.reader-dark .reader-button{border-color:#555}.reader-dark .reader-button:not([data-theme]){background:#2a2a2a;color:#fff}
.reader-dark .story-breadcrumb,.reader-dark .reader-group-label,.reader-dark .post-meta,.reader-dark .toc-count{color:#aaa}
.reader-dark .header-search input{background:#262626;color:#eee;border-color:#444}

@media(max-width:850px){
  .featured-grid{grid-template-columns:1fr 1fr}.featured-card:first-child{grid-column:1/-1}
  .news-card{grid-template-columns:180px minmax(0,1fr)}
  .same-category-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .story-title{font-size:33px}
}

/* Mobile-first experience: 360–430px is the primary target. */
@media(max-width:600px){
  .os-wrap{width:100%;padding-inline:var(--os-mobile-pad)}
  .site-header{height:58px;padding:0;position:sticky;top:0;background:rgba(255,255,255,.97);backdrop-filter:saturate(150%) blur(8px);-webkit-backdrop-filter:saturate(150%) blur(8px)}
  .reader-dark .site-header{background:rgba(28,28,28,.97)}
  .site-header-inner{height:58px;gap:8px;flex-wrap:nowrap;position:relative}
  .site-branding{font-size:20px;max-width:calc(100% - 50px)}
  .site-branding img{max-height:32px;max-width:210px}
  .header-search-toggle{display:inline-grid;place-items:center;flex:0 0 42px}
  .header-search{display:none;position:absolute;left:0;right:0;top:58px;width:auto;margin:0 -14px;padding:10px 14px;background:var(--os-surface);border-top:1px solid var(--os-border);border-bottom:1px solid var(--os-border);z-index:50}
  .header-search.is-open{display:block}
  .header-search input{height:44px;background:#f7f7f7}

  .main-space{padding:20px 0 46px}
  .section-title{font-size:21px;margin-bottom:15px}

  /* Featured: exactly one hero + compact secondary cards. Prevents oversized/overlapping blocks. */
  .featured-grid{display:flex;flex-direction:column;gap:0;margin-bottom:30px}
  .featured-card{width:100%;overflow:visible}
  .featured-card:first-child{padding-bottom:18px;margin-bottom:4px}
  .featured-card:first-child .thumb{aspect-ratio:16/9;max-height:246px;border-radius:7px}
  .featured-card:first-child h2{font-size:23px;line-height:1.19;margin:6px 0 4px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
  .featured-card.small{display:grid;grid-template-columns:104px minmax(0,1fr);grid-template-rows:auto 1fr;column-gap:12px;padding:13px 0;border-top:1px solid var(--os-border);align-items:start}
  .featured-card.small .thumb{grid-column:1;grid-row:1/3;aspect-ratio:1/1;border-radius:7px}
  .featured-card.small .post-cat{grid-column:2;grid-row:1;margin:1px 0 4px;font-size:10px}
  .featured-card.small h2{grid-column:2;grid-row:2;font-size:16px;line-height:1.28;margin:0;display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden}
  .post-cat{margin-top:8px;font-size:11px}
  .post-meta{font-size:11px;flex-wrap:wrap}

  /* Feed */
  .news-card{grid-template-columns:104px minmax(0,1fr);gap:12px;padding:14px 0;align-items:start;content-visibility:visible}
  .news-thumb{border-radius:7px;aspect-ratio:1/1}
  .news-body h2{font-size:16px;line-height:1.3;margin:3px 0 0;display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden}
  .news-excerpt{display:none}
  .load-more-wrap{padding-top:22px}
  .os-load-more{width:100%;min-height:48px;font-size:15px}
  .viewed-section{margin-top:34px;padding-top:21px}
  .viewed-list{display:block}
  .viewed-item{display:block;padding:13px 0;border-top:1px solid var(--os-border);font-size:15px}
  .viewed-item:first-child{border-top:0;padding-top:0}

  .archive-head{margin-bottom:18px}.archive-head h1{font-size:26px}

  /* Story */
  .story-shell{width:100%;padding:20px var(--os-mobile-pad) 46px}
  .story-head{width:100%}
  .story-breadcrumb{font-size:12px;margin-bottom:7px}
  .story-title{font-size:clamp(28px,7.8vw,35px);line-height:1.12;margin-bottom:11px}
  .chapter-kicker{font-size:19px;margin-bottom:15px}
  .reader-tools{display:grid;grid-template-columns:1fr 1fr;gap:12px;padding:11px 0 13px;margin-bottom:18px}
  .reader-group-label{font-size:11px;margin-bottom:5px}
  .reader-buttons{gap:6px}
  .reader-button{width:36px;height:34px}
  .story-content{width:100%;font-size:20px;line-height:1.7}
  .story-content p{margin-bottom:1.08em}
  .story-content img{max-width:100%;height:auto;margin:1.15em auto}
  .chapter-nav{width:100%;margin-top:26px;grid-template-columns:1fr;gap:10px}
  .chapter-nav>div:empty{display:none}
  .chapter-nav>div:last-child{text-align:left}
  .chapter-nav a{width:100%;min-height:54px;border-radius:9px;font-size:15px}
  .chapter-nav>div:last-child a{background:#111;color:#fff;border-color:#111}
  .reader-dark .chapter-nav>div:last-child a{background:#f1f1f1;color:#111;border-color:#f1f1f1}
  .toc-box{width:100%;margin-top:27px;padding-top:21px}
  .toc-title{display:block}.toc-title h3{font-size:17px}.toc-count{display:block;margin-top:4px}
  .toc-list a{min-height:48px;font-size:15px}
  .same-category{width:100%;margin-top:36px;padding-top:24px}
  .same-category-grid{grid-template-columns:1fr;gap:20px}
  .same-card h3{font-size:18px}

  /* Ad containers only exist when configured. Reserve stable space to reduce CLS. */
  .os-ad-slot{width:100%;margin:20px auto;min-height:250px;display:flex;flex-direction:column;justify-content:center;content-visibility:auto;contain-intrinsic-size:250px}
  .main-space>.os-wrap>.os-ad-slot{margin:2px 0 25px;min-height:180px}
  .news-list>.os-ad-slot{min-height:250px;margin:15px 0;padding-bottom:15px}

  .site-footer{padding:24px 0 calc(32px + env(safe-area-inset-bottom))}
  .footer-top{display:block}.footer-title{margin-bottom:13px}.footer-nav{gap:10px 15px;line-height:1.6}
  body{padding-bottom:env(safe-area-inset-bottom)}
}

@media(max-width:370px){
  :root{--os-mobile-pad:12px}
  .featured-card.small{grid-template-columns:96px minmax(0,1fr);gap:10px}
  .news-card{grid-template-columns:96px minmax(0,1fr);gap:10px}
  .news-body h2{font-size:15px}
  .story-content{font-size:19px}
  .reader-tools{grid-template-columns:1fr}
}

@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important;animation:none!important}}
