/*
Theme Name: J4Y Mainframe
Theme URI: https://j4y.org
Author: Jay
Author URI: https://j4y.org
Description: A retro-themed blog with dual modes - Amber CRT (dark) and Macintosh System 6 (light). Features scanline effects, keyboard shortcuts, and window chrome styling for code blocks.
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: j4y-mainframe
Tags: blog, one-column, custom-menu, featured-images, translation-ready, dark-mode
*/

/*
 * j4y.org - Mainframe Theme (System 6 / Amber CRT)
 */

:root {
    /* Base Variables */
    --spacing-unit: 1rem;
    --container-width: 800px;
    --radius: 2px;
    --border-width: 1px;

    /* Fonts */
    --font-sys-6: "Chicago", "Geneva", "Pixel Arial11", sans-serif;
    --font-sys-6-body: "Geneva", "Helvetica", sans-serif;
    --font-crt: "Courier New", Courier, monospace;
}

/*
 * MODE: DARK (Amber CRT)
 * Default for systems with no preference or explicit dark preference
 */
:root,
body[data-mode="dark"] {
    --bg-color: #120f00;
    --text-color: #fbbf24; /* Amber */
    --secondary-text: #b45309;
    --border-color: #78350f;
    --accent-color: #f59e0b;

    --code-bg: #1a1500;
    --code-text: #fbbf24;

    --font-display: var(--font-crt);
    --font-body: var(--font-crt);

    --token-keyword: #fcd34d;
    --token-type: #f59e0b;
    --token-function: #d97706;
    --token-comment: #78350f;
    --token-string: #fbbf24;

    --text-shadow: 0 0 4px rgba(251, 191, 36, 0.4);
    --scanline-opacity: 0.4;

    /* Modal Specifics */
    --modal-overlay: rgba(0, 0, 0, 0.8);
    --modal-bg: #120f00;
    --modal-border: #fbbf24;
}

/*
 * MODE: LIGHT (Macintosh System 6)
 */
@media (prefers-color-scheme: light) {
    :root {
        --mode-defaults: "light";
    }
}

body[data-mode="light"] {
    --bg-color: #ffffff; /* Override fallback to white just in case */
    --text-color: #000000;
    --secondary-text: #000000;
    --border-color: #000000;
    --accent-color: #000000;

    --code-bg: #ffffff;
    --code-text: #000000;

    --font-display: var(--font-sys-6);
    --font-body: var(--font-sys-6-body);

    --token-keyword: #000000;
    --token-type: #000000;
    --token-function: #000000;
    --token-comment: #000000;
    --token-string: #000000;

    --text-shadow: none;
    --scanline-opacity: 0;

    /* Modal Specifics */
    --modal-overlay: rgba(255, 255, 255, 0.5); /* Dithered look handled via pattern if possible, but simple alpha for now */
    --modal-bg: #ffffff;
    --modal-border: #000000;
}

/* Light Mode Checkerboard Background - uses ::before for true fixed positioning (iOS compatible) */
body[data-mode="light"]::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background-color: #ffffff;
    background-image:
        linear-gradient(45deg, #000 25%, transparent 25%, transparent 75%, #000 75%, #000),
        linear-gradient(45deg, #000 25%, transparent 25%, transparent 75%, #000 75%, #000);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
}

/* RESET */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
    line-height: 1.6;
    transition: background-color 0s, color 0s; /* Instant switch for retro feel */
    min-height: 100vh;
    text-shadow: var(--text-shadow);
    overflow-x: hidden;
}

/* Scanline Effect Overlay */
@keyframes crt-flicker {
    0% { opacity: 0.9; }
    25% { opacity: 1.0; }
    50% { opacity: 0.95; }
    75% { opacity: 1.0; }
    100% { opacity: 0.9; }
}

