/* =========================================
   1. CORE VARIABLES & FONTS
   ========================================= */
:root {
    /* P3R Surface Theme (Blue/Cyan/White) */
    --bg-color: #e1f5fe;
    --main-accent: #0084ff;
    --sub-accent: #00e5ff;
    --card-bg: #ffffff;
    --text-color: #003060;
    --header-color: #001a35;
    --reply-bg: #f0f8ff;
    --border-radius: 14px;
    --border-color: #b3e5fc;
    --shadow: 0 4px 15px rgba(0, 132, 255, 0.15);
}

html { scroll-behavior: smooth; }

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 20px;
    transition: all 0.4s ease;
}

/* =========================================
   2. PERSONA 5 THEME (NIGHT MODE / NSFW)
   ========================================= */
body.night-mode {
    --bg-color: #0a0a0a;
    --main-accent: #ff0000;   /* P5 Red */
    --sub-accent: #ffffff;    /* P5 White */
    --card-bg: #1a1a1a;
    --text-color: #eeeeee;
    --header-color: #ff0000;
    --reply-bg: #252525;
    --border-color: #440000;
    --shadow: 0 4px 20px rgba(255, 0, 0, 0.3);
}

/* =========================================
   3. GLOBAL LAYOUT (1000px Column)
   ========================================= */
/* Constrain main elements to a centered column */
.header, 
.post-box, 
#boardView, 
#threadView, 
#homeView {
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

#boardView, #threadView, #homeView {
    padding-bottom: 50px;
}

/* =========================================
   4. HEADER & NAVIGATION
   ========================================= */
.header { text-align: center; margin-bottom: 30px; }
.header h1 { 
    color: var(--header-color); 
    font-size: 2.5em; 
    font-weight: 900; 
    text-transform: uppercase;
    letter-spacing: -1px;
}

.nav-boards, .nav-site { 
    margin-bottom: 10px; 
    font-weight: bold; 
}
a { color: var(--main-accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--sub-accent); }

/* =========================================
   5. POST FORM (STYLIZED)
   ========================================= */
.post-box {
    background-color: var(--card-bg);
    border: 2px solid var(--main-accent);
    border-radius: var(--border-radius);
    padding: 0;
    margin-bottom: 30px; /* Space before threads */
    box-shadow: var(--shadow);
    overflow: hidden;
}

.form-header {
    background-color: var(--main-accent);
    color: #fff;
    font-weight: 900;
    text-align: center;
    padding: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

form { padding: 15px; display: flex; flex-direction: column; gap: 8px; }
input, textarea { 
    border: 1px solid var(--border-color); 
    border-radius: 8px; 
    padding: 10px; 
    background: var(--reply-bg);
    color: var(--text-color);
}

#uploadBtn {
    background-color: var(--sub-accent);
    color: var(--header-color);
    border: none;
    padding: 0 15px;
    border-radius: 8px;
    font-weight: 900;
    cursor: pointer;
}

#submitBtn {
    background-color: var(--main-accent);
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 900;
    text-transform: uppercase;
    cursor: pointer;
}

/* =========================================
   6. THREAD CARDS (OP)
   ========================================= */
.thread-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    width: auto; /* Fills the 1000px container */
    overflow: hidden;
}

/* Header Row */
.post-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.subject { color: var(--main-accent); font-weight: 900; font-size: 1.2em; }
.name { color: #2e7d32; font-weight: bold; }
body.night-mode .name { color: #4ade80; }
.time, .post-id { color: #666; font-size: 0.85em; }

.reply-link {
    margin-left: auto;
    background: var(--header-color);
    color: #fff !important;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: bold;
}

/* Content Area */
.post-content {
    display: block;
    min-height: 80px;
}

/* =========================================
   THREAD SEPARATOR (Restored)
   ========================================= */
.thread-separator {
    border: 0;
    border-bottom: 2px dashed var(--border-color); /* Matches P3R/P5 theme automatically */
    margin: 40px auto; /* Spacing between threads */
    width: 100%;
    display: block;
    opacity: 0.6;
}

/* =========================================
   7. REPLIES LAYOUT
   ========================================= */
.reply {
    background-color: var(--reply-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    
    /* Indent relative to the 1000px container */
    margin: 10px 0 10px 40px; 
    padding: 12px;
    
    display: table; /* Shrink to fit content */
    max-width: calc(100% - 40px); /* Don't overflow container */
    min-width: 300px;
    
    overflow: hidden; /* Clearfix for media */
    box-shadow: 2px 2px 8px rgba(0,0,0,0.05);
}

.comment { 
    margin: 10px 0;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Thread Summary (at bottom of OP) */
.thread-summary {
    clear: both;
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
    font-size: 0.85em;
    font-weight: bold;
}
.reply-count-num { color: var(--main-accent); }

/* =========================================
   8. MEDIA HANDLING
   ========================================= */
.thread-image, .media-container {
    float: left;
    margin: 0 15px 10px 0;
    position: relative;
    cursor: pointer;
    border: 3px solid var(--header-color);
    border-radius: 10px;
    overflow: hidden;
    line-height: 0;
    display: inline-block;
}

/* FORCE 200px LIMIT */
.thread-image, .media-container img {
    display: block;
    max-width: 200px !important;
    max-height: 200px !important;
    width: auto;
    height: auto;
}

.play-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: #fff; font-size: 30px;
    width: 50px; height: 50px;
    text-align: center; line-height: 50px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
}

.file-placeholder {
    width: 180px; height: 130px;
    background: #000; color: #fff;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.file-ext { font-weight: bold; font-size: 24px; color: #ffcc00; }

/* X (Twitter) Placeholder */
.x-placeholder {
    background-color: #000; 
    border: 2px solid #1DA1F2;
}

/* =========================================
   9. SPECIAL FEATURES (Links, Blur, Gate)
   ========================================= */
.quote-link { color: var(--main-accent); font-weight: bold; }
.backlink-container { margin-top: 10px; font-size: 0.8em; }
.backlink { color: var(--header-color); text-decoration: underline; margin-right: 5px; }

/* NSFW Blur (P5 Styled) */
body.night-mode .thread-image,
body.night-mode .media-container img,
body.night-mode .file-placeholder {
    filter: blur(30px);
    transition: filter 0.3s ease;
    opacity: 0.7;
}
body.night-mode .thread-image:hover,
body.night-mode .media-container:hover img,
body.night-mode .media-container:hover .file-placeholder {
    filter: blur(0);
    opacity: 1;
}
/* Ensure Play Overlay hides when blurred */
body.night-mode .media-container .play-overlay { opacity: 0; transition: opacity 0.3s; }
body.night-mode .media-container:hover .play-overlay { opacity: 1; }

/* Lightbox */
#lightbox {
    display: none; position: fixed; z-index: 10000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.9);
    justify-content: center; align-items: center;
}
#lightboxContent {
    max-width: 95%; max-height: 95%;
    display: flex; justify-content: center; align-items: center;
    width: 100%; height: 100%;
}
#lightbox img { max-width: 90%; max-height: 90%; border: 4px solid var(--sub-accent); border-radius: 15px; opacity: 1 !important; filter: blur(0) !important; }
#lbVideo, #lbFrame { max-width: 90vw; max-height: 90vh; background: black; opacity: 1 !important; filter: blur(0) !important; }
#lbFrame { width: 800px; height: 450px; }

/* NSFW Gate */
#nsfwGate {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #000; z-index: 99999; display: flex;
    justify-content: center; align-items: center;
}
.gate-box { 
    background: #1a1a1a; padding: 40px; border: 4px solid #ff0000; 
    border-radius: 20px; text-align: center; color: white;
    max-width: 400px;
}
.btn-enter { background: #b90000; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-weight: 900; }
.btn-exit { background: #444; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; margin-left: 10px;}

/* Admin */
.admin-delete-btn { color: #ff4444; font-weight: bold; cursor: pointer; margin-left: 10px; display: none; }
.mod-mode-active .admin-delete-btn { display: inline-block; }

/* =========================================
   10. HOME PAGE STYLES
   ========================================= */
.home-container {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.welcome-section { text-align: center; border-bottom: 2px solid var(--main-accent); padding-bottom: 10px; }
.instruction-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
.ins-card { background: var(--reply-bg); padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); }
.home-links a { display: block; font-size: 1.1em; font-weight: bold; margin: 8px 0; padding: 5px; border-bottom: 1px solid var(--border-color); }
.rules-box { margin-top: 20px; padding: 15px; border: 2px dashed var(--header-color); font-size: 0.9em; border-radius: 8px; }
.footer-secret { text-align: center; margin-top: 50px; }
.secret-link { color: var(--bg-color); text-decoration: none; font-size: 10px; transition: color 0.5s; }
.secret-link:hover { color: #888; }



/* =========================================
   11. MOBILE RESPONSIVENESS
   ========================================= */
@media (max-width: 768px) {
    body { padding: 10px; }
    
    .instruction-grid { grid-template-columns: 1fr; } /* Stack home columns */
    
    .thread-card { 
        border-radius: 0; 
        margin-left: -10px; margin-right: -10px; 
        padding: 10px; 
        width: auto; /* Full width */
    }
    
    .reply { 
        margin-left: 10px; 
        max-width: 90%; 
    }
    
    .thread-image, .media-container { max-width: 150px !important; }
    
    /* Make header responsive */
    .header h1 { font-size: 1.8em; }
}