/* Base Variables and Layout */
@import url('https://fonts.googleapis.com/css2?family=Bangers&family=Comic+Neue:wght@400;700&display=swap');

#blackandwhite-app-wrapper {
    --bw-text: #000000;
    --bw-border: #111827;
    --bw-border-soft: #cbd5e1;
    --bw-bg: #ffffff;
    --bw-card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --bw-input-bg: #f8fafc;
    
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: transparent;
    color: var(--bw-text);
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: clip;
}

#blackandwhite-app-wrapper * {
    box-sizing: border-box;
}

/* Base Typography */
#blackandwhite-app-wrapper h1 {
    margin-bottom: 0.5rem;
    color: #000000;
    font-family: 'Bangers', cursive;
    font-size: 3rem;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0px #ffffff, 4px 4px 0px #000000;
    text-align: center;
}

#blackandwhite-app-wrapper p {
    color: #1f2937;
    margin-top: 0;
    margin-bottom: 2rem;
    text-align: center;
    font-weight: 500;
}

/* =========================================
   Layout: Responsive 3-Column Grid
   ========================================= */
#blackandwhite-app-wrapper .bw-main-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100% !important;
    padding: 10px 0;
}

#blackandwhite-app-wrapper .bw-comic-pane,
#blackandwhite-app-wrapper .bw-settings-pane,
#blackandwhite-app-wrapper .bw-expression-pane {
    width: 100%;
    min-width: 0;
}

/* Desktop: 3 Columns */
@media (min-width: 1024px) {
    #blackandwhite-app-wrapper .bw-main-container {
        flex-direction: row;
        align-items: flex-start;
    }
    #blackandwhite-app-wrapper .bw-comic-pane {
        flex: 2;
    }
    #blackandwhite-app-wrapper .bw-settings-pane,
    #blackandwhite-app-wrapper .bw-expression-pane {
        flex: 1;
        max-width: 450px;
    }
}

/* =========================================
   Modern B&W UI: Settings Pane & Controls
   ========================================= */
