/*
Theme Name: UpFypSO
Theme URI: https://upfypso.com
Author: UpFypSO
Author URI: https://upfypso.com
Description: YouTube-style dark gaming theme with sidebar, auto post loading, views counter, AdSense ready, SEO optimized (Rank Math compatible), fully responsive.
Version: 1.0.0
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 8.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: upfypso
Tags: dark, gaming, video, youtube-style, sidebar, responsive, seo-ready, adsense-ready
*/

/* === RESET & BASE === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --red: #cc0000;
  --red-bright: #ff1a1a;
  --red-glow: rgba(204,0,0,.35);
  --red-dim: rgba(204,0,0,.12);
  --gold: #ffcc00;
  --bg: #0a0a0a;
  --bg2: #111111;
  --bg3: #181818;
  --bg4: #222222;
  --border: #2a2a2a;
  --border2: #333333;
  --text: #e8e8e8;
  --muted: #999999;
  --muted2: #666666;
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 240px;
  --header-h: 60px;
  --font: 'Prompt', 'Noto Sans Thai', sans-serif;
  --transition: .2s ease;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: var(--text); }
img { max-width: 100%; height: auto; display: block; }
button { font-family: var(--font); cursor: pointer; border: none; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--red); }

/* === HEADER === */
.upf-header {
  position: sticky;
  top: 0;
  z-index: 500;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.upf-header__hamburger {
  width: 40px; height: 40px;
  background: none;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px; border-radius: 50%;
  transition: background var(--transition);
  flex-shrink: 0;
}
.upf-header__hamburger:hover { background: var(--bg4); }
.upf-header__hamburger span {
  display: block; width: 20px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: var(--transition);
}

.upf-header__logo {
  display: flex; align-items: center; gap: 8px;
  min-width: 140px; flex-shrink: 0;
  text-decoration: none;
}
.upf-header__logo-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--red);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
  position: relative; overflow: hidden;
}
.upf-header__logo-icon::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,.15));
}
.upf-header__logo-text {
  font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -.3px;
}
.upf-header__logo-text em { color: var(--red); font-style: normal; }

.upf-header__search {
  flex: 1; max-width: 640px; display: flex;
}
.upf-header__search-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border2);
  border-right: none; border-radius: 24px 0 0 24px;
  padding: 0 18px; height: 40px; color: var(--text);
  font-size: 14px; font-family: var(--font); outline: none;
  transition: border-color var(--transition);
}
.upf-header__search-input:focus { border-color: #555; }
.upf-header__search-input::placeholder { color: var(--muted2); }
.upf-header__search-btn {
  background: var(--bg4); border: 1px solid var(--border2);
  border-left: none; border-radius: 0 24px 24px 0;
  padding: 0 18px; height: 40px; color: var(--muted);
  transition: var(--transition); font-size: 16px;
}
.upf-header__search-btn:hover { background: var(--border2); color: var(--text); }

.upf-header__nav {
  display: flex; align-items: center; gap: 4px; margin-left: auto;
}
.upf-header__nav a {
  padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13px; font-weight: 500;
  transition: var(--transition); white-space: nowrap;
}
.upf-header__nav a:hover, .upf-header__nav a.current { color: var(--text); background: var(--bg4); }

/* === LAYOUT === */
.upf-layout { display: flex; min-height: calc(100vh - var(--header-h)); }

/* === SIDEBAR === */
.upf-sidebar {
  width: var(--sidebar-w);
  min-height: calc(100vh - var(--header-h));
  background: var(--bg2);
  border-right: 1px solid var(--border);
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; flex-shrink: 0;
  padding: 10px 0;
  transition: width var(--transition), transform var(--transition);
}
.upf-sidebar.collapsed { width: 72px; }
.upf-sidebar::-webkit-scrollbar { width: 0; }

.upf-sidebar__section { margin-bottom: 4px; }
.upf-sidebar__label {
  padding: 8px 16px 4px;
  font-size: 11px; font-weight: 600; color: var(--muted2);
  text-transform: uppercase; letter-spacing: .6px;
  white-space: nowrap; overflow: hidden;
}
.upf-sidebar.collapsed .upf-sidebar__label { opacity: 0; }

.upf-sidebar__item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; border-radius: 8px; margin: 2px 8px;
  color: var(--text); font-size: 14px;
  transition: background var(--transition);
  white-space: nowrap; overflow: hidden;
  position: relative;
}
.upf-sidebar__item:hover { background: var(--bg3); color: var(--text); }
.upf-sidebar__item.active {
  background: var(--red-dim);
  color: var(--red-bright);
  font-weight: 600;
}
.upf-sidebar__item.active::before {
  content: '';
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: var(--red);
  border-radius: 0 2px 2px 0;
}
.upf-sidebar__icon { font-size: 20px; width: 22px; text-align: center; flex-shrink: 0; }
.upf-sidebar__text { flex: 1; }
.upf-sidebar.collapsed .upf-sidebar__text,
.upf-sidebar.collapsed .upf-sidebar__badge { display: none; }
.upf-sidebar__badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 10px; color: #fff; flex-shrink: 0;
}
.upf-sidebar__badge.new { background: var(--red); }
.upf-sidebar__badge.hot { background: #ff6600; }

.upf-sidebar__divider {
  border: none; border-top: 1px solid var(--border);
  margin: 8px 16px;
}

/* === MAIN === */
.upf-main { flex: 1; min-width: 0; padding: 24px 28px 60px; }

/* === SEARCH RESULTS === */
.upf-search-notice {
  padding: 12px 0 20px;
  font-size: 15px; color: var(--muted);
}
.upf-search-notice strong { color: var(--text); }

/* === CHANNEL COVER === */
.upf-cover {
  border-radius: var(--radius);
  overflow: hidden; position: relative;
  height: 220px; margin-bottom: 20px;
  background: var(--bg3);
}
.upf-cover img { width: 100%; height: 100%; object-fit: cover; }
.upf-cover__overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.85) 0%, transparent 60%);
}
.upf-cover__channel {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: flex-end; gap: 18px; padding: 20px 24px;
}
.upf-cover__avatar {
  width: 80px; height: 80px; border-radius: 50%;
  border: 3px solid var(--red);
  object-fit: cover; flex-shrink: 0;
  background: var(--bg3);
}
.upf-cover__name { font-size: 26px; font-weight: 700; line-height: 1.2; }
.upf-cover__meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.upf-cover__follow {
  margin-left: auto; background: var(--red);
  color: #fff; padding: 9px 22px; border-radius: 24px;
  font-size: 14px; font-weight: 600; flex-shrink: 0;
  transition: var(--transition);
}
.upf-cover__follow:hover { background: var(--red-bright); }

