/*
Theme Name: KS Modern
Theme URI: https://example.com/ks-modern
Author: Knongsrok
Author URI: https://www.knongsrok.com/
Description: A clean, modern, responsive WordPress theme with card grids, sticky header, and polished typography.
Version: 1.0.6
Requires at least: 6.3
Tested up to: 6.8
Requires PHP: 7.4
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: ks-modern
*/

/* ============================
   Design Tokens / Base
============================ */
:root{
  --bg:#0b0b0c; --bg-2:#121214; --card:#161618; --text:#e9e9ea; --muted:#a1a1a6;
  --link:#7aa7ff; --accent:#ffb703; --accent-2:#219ebc; --border:#2a2a2e;
  --radius:16px; --shadow:0 6px 28px rgba(0,0,0,.22);
  --max:1120px; --container-pad:20px;
  --fs-xs:12px; --fs-sm:14px; --fs-base:16px; --fs-lg:18px; --fs-xl:22px; --fs-2xl:28px;
  --lh:1.6;
}

*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0;
  background:linear-gradient(180deg,var(--bg) 0%,var(--bg-2) 100%);
  color:var(--text);
  font:var(--fs-base)/var(--lh) Inter,system-ui,-apple-system,Segoe UI,Roboto,Noto Sans,Arial,"Khmer OS Battambang","Hanuman",sans-serif;
  text-rendering:optimizeLegibility;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}
img{max-width:100%;height:auto;border-radius:calc(var(--radius) - 6px)}
a{color:var(--link);text-decoration:none}
a:hover{text-decoration:underline}
hr{border:0;border-top:1px solid var(--border);margin:24px 0}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:8px}
.container{width:min(100%,var(--max));margin:0 auto;padding:0 var(--container-pad)}
.mt-2{margin-top:.5rem}.mt-4{margin-top:1rem}.mt-6{margin-top:1.5rem}.mb-0{margin-bottom:0}.center{text-align:center}

/* ============================
   Header (logo centered, menu left, search right)
============================ */
.site-header{
  position:sticky; top:0; z-index:1000;
  background:rgba(18,18,20,.85);
  backdrop-filter:blur(10px);
  border-bottom:1px solid var(--border);
}
/* avoid admin bar overlap */
.admin-bar .site-header{top:32px}
@media (max-width:782px){.admin-bar .site-header{top:46px}}

.header-inner{display:flex; align-items:center; gap:16px; padding:14px 0; position:relative}

/* buttons */
.menu-toggle{
  display:none; justify-content:center; align-items:center;
  height:36px; min-width:44px; padding:0 10px; cursor:pointer;
  border:1px solid var(--border); background:var(--card); color:var(--text);
  border-radius:12px; z-index:1001;
}

/* search container (icon + expanding input) */
.header-search{margin-left:auto; position:relative; display:flex; align-items:center; gap:8px}
.header-search .search-form{display:flex; align-items:center; gap:8px; margin:0}
.header-search input[type="search"]{
  width:0; opacity:0; padding:0; border:none; background:transparent;
  transition:all .22s ease; border-radius:12px; color:var(--text);
}
.header-search .search-toggle{
  display:inline-flex; justify-content:center; align-items:center;
  height:36px; min-width:44px; padding:0 10px; cursor:pointer;
  border:1px solid var(--border); background:var(--card); color:var(--text);
  border-radius:12px;
}
/* expanded state */
.header-search.active input[type="search"]{
  width:200px; opacity:1; padding:8px 10px;
  background:var(--card); border:1px solid var(--border);
}

/* brand centered */
.site-branding{display:flex; align-items:center; gap:10px; position:absolute; left:50%; transform:translateX(-50%)}
.brand-logo{width:40px;height:40px;border-radius:12px;display:inline-block;background:linear-gradient(135deg,var(--accent),var(--accent-2))}
.brand-title{font-weight:800;letter-spacing:.2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:60vw}
.custom-logo-link{display:inline-flex;align-items:center}
.custom-logo-link img,.custom-logo{max-height:50px;width:auto;height:auto;border-radius:8px;display:block}

