:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-color: #f0f0f0;
    --text-muted: #aaaaaa;
    --primary-color: #2ecc71;
    --primary-hover: #27ae60;
    --yellow: #f1c40f;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    background: radial-gradient(circle at top left, #1a2a40, #121212 50%, #2a1120);
    min-height: 100vh;
    height: auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.header-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: rgba(0, 0, 0, 0.4);
    width: 100%;
    box-sizing: border-box;
}

.header-right-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.public-memes-btn {
    background-color: var(--primary-color);
    color: #fff !important;
    padding: 10px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.3s ease;
    white-space: nowrap;
}

.public-memes-btn:hover {
    background-color: var(--primary-hover);
}

@media (max-width: 768px) {
    .header-right-actions .public-memes-btn {
        display: none !important;
    }
    
    .header-right .public-memes-btn {
        display: none !important;
    }

    .calculator-container {
        flex-direction: column !important;
        width: 100% !important;
    }
}

.menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

.main-content {
    padding: 40px 10px;
    text-align: center;
    max-width: 100% !important;
    box-sizing: border-box;
    flex: 1;
}

.floating-h1 {
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: #fff;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.highlight-yellow {
    color: var(--yellow);
}

.calculator-container {
    display: flex;
    flex-direction: row;
    gap: 30px;
    justify-content: center;
    max-width: 1040px;
    margin: 0 auto;
    flex-wrap: wrap;
    box-sizing: border-box;
    width: 100%;
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.05);
    flex: 1;
    min-width: 320px;
    box-sizing: border-box;
}

.card-left, .card-right {
    max-width: 505px;
    width: 100%;
    box-sizing: border-box;
}
.card-right {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.meme-preview-box {
    position: relative;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.meme-preview-box img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
}

.text-wrapper {
    position: absolute;
    box-sizing: border-box;
    cursor: move;
    z-index: 10;
    border: 2px dashed transparent;
    padding: 4px;
    transform-origin: center center;
    user-select: none;
}

.text-wrapper.active {
    border: 2px dashed #f1c40f;
    z-index: 20;
}

.text-wrapper:not(.active) .resize-handle,
.text-wrapper:not(.active) .rotate-handle,
.text-wrapper:not(.active) .delete-text-btn {
    display: none !important;
}

.meme-text {
    text-align: center;
    color: #ffffff;
    font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, sans-serif;
    font-weight: bold;
    font-size: 42px;
    line-height: 1.1;
    word-wrap: break-word;
    width: 100%;
    box-sizing: border-box;
    user-select: none;
    -webkit-text-stroke: 0.05em #000;
    text-shadow: 0 0 0.1em rgba(0,0,0,0.9), 0 0.05em 0.1em rgba(0,0,0,0.8);
}

.meme-text-small {
    font-size: 32px;
}

.text-wrapper.active .resize-handle {
    display: block !important;
}

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #f1c40f;
    border: 1px solid #000;
    z-index: 12;
}
.handle-tl { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-tr { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-br { bottom: -6px; right: -6px; cursor: nwse-resize; }

.rotate-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #f1c40f;
    border: 2px solid #000;
    border-radius: 50%;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    cursor: grab;
    z-index: 12;
}
.rotate-handle:active {
    cursor: grabbing;
}

.delete-text-btn {
    position: absolute;
    bottom: -22px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 22px;
    background: #e74c3c;
    color: #fff;
    border: 1px solid #000;
    border-radius: 50%;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 15;
    transition: 0.2s;
}
.delete-text-btn:hover {
    background: #c0392b;
    transform: translateX(-50%) scale(1.1);
}

.add-text-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin: 5px 0;
    width: 100%;
    box-sizing: border-box;
    padding-right: 5px;
}

.add-text-label {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
}

.add-text-btn {
    width: 32px;
    height: 32px;
    background-color: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    flex-shrink: 0;
}
.add-text-btn:hover {
    background-color: var(--primary-hover);
    transform: scale(1.1);
}

.input-delete-btn {
    background: none;
    border: none;
    color: #e74c3c;
    font-size: 14px;
    cursor: pointer;
    padding: 0 10px;
    transition: 0.2s;
}
.input-delete-btn:hover {
    color: #c0392b;
    transform: scale(1.1);
}

.drop-zone {
    border: 2px dashed rgba(255,255,255,0.2);
    padding: 20px;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
    text-align: center;
}
.drop-zone:hover {
    border-color: var(--yellow);
    background: rgba(255, 255, 255, 0.02);
}
.drop-zone input[type="file"] {
    display: none;
}

.input-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.input-with-controls {
    display: flex;
    background: #2a2a2a;
    border-radius: 8px;
    padding: 4px;
    align-items: center;
    border: 1px solid #333;
    width: 100%;
    box-sizing: border-box;
}