/* === TABS === */
.upf-tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.upf-tabs__item {
  padding: 12px 18px; color: var(--muted);
  font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  cursor: pointer; white-space: nowrap;
}
.upf-tabs__item:hover { color: var(--text); }
.upf-tabs__item.active { color: var(--text); border-bottom-color: var(--red); }

/* === SECTION HEADER === */
.upf-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.upf-section-title {
  font-size: 18px; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
.upf-section-title::before {
  content: '';
  display: inline-block; width: 4px; height: 22px;
  background: var(--red); border-radius: 2px;
}
.upf-section-more {
  color: var(--red); font-size: 13px; font-weight: 600;
  transition: var(--transition);
}
.upf-section-more:hover { color: var(--red-bright); text-decoration: underline; }

/* === VIDEO GRID === */
.upf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 18px;
  margin-bottom: 36px;
}
.upf-grid--shorts {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.upf-grid--list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 36px; }

/* === CARD === */
.upf-card {
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition);
  background: transparent;
}
.upf-card:hover { transform: translateY(-3px); }
.upf-card:hover .upf-card__thumb-img { transform: scale(1.04); }

.upf-card__thumb {
  position: relative;
  aspect-ratio: 16/9;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg3);
}
.upf-grid--shorts .upf-card__thumb { aspect-ratio: 9/16; }

.upf-card__thumb-img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .4s ease;
}
.upf-card__thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  background: linear-gradient(135deg, var(--bg3), var(--bg4));
}