/* nav (desktop) */
.primary-nav{margin-left:auto;position:relative;display:flex;align-items:center}
.primary-nav ul{list-style:none;margin:0;padding:0;display:flex;gap:16px}
.primary-nav a{display:block;padding:8px 12px;border-radius:10px}
.primary-nav a:hover{background:rgba(255,255,255,.06);text-decoration:none}

/* ---------- Mobile header layout (one row) ---------- */
@media (max-width:860px){
  .header-inner{
    display:flex !important;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    padding:10px 12px;
    position:relative;
  }

  .menu-toggle{
    display:inline-flex !important;
    justify-content:center; align-items:center;
    height:36px; min-width:44px; padding:0 10px;
    border:1px solid var(--border); background:var(--card); color:var(--text);
    border-radius:12px; z-index:1001; margin:0 !important;
  }

  .site-branding{
    position:absolute !important; left:50%; transform:translateX(-50%) !important;
    display:flex; align-items:center; gap:8px; margin:0 !important; min-width:0;
  }
  .custom-logo-link img, .custom-logo{ max-height:40px; height:auto; width:auto; display:block }
  .brand-title{ max-width:55vw; white-space:nowrap; overflow:hidden; text-overflow:ellipsis }
  @media (max-width:420px){ .brand-title{ display:none } }

  .header-search{ margin-left:auto; display:flex; align-items:center; z-index:1001; }

  /* Dropdown on its own row under the bar */
  .primary-nav{ position:absolute; left:0; right:0; top:100%; width:100% }
  .primary-nav ul{
    display:none; position:absolute; left:0; right:0; top:0;
    padding:12px 20px; gap:12px;
    background:var(--bg-2);
    border-top:1px solid var(--border);
    border-bottom:1px solid var(--border);
    animation:fadeSlide .18s ease-out;
  }
  .primary-nav ul.open{ display:block }
}
@keyframes fadeSlide{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:translateY(0)}}

/* ============================
   Footer
============================ */
.site-footer{border-top:1px solid var(--border);background:var(--bg-2);color:var(--muted);padding:40px 0}
.footer-widgets{display:grid;grid-template-columns:repeat(12,1fr);gap:20px}
.footer-col{grid-column:span 4;background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:18px}
@media (max-width:920px){.footer-col{grid-column:span 12}}

/* ============================
   Layout / Cards
============================ */
.site-main{padding:26px 0 60px}
.grid{display:grid;grid-template-columns:repeat(12,1fr);gap:20px}
.card{grid-column:span 4;background:var(--card);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow)}
.card-body{padding:16px}
.card-title{font-size:1.05rem;font-weight:700;margin:.2rem 0 .4rem}
.card-meta{color:var(--muted);font-size:.9rem}
@media (max-width:920px){.card{grid-column:span 6}}
@media (max-width:640px){.card{grid-column:span 12}}

/* Grid cards: image + 2-line title only (compact mode) */
.card .card-img{ display:block; width:100%; height:auto }
.grid .card{ display:flex; flex-direction:column }
.card-body .card-title a{ color:var(--text); text-decoration:none }
.card-body .card-title a:hover{ text-decoration:underline }
.card--compact { padding-bottom:8px }
.card--compact .card-media img{ display:block; width:100%; height:auto; border-radius:calc(var(--radius) - 6px) }
.card--compact .card-body{ padding:14px 16px }
.card--compact .card-title{ margin:0 }
.card--compact .card-title a{
  color:var(--text); text-decoration:none; display:-webkit-box;
  -webkit-box-orient:vertical; -webkit-line-clamp:2; overflow:hidden;
}
.card--compact .card-meta, .card--compact p{ display:none !important }