.input-with-controls input[type="text"], 
#shareLinkInput {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    color: #fff;
    padding: 10px;
    outline: none;
    font-size: 15px;
}

#shareLinkInput {
    background: #2a2a2a;
    border-radius: 8px;
    border: 1px solid #333;
    width: 100%;
    box-sizing: border-box;
}

.visibility-box {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #2a2a2a;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
    cursor: help;
}

.toggle-label-container {
    display: flex;
    flex-direction: column;
    text-align: left;
}
.toggle-title {
    font-weight: bold;
    color: var(--yellow);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #555; 
    transition: .4s;
    border-radius: 34px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}
input:checked + .slider:before {
    transform: translateX(22px);
}

.calc-btn {
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 16px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    width: 100%;
}
.calc-btn:hover {
    background: var(--primary-hover);
}

.sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100%;
    background-color: #1a1a1a;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
    transition: left 0.3s ease-in-out;
    z-index: 1000;
    padding: 30px 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

.sidebar.active {
    left: 0;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 40px 0 0 0;
    text-align: left;
}

.sidebar ul li {
    margin-bottom: 15px;
    text-align: left;
}

.sidebar ul li a {
    color: #fff;
    text-decoration: none;
    font-size: 16px;
    display: block;
    padding: 8px 0;
    text-align: left;
    transition: color 0.2s;
}

.sidebar ul li a:hover, 
.sidebar ul li a.active {
    color: var(--yellow);
}

.close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
    position: absolute;
    top: 20px;
    right: 20px;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    z-index: 999;
}

.sidebar-overlay.active {
    visibility: visible;
    opacity: 1;
}

.agency-footer { 
    text-align: center; 
    padding: 25px; 
    margin-top: auto; 
    border-top: 1px solid rgba(255, 255, 255, 0.05); 
    width: 100%; 
    box-sizing: border-box; 
    color: var(--text-muted); 
    font-size: 14px; 
}
.agency-footer a { color: var(--text-muted); text-decoration: none; }
.agency-footer a:hover { color: #fff; }

.gallery-container { 
    width: 100% !important; 
    max-width: 100% !important; 
    margin: 0; 
    padding: 0 20px; 
    box-sizing: border-box; 
}

.gallery-grid { 
    column-count: 4; 
    column-gap: 20px; 
    width: 100%; 
    margin-top: 30px; 
    box-sizing: border-box; 
}

@media (max-width: 1000px) { 
    .gallery-grid { column-count: 2; } 
}
@media (max-width: 600px) { 
    .gallery-grid { column-count: 1; } 
}

.meme-card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 15px 35px rgba(0,0,0,0.5);
    margin-bottom: 20px;
    display: inline-block;
    width: 100%;
    break-inside: avoid;
    transition: transform 0.3s ease, border-color 0.3s ease;
    box-sizing: border-box;
}

.meme-card:hover { 
    transform: translateY(-5px); 
    border-color: #f1c40f; 
}

.meme-card img { 
    width: 100%; 
    height: auto; 
    display: block; 
    object-fit: contain; 
    background: #000; 
    cursor: pointer; 
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

.meme-card img.loaded {
    opacity: 1;
}

.meme-card-info { 
    padding: 15px 15px; 
    text-align: left; 
    border-top: 1px solid rgba(255, 255, 255, 0.05); 
    box-sizing: border-box;
}

.meme-card-info p {
    margin: 0;
    font-size: 14px;
    color: #ffffff !important;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
}

.no-memes { 
    width: 100%; 
    padding: 50px; 
    font-size: 1.2rem; 
    color: var(--text-muted); 
    text-align: center; 
}

.full-width-template-btn {
    display: block;
    width: 100%;
    background-color: var(--yellow);
    color: #000;
    text-align: center;
    padding: 14px 20px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 16px;
    text-decoration: none;
    margin-top: 20px;
    box-sizing: border-box;
    transition: background-color 0.3s ease;
}
.full-width-template-btn:hover { background-color: #d4ac0d; }

#memeLightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#memeLightbox.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-content img {
    max-width: 85vw;
    max-height: 85vh;
    border-radius: 12px;
    object-fit: contain;
    display: block;
    box-shadow: 0 0 30px rgba(241, 196, 15, 0.4), 0 0 60px rgba(46, 204, 113, 0.3);
}

.lightbox-close {
    position: absolute;
    top: -45px;
    right: 0;
    font-size: 36px;
    color: #fff;
    cursor: pointer;
    background: rgba(0,0,0,0.5);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    border: 1px solid rgba(255,255,255,0.2);
}

.lightbox-close:hover {
    background: #e74c3c;
    border-color: #e74c3c;
}