.upf-card__duration {
  position: absolute; bottom: 7px; right: 8px;
  background: rgba(0,0,0,.88); color: #fff;
  font-size: 12px; font-weight: 600; padding: 2px 6px;
  border-radius: 4px;
}
.upf-card__tag {
  position: absolute; top: 8px; left: 8px;
  font-size: 11px; font-weight: 700; padding: 3px 8px;
  border-radius: 4px; color: #fff;
}
.upf-card__tag--red { background: var(--red); }
.upf-card__tag--gold { background: var(--gold); color: #000; }
.upf-card__tag--green { background: #16a34a; }
.upf-card__tag--purple { background: #7c3aed; }

.upf-card__play-icon {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--transition);
}
.upf-card:hover .upf-card__play-icon { opacity: 1; }
.upf-card__play-icon::before {
  content: '';
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
}
.upf-card__play-icon svg {
  position: absolute;
  width: 20px; height: 20px; fill: #fff;
  margin-left: 3px;
}

.upf-card__body { padding: 10px 4px 4px; }
.upf-card__title {
  font-size: 14px; font-weight: 600; line-height: 1.45;
  margin-bottom: 6px; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.upf-card__meta {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px;
}
.upf-card__views {
  display: flex; align-items: center; gap: 4px;
}
.upf-card__category {
  background: var(--bg4); color: var(--muted);
  padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600;
}

/* === LIST CARD === */
.upf-card--list {
  display: flex; gap: 14px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  transform: none !important;
}
.upf-card--list:hover { background: var(--bg3); border-color: var(--border2); }
.upf-card--list .upf-card__thumb {
  width: 220px; flex-shrink: 0; aspect-ratio: 16/9; border-radius: var(--radius-sm);
}
.upf-card--list .upf-card__body { padding: 0; flex: 1; }
.upf-card--list .upf-card__title { font-size: 16px; -webkit-line-clamp: 2; }
.upf-card--list .upf-card__desc {
  font-size: 12px; color: var(--muted); line-height: 1.5;
  margin: 6px 0 10px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.upf-card--list .upf-card__tags { display: flex; flex-wrap: wrap; gap: 6px; }
.upf-card--list .upf-card__feature-tag {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 4px;
  background: var(--red-dim); border: 1px solid rgba(204,0,0,.3); color: var(--red-bright);
}
.upf-card--list .upf-card__feature-tag--gold {
  background: rgba(255,204,0,.1); border-color: rgba(255,204,0,.3); color: var(--gold);
}

/* === FILTER PILLS === */
.upf-filters {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px;
}
.upf-filter-pill {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 20px; padding: 6px 16px;
  font-size: 13px; color: var(--text); cursor: pointer;
  transition: var(--transition); white-space: nowrap;
  font-family: var(--font);
}
.upf-filter-pill:hover { background: var(--bg4); border-color: #555; }
.upf-filter-pill.active {
  background: var(--red); border-color: var(--red);
  color: #fff; font-weight: 600;
}

/* === NOTICE === */
.upf-notice {
  background: linear-gradient(90deg, rgba(204,0,0,.1), rgba(255,102,0,.08));
  border: 1px solid rgba(204,0,0,.25); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 22px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; line-height: 1.5;
}
.upf-notice strong { color: var(--gold); }

/* === AD SLOTS === */
.upf-ad {
  background: var(--bg2); border: 1px dashed var(--border2);
  border-radius: var(--radius); padding: 20px;
  text-align: center; color: var(--muted2); font-size: 12px;
  margin-bottom: 24px; min-height: 90px;
  display: flex; align-items: center; justify-content: center;
}

/* === PAGINATION === */
.upf-pagination {
  display: flex; justify-content: center; gap: 6px;
  margin-top: 32px;
}
.upf-pagination a, .upf-pagination span {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--muted); transition: var(--transition);
}
.upf-pagination a:hover { background: var(--bg4); color: var(--text); }
.upf-pagination .current {
  background: var(--red); border-color: var(--red); color: #fff;
}

/* === FOOTER === */
.upf-footer {
  border-top: 1px solid var(--border);
  padding: 30px 28px;
  color: var(--muted2); font-size: 12px;
}
.upf-footer__inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
}
.upf-footer__links { display: flex; gap: 14px; flex-wrap: wrap; }
.upf-footer__links a { color: var(--muted2); transition: var(--transition); }
.upf-footer__links a:hover { color: var(--red); }

/* === VIEWS COUNTER WIDGET === */
.upf-views-widget {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 20px;
}
.upf-views-widget__title {
  font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 12px;
  text-transform: uppercase; letter-spacing: .5px;
}
.upf-views-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.upf-views-row:last-child { border-bottom: none; }
.upf-views-row__rank {
  font-size: 13px; font-weight: 700; color: var(--muted2); width: 18px;
}
.upf-views-row__thumb {
  width: 64px; height: 36px; border-radius: 5px;
  object-fit: cover; background: var(--bg3); flex-shrink: 0;
}
.upf-views-row__title {
  flex: 1; font-size: 12px; line-height: 1.4; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.upf-views-row__count { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* === SINGLE POST === */
.upf-single { max-width: 900px; }
.upf-single__video-wrap {
  aspect-ratio: 16/9; background: #000;
  border-radius: var(--radius); overflow: hidden;
  margin-bottom: 18px;
}
.upf-single__video-wrap iframe {
  width: 100%; height: 100%; border: none;
}
.upf-single__title {
  font-size: 20px; font-weight: 700; margin-bottom: 10px; line-height: 1.4;
}
.upf-single__meta {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  color: var(--muted); font-size: 13px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border); margin-bottom: 18px;
}
.upf-single__meta-views { color: var(--text); font-weight: 600; }
.upf-single__content {
  font-size: 15px; line-height: 1.8; color: var(--text);
}
.upf-single__content h2, .upf-single__content h3 {
  margin: 24px 0 10px; font-weight: 700;
}
.upf-single__content p { margin-bottom: 14px; }
.upf-single__content a { color: var(--red-bright); }
.upf-single__content img { border-radius: var(--radius-sm); margin: 16px 0; }

/* === SKELETON LOADER === */
.upf-skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: upf-shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes upf-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* === RESPONSIVE === */
@media (max-width: 1100px) {
  :root { --sidebar-w: 72px; }
  .upf-sidebar__text, .upf-sidebar__badge, .upf-sidebar__label { display: none; }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .upf-sidebar { display: none; }
  .upf-main { padding: 16px 14px 40px; }
  .upf-header__nav { display: none; }
  .upf-cover { height: 160px; }
  .upf-cover__name { font-size: 20px; }
  .upf-cover__avatar { width: 56px; height: 56px; }
  .upf-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .upf-grid--list .upf-card--list { flex-direction: column; }
  .upf-grid--list .upf-card--list .upf-card__thumb { width: 100%; }
}
@media (max-width: 480px) {
  .upf-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .upf-grid--shorts { grid-template-columns: repeat(2, 1fr); }
  .upf-header__search { display: none; }
  .upf-section-title { font-size: 16px; }
}