body::after {
    content: "";
    position: fixed;
    inset: 0;

    /*
     * COMPOSITE CRT LAYER
     * 1. Vignette (Dark corners)
     * 2. Scanlines (Sharp 50% lines)
     */
    background:
        radial-gradient(circle, rgba(0,0,0,0) 60%, rgba(0,0,0,0.6) 100%),
        linear-gradient(to bottom, #000 0%, rgba(0,0,0,0) 15%, rgba(0,0,0,0) 85%, #000 100%);

    background-size: 100% 100%, 100% 3px; /* 3px scanline height */

    opacity: var(--scanline-opacity);
    pointer-events: none;
    z-index: 10001; /* Ensure scanlines are on top of EVERYTHING, including modals (10000) */
}

/* Add a subtle flicker to the whole body content only in dark mode */
body[data-mode="dark"] .site-wrapper {
    animation: crt-flicker 0.1s infinite;
    /* Ensure the text shadow blooms a bit more */
    text-shadow: 0 0 2px rgba(251, 191, 36, 0.6), 0 0 4px rgba(251, 191, 36, 0.4);
}

a { color: var(--accent-color); text-decoration: none; border-bottom: 1px dashed var(--accent-color); }
a:hover { background-color: var(--accent-color); color: var(--bg-color); text-decoration: none; text-shadow: none; }

/*
 * LAYOUT & CHROME
 */

.site-wrapper {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    position: relative;
}

/* LIGHT MODE CHROME (System 6 Window) */
/* (Background logic moved to body[data-mode="light"] definition above) */

body[data-mode="light"] .site-wrapper {
    background: #ffffff;
    border: 1px solid #000000;
    box-shadow: 4px 4px 0 #000000;
    margin-top: 3rem;
    margin-bottom: 3rem;
}

/* Content Padding inside the Window */
.content-inner {
    padding: 0 2rem 2rem 2rem;
}

/* HEADER */
header.site-header {
    margin-bottom: 3rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.logo {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.5rem;
    text-transform: lowercase;
}

.logo a {
    border: none;
    color: var(--text-color);
}

.logo a:hover {
    background: none;
    color: var(--accent-color);
}

/* Light Mode Logo Tweak */
body[data-mode="light"] .logo {
    text-transform: none; /* System 6 didn't do lowercase trendy logos */
    letter-spacing: -0.5px;
}

nav.main-nav ul { display: flex; gap: 1.5rem; list-style: none; }
nav.main-nav a { border: none; }
nav.main-nav a:hover { text-decoration: underline; background: none; color: var(--text-color); }

/* WordPress Menu Classes */
.menu { display: flex; gap: 1.5rem; list-style: none; }
.menu-item a { border: none; }
.menu-item a:hover { text-decoration: underline; background: none; color: var(--text-color); }

/* CONTENT */
h1, h2, h3 {
    font-family: var(--font-display);
    margin-bottom: 1rem;
    line-height: 1.2;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; margin-top: 2rem; text-decoration: underline; }

p { margin-bottom: 1.5rem; max-width: 65ch; }

/* WordPress Content Styles */
.entry-content p { margin-bottom: 1.5rem; max-width: 65ch; }
.entry-content ul, .entry-content ol { margin-bottom: 1.5rem; margin-left: 2rem; }
.entry-content li { margin-bottom: 0.5rem; }

/* WordPress Image Alignment */
.alignleft {
    float: left;
    margin: 0.5em 1.5em 1em 0;
}

.alignright {
    float: right;
    margin: 0.5em 0 1em 1.5em;
}

.aligncenter {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.alignnone {
    display: inline-block;
    margin: 0.5em 0;
}

/* WordPress Images */
.entry-content img {
    max-width: 100%;
    height: auto;
}

.entry-content figure {
    margin: 0 0 1.5rem 0;
    max-width: 100%;
}

.entry-content figure.alignleft,
.entry-content figure.alignright {
    max-width: 50%;
}

.entry-content figcaption {
    font-size: 0.85rem;
    color: var(--secondary-text);
    font-family: var(--font-crt);
    margin-top: 0.5rem;
}

/* Clear floats after content */
.entry-content::after {
    content: "";
    display: table;
    clear: both;
}

/*
 * SHARED WINDOW CHROME (Code Blocks & Modals)
 */

/* 1. Base Structure */
.code-wrapper,
.modal-window {
    border: 1px solid var(--border-color);
    background: var(--code-bg);
    position: relative;
}

.code-wrapper { margin: 2rem 0; }
.modal-window { width: 100%; max-width: 500px; }

.code-header,
.modal-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding: 0 8px;
    height: 32px; /* Fixed height for consistent stripes */
    font-family: var(--font-display);
    font-size: 0.8rem;
    background: var(--bg-color);
    overflow: hidden;
}

.header-title,
.modal-title {
    flex-grow: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.copy-btn,
.window-btn {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1;
}

/* 2. DARK MODE Override */
body[data-mode="dark"] .code-header,
body[data-mode="dark"] .modal-header {
    background: var(--text-color);
    color: rgba(18, 15, 0, 0.85);
    border-bottom: 1px solid var(--border-color);
}

body[data-mode="dark"] .header-title,
body[data-mode="dark"] .modal-title {
    text-transform: uppercase;
    font-weight: bold;
    font-size: 1.5rem;
    letter-spacing: 1px;
}

body[data-mode="dark"] .copy-btn,
body[data-mode="dark"] .window-btn {
    border: 1px solid rgba(18, 15, 0, 0.85);
    background: var(--text-color);
    color: rgba(18, 15, 0, 0.85);
}

body[data-mode="dark"] .copy-btn:hover,
body[data-mode="dark"] .window-btn:hover {
    background: rgba(18, 15, 0, 0.85);
    color: var(--text-color);
}

body[data-mode="dark"] .modal-window {
    border: 2px solid var(--text-color);
    box-shadow: 0 0 10px var(--text-color);
}

/* Icons for Dark Mode */
body[data-mode="dark"] .copy-btn::after {
    content: "C";
    font-weight: bold;
    font-size: 10px;
}
body[data-mode="dark"] .close-modal::after {
    content: "X";
    font-weight: bold;
    font-size: 10px;
}

/* 3. LIGHT MODE Override (System 6) */

/* Wrapper Border/Shadow */
body[data-mode="light"] .code-wrapper,
body[data-mode="light"] .modal-window {
    box-shadow: 4px 4px 0 #000;
    border: 2px solid #000 !important; /* Force black border */
    background: #fff;
}

/* Striped Header */
body[data-mode="light"] .code-header,
body[data-mode="light"] .modal-header {
    border-bottom: 2px solid #000;
    background-color: #fff;
    background-image: repeating-linear-gradient(
        to bottom,
        #000 0px,
        #000 2px,
        #fff 2px,
        #fff 4px
    );
    background-size: 100% 22px;
    background-position: center;
    background-repeat: no-repeat;
    background-origin: content-box;
    padding: 0 1.5px;
}

/* Title Label */
body[data-mode="light"] .header-title,
body[data-mode="light"] .modal-title {
    background: #fff;
    color: #000 !important; /* Force black text */
    padding: 0 12px;
    flex-grow: 0;
    margin: 0 auto;
    font-weight: bold;
    font-size: 1.5rem;
    text-transform: capitalize;
    opacity: 1; /* Ensure visibility */
}

/* Buttons */
body[data-mode="light"] .copy-btn,
body[data-mode="light"] .window-btn {
    border: 2px solid #000;
    width: 22px;
    height: 22px;
    background: #fff;
    box-shadow: 0 0 0 1.5px #fff;
    margin: 0 12px;
    color: #000;
}

body[data-mode="light"] .copy-btn:active,
body[data-mode="light"] .window-btn:active {
    transform: none;
    background: #000;
    background-clip: padding-box;
    box-shadow: 0 0 0 1.5px #fff;
}

body[data-mode="light"] .copy-btn::after { content: none; }


pre {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1.5rem;
    overflow-x: auto;
    margin: 0;
    border: none;
    font-family: var(--font-crt);
}

code {
    font-family: var(--font-crt);
    background: var(--code-bg);
    padding: 0.2em 0.4em;
}

/* POST LIST */
.post-list { list-style: none; }
.post-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--border-color);
}
.post-item:last-child { border: none; }
.post-date { font-family: var(--font-crt); font-size: 0.85rem; color: var(--secondary-text); }

/* Featured Post */
.featured-post {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid var(--border-color);
}

.featured-post h2 {
    margin-top: 1.5rem;
}

.featured-title {
    font-size: 1.75rem;
    margin-bottom: 1rem;
    text-decoration: none;
}

.featured-title a {
    border-bottom: none;
}

.featured-title a:hover {
    border-bottom: 1px dashed var(--accent-color);
    background: none;
    color: var(--accent-color);
}

.featured-excerpt {
    margin-bottom: 1rem;
    max-width: 65ch;
}

.featured-excerpt p {
    margin-bottom: 0;
}

.read-more {
    font-family: var(--font-crt);
    font-size: 0.9rem;
}

/* Post Meta */
.entry-meta {
    margin-bottom: 1rem;
}

.entry-meta .post-date {
    font-family: var(--font-crt);
    font-size: 0.85rem;
    color: var(--secondary-text);
}

.entry-meta .post-categories {
    font-family: var(--font-crt);
    font-size: 0.85rem;
    color: var(--secondary-text);
}

/* CONTROLS */
.controls {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    z-index: 100;
    font-family: var(--font-display);
    font-size: 0.8rem;
}

button {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-family: inherit;
}
button:hover {
    background: var(--text-color);
    color: var(--bg-color);
}

/* Light Mode Control Styling */
body[data-mode="light"] .controls {
    background: #fff;
    border: 1px solid #000;
    box-shadow: 2px 2px 0 #000;
}
body[data-mode="light"] button {
    box-shadow: 1px 1px 0 #000;
}
body[data-mode="light"] button:active {
    box-shadow: none;
    transform: translate(1px, 1px);
}

/* System 6 Button Style for Switch Theme */
body[data-mode="light"] #mode-toggle {
    border: 2px solid #000;
    border-radius: 6px; /* Rounded rectangle, not pill */
    background: #fff;
    color: #000;
    font-family: var(--font-sys-6);
    padding: 4px 16px;
    box-shadow: 1px 1px 0 #000; /* Sharp black shadow */
    font-size: 12px;
    transform: none;
    letter-spacing: 0.5px;
}

body[data-mode="light"] #mode-toggle:hover {
    background: #fff;
    color: #000;
}

body[data-mode="light"] #mode-toggle:active {
    background: #000;
    color: #fff;
    box-shadow: none;
    transform: translate(0, 0); /* No movement, just invert */
}

/* SYNTAX TOKENS */
.token-keyword { color: var(--token-keyword); font-weight: bold; }
.token-type { color: var(--token-type); }
.token-function { color: var(--token-function); }
.token-comment { color: var(--token-comment); font-style: italic; }
.token-string { color: var(--token-string); font-style: italic; }

/* Light Mode Syntax overrides (B&W) */
body[data-mode="light"] .token-type {
    text-decoration: underline;
    font-weight: bold;
}
body[data-mode="light"] .token-comment {
    font-style: normal;
    border-bottom: 1px dotted #000;
}

/*
 * MODAL WINDOW
 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--modal-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease-in-out;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* .modal-window Styles handled in SHARED WINDOW CHROME section */

.modal-body {
    padding: 1.5rem;
    font-family: var(--font-body);
}

.shortcut-list {
    list-style: none;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--border-color);
}
.shortcut-item:last-child { border: none; }

.key-badge {
    border: 1px solid var(--text-color);
    padding: 0 0.5rem;
    font-family: var(--font-crt);
    font-size: 0.9em;
}

body[data-mode="light"] .key-badge {
    border: 1px solid #000;
    box-shadow: 1px 1px 0 #000;
    background: #fff;
}

/* WordPress Admin Bar Compatibility */
body.admin-bar .controls {
    bottom: calc(1rem + 32px);
}

@media screen and (max-width: 782px) {
    body.admin-bar .controls {
        bottom: calc(1rem + 46px);
    }
}

/* Pagination */
.pagination {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border-color);
    display: flex;
    justify-content: space-between;
}

.pagination a {
    font-family: var(--font-crt);
}

/* No Posts */
.no-posts {
    padding: 2rem 0;
    text-align: center;
    color: var(--secondary-text);
}

/* Screen Reader Text */
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}
