/* ====== worms.css ====== */

/* General Layout & Global Styles */
html, body {
    margin: 0;
    padding: 0;
    /* Mellow tiled SVG background */
    background-color: #fafafa; /* fallback */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23fafafa'/%3E%3Ccircle cx='4' cy='4' r='1.25' fill='%23e7e7e7'/%3E%3Ccircle cx='20' cy='12' r='1' fill='%23ececec'/%3E%3Ccircle cx='12' cy='24' r='1.25' fill='%23e7e7e7'/%3E%3Ccircle cx='28' cy='28' r='1' fill='%23eaeaea'/%3E%3Ccircle cx='8' cy='16' r='0.9' fill='%23dde7ff'/%3E%3Ccircle cx='24' cy='4' r='0.9' fill='%23ffeedd'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 32px 32px;
    background-attachment: fixed;
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif;
    color: #222;
    font-size: 16px;
}

.container-app {
    display: grid;
    grid-template-columns: 1fr 630px 1fr;
    gap: 16px;
    margin-left: 88px;
}

/* Inline admin status selector */
.worm-status-card {
    border: 1px solid #e5e5e5;
    background: #fff;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0 0 0;
}
.worm-status-card .title { font-weight: 600; margin-bottom: 8px; }
.worm-status-card .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.worm-status-card .actions button { padding: 4px 10px; }
.worm-status-card .close { float: right; font-size: 12px; opacity: .7; }

.left-grid {
    display: grid;
    grid-template-columns:1fr;
    gap: 16px;
}