/* ============================
   Typography & Content
============================ */
.post-header{margin-bottom:16px}
.post-title{font-size:clamp(1.6rem,3vw,2.2rem);line-height:1.2;margin:.2rem 0 .6rem}
.post-meta{color:var(--muted);font-size:.95rem}
.post-content{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:24px}
.post-content ul,.post-content ol{padding-left:1.2rem;margin:.6rem 0}
.post-content li+li{margin-top:.25rem}
.post-content :where(h2,h3,h4){margin-top:1.6rem}
.post-content blockquote{margin:1.2rem 0;padding:12px 16px;background:#101013;border-left:4px solid var(--accent);border-radius:12px}
.post-content pre,.post-content code{background:#0f0f12;border-radius:8px;padding:.2em .4em;overflow-x:auto}
.post-content img,.post-content figure img{max-width:100%;height:auto}
.alignleft{float:left;margin:.5rem 1rem .5rem 0}
.alignright{float:right;margin:.5rem 0 .5rem 1rem}
.aligncenter{display:block;margin-left:auto;margin-right:auto}
.rounded{ border-radius:calc(var(--radius) - 6px) }

/* Tags & Pagination */
.tag{display:inline-block;font-size:.85rem;color:#111;background:#ffd166;border-radius:999px;padding:4px 10px;margin-right:8px}
.pagination{display:flex;flex-wrap:wrap;gap:10px;margin-top:20px}
.pagination a,.pagination span{padding:8px 12px;border-radius:10px;background:var(--card);border:1px solid var(--border)}

/* ============================
   Forms / Comments
============================ */
.search-form{display:flex;gap:10px}
.search-form input[type="search"]{flex:1;padding:10px 12px;background:var(--card);color:var(--text);border:1px solid var(--border);border-radius:12px;outline:none}
.search-form button{padding:10px 14px;border-radius:12px;border:1px solid var(--border);background:var(--bg-2);color:var(--text);cursor:pointer}
.commentlist{list-style:none;margin:0;padding:0}
.commentlist li{margin:0 0 16px;padding:16px;background:var(--card);border:1px solid var(--border);border-radius:12px}
.commentlist .comment-author{font-weight:700}
.commentlist .comment-meta{color:var(--muted);font-size:.9rem}

/* Widgets */
.widget{margin:0 0 20px;background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:16px}
.widget-title{margin:0 0 12px;font-weight:800}

/* Buttons */
.btn{display:inline-flex;gap:8px;align-items:center;padding:10px 14px;border-radius:12px;text-decoration:none;background:linear-gradient(135deg,var(--accent),var(--accent-2));color:#101011;font-weight:700;border:0}
.btn:hover{opacity:.92;text-decoration:none}

/* ============================
   Hero (home)
============================ */
.hero-section{
  position:relative; min-height:52vh; display:flex; align-items:flex-end;
  border-bottom:1px solid var(--border); background:#0d0d10;
}
.hero-bg{ position:absolute; inset:0; background-size:cover; background-position:center; filter:contrast(1.05) brightness(.8) }
.hero-overlay{ position:absolute; inset:0; background:linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(11,11,12,.75) 60%, rgba(11,11,12,1) 100%) }
.hero-inner{ position:relative; z-index:2; padding:48px 0 }
.hero-content{ max-width:760px; padding:16px 0 32px }
.hero-kicker{ color:var(--muted); margin:0 0 6px }
.hero-title{ font-size:clamp(1.8rem,3.6vw,2.8rem); line-height:1.15; margin:.2rem 0 .6rem; font-weight:800 }
.hero-title a{ color:var(--text); text-decoration:none }
.hero-meta{ color:var(--muted); margin:.2rem 0 1rem }
.hero-excerpt{ color:var(--text); max-width:60ch; margin:0 0 1rem }
@media (max-width:860px){ .hero-section{ min-height:42vh } .hero-inner{ padding:28px 0 } }
.section-title{ font-size:clamp(1.2rem,2.2vw,1.4rem); font-weight:800; margin:0 0 12px }
.featured-row .grid{ margin-top:12px }

/* ============================
   Layout with right sidebar
============================ */
.layout{
  display:grid;
  grid-template-columns: minmax(0,1fr) 320px;
  gap:24px;
}
.content-area, .loop-area{ min-width:0 }
.sidebar{ position:relative }
@media (max-width:1000px){
  .layout{ grid-template-columns:1fr }
  .sidebar{ order:2 }
}

/* ============================
   Gutenberg / Blocks
============================ */
.alignwide{max-width:1120px;margin-left:auto;margin-right:auto}
.alignfull{width:100vw;margin-left:50%;transform:translateX(-50%)}
.wp-block-image img{border-radius:calc(var(--radius) - 6px)}
.wp-block-quote{border-left:4px solid var(--accent);background:#101013;padding:12px 16px;border-radius:12px}
.wp-block-code{background:#0f0f12;color:#eaeaea;border-radius:8px}
.wp-block-pullquote{border-top:1px solid var(--border);border-bottom:1px solid var(--border)}
.wp-block-table{border-color:var(--border)}
.wp-block-button__link{background:linear-gradient(135deg,var(--accent),var(--accent-2));color:#101011;border-radius:12px;padding:10px 14px}

/* ============================
   Captions / Accessibility / Tables
============================ */
.wp-caption{max-width:100%}
.wp-caption-text{color:var(--muted);font-size:.9rem;margin-top:6px}
.screen-reader-text{position:absolute!important;height:1px;width:1px;overflow:hidden;clip:rect(1px,1px,1px,1px);white-space:nowrap;border:0;padding:0;margin:-1px}
.screen-reader-text:focus{position:static!important;height:auto;width:auto;clip:auto;margin:0;padding:8px 12px;background:var(--accent);color:#111;border-radius:8px}
table{width:100%;border-collapse:collapse;margin:1rem 0;background:var(--card);border:1px solid var(--border);border-radius:12px;overflow:hidden}
th,td{padding:10px 12px;border-bottom:1px solid var(--border)}
thead th{background:#1b1b1f;text-align:left}

/* ============================
   Responsive tweaks
============================ */
@media (max-width:700px){
  :root{--container-pad:16px}
  .post-content{padding:18px}
  .header-inner{padding:10px 0}
}

/* ============================
   Ads helpers
============================ */
.ks-ad--top, .ks-ad--inline, .ks-ad--bottom { display:block; text-align:center; }
.ks-ad--top > *, .ks-ad--inline > *, .ks-ad--bottom > * { margin-left:auto; margin-right:auto; }
/* hide empty ad boxes */
.ks-ad--top:empty, .ks-ad--inline:empty, .ks-ad--bottom:empty { display:none !important; }

/* ============================
   Responsive embeds (CSS part)
============================ */
.embed-responsive,
.wp-block-embed__wrapper,
.wp-has-aspect-ratio,
.wp-block-video,
.wp-block-embed,
.wp-embed-aspect-16-9,
.wp-embed-aspect-4-3 {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border-radius: calc(var(--radius) - 6px);
  background: #000;
}
/* default ratio if none detected */
.embed-responsive,
.wp-block-embed__wrapper,
.wp-block-video { aspect-ratio: 16 / 9; }
/* respect WP aspect classes when present */
.wp-embed-aspect-16-9 { aspect-ratio: 16/9; }
.wp-embed-aspect-4-3  { aspect-ratio: 4/3;  }
.wp-embed-aspect-1-1  { aspect-ratio: 1/1;  }
/* make children fill the box */
.embed-responsive iframe,
.embed-responsive video,
.wp-block-embed__wrapper iframe,
.wp-block-video video,
.wp-has-aspect-ratio iframe,
.wp-has-aspect-ratio video,
.wp-block-embed iframe,
.wp-block-embed object,
.wp-block-embed embed {
  position:absolute; inset:0; width:100%; height:100%; border:0;
}
/* social widgets */
.twitter-tweet, .instagram-media, .fb-post, .tiktok-embed {
  max-width:100% !important; margin-left:auto; margin-right:auto;
}

/* ============================
   Empty-content safety
============================ */
.entry-content:empty,
.post-content:empty {
  min-height:0 !important;
  padding:0 !important;
  margin:0 !important;
}
.content-area { min-height:unset !important; }
/* ============================
   Responsive Embeds Refinement
   ============================ */
.embed-responsive,
.wp-block-embed__wrapper,
.wp-block-embed,
.wp-has-aspect-ratio {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 1.5em 0;
  background: #000; /* keep black for videos */
  overflow: hidden;
}

/* Default aspect ratio (16:9) */
.embed-responsive iframe,
.wp-block-embed__wrapper iframe,
.wp-block-embed iframe,
.wp-has-aspect-ratio iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
}

/* Remove giant empty boxes when no iframe exists */
.embed-responsive:empty,
.wp-block-embed__wrapper:empty,
.wp-block-embed:empty {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Smarter default ratio — only apply padding if iframe exists */
.embed-responsive:has(iframe),
.wp-block-embed__wrapper:has(iframe),
.wp-block-embed:has(iframe) {
  padding-bottom: 56.25%; /* 16:9 */
}

/* If content is shorter (like SoundCloud embeds) */
.wp-block-embed.is-type-rich {
  padding-bottom: 120px !important;
  height: auto !important;
}

/* YouTube Shorts & TikTok (vertical embeds) */
.wp-block-embed.is-provider-youtube:has(iframe[src*="shorts"]),
.wp-block-embed.is-provider-tiktok:has(iframe) {
  padding-bottom: 177.77% !important; /* ~9:16 */
}
/* --- Fix: collapse empty embed boxes / ad frames --- */
.embed-responsive{ aspect-ratio:auto; min-height:0; background:#000; }
.embed-responsive.is-empty{ display:none !important; }

/* If an iframe lives in an ad container, never force height */
.ks-ad iframe,
.ks-ad--top iframe,
.ks-ad--inline iframe,
.ks-ad--bottom iframe{ height:auto !important; max-height:none !important; }

/* Safety cap for huge embeds */
.embed-responsive > iframe,
.embed-responsive > video{ max-height:70vh; object-fit:contain; }

/* ================================
   KS Modern – LIGHT NEWS THEME
   Paste at the very end of style.css
================================ */

/* 1) Palette overrides (tokens) */
:root{
  --bg:#ffffff;
  --bg-2:#ffffff;
  --card:#ffffff;
  --text:#111111;
  --muted:#555d66;          /* secondary text */
  --link:#0a58ca;           /* newsy blue */
  --accent:#e00000;         /* red accent vibe */
  --accent-2:#0a58ca;       /* blue accent */
  --border:#e6e8eb;         /* light grey lines */
  --radius:10px;            /* a bit tighter than dark look */
  --shadow:0 1px 2px rgba(16,24,40,.06), 0 1px 1px rgba(16,24,40,.04);
}

/* 2) Global surface + copy color */
html, body { background:#fff !important; color:var(--text) !important; }

/* 3) Header: white bar with subtle divider */
.site-header{
  background:#fff !important;
  backdrop-filter:none !important;
  border-bottom:1px solid var(--border) !important;
  box-shadow:0 1px 0 var(--border);
}
.menu-toggle,
.header-search .search-toggle{
  background:#fff; color:#111; border:1px solid var(--border);
}
.header-search.active input[type="search"]{
  background:#fff; color:#111; border:1px solid var(--border);
}
.primary-nav a{ color:#111; }
.primary-nav a:hover{ background:#f3f4f6; text-decoration:none; }

/* 4) Brand/title color */
.brand-title{ color:#111 !important; }

/* 5) Cards & grids: flat white, hairline borders */
.card{
  background:#fff !important;
  border:1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
  border-radius: var(--radius) !important;
}
.card-title a{ color:#111 !important; }
.card-title a:hover{ color:#0a58ca; text-decoration:underline; }
.card-meta{ color:var(--muted) !important; }

/* Compact cards (home “Latest”) still 2‑line clamp but on white */
.card--compact .card-title a{ color:#111 !important; }

/* 6) Article surfaces */
.post-content,
.post-featured,
.content-area{
  background:#fff !important;
  border:1px solid var(--border);
  border-radius:var(--radius);
}
.post-meta{ color:var(--muted) !important; }
.post-content blockquote{
  background:#fafafa; border-left:4px solid var(--accent);
}

/* 7) Links */
a{ color:var(--link); }
a:hover{ color:#0a3e91; }

/* 8) Footer: white with divider, not dark */
.site-footer{
  background:#fff !important;
  color:#111 !important;
  border-top:1px solid var(--border) !important;
}
.footer-col{
  background:#fff !important;
  border:1px solid var(--border);
  box-shadow: var(--shadow);
}

/* 9) Sidebar/Widgets: white cards, readable titles */
.sidebar, .widget{
  background:#fff !important;
  border:1px solid var(--border);
  box-shadow: var(--shadow);
}
.widget-title{ color:#111 !important; }

/* 10) Tag cloud / keywords on white */
.tagcloud a{
  background:#f3f4f6;
  color:#111 !important;
  border:1px solid var(--border);
  border-radius:6px;
  padding:4px 8px;
  margin:4px;
  display:inline-block;
}

/* 11) Hero section (if used): soften the overlay for light theme */
.hero-section{ background:#fff; border-bottom:1px solid var(--border); }
.hero-bg{ filter: none; }
.hero-overlay{
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,.85) 70%, #fff 100%);
}
.hero-title a{ color:#111; }
.hero-meta{ color:var(--muted); }

/* 12) Tables on white */
table{ background:#fff; border:1px solid var(--border); }
thead th{ background:#f6f7f9; }

/* 13) Forms on white */
.search-form input[type="search"]{
  background:#fff; color:#111; border:1px solid var(--border);
}
.search-form button{
  background:#fff; color:#111; border:1px solid var(--border);
}

/* 14) Ad blocks on white – centered, with subtle caption */
.ks-ad--top, .ks-ad--inline, .ks-ad--bottom{ background:#fff; }
.ks-ad-label{
  display:block; font-size:12px; color:#6b7280; text-transform:uppercase;
  letter-spacing:.08em; text-align:center; margin:8px 0;
}

/* 15) Responsive embeds keep light chrome */
.embed-responsive,
.wp-block-embed__wrapper,
.wp-has-aspect-ratio,
.wp-block-video{ background:#fff; border:1px solid var(--border); }

/* 16) Remove dark gradients that might linger */
body::before, body::after{ background:none !important; }
/* Footer link style for light theme */
.site-footer .footer-link{
  color:#111; text-decoration:none;
}
.site-footer .footer-link:hover{
  color:#0a58ca; text-decoration:underline;
}
.site-footer .footer-inline span[aria-hidden="true"]{
  color:#c6cbd1;
}
/* === Gradient "Read more" button styled like logo background === */
a.read-more,
a.more-link,
button.read-more,
.btn-readmore,
.hero .btn,
.btn {
  background: linear-gradient(90deg, #ffb347 0%, #ff7f50 50%, #cc0000 100%);
  color: #fff !important;
  border: 0;
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 700;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none !important;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
  transition: opacity .2s ease, transform .05s ease;
}

a.read-more:hover,
a.more-link:hover,
button.read-more:hover,
.btn-readmore:hover,
.hero .btn:hover,
.btn:hover {
  opacity: 0.9;          /* subtle dim on hover */
  text-decoration: none;
}

a.read-more:active,
a.more-link:active,
button.read-more:active,
.btn-readmore:active,
.hero .btn:active,
.btn:active {
  transform: translateY(1px);
}
/* ============================================================
   Hide site title text on DESKTOP only (keep logo + mobile)
============================================================ */

/* Desktop & tablet */
@media (min-width: 769px) {
  .site-branding .brand-title {
    display: none !important;
  }
}

/* Mobile keeps title visible */
@media (max-width: 768px) {
  .site-branding .brand-title {
    display: inline !important;
  }
}