.bw-controls-modern {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bw-ui-card {
    background: var(--bw-bg);
    border: 2px solid #111827;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 3px 3px 0px #111827;
}

.bw-compact-card {
    padding: 8px 12px;
}

/* Utilities for Grids & Flex */
.bw-ui-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bw-ui-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bw-flex-between { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.bw-ui-field-group { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.bw-ui-field-group > label {
    font-size: 0.7rem;
    font-weight: 800;
    color: #111827;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* =========================================
   Inputs and Buttons
   ========================================= */
.bw-modern-input, .bw-modern-select {
    width: 100%;
    background: var(--bw-input-bg);
    border: 1.5px solid #111827;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #000000;
    outline: none;
    transition: all 0.2s;
    height: 32px;
}

.bw-modern-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2214%22%20height%3D%2214%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23000000%22%20stroke-width%3D%222.5%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

.bw-modern-input:focus, .bw-modern-select:focus {
    border-color: #000000;
    background: #ffffff;
    box-shadow: 2px 2px 0px #000000;
}

/* Buttons */
.bw-modern-btn {
    border: 2px solid #000000;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-weight: 800;
    font-size: 0.8rem;
    text-transform: uppercase;
    border-radius: 6px;
    height: 34px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background-color 0.2s, color 0.2s, box-shadow 0.2s;
    color: #ffffff;
    background: #111827;
    box-shadow: 2px 2px 0px #000000;
}

select.bw-modern-btn {
    color: #ffffff !important;
    padding-right: 28px;
    padding-left: 10px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2214%22%20height%3D%2214%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23ffffff%22%20stroke-width%3D%223%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.bw-modern-btn:hover {
    background: #000000;
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0px #000000;
}

.bw-modern-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px #000000;
}

/* Monochrome Button Variants */
.bw-btn-dark { background: #111827; color: #ffffff; }
.bw-export-btn { background: #ffffff; color: #000000; }
.bw-export-btn:hover { background: #f1f5f9; color: #000000; }
.bw-share-btn { background: #111827; color: #ffffff; }
.bw-wp-save-btn { background: #ffffff; color: #000000; }
.bw-wp-save-btn:hover { background: #f1f5f9; color: #000000; }
.bw-wp-pub-btn { background: #000000; color: #ffffff; }
.bw-wp-my-btn { background: #374151; color: #ffffff; }

/* =========================================
   Custom Input Groups
   ========================================= */
.bw-input-with-addon, .bw-input-range-group {
    display: flex;
    align-items: center;
    background: var(--bw-input-bg);
    border: 1.5px solid #111827;
    border-radius: 6px;
    overflow: hidden;
}

.bw-input-with-addon input[type="number"],
.bw-input-range-group input[type="number"] {
    border: none;
    border-radius: 0;
    background: transparent;
    flex: 1;
}

.bw-cb-label-addon {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    font-size: 0.75rem;
    font-weight: 800;
    border-left: 1.5px solid #111827;
    cursor: pointer;
    background: #f1f5f9;
    height: 100%;
}

.bw-x-divider {
    color: #111827;
    font-weight: bold;
    padding: 0 4px;
}

/* =========================================
   Character Builder (Rows & Columns)
   ========================================= */
.bw-char-header-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 2px solid #111827;
    margin-bottom: 6px;
    padding-bottom: 4px;
}

.bw-char-header {
    flex: 1;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 800;
    color: #000000;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bw-char-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dashed #cbd5e1;
}

.bw-char-row:last-child {
    border-bottom: none;
}

.bw-char-col {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 0 6px;
    min-width: 0;
}

.bw-char-col.bw-divider {
    border-left: 1.5px solid #e2e8f0;
    margin-left: 4px;
    padding-left: 10px;
}

.bw-char-col label {
    font-size: 0.75rem;
    font-weight: 800;
    color: #111827;
    white-space: nowrap;
}

/* Checkboxes */
.bw-cb-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 0.75rem !important;
    accent-color: #000000;
}

/* Range Sliders */
.bw-slider-col {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.bw-slider-label {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    font-weight: 800;
    color: #111827;
}

#blackandwhite-app-wrapper input[type="range"] {
    width: 100%;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

#blackandwhite-app-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #000000;
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1.5px #000000;
}

/* =========================================
   Comic Rendering Core & Unchanged Textarea
   ========================================= */
#bw-comic-container {
    width: 100%;
    overflow-x: auto;
    display: flex;
    justify-content: center;
    padding: 10px 0;
}

#bw-comic-svg {
    max-width: 100%;
    height: auto !important;
    border-radius: 4px;
}

/* Speech bubble text area kept exactly unchanged[cite: 2] */
.comic-text {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    resize: none;
    text-align: center;
    font-family: 'Comic Neue', Arial, sans-serif;
    font-size: 16px;
    font-weight: bold;
    color: #1f2937;
    overflow: hidden;
    outline: none;
    line-height: 1.2;
}

.comic-text::placeholder { color: rgba(31, 41, 55, 0.3); }

.author-text {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    font-family: 'Comic Neue', Arial, sans-serif;
    font-size: 16px;
    font-weight: bold;
    color: #6b7280;
    outline: none;
}

.author-text::placeholder { color: rgba(107, 114, 128, 0.5); }

.bw-hidden-canvas { display: none; }

/* =========================================
   Modals & Loaders
   ========================================= */
.bw-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.bw-modal-content {
    background-color: #ffffff;
    margin: 10% auto;
    padding: 24px;
    border: 3px solid #000000;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    box-shadow: 6px 6px 0px #000000;
}

.bw-alert-modal-content {
    max-width: 350px;
    text-align: center;
    padding: 30px 20px;
}

.bw-close {
    color: #64748b;
    float: right;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.bw-close:hover { color: #000000; }

.bw-comic-list-item {
    border-bottom: 1.5px dashed #cbd5e1;
    padding: 15px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bw-comic-list-item h4 { margin: 0 0 4px 0; color: #000000; font-size: 1rem; }
.bw-comic-list-item span { font-size: 0.8rem; color: #475569; }

.bw-badge {
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 10px;
    text-transform: uppercase;
    border: 1.5px solid #000000;
}

.bw-badge.private { background-color: #ffffff; color: #000000; }
.bw-badge.publish { background-color: #000000; color: #ffffff; }

#blackandwhite-loader {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.92);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Bangers', cursive;
    font-size: 2rem;
    color: #000000;
}

.bw-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #000000;
    border-radius: 50%;
    animation: bw-spin 0.8s linear infinite;
    margin-bottom: 15px;
}

@keyframes bw-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.bw-alert-text {
    margin: 20px 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #000000;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

.bw-alert-btn {
    margin-top: 10px;
    padding: 10px 30px;
    font-size: 0.9rem;
}

/* =========================================
   Frontend Viewer Specific Styles
   ========================================= */
.bw-comic-frontend-viewer {
    display: block;
    width: 100%;
    position: relative;
}

.bw-comic-frontend-viewer svg {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto !important;
    border-radius: 4px;
    box-shadow: var(--bw-card-shadow);
}

.bw-btn-repost, .bw-btn-download {
    display: inline-block;
    padding: 12px 24px;
    text-decoration: none !important;
    border-radius: 8px;
    font-weight: 800;
    font-size: 1.1rem;
    font-family: 'Comic Neue', 'Segoe UI', system-ui, sans-serif;
    text-transform: uppercase;
    border: 3px solid #000000;
    box-shadow: 4px 4px 0px #000000;
    transition: all 0.2s;
    cursor: pointer;
}

.bw-btn-repost {
    background-color: #ffffff;
    color: #000000 !important;
}

.bw-btn-repost:hover {
    background-color: #f1f5f9;
}

.bw-btn-download {
    background-color: #111827;
    color: #ffffff !important;
}

.bw-btn-download:hover {
    background-color: #000000;
}

.bw-btn-repost:hover, .bw-btn-download:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0px #000000;
}

.bw-btn-repost:active, .bw-btn-download:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px #000000;
}