/* ====== comments (FE-only, SPA) ====== */
.worm-comments { margin-top: 8px; }
.worm-comments .toggle-comments { font-size: 13px; padding: 0; text-decoration: none; }
.worm-comments .toggle-comments .badge { vertical-align: baseline; }
.worm-comments .comments-body { display: none; border-top: 1px solid #eee; padding-top: 8px; margin-top: 6px; }
.worm-comments.open .comments-body { display: block; }
.worm-comments .comment-item { padding: 6px 0; border-bottom: 1px dashed #eee; }
.worm-comments .comment-meta { color: #666; font-size: 12px; margin-bottom: 2px; }
.worm-comments .comment-content { font-size: 14px; white-space: pre-wrap; }
.worm-comments .comments-list { max-height: 280px; overflow-y: auto; }
.worm-comments .comment-form textarea { width: 100%; min-height: 56px; resize: vertical; font-size: 14px; }
.worm-comments .comment-form .actions { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.worm-comments .signin-hint { color: #777; font-size: 13px; }
/* replies */
.worm-comments .replies { margin-top: 6px; padding-left: 10px; border-left: 2px solid #f0f0f0; }
[dir="rtl"] .worm-comments .replies { padding-left: 0; padding-right: 10px; border-left: 0; border-right: 2px solid #f0f0f0; }
.worm-comments .reply-actions { margin-top: 4px; }
.worm-comments .reply-toggle { font-size: 12px; padding: 0; text-decoration: none; }
.worm-comments .reply-form textarea { width: 100%; min-height: 44px; resize: vertical; font-size: 13px; }
.worm-comments .reply-item { padding: 4px 0; border-bottom: 1px dotted #f2f2f2; }

.center {
    width: 630px;
    margin: 0 auto;
    min-height: 100vh;
}

.right {
    position: sticky;
    top: 16px;
    align-self: start;
    height: calc(100vh - 32px);
    overflow: auto;
}

.menu-vertical {
    position: fixed;
    top: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    width: 44px;
    background: #fff;
    border: 1px solid #dbdbdb;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
    align-items: center;
    z-index: 1000;
}

.menu-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #222;
    text-decoration: none;
    border: 1px solid #e5e5e5;
    background: #fafafa;
}

.menu-btn:hover {
    background: #f0f0f0;
}

.menu-btn.active {
    background: #e8f0fe;
    border-color: #4a90e2;
    color: #1a73e8;
}

.menu-btn svg {
    width: 18px;
    height: 18px;
}

.menu-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    gap: 24px;
    justify-content: center;
    padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
    background: #fff;
    border-top: 1px solid #dbdbdb;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
    z-index: 1000;
}

.menu-bottom .menu-btn, .menu-vertical .menu-btn {
    flex: 0 0 auto;
}

@media (max-width: 1024px) {
    .container-app {
        grid-template-columns:1fr;
        grid-template-areas:"center";
        margin-left: 0;
    }

    .center {
        width: 100%;
    }

    .left, .right {
        display: none;
    }

    .menu-bottom {
        display: flex;
    }

    .menu-vertical {
        display: none;
    }

    body {
        padding-bottom: 64px;
    }
}

@media (max-width: 768px) {
    .container-app {
        grid-template-columns:1fr;
        grid-template-areas:"center";
        margin-left: 0;
    }

    .center {
        width: 100%;
    }

    .left, .right {
        display: none;
    }

    .menu-bottom {
        display: flex;
    }

    .menu-vertical {
        display: none;
    }

    body {
        padding-bottom: 64px;
    }
}

.worm-follow-link {
    font-weight: 500;
    font-size: 14px;
    color: #1a73e8;
    text-decoration: none;
    margin: 0 6px;
}

.like-btn {
    font-size: 18px;
    line-height: 1;
    width: 36px;
    height: 36px;
    border-radius: 18px;
    border: 1px solid #dbdbdb;
    background: #fff;
    cursor: pointer;
    color: #444;
}

/* When liked, change only the icon (foreground) color, keep background unchanged for clarity */
.like-btn[aria-pressed="true"] {
    color: #e11d48;
}

.action-btn {
    padding: 8px 12px;
    border: 1px solid #dbdbdb;
    border-radius: 6px;
    background: #f5f5f5;
    cursor: pointer;
}

.action-btn.correct {
    background: #d1fae5;
    border-color: #10b981;
    color: #065f46;
}

.action-btn.incorrect {
    background: #fee2e2;
    border-color: #ef4444;
    color: #7f1d1d;
}

.action-btn.failed {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #78350f;
}

.action-btn:disabled {
    cursor: default;
}

.action-btn.disabled-sibling {
 /*   text-decoration: line-through;*/
    opacity: .6;
}

.key-btn.correct {
    background: #d1fae5;
    border-color: #10b981;
    color: #065f46;
}

.key-btn.incorrect {
    background: #fee2e2;
    border-color: #ef4444;
    color: #7f1d1d;
}

.key-btn.failed {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #78350f;
}

.key-btn.disabled-sibling {
    /*text-decoration: line-through;*/
    opacity: .6;
}

/* ====== header.html (styles) ====== */
:root {
    --header-bg: #0b1020;
    --header-text: #e2e8f0;
    --header-accent: #3b82f6;
    --header-accent-2: #f97316;
    --header-accent-3: #22c55e;
    --header-border: rgba(148, 163, 184, .18);
}

.sq-header {
    position: relative;
    z-index: 100;
    color: var(--header-text);
    border-bottom: 1px solid var(--header-border);
    background: linear-gradient(90deg, rgba(59, 130, 246, .18), rgba(249, 115, 22, .18) 40%, rgba(34, 197, 94, .18) 80%), var(--header-bg);
    overflow: hidden;
}

.sq-header svg.decor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: .6;
}

.sq-header__inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: .6rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: relative;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    color: var(--header-text);
    text-decoration: none;
    font-weight: 800;
}

.brand-logo {
    width: 28px;
    height: 28px;
}

.brand-text {
    letter-spacing: .3px;
    font-size: 1.05rem;
}

.nav {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: .4rem;
}

.nav a {
    color: var(--header-text);
    text-decoration: none;
    padding: .45rem .7rem;
    border-radius: 8px;
}

.nav a:hover {
    background: rgba(59, 130, 246, .12);
}

.logout {
    appearance: none;
    padding: .4rem .7rem;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, .25);
    background: transparent;
    color: var(--header-text);
    cursor: pointer;
}

.logout:hover {
    background: rgba(59, 130, 246, .12);
}

.nav-toggle {
    display: none;
    width: 38px;
    height: 34px;
    border: 1px solid rgba(148, 163, 184, .25);
    border-radius: 8px;
    background: transparent;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
}

.nav-toggle .bar {
    width: 20px;
    height: 2px;
    background: var(--header-text);
}

@media (max-width: 840px) {
    .sq-header {
        overflow: visible;
    }

    .nav-toggle {
        display: inline-flex;
        position: relative;
        z-index: 1101;
    }

    .nav {
        display: none;
        position: absolute;
        right: 1rem;
        top: 56px;
        background: var(--header-bg);
        border: 1px solid var(--header-border);
        border-radius: 10px;
        padding: .4rem;
        flex-direction: column;
        z-index: 1000;
        box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
        width: min(86vw, 360px);
        max-height: calc(100vh - 80px);
        overflow: auto;
    }

    .nav.open {
        display: flex;
    }
}

/* ====== worm-item.html (card-specific styles) ====== */
.worm-item {
    background: #fff;
    border: 1px solid #dbdbdb;
    margin: 16px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.worm-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    font-weight: 600;
}

/* Admin-only visibility helper */
[data-admin-only] { display: none; }
/* Reveal admin-only elements only when body carries an explicit admin flag. */
body[data-admin="true"] [data-admin-only] { display: initial; }

/* Right-aligned language flags inside header */
.worm-header .worm-flags {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 18px; /* slightly larger for emoji visibility */
    line-height: 1;
}

.worm-body {
    font-size: 180%;
}

.worm-text {
    padding: 0 16px 0;
    line-height: 1.5;
    white-space: pre-wrap;
}

.worm-image {
    position: relative;
}

.worm-image img {
    width: 100%;
    display: block;
}

.heart-overlay {
    position: absolute;
    left: 12px;
    bottom: 12px;
    padding: 6px 10px;
    border: none;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}

.heart-overlay:focus {
    outline: 2px solid rgba(255, 255, 255, .8);
    outline-offset: 2px;
}

.worm-overlay {
    position: absolute;
    right: 12px;
    bottom: 12px;
    padding: 6px 10px;
    border: none;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}

.worm-overlay:focus {
    outline: 2px solid rgba(255, 255, 255, .8);
    outline-offset: 2px;
}

.worm-overlay .worm-icon {
    width: 22px;
    height: 22px;
    display: block;
}

.worm-text a.hashtag, .worm-text a.hashtag:visited, .worm-text a.hashtag:hover {
    text-decoration: none;
}

.worm-text a.hashtag {
    /* Hide all hashtags by default */
    display: none;
    /* Make hashtags smaller than the surrounding text */
    font-size: 0.7em;
    /* Tighten vertical spacing when hashtags wrap to multiple lines */
    line-height: 1;
}

/* Show hashtags after first reveal */
.worm-item.show-tags .worm-text a.hashtag {
    display: inline;
}

/* Apply RTL only to text areas when needed */
.worm-text[dir="rtl"],
.worm-text .worm-main[dir="rtl"],
.more-text[dir="rtl"] {
    direction: rtl;
    text-align: right;
    font-family: 'Vazir', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Explanation card: make text RTL when card dir is rtl (e.g., Persian 'fa') */
.worm-explanation[dir="rtl"] [data-role="text"] {
    direction: rtl;
    text-align: right;
    font-family: 'Vazir', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Split sections: main text and hashtags */
.worm-text .worm-main {
    display: block;
    white-space: pre-wrap;
}

.worm-text .worm-tags {
    /* Hide the dedicated hashtags section by default */
    display: none;
    margin-top: 0;
    white-space: pre-wrap;
    font-size: 0.95em;
    color: #333;
    /* Reduce vertical spacing between lines when tag list wraps */
    line-height: 1;
}

.worm-text .worm-tags-ltr {
    direction: ltr;
    text-align: left;
}

.worm-text .worm-tags-rtl {
    direction: rtl;
    text-align: right;
    font-family: 'Vazir', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* When the show-tags class is present, display tags */
.worm-item.show-tags .worm-text .worm-tags {
    display: block;
}

/* When the show-answers class is present, display keys */
.worm-item.show-answers .worm-keys {
    display: flex;
}

.comments-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 16px;
}

.meta-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 0 4px;
}

.meta-actions .btn-link {
    text-decoration: none;
    font-size: 1.2rem;
    line-height: 1;
}

.meta-actions .toggle-explanation {
    font-size: 1.1rem;
}

/* Hide elements during editing */
.worm-item.editing .worm-tags,
.worm-item.editing .worm-keys,
.worm-item.editing .worm-comments,
.worm-item.editing .comments-controls {
    display: none !important;
}

/* Hashtags inside the dedicated tags section are always visible */
.worm-text .worm-tags a.hashtag,
.worm-text .worm-tags a.hashtag:visited,
.worm-text .worm-tags a.hashtag:hover {
    text-decoration: none;
    display: inline;
    /* Keep hashtags smaller within the dedicated tags section as well */
    font-size: 0.7em;
    /* Ensure anchors themselves don't expand the line box */
    line-height: 1;
}

.worm-explanation {
    margin: 4px 16px 8px;
}

/* Minimal Markdown presentation for legacy containers */
.markdown-body { line-height: 1.55; }
.markdown-body p { margin: 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.25rem; margin: 0 0 4px 0; }
.markdown-body pre { background: #f6f8fa; border: 1px solid #eee; border-radius: 6px; padding: 8px; overflow: auto; }
.markdown-body code { background: #f6f8fa; border-radius: 4px; padding: 0 3px; }
/* zero-md host adjustments inside explanation cards */
.worm-explanation zero-md { display:block; }

.key-btn.correct {
    background-color: #dcfce7 !important;
    border-color: #22c55e !important;
    border-width: 2px !important;
}

.key-btn.incorrect {
    background-color: #fee2e2 !important;
    border-color: #ef4444 !important;
    border-width: 2px !important;
}

/* Activity visuals (icons + text) */
.act {
    display: flex;
    align-items: center;
    gap: 8px;
}
.act .act-ic {
    width: 32px;
    height: 32px;
    display: inline-flex;
}
.act.create .act-ic { color: #2563eb; }
.act.like .act-ic { color: #e11d48; }
.act.correct .act-ic { color: #16a34a; }
.act.incorrect .act-ic { color: #dc2626; }

/* Ensure each activity renders on a single line in the More card */
.more-acts > li {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap; /* force one line */
    overflow: hidden;    /* hide overflow if too long */
}
.more-acts > li .act {
    flex: 1 1 auto;      /* main content grows */
    min-width: 0;        /* allow ellipsis */
    overflow: hidden;    /* clip overflowed content */
    text-overflow: ellipsis; /* show ellipsis for long names */
}
.more-acts > li .act-time {
    flex: 0 0 auto;      /* time stays visible and won’t shrink */
}

.tags-btn, .more-btn {
    display: none;
}

.phase-1-btn, .phase-2-btn, .phase-3-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
    display: inline-block !important;
}

.phase-1-btn:hover, .phase-2-btn:hover, .phase-3-btn:hover {
    opacity: 1;
}

.worm-keys {
    padding: 0 16px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.key-btn {
    padding: 6px 10px;
    border: 1px solid #bbb;
    border-radius: 6px;
    background: #f7f7f7;
    cursor: pointer;
    font-size: 100%;
}

.key-btn[disabled] {
    opacity: .6;
    cursor: default;
}

/* When there are exactly two keys, make them fill the whole row equally */
.worm-keys.two .key-btn {
    flex: 1 1 0;
    text-align: center;
}

.worm-item .worm-keys {
    display: none;
}

/* Phased reveal rules (legacy support for data-phase) */
.worm-item[data-phase="1"] .worm-keys,
.worm-item[data-phase="2"] .worm-keys,
.worm-item[data-phase="3"] .worm-keys {
    display: flex;
}

.worm-item[data-phase="2"] .worm-tags,
.worm-item[data-phase="3"] .worm-tags {
    display: block;
}

/* About section: NO overlay. Keep DOM position. Horizontally align with center pane (630px). */
.about-page {
    position: static; /* normal flow */
    width: 630px; /* match center column */
    /* Align with center column considering fixed 88px left menu and symmetric side fr columns */
    margin-left: calc((100vw - 88px - 630px) / 2 + 88px);
    margin-right: 0;
    margin-top: 12px;
    margin-bottom: 16px;
    background: #ffffff;
    border: 1px solid #eaeaea;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.08);
    padding: 20px;
    text-align: start;
}
/* When viewport is narrow (menu collapses and center becomes fluid), use full width with gutters */
@media (max-width: 992px) {
    .about-page {
        width: calc(100vw - 32px);
        margin-left: 16px;
        margin-right: 16px;
    }
}
@media (max-width: 576px) {
    .about-page { padding: 16px; border-radius: 10px; }
}

#page-collections .collection-card { cursor: pointer; transition: transform 0.1s; }
#page-collections .collection-card:hover { transform: scale(1.02); }
#page-collections .collection-header { display: flex; justify-content: space-between; align-items: center; }

/* Compact modal styling */
.modal-content-compact { border-radius: 12px; border: none; box-shadow: 0 10px 40px rgba(0,0,0,0.1); }
.modal-header-compact { border-bottom: 1px solid #f0f0f0; padding: 12px 16px; }
.modal-body-compact { padding: 16px; }
.modal-footer-compact { border-top: 1px solid #f0f0f0; padding: 10px 16px; }

/* Related Worms Mini Row */
.related-worms-mini {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.mini-worms-container {
    display: flex;
    flex-direction: row;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.mini-worm-card {
    flex: 0 0 120px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
}

.mini-worm-card:hover {
    border-color: #0d6efd;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mini-worm-img {
    width: 100%;
    height: 68px;
    object-fit: cover;
}

.mini-worm-text {
    padding: 5px;
    font-size: 0.75rem;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.view-all-relations {
    text-align: right;
    margin-top: 5px;
}

/* Parent Context Banner */
.parent-context-preview {
    margin-bottom: 8px;
}

.parent-worm-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: #f0f7ff;
    border: 1px solid #cce3ff;
    border-radius: 6px;
    text-decoration: none;
    color: #0056b3;
    font-size: 0.85rem;
}

.parent-worm-link:hover {
    background: #e1efff;
    border-color: #b3d7ff;
    color: #004494;
}

.context-label {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #666;
}

.parent-worm-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

/* Frozen Header for Relations Page */
.frozen-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: #f8f9fa;
    border-bottom: 2px solid #0d6efd;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Tag selector in composer */
.tag-selector-container { position: relative; }
.tag-suggestions {
    position: absolute; top: 100%; left: 0; right: 0;
    background: #fff; border: 1px solid #ddd; border-radius: 8px;
    max-height: 200px; overflow-y: auto; z-index: 2000;
    display: none; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.tag-suggestion-item { padding: 8px 12px; cursor: pointer; }
.tag-suggestion-item:hover, .tag-suggestion-item.active { background: #f0f7ff; }
.selected-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-pill {
    background: #eef2ff; color: #4338ca; padding: 2px 10px;
    border-radius: 999px; font-size: 13px; display: flex; align-items: center; gap: 4px;
}
.tag-pill .remove { cursor: pointer; font-weight: bold; font-size: 14px; opacity: 0.6; }
.tag-pill .remove:hover { opacity: 1; }
