/*
Theme Name: Johlits
Theme URI: https://example.com/johlits
Author: johlits
Author URI: https://example.com
Description: Dark-themed WordPress theme with sidebar, featured-image grid on the front page, and dropdown menus.
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: johlits
Tags: dark, responsive, two-columns, blog, sidebar, grid, dropdown-menu
*/

/* Root variables (dark theme) */
:root{
  --bg: #111317;
  --bg-elev: #161a1f;
  --text: #e6e8ee;
  --muted: #aab0bd;
  --primary: #4a6fa5;
  --primary-600: #3d5c87;
  --border: #242933;
  --card: #1a1f26;
  --accent: #0ea5e9;
  /* Fonts */
  --font-display: 'Oxanium', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-body: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Desktop: fix dropdowns below sticky header so they don't push layout */
@media (min-width: 901px){
  .primary-nav{ position: relative; z-index: 2000; }
  .primary-nav .menu{ flex-wrap: nowrap; white-space: nowrap; }
  .primary-nav .menu > li{ position: relative; }
  .primary-nav .menu > li.open-desktop > .sub-menu{ display: block; }
  /* Strong specificity to override any base absolute positioning */
  .site-header .primary-nav .menu > li > .sub-menu,
  .primary-nav .sub-menu{
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 2001;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden; /* avoid horizontal scrollbar from hover-bridge */
    margin-top: 0 !important;
    /* Always in the document flow on desktop to avoid reflow gaps */
    display: block;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease, visibility 0s linear .12s;
    will-change: opacity, transform;
  }
  /* Show submenu on hover/focus/open without changing display */
  .primary-nav .menu > li:hover > .sub-menu,
  .primary-nav .menu > li:focus-within > .sub-menu,
  .primary-nav .menu > li.open-desktop > .sub-menu{
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    transition: opacity .12s ease, transform .12s ease, visibility 0s linear 0s;
  }
  /* Hover bridge: small hit area above submenu so pointer doesn't fall through a gap */
  .primary-nav .sub-menu::before{
    content: '';
    position: absolute;
    left: -12px; right: -12px; /* modest horizontal buffer to prevent hover gap */
    top: -10px; height: 10px;
    pointer-events: auto;
  }
}

html { box-sizing: border-box; }
*, *:before, *:after { box-sizing: inherit; }

body{
  margin: 0; font-family: var(--font-body); color: var(--text); background: var(--bg);
  line-height: 1.6; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}

/* Guard against horizontal overflow on mobile */
html, body { max-width: 100%; overflow-x: hidden; }

/* Headings: use display font */
h1, h2, h3, h4, h5, h6{ font-family: var(--font-display); letter-spacing: 0.2px; }

img{ max-width: 100%; height: auto; display: block; }

/* Layout */
.site-header{ background: var(--bg-elev); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1000; overflow: visible; }
.main, .content{ overflow-x: hidden; }
.container{ width: min(1200px, 92%); margin: 0 auto; overflow-x: hidden; }
.header-inner{ display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; min-width: 0; overflow: visible; flex-wrap: nowrap; }
.site-title a{ color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.25rem; font-family: var(--font-display); letter-spacing: 0.2px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* Site icon branding */
.branding{ display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
.branding .site-icon-link{ display: inline-flex; align-items: center; line-height: 0; }
.branding .site-icon{ width: 48px; height: 48px; border-radius: 8px; display: block; }
.site-description{ color: var(--muted); font-size: .9rem; margin-top: 2px; }

/* Navigation */
.menu-open{ overflow: hidden; }
.menu-toggle{ display: none; background: transparent; border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 6px; cursor: pointer; position: relative; z-index: 2500; flex: 0 0 auto; }
.primary-nav{ position: relative; overflow: visible; z-index: 1500; }
.primary-nav .menu{ list-style: none; padding: 0; margin: 0; display: flex; gap: 10px; flex-wrap: wrap; max-width: 100%; }
.primary-nav .menu, .primary-nav .menu ul, .primary-nav .menu li{ list-style: none; margin: 0; padding: 0; }
.primary-nav .menu > li{ position: relative; }
.primary-nav a{ color: var(--text); text-decoration: none; padding: 10px 12px; display: block; border-radius: 6px; font-family: var(--font-display); letter-spacing: 0.2px; }
.primary-nav a:hover, .primary-nav .current-menu-item > a{ background: var(--card); }
/* Highlight parent when its submenu is expanded (desktop or mobile) */
.primary-nav .menu > li.open-desktop > a,
.primary-nav .menu > li.open > a{ background: var(--card); }
/* Accessible focus styles */
.primary-nav a:focus-visible{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Ensure comfortable touch targets for top-level items */
.primary-nav .menu > li > a{
  display: flex; align-items: center;
  min-height: 44px; /* Apple/Google recommended minimum */
  line-height: 1;
}

/* Menu toggle focus styles and target size */
.menu-toggle{ min-height: 40px; min-width: 44px; }
.menu-toggle:focus-visible{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Dropdowns */
.primary-nav ul, .primary-nav li{ list-style: none; margin: 0; padding: 0; }
.primary-nav .sub-menu{ list-style: none; position: absolute; left: 0; top: 100%; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; min-width: 200px; padding: 6px; margin: 0; display: none; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.primary-nav .sub-menu ul, .primary-nav .sub-menu li{ list-style: none; margin: 0; padding: 0; }
.primary-nav .sub-menu li{ position: relative; list-style: none; }
.primary-nav li:hover > .sub-menu, .primary-nav li:focus-within > .sub-menu{ display: block; }
.primary-nav .sub-menu a{ padding: 8px 10px; }
.primary-nav .sub-menu a{ min-height: 40px; display: flex; align-items: center; }
.primary-nav .sub-menu a:focus-visible{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.primary-nav .menu li.menu-item-has-children > a::after{ content: "▾"; margin-left: .4rem; font-size: .8em; color: var(--muted); }
/* Flip caret when open */
.primary-nav .menu > li.open-desktop > a::after,
.primary-nav .menu > li.open > a::after{ content: "▴"; }

/* Nested submenus default open to the right */
.primary-nav .sub-menu .sub-menu{ top: 0; left: 100%; }

/* Flip right-edge dropdowns to open inward (to the left) */
.primary-nav .menu > li:last-child > .sub-menu,
.primary-nav .menu > li:nth-last-child(1) > .sub-menu{ left: auto; }

/* And ensure their children open to the left as well */
.primary-nav .menu > li:last-child > .sub-menu .sub-menu,
.primary-nav .menu > li:nth-last-child(1) > .sub-menu .sub-menu{ left: auto; right: 100%; top: 0; }

/* (Removed duplicate desktop override that conflicted with --submenu-top) */

/* Mobile nav */
@media (max-width: 900px){
  .menu-toggle{ display: inline-flex; align-items: center; gap: 8px; }
  /* Fixed dropdown below sticky header */
  .primary-nav .menu{ display: none; position: fixed; left: 0; right: 0; top: calc(var(--menu-top, var(--header-height, 64px)) + var(--menu-offset, 16px)); flex-direction: column; background: var(--bg-elev); border-top: 1px solid var(--border); padding: 16px 10px 10px; z-index: 90; max-height: calc(100vh - (var(--menu-top, var(--header-height, 64px)) + var(--menu-offset, 16px))); overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
  .primary-nav.open .menu{ display: flex; z-index: 3000; }
  .primary-nav .sub-menu{ position: static; border: none; box-shadow: none; padding-left: 12px; display: none; }
  /* On mobile, disable hover-open. Only show when .open is present */
  .primary-nav .menu li > .sub-menu{ display: none !important; }
  .primary-nav .menu li.open > .sub-menu{ display: block !important; }
  /* Ensure the first item's submenu isn't cramped under the header */
  .primary-nav.open .menu > li:first-child > .sub-menu{ margin-top: 10px; }
  .primary-nav .menu li.open > .sub-menu{ display: block; }
}

/* Extra safety for very small screens: allow header to wrap and constrain text */
@media (max-width: 640px){
  /* Keep header in a single row; allow title to truncate */
  .header-inner{ flex-wrap: nowrap; }
  .site-title a{ overflow-wrap: normal; word-break: normal; }
  .primary-nav{ width: auto; flex: 0 0 auto; }
}

/* Ultra-small screens: slightly reduce icon and title size to keep single row */
@media (max-width: 400px){
  .branding .site-icon{ width: 40px; height: 40px; }
  .site-title a{ font-size: 1.1rem; }
}

/* Main layout */
.main{ display: flex; gap: 24px; padding: 0 0 24px; align-items: flex-start; }
.content{ flex: 1 1 auto; min-width: 0; padding-top: 24px; }
.sidebar{ flex: 0 0 clamp(180px, 20vw, 220px); max-width: clamp(180px, 20vw, 220px); }
@media (max-width: 900px){
  .main{ flex-direction: column; }
  .sidebar{ width: 100%; max-width: 100%; flex: 0 0 auto; position: static; top: auto; }
}

.sidebar{ flex: 0 0 clamp(180px, 22vw, 220px); position: sticky; top: calc(var(--header-height, 64px) + var(--sidebar-offset, 0px)); align-self: flex-start; overflow: visible; }
@media (max-width: 900px){
  /* Ensure sidebar/widgets are full width on small screens (override sticky sizing) */
  .sidebar{ flex: 0 0 auto; width: 100%; max-width: 100%; position: static; top: auto; align-self: stretch; }
}
/* Increase offset so anchored/focused elements don't stick under header */
.sidebar .menu li, .sidebar a, .content [id]{ scroll-margin-top: calc(var(--header-height, 64px) + 24px); }
/* Use same sidebar offset across pages (front page look) */
/* (No custom --sidebar-offset overrides) */
.widget{ background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 16px; }
.widget-title{ margin-top: 0; font-size: 1.05rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; font-family: var(--font-display); letter-spacing: 0.2px; }

/* Constrain widget contents (iframes/embeds/images) */
.sidebar .widget{ overflow: visible; }
.sidebar .widget img{ max-width: 100%; height: auto; display: block; }
.sidebar .widget iframe,
.sidebar .widget embed,
.sidebar .widget object,
.sidebar .widget video{ display: block; max-width: 100% !important; width: 100% !important; height: auto; border: 0; }
/* Gutenberg embed wrappers */
/* Ghost placeholders to ensure at least 2 rows in grids */
.content .grid .card.ghost{
  visibility: hidden;
  pointer-events: none;
  box-shadow: none !important;
  border: none !important;
  background: transparent !important;
  margin: 0;
}
.sidebar .widget .wp-block-embed,
.sidebar .widget .wp-block-embed__wrapper{ max-width: 100%; }
/* Catch Twitch classes */
.sidebar .widget .twitch-embed,
.sidebar .widget [class*="twitch"]{ max-width: 100%; }

/* Specific: Straightvisions Twitch block - responsive 16:9 without clipping */
.sidebar .widget .wp-block-straightvisions-twitch-stream{ position: relative; width: 100%; height: 0; padding-top: 56.25%; }
.sidebar .widget .wp-block-straightvisions-twitch-stream iframe{
  position: absolute; inset: 0; width: 100% !important; height: 100% !important; max-width: 100% !important; border: 0;
}

/* Cards grid (front page) */
.grid{ display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; width: 100%; }
.grid > *{ min-width: 0; }
@media (max-width: 980px){ .grid{ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; } }
@media (max-width: 820px){ .grid{ grid-template-columns: 1fr; } }
@media (min-width: 1100px){ .grid{ grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card{ background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.card-thumb{ display: block; aspect-ratio: 16/9; background: #0b0d11; }
.card-thumb img{ width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body{ padding: 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card-title{ margin: 0; font-size: 1.05rem; font-family: var(--font-display); letter-spacing: 0.2px; overflow-wrap: anywhere; word-break: break-word; }
.card-title a{ color: var(--text); text-decoration: none; }
.card-meta{ color: var(--muted); font-size: .85rem; }
.card-excerpt{ color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; word-break: break-word; }
.card a.more{ align-self: flex-start; margin-top: 6px; font-weight: 600; color: var(--accent); text-decoration: none; border: none; border-radius: 8px; padding: 6px 10px; background: transparent; transition: background .2s ease, color .2s ease, border-color .2s ease, box-shadow .2s ease; }
/* Read More: only change text color on hover/focus (no filled background) */
.card a.more:hover, .card a.more:focus{ background: transparent; color: var(--accent) !important; border: none; outline: none; box-shadow: none; }
/* When hovering anywhere on the card/post, reflect the same (text-only) hover on Read More */
.card:hover a.more, .post:hover a.more{ background: transparent; color: var(--accent) !important; border: none; box-shadow: none; }

/* Make post title turn accent when hovering anywhere on the article/card */
.card:hover .card-title a, .card:focus-within .card-title a,
.post:hover h1 a, .post:focus-within h1 a{
  color: var(--accent) !important;
}

/* Full-card clickable overlay for cards and list posts */
.card, .post{ position: relative; }
.card .card-link-overlay, .post .card-link-overlay{
  position: absolute; inset: 0; z-index: 1; overflow: hidden; border-radius: inherit;
}
/* Keep explicit links clickable above overlay */
.card a, .post a{ position: relative; z-index: 2; }

/* Pagination */
.pagination{ display: flex; justify-content: center; margin-top: 16px; }
nav.navigation.pagination{ display: flex; justify-content: center; margin-top: 16px; }
nav.navigation.pagination .nav-links{ display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pagination .nav-links{ display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* WordPress outputs .page-numbers items */
.page-numbers{ display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text) !important; text-decoration: none; font-weight: 600; transition: background .2s ease, color .2s ease, border-color .2s ease; }
.page-numbers:hover, .page-numbers:focus{ background: var(--card); color: var(--accent) !important; outline: none; border-color: var(--border); }
.page-numbers.current{ background: var(--accent); color: #fff !important; border-color: transparent; cursor: default; }
.page-numbers.dots{ background: transparent; border: none; color: var(--muted) !important; min-width: auto; padding: 0 4px; }
.page-numbers.prev, .page-numbers.next{ padding: 0 12px; }

@media (max-width: 640px){
  .page-numbers{ min-width: 32px; height: 32px; border-radius: 6px; padding: 0 8px; }
}

/* Footer */
.site-footer{ border-top: 1px solid var(--border); background: var(--bg-elev); padding: 20px 0; color: var(--muted); text-align: center; }

/* Respect user preference for reduced motion */
@media (prefers-reduced-motion: reduce){
  *{ animation: none !important; transition: none !important; }
  .primary-nav .menu,
  .primary-nav .sub-menu{ scroll-behavior: auto; }
  /* Soften visual intensity */
  .primary-nav .sub-menu{ box-shadow: none; }
}

/* Global link styles (override UA/plugin defaults) */
body a:link, body a:visited,
.content a:link, .content a:visited,
.entry a:link, .entry a:visited,
.widget a:link, .widget a:visited,
nav a:link, nav a:visited,
.site-footer a:link, .site-footer a:visited{ color: var(--text) !important; text-decoration: none; }

body a:hover, body a:focus,
.content a:hover, .content a:focus,
.entry a:hover, .entry a:focus,
.widget a:hover, .widget a:focus,
nav a:hover, nav a:focus,
.site-footer a:hover, .site-footer a:focus{ color: var(--accent) !important; }

/* Entry/content typography */
.entry{ color: var(--text); line-height: 1.8; }
.entry h1, .entry h2, .entry h3, .entry h4, .entry h5, .entry h6{ color: var(--text); line-height: 1.25; margin: 0 0 12px; font-family: var(--font-display); letter-spacing: 0.2px; }
.entry p{ margin: 0 0 12px; }
.entry ul, .entry ol{ margin: 0 0 12px; padding-left: 1.25rem; }
.entry li{ margin: 4px 0; }
.entry blockquote{ margin: 12px 0; padding: 10px 14px; border-left: 3px solid var(--border); background: var(--bg-elev); border-radius: 6px; }
.entry hr{ border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.entry table{ width: 100%; border-collapse: collapse; margin: 12px 0; }
.entry th, .entry td{ border: 1px solid var(--border); padding: 8px; text-align: left; }

:where(.widget) :where(figure) { margin-block-end: 0; }