:root {
    /* Lion and Sun Palette */
    --flag-green: #009A44; --flag-red: #D81D2D; --flag-white: #FFFFFF; --flag-gold: #F9D342;
    /* Dark Theme (Default) */
    --bg-color: #1a1a1a; --box-bg: #222; --text-color: #e0e0e0; --muted-text: #888;
    --border-color: #444; --input-bg: #111; --input-text: #fff; --card-bg: #1e1e1e;
    --widget-bg: #222; --btn-text: #fff; --secondary-bg: #444; --secondary-hover: #666;
    --secondary-text: #fff; --modal-bg: #1a1a1a; --terminal-bg: #000;
}
body.light-theme {
    --bg-color: #f0f2f5; --box-bg: #ffffff; --text-color: #1a1a1a; --muted-text: #666;
    --border-color: #ccc; --input-bg: #f9f9f9; --input-text: #000; --card-bg: #ffffff;
    --widget-bg: #ffffff; --btn-text: #fff; --secondary-bg: #e4e6eb; --secondary-hover: #d8dadf;
    --secondary-text: #050505; --modal-bg: #ffffff; --terminal-bg: #1a1a1a;
}
body { background: var(--bg-color); color: var(--text-color); font-family: monospace; padding: 2rem; padding-top: 4rem; transition: background 0.3s, color 0.3s; }

@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');

/* --- MAIN LAYOUT & RESPONSIVENESS --- */
.main-container { max-width: 800px; margin: 0 auto; margin-right: auto; transition: margin-right 0.3s; }

/* Desktop Widget Positioning */
@media (min-width: 1300px) {
    .main-container { margin-right: 340px; margin-left: auto; }
    .user-widget { right: 20px; left: auto; }

    /* RTL Desktop Overrides */
    body.lang-fa .main-container { margin-left: 340px; margin-right: auto; }
    body.lang-fa .user-widget { left: 20px; right: auto; }
}

/* Headings */
h1, h2, h3 {
    color: var(--flag-green);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
    margin-top: 0;
    margin-bottom: 0.8rem;
}
.box-identity h2, .box-identity h3 { color: var(--flag-gold); border-bottom-color: #665500; }
.box-identity { border-color: var(--flag-gold) !important; }

/* Main Box (With the Flag Stripe) */
.box {
    border: 1px solid var(--border-color);
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--box-bg);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}
/* The 3-Color Flag Stripe */
.box::before { content: ''; position: absolute; top: 0; bottom: 0; width: 4px; background: linear-gradient(to bottom, var(--flag-green) 0%, var(--flag-green) 33.333%, var(--flag-white) 33.333%, var(--flag-white) 66.666%, var(--flag-red) 66.666%, var(--flag-red) 100%); z-index: 1; }

/* LTR Stripe Logic (Default) */
body:not(.lang-fa) .box::before { left: 0; }
body:not(.lang-fa) .box { padding-left: 1.5rem; }

/* RTL Stripe Logic (Farsi) */
body.lang-fa .box::before { right: 0; }
body.lang-fa .box { padding-right: 1.5rem; }


/* Inputs */
textarea {
    width: 100%; height: 60px; background: var(--input-bg); color: var(--input-text);
    border: 1px solid var(--border-color); padding: 8px; margin-bottom: 8px;
    font-family: inherit; box-sizing: border-box;
}

/* Buttons */
button { background: var(--flag-green); color: var(--btn-text); border: none; padding: 6px 12px; cursor: pointer; font-weight: bold; border-radius: 2px; font-family: inherit; transition: background 0.2s; font-size: 0.9rem; }
button:hover { background: #00b350; }
button:disabled { background: var(--secondary-bg); color: var(--muted-text); cursor: not-allowed; }
button.secondary { background: var(--secondary-bg); color: var(--secondary-text); font-size: 0.75rem; padding: 3px 8px; }
button.secondary:hover { background: var(--secondary-hover); }

/* App Controls (Top Buttons) */
.app-controls { position: fixed; top: 10px; left: 10px; z-index: 950; display: flex; gap: 8px; }
.control-btn { background: var(--box-bg); border: 1px solid var(--border-color); color: var(--text-color); padding: 4px 8px; cursor: pointer; border-radius: 4px; display: flex; align-items: center; gap: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.control-btn:hover { background: var(--secondary-hover); }
.control-btn svg { width: 18px; height: 18px; display: block; }

/* User Widget */
.user-widget { position: fixed; background: var(--widget-bg); border: 1px solid var(--flag-gold); z-index: 900; padding: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.2); transition: all 0.3s ease; }
@media (min-width: 1100px) { .user-widget { top: 20px; width: 260px; bottom: auto; border-radius: 4px; max-height: 90vh; overflow-y: auto; } .mobile-toggle { display: none; } .widget-body { display: block !important; } .mobile-summary { display: none; } }
@media (max-width: 1099px) { .user-widget { top: auto; bottom: 0; left: 0; right: 0; width: 100%; border-radius: 0; border: none; border-top: 2px solid var(--flag-gold); padding: 8px 12px; box-sizing: border-box; } .widget-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; } .widget-header h3 { border: none; margin: 0; padding: 0; font-size: 0.9rem; display: inline-block; } .widget-body { display: none; margin-top: 10px; padding-bottom: 15px; border-top: 1px solid var(--border-color); padding-top: 10px; } .widget-body.expanded { display: block; } .mobile-toggle { background: none; border: none; color: var(--flag-gold); font-size: 1.1rem; padding: 0; } .mobile-summary { color: var(--muted-text); font-size: 0.8rem; margin-left: 10px; } body.lang-fa .mobile-summary { margin-left: 0; margin-right: 10px; } body { padding-bottom: 60px; } }

/* Mobile Specifics */
@media (max-width: 768px) {
    body { font-size: 15px; padding: 0.25rem; padding-top: 3.5rem; padding-bottom: 80px; }
    .box { padding: 0.75rem; padding-left: 1.2rem !important; margin-bottom: 0.75rem; }
    /* Mobile RTL Box Fix */
    body.lang-fa .box { padding-right: 1.2rem !important; }
}

/* Status Grid */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.status-card { background: var(--input-bg); border: 1px solid var(--border-color); padding: 6px; border-radius: 4px; }
.status-label { font-size: 0.7rem; color: var(--muted-text); display: block; margin-bottom: 2px; }
.status-value { font-size: 0.9rem; font-weight: bold; }

/* Idea Cards */
.idea-card { border: 1px solid var(--border-color); padding: 0.75rem; margin-bottom: 8px; background: var(--card-bg); display: flex; gap: 10px; position: relative; }
.vote-box { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; min-width: 32px; padding-top: 2px; }
.vote-btn { background: none; border: 1px solid var(--border-color); color: var(--muted-text); padding: 0px 6px; margin: 1px 0; font-size: 1rem; cursor: pointer; transition: all 0.2s; line-height: 1.2; }
.vote-btn:hover { background: var(--secondary-hover); color: var(--text-color); }

/* Active Vote States */
.vote-btn.active-up { color: var(--flag-green); transform: scale(1.2); text-shadow: 0 0 5px rgba(0, 255, 0, 0.3); font-weight: bold; }
.vote-btn.active-down { color: var(--flag-red, #ff4444); transform: scale(1.2); text-shadow: 0 0 5px rgba(255, 0, 0, 0.3); font-weight: bold; }

.idea-body { flex-grow: 1; min-width: 0; }
.idea-content { white-space: pre-wrap; font-size: 1rem; cursor: pointer; overflow-wrap: break-word; word-break: break-word; margin-bottom: 6px; }
.idea-content:hover { opacity: 0.8; }

/* Idea Meta */
.idea-meta { display: flex; flex-direction: column; gap: 2px; font-size: 0.75rem; color: var(--muted-text); }
.meta-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meta-bottom { display: flex; align-items: center; gap: 10px; font-size: 0.7rem; }

/* Action Buttons */
.icon-action-btn { background: none; border: none; padding: 0; cursor: pointer; color: var(--flag-gold); opacity: 0.8; transition: opacity 0.2s; display: inline-flex; align-items: center; }
.text-action-btn { background: none; border: none; padding: 0; font-size: 0.7rem; cursor: pointer; color: var(--text-color); text-decoration: underline; opacity: 0.6; }

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 2000; display: none; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-content { background: var(--modal-bg); border: 1px solid var(--flag-green); padding: 1.5rem; width: 90%; max-width: 600px; border-radius: 8px; box-shadow: 0 0 30px rgba(0, 154, 68, 0.15); font-family: 'Courier New', Courier, monospace; max-height: 90vh; overflow-y: auto; color: var(--text-color); }
.mining-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }

/* Inputs in Modals */
.input-dark { background: var(--input-bg); border: 1px solid var(--border-color); color: var(--text-color); padding: 8px; width: 100%; box-sizing: border-box; margin-bottom: 8px; font-family: monospace; font-size: 0.9rem; }

/* Markdown & Preview */
.markdown-body { line-height: 1.5; }
.markdown-body blockquote { border-left: 3px solid var(--flag-gold); margin: 0; padding-left: 10px; color: var(--muted-text); }
#previewContainer { background: var(--input-bg); color: var(--text-color); width: 100%; box-sizing: border-box; margin-bottom: 8px; border-radius: 4px; overflow-y: auto; max-height: 300px; }

/* Toasts */
.toast-msg { position: fixed; bottom: 20px; right: 20px; background: #333; color: #fff; padding: 12px 20px; border-radius: 4px; border-left: 4px solid var(--flag-gold); box-shadow: 0 4px 12px rgba(0,0,0,0.3); font-size: 0.9rem; opacity: 0; transform: translateY(20px); transition: all 0.3s ease; z-index: 10000; }
.toast-msg.show { opacity: 1; transform: translateY(0); }
.toast-msg.success { border-left-color: var(--flag-green); }
.toast-msg.error { border-left-color: var(--flag-red, #ff4444); }

/* Seed Phrase Box */
.seed-box { background: #000; border: 1px solid var(--border-color); padding: 15px; font-family: 'Courier New', monospace; font-size: 1rem; color: var(--flag-green); margin: 5px 0; border-radius: 4px; word-spacing: 8px; line-height: 1.6; user-select: all; word-break: break-all; }

/* External Links */
a.external-link { cursor: alias; color: var(--flag-green); text-decoration: underline; }
a.external-link::after { content: " \2197"; font-size: 0.75em; opacity: 0.5; margin-left: 1px; vertical-align: top; display: inline-block; }


/* =========================================
   RTL SUPPORT (Farsi / Persian Mode)
   ========================================= */

body.lang-fa {
    direction: rtl;
    font-family: 'Vazirmatn', "Tahoma", "Segoe UI", sans-serif;
    text-align: right;
}

/* 1. Layout Flipping (Controls vs Widget) */
body.lang-fa .app-controls {
    left: auto; right: 10px; /* Moves controls to Top-Right */
}

body.lang-fa .user-widget {
    right: auto; left: 10px; /* Moves Widget to Top-Left */
    /* Note: Desktop override for this is in the media query at the top */
}

/* 2. Component Flipping */
body.lang-fa .vote-box { margin-left: 15px; margin-right: 0; }
body.lang-fa .idea-card { gap: 10px; border-left: none; border-right: 1px solid var(--border-color); }
body.lang-fa .status-label { text-align: right; }
body.lang-fa .widget-header { flex-direction: row-reverse; }

/* 3. Toasts Flip */
body.lang-fa .toast-msg {
    right: auto; left: 20px;
    border-left: none; border-right: 4px solid var(--flag-gold);
    transform: translateX(-20px);
}
body.lang-fa .toast-msg.show { transform: translateX(0); }
body.lang-fa .toast-msg.success { border-right-color: var(--flag-green); }
body.lang-fa .toast-msg.error { border-right-color: var(--flag-red, #ff4444); }

/* 4. Inputs & Text */
body.lang-fa input,
body.lang-fa textarea,
body.lang-fa .hash-terminal {
    direction: rtl; text-align: right;
}
/* Exception: Hash terminal content is usually code/hex, so keep it LTR inside */
body.lang-fa .hash-terminal { direction: ltr; text-align: left; }

/* 5. Flexbox Order Fixes */
body.lang-fa .idea-meta,
body.lang-fa .meta-top,
body.lang-fa .meta-bottom { flex-direction: row; }
body.lang-fa .mining-header { flex-direction: row-reverse; }
body.lang-fa #postForm > div { flex-direction: row; }

/* 6. Icons */
body.lang-fa .link-badge { margin-left: 0; margin-right: 5px; transform: scaleX(-1); display: inline-block; }
body.lang-fa #filterBanner { flex-direction: row; }
body.lang-fa #filterBanner button { margin-left: 0; margin-right: auto; }
#linkIndicator {
    margin-bottom: 8px;
    padding: 4px 8px;
    background: var(--secondary-bg);
    border-left: 3px solid var(--flag-green);
    /* HIDDEN BY DEFAULT */
    display: none;
    justify-content: space-between;
    align-items: center;
}

/* Add this to handle the flex display toggle in JS */
#linkIndicator.active {
    display: flex;
}