/*
Theme Name: Arti-Cool Lite
Description: Ultra-clean theme for three-column articles with animated landing page, text-to-speech, and interactive endnotes. Optimised for New Zealand content creators with enhanced security and accessibility.
Version: 1.3
Requires at least: 6.0
Tested up to: 6.9
Requires PHP: 8.0
Author: Arti-Cool Team
License: GPL v2 or later
Text Domain: articool-lite
*/

/* Security and Performance Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent content-injection attacks */
*::before,
*::after {
    content: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #ffffff;
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
}

/* Security-focused media restrictions */
/* Hide potentially dangerous embeds by default */
object,
embed {
    display: none !important;
}

/* Allow trusted iframe sources */
iframe {
    display: none;
    max-width: 100%;
}

iframe[src*="youtube.com"],
iframe[src*="youtube-nocookie.com"],
iframe[src*="vimeo.com"],
iframe[src*="dailymotion.com"],
iframe[src*="localhost"],
iframe[src*="127.0.0.1"] {
    display: block;
    max-width: 100%;
    border: none;
}

/* WordPress Required Classes */
.alignleft { 
    float: left; 
    margin: 0 1rem 1rem 0; 
    max-width: 50%;
}

.alignright { 
    float: right; 
    margin: 0 0 1rem 1rem; 
    max-width: 50%;
}

.aligncenter { 
    text-align: center; 
    margin: 1rem auto; 
    display: block;
}

.alignwide {
    width: 100%;
    max-width: none;
}

.alignfull {
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

.wp-caption { 
    max-width: 100%; 
    background: #f8f9fa;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 0.5rem;
}

.wp-caption-text { 
    font-style: italic; 
    text-align: center; 
    margin-top: 0.5rem; 
    font-size: 0.9rem;
    color: #666;
}

.gallery { 
    margin-bottom: 1.5rem; 
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.bypostauthor { 
    font-weight: 600; 
    border-left: 3px solid #0073aa;
    padding-left: 1rem;
}

.sticky { 
    background: #f9f9f9; 
    border-left: 4px solid #0073aa;
    padding: 1rem;
    margin-bottom: 1rem;
}

.screen-reader-text { 
    position: absolute !important; 
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* Focus management for accessibility */
.screen-reader-text:focus {
    position: static !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    background: #0073aa;
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    z-index: 1000;
}

/* Typography with New Zealand English preferences */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 1rem;
    color: #333;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.1rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: 1rem;
    max-width: 65ch; /* Optimal reading width */
}

/* Links with security considerations */
a {
    color: #0073aa;
    text-decoration: none;
    transition: color 0.3s ease;
    outline-offset: 2px;
}

a:hover,
a:focus {
    color: #005a87;
    text-decoration: underline;
}

a:focus {
    outline: 2px solid #0073aa;
    border-radius: 2px;
}

/* External links warning (security) */
a[href^="http"]:not([href*="localhost"]):not([href*="127.0.0.1"])::after {
    content: " ↗";
    font-size: 0.8em;
    opacity: 0.7;
}

/* Lists */
ul, ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

li {
    margin-bottom: 0.5rem;
}

/* Definition lists */
dl {
    margin: 1rem 0;
}

dt {
    font-weight: 600;
    margin-top: 1rem;
}

dd {
    margin-left: 2rem;
    margin-bottom: 0.5rem;
}

/* Images with security and performance */
img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    loading: lazy; /* Performance */
    display: block; /* Prevent inline spacing issues */
}

/* Ensure images in content areas display properly */
.entry-content img,
.lite-column-content img,
.post-content img {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
    border-radius: 4px;
}

/* Fix for images in paragraphs */
p img {
    display: inline-block;
    vertical-align: middle;
    margin: 0;
}

/* Lazy loading fallback */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded,
img:not([loading="lazy"]) {
    opacity: 1;
}

/* Warn about external images (security consideration) but don't break them */
img[src^="http"]:not([src*="localhost"]):not([src*="127.0.0.1"]):not([src*="192.168"]):not([src*="10."]):not([src*="172."]) {
    /* Only add a subtle indicator for external images */
    position: relative;
}

img[src^="http"]:not([src*="localhost"]):not([src*="127.0.0.1"]):not([src*="192.168"]):not([src*="10."]):not([src*="172."])::after {
    content: "🔗";
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 12px;
    pointer-events: none;
}

/* Figure and captions */
figure {
    margin: 1rem 0;
}

figcaption {
    font-style: italic;
    color: #666;
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
}

@media (min-width: 768px) {
    table {
        display: table;
        white-space: normal;
    }
}

th, td {
    padding: 0.75rem;
    border: 1px solid #ddd;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    position: sticky;
    top: 0;
}

/* Forms with security */
input, textarea, select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

/* Prevent autocomplete on sensitive fields */
input[name*="password"],
input[name*="credit"],
input[name*="card"] {
    autocomplete: off;
}

button {
    padding: 0.75rem 1.5rem;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
    min-width: 44px; /* Accessibility */
    min-height: 44px;
}

button:hover,
button:focus {
    background: #005a87;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 115, 170, 0.3);
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Code and pre elements */
code {
    background: #f4f4f4;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #d73e48;
}

pre {
    background: #f4f4f4;
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1rem 0;
    border-left: 4px solid #0073aa;
}

pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* Blockquotes */
blockquote {
    border-left: 4px solid #0073aa;
    padding-left: 1rem;
    margin: 1.5rem 0;
    font-style: italic;
    color: #555;
    position: relative;
}

blockquote::before {
    content: """;
    font-size: 3rem;
    color: #0073aa;
    position: absolute;
    left: -1rem;
    top: -0.5rem;
    opacity: 0.3;
}

/* Utility Classes */
.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.float-left { float: left; margin-right: 1rem; }
.float-right { float: right; margin-left: 1rem; }
.float-none { float: none; }

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Responsive Images */
.size-thumbnail { max-width: 150px; }
.size-medium { max-width: 300px; }
.size-large { max-width: 800px; }
.size-full { width: 100%; }

/* Additional WordPress image sizes */
.attachment-thumbnail { max-width: 150px; }
.attachment-medium { max-width: 300px; }
.attachment-large { max-width: 800px; }
.attachment-full { width: 100%; }

/* Image alignment classes */
.wp-image-left {
    float: left;
    margin: 0 1rem 1rem 0;
}

.wp-image-right {
    float: right;
    margin: 0 0 1rem 1rem;
}

.wp-image-center {
    display: block;
    margin: 1rem auto;
    text-align: center;
}

/* Featured images */
.post-thumbnail img,
.featured-image img {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* WordPress Blocks */
.wp-block-image { 
    margin: 1rem 0; 
    text-align: center;
}

.wp-block-image img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.wp-block-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.wp-block-media-text {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: center;
    margin: 2rem 0;
}

@media (max-width: 768px) {
    .wp-block-media-text {
        grid-template-columns: 1fr;
    }
}

/* SVG support */
svg {
    max-width: 100%;
    height: auto;
    fill: currentColor;
}

/* WebP and modern image format support */
picture {
    display: block;
    width: 100%;
}

picture img {
    width: 100%;
    height: auto;
}

.wp-block-quote { 
    border-left: 4px solid #0073aa; 
    padding-left: 1rem; 
    margin: 1.5rem 0; 
    font-style: italic; 
}

.wp-block-code,
.wp-block-preformatted { 
    background: #f4f4f4; 
    padding: 1rem; 
    border-radius: 4px; 
    font-family: monospace;
    overflow-x: auto;
}

.wp-block-separator {
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, #ddd, transparent);
    margin: 2rem 0;
}

.wp-block-spacer {
    clear: both;
}

/* Skip links for accessibility */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: #0073aa;
    color: white;
    padding: 1rem;
    text-decoration: none;
    z-index: 9999;
}

.skip-link:focus {
    left: 0;
}

/* Text-to-Speech and Endnotes for Three-Column Layout */
.lite-audio-controls .audio-btn,
.endnote-ref {
    min-width: unset;
    min-height: unset;
}

.endnote-ref {
    touch-action: manipulation;
}

.endnote-bubble {
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 300px;
    word-wrap: break-word;
    hyphens: auto;
}

@media (max-width: 480px) {
    .endnote-bubble {
        max-width: 250px;
        font-size: 0.85rem;
    }
    
    .lite-audio-controls .audio-btn {
        min-width: 40px;
        min-height: 40px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    * {
        border-color: #000 !important;
    }
    
    a {
        text-decoration: underline;
    }
    
    button {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    h1, h2, h3, h4, h5, h6 {
        color: #ffffff;
    }
    
    a {
        color: #4fc3f7;
    }
    
    a:hover,
    a:focus {
        color: #81d4fa;
    }
    
    code,
    pre {
        background: #2d2d2d;
        color: #f0f0f0;
    }
    
    th {
        background: #2d2d2d;
    }
    
    th, td {
        border-color: #444;
    }
    
    input, textarea, select {
        background: #2d2d2d;
        color: #e0e0e0;
        border-color: #444;
    }
    
    .wp-caption {
        background: #2d2d2d;
        border-color: #444;
    }
}

/* Print Styles */
@media print {
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    body { 
        font-size: 12pt; 
        line-height: 1.5; 
        margin: 2cm;
    }
    
    h1 { font-size: 18pt; page-break-after: avoid; }
    h2 { font-size: 16pt; page-break-after: avoid; }
    h3 { font-size: 14pt; page-break-after: avoid; }
    
    p, h2, h3 {
        orphans: 3;
        widows: 3;
    }
    
    h2, h3 {
        page-break-after: avoid;
    }
    
    a {
        text-decoration: underline;
    }
    
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    pre,
    blockquote {
        border: 1px solid #999;
        page-break-inside: avoid;
    }
    
    thead {
        display: table-header-group;
    }
    
    tr,
    img {
        page-break-inside: avoid;
    }
    
    /* Hide non-essential elements when printing */
    .no-print,
    nav,
    .navigation,
    .sidebar,
    .widget,
    .comments-area,
    button,
    input,
    textarea,
    select {
        display: none !important;
    }
}
/* --------------------------
   Three Column Layout: Hover to Widen on Desktop. V1.2
----------------------------- */
@media (min-width: 900px) {
  .lite-columns-container {
    display: flex;
  }
  .lite-column {
    flex: 1 1 33.3%;
    transition: flex-basis 0.3s, box-shadow 0.2s;
    min-width: 0;
    overflow: auto;
  }
  .lite-column:hover {
    flex: 1 1 44%;
    box-shadow: 0 0 14px 0 rgba(0,0,0,0.08);
    z-index: 2;
  }
  .lite-column:not(:hover) {
    flex: 1 1 28%;
    opacity: 0.93;
    z-index: 1;
  }
}

/* Column labels for mobile navigation (v1.3) */
.lite-column-labels {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.2rem;
}
.lite-column-label {
  font-size: 1.1rem;
  background: #f7f7f7;
  color: #222;
  padding: 0.5em 1em;
  border-radius: 1.5em;
  font-weight: 500;
  opacity: 0.4;
  transition: opacity 0.3s, background 0.3s, box-shadow 0.2s;
  pointer-events: none;
}

.lite-column-label.active {
  opacity: 1;
  background: #ffe;
  box-shadow: 0 0 8px #ddd;
  pointer-events: auto;
}

@media (max-width: 900px) {
  .lite-column-labels {
    margin-top: 1.2rem;
  }
}
/* Desktop: show label, hide icon (updated v1.3) */
@media (min-width: 900px) {
  .audio-btn .audio-icon {
    display: none;
  }
  .audio-btn .audio-label {
    display: inline;
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    padding: 0 1em;
  }
}

/* Mobile: show icon, hide label (updated v1.3) */
@media (max-width: 899px) {
  .audio-btn .audio-icon {
    display: inline;
    font-size: 1.2em;
    vertical-align: middle;
  }
  .audio-btn .audio-label {
    display: none;
  }
}

/* Mobile peek navigation for columns (v1.3) */
@media (max-width: 768px) {
  .lite-columns-container {
    position: relative;
    overflow: hidden;
    width: 100%;
  }
  
  .lite-column {
    position: absolute;
    top: 0;
    left: 0;
    width: 80vw;
    min-height: 100%;
    transition: transform 0.3s ease;
    background: white;
  }
  
  .lite-column.active-column {
    display: block;
  }
}
