/*
 * 폰·태블릿 기사 도구 — 제목 아래 공유·복사·글자 크기·저장, 읽는 동안 상단 공유·복사, 본문 끝 공유.
 * 1200px 이하에서만 보이고, 그때는 왼쪽 세로 막대(.tn-share-rail)를 숨긴다 — 그 막대는 이 폭에서 한 줄로 펴져
 * 사이드 위젯·광고 뒤, 바닥글 바로 위에 붙었다(tnews-theme.css 의 1200px 규칙 order: 2). 1200px 은 그 규칙과 같은 경계다.
 * 색·선은 그 언론사 값(--tn-red · --tn-ink · --tn-line)을 따른다.
 */

.tn-article-tools,
.tn-article-share-sticky,
.tn-article-share-end {
    display: none;
}

.tn-article-share-sticky[hidden],
body.tn-menu-open .tn-article-share-sticky,
.tn-at-feedback[hidden],
.tn-at-feedback:empty {
    display: none !important;
}

.tn-at-feedback {
    position: fixed;
    top: calc(var(--tn-at-top, 0px) + 64px);
    left: 50%;
    z-index: 110;
    box-sizing: border-box;
    width: max-content;
    max-width: 90vw;
    padding: 11px 16px;
    border-radius: 10px;
    background: #111827;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.2);
    color: #fff;
    font: 600 14px/1.5 sans-serif;
    text-align: center;
    transform: translateX(-50%);
    pointer-events: none;
}

@media (max-width: 1200px) {
    :is(.tn-article-tools, .tn-article-share-sticky, .tn-article-share-end) {
        --tn-at-accent: #1f3f58;
        --tn-at-accent-hover: #142e43;
        --tn-at-soft: #f4f7fa;
    }

    @supports (color: color-mix(in srgb, #000, #fff)) {
        :is(.tn-article-tools, .tn-article-share-sticky, .tn-article-share-end) {
            /* 현재 3사 매체색을 어둡게 보정해 흰 글자 대비를 확보한다(청색경제 약 5.1:1). */
            --tn-at-accent: color-mix(in srgb, var(--tn-red, #0072bc) 60%, #111827);
            --tn-at-accent-hover: color-mix(in srgb, var(--tn-red, #0072bc) 48%, #111827);
            --tn-at-soft: color-mix(in srgb, var(--tn-red, #0072bc) 4%, #fff);
        }
    }

    .tn-share-rail {
        display: none !important;
    }

    /* 1) 제목 아래 직접 공유·복사와 기존 보조 도구 */
    .tn-article-tools {
        position: relative;
        z-index: 20;
        display: flex;
        align-items: stretch;
        gap: 4px 8px;
        margin: 14px 0 6px;
        padding: 4px 6px;
        border: 1px solid var(--tn-line, #e5e7eb);
        border-radius: 12px;
        background: #f8fafc;
        color: var(--tn-ink, #111827);
    }

    /* JS가 본문 편집기 밖(body)으로 옮겨 transform/overflow의 영향을 받지 않게 한다. */
    .tn-article-share-sticky {
        position: fixed;
        top: var(--tn-at-top, 0px);
        right: 0;
        left: 0;
        z-index: 100;
        display: block;
        border-bottom: 1px solid var(--tn-line, #e5e7eb);
        background: #fff;
        box-shadow: 0 4px 18px rgba(15, 23, 42, 0.08);
        color: var(--tn-ink, #111827);
    }

    .tn-at-sticky-tools {
        display: flex;
        align-items: stretch;
        gap: 8px;
        box-sizing: border-box;
        max-width: 720px;
        margin: 0 auto;
        padding: 4px max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
    }

    /* 편집기 칸(.tn-article-layout-slot)마다 transform 이 있어 칸마다 쌓임 맥락이 생긴다 — 그대로 두면 다음 칸(본문)이
       펼친 상자 위에 그려진다. 펼친 동안만 이 줄이 든 칸을 위로 올린다. */
    .tn-article-layout-slot:has(.tn-at-item[open]),
    .tn-article-header:has(.tn-at-item[open]),
    .tn-article-main-slot:has(.tn-at-item[open]) {
        position: relative;
        z-index: 60;
    }

    .tn-at-item {
        position: relative;
        flex: 1 1 0;
        min-width: 0;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn,
    .tn-article-tools .tn-bookmark-btn.tn-at-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        gap: 7px;
        width: 100%;
        height: auto;
        min-height: 48px;
        margin: 0;
        padding: 0 8px;
        border: 1px solid transparent;
        border-radius: 10px;
        background: transparent;
        color: var(--tn-ink-soft, #475569);
        font: inherit;
        font-size: 14px;
        font-weight: 700;
        letter-spacing: -0.02em;
        line-height: 1.35;
        white-space: nowrap;
        list-style: none;
        cursor: pointer;
        transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    /* 메타 칸의 '북마크 보이기'(data-show-bookmark=0)는 칸 안 기사 카드용이다. 이 줄의 저장은 데스크톱 세로 막대처럼 늘 보인다. */
    .tn-article-tools .tn-at-save .tn-bookmark-btn.tn-at-btn {
        display: flex !important;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn::-webkit-details-marker {
        display: none;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn::marker {
        content: "";
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn i {
        color: inherit;
        font-size: 15px;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn:focus-visible {
        outline: 2px solid var(--tn-at-accent);
        outline-offset: 2px;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn:active {
        background: var(--tn-at-soft);
    }

    .tn-at-item[open] > .tn-at-btn,
    .tn-article-tools .tn-bookmark-btn.is-active,
    .tn-article-tools .tn-bookmark-btn.is-active i {
        color: var(--tn-at-accent);
    }

    .tn-article-tools :is(.tn-at-size, .tn-at-save) .tn-at-btn {
        font-size: 13px;
        font-weight: 600;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-share > .tn-at-btn {
        border-color: var(--tn-at-accent);
        background: var(--tn-at-accent);
        box-shadow: 0 2px 5px rgba(15, 23, 42, 0.12);
        color: #fff;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-copy > .tn-at-btn {
        border-color: var(--tn-at-accent);
        background: #fff;
        color: var(--tn-at-accent);
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-share > .tn-at-btn:active {
        border-color: var(--tn-at-accent-hover);
        background: var(--tn-at-accent-hover);
        box-shadow: none;
    }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-copy > .tn-at-btn:active {
        border-color: var(--tn-at-accent);
        background: var(--tn-at-soft);
    }

    @media (hover: hover) {
        :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn:hover {
            background: var(--tn-at-soft);
        }

        :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-share > .tn-at-btn:hover {
            border-color: var(--tn-at-accent-hover);
            background: var(--tn-at-accent-hover);
        }

        :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-copy > .tn-at-btn:hover {
            border-color: var(--tn-at-accent);
        }
    }

    .tn-at-ico-size {
        display: inline-flex;
        align-items: baseline;
        font-size: 16px;
        font-weight: 900;
        letter-spacing: -0.06em;
    }

    .tn-at-ico-size small {
        font-size: 11px;
        font-weight: 800;
    }

    /* 펼침 상자 — 글자 크기 세 칸, 공유 목록 */
    .tn-at-pop {
        position: absolute;
        top: calc(100% + 8px);
        left: 50%;
        z-index: 40;
        display: flex;
        gap: 6px;
        padding: 8px;
        border: 1px solid var(--tn-line, #e5e7eb);
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
        transform: translateX(-50%);
        white-space: nowrap;
        animation: tn-at-pop 0.16s ease-out;
    }

    .tn-at-size .tn-at-pop {
        left: 8px;
        transform: none;
    }

    .tn-at-share .tn-at-pop {
        left: 0;
        transform: none;
        box-sizing: border-box;
        flex-direction: column;
        width: min(280px, calc(100vw - 32px));
    }

    .tn-at-share .tn-at-pop :is(button, a) {
        justify-content: flex-start;
        gap: 10px;
    }

    .tn-at-share .tn-at-pop i {
        width: 18px;
        text-align: center;
    }

    .tn-at-pop button,
    .tn-at-pop a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        min-width: 56px;
        min-height: 44px;
        padding: 0 12px;
        border: 1px solid var(--tn-line, #e5e7eb);
        border-radius: 10px;
        background: #fff;
        color: var(--tn-ink, #111827);
        font: inherit;
        font-size: 13.5px;
        font-weight: 700;
        text-decoration: none;
        cursor: pointer;
    }

    .tn-at-pop .tn-at-size-small { font-size: 12.5px; }
    .tn-at-pop .tn-at-size-large { font-size: 16px; }

    .tn-at-pop [aria-pressed="true"] {
        border-color: var(--tn-at-accent);
        background: var(--tn-at-accent);
        color: #fff;
    }

    .tn-at-pop .is-done,
    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn.is-done,
    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn.is-done i,
    .tn-ase-btn.is-done .tn-ase-ico {
        border-color: #86efac;
        background: #f0fdf4;
        color: #166534;
    }

    /* 2) 본문 끝 — 이 기사 공유하기 */
    .tn-article-share-end {
        display: block;
        margin: 26px 0 8px;
        padding: 16px 14px 14px;
        border: 1px solid var(--tn-line, #e5e7eb);
        border-radius: var(--tn-radius, 10px);
        background: var(--tn-at-soft);
        text-align: center;
    }

    .tn-ase-title {
        display: block;
        margin-bottom: 12px;
        color: var(--tn-ink, #111827);
        font-size: 14.5px;
        font-weight: 800;
        letter-spacing: -0.02em;
    }

    .tn-ase-list {
        display: flex;
        justify-content: center;
        gap: 6px;
    }

    .tn-ase-btn {
        display: inline-flex;
        flex: 0 1 76px;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        min-width: 0;
        padding: 0;
        border: 0;
        background: none;
        color: var(--tn-ink-soft, #4b5563);
        font: inherit;
        font-size: 12px;
        font-weight: 700;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .tn-ase-btn[hidden] {
        display: none;
    }

    .tn-ase-ico {
        display: inline-grid;
        place-items: center;
        width: 46px;
        height: 46px;
        border: 1px solid var(--tn-line, #e5e7eb);
        border-radius: 50%;
        background: #fff;
        color: var(--tn-ink, #111827);
        font-size: 17px;
        transition: transform 0.12s ease;
    }

    .tn-ase-btn:active .tn-ase-ico {
        transform: scale(0.94);
    }

    .tn-ase-native .tn-ase-ico {
        border-color: #fee500;
        background: #fee500;
        color: #191919;
    }

    .tn-ase-btn.is-facebook .tn-ase-ico { color: #1877f2; }

    .tn-ase-btn:focus-visible {
        outline: none;
    }

    .tn-ase-btn:focus-visible .tn-ase-ico {
        outline: 2px solid var(--tn-red, #e6003c);
        outline-offset: 2px;
    }
}

@media (max-width: 520px) {
    .tn-article-tools {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tn-article-tools .tn-at-size:last-child {
        grid-column: 1 / -1;
    }
}

@keyframes tn-at-pop {
    from { opacity: 0; transform: translate(-50%, -4px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.tn-at-size .tn-at-pop,
.tn-at-share .tn-at-pop {
    animation-name: tn-at-pop-left;
}

@keyframes tn-at-pop-left {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .tn-at-pop { animation: none; }

    :is(.tn-article-tools, .tn-article-share-sticky) .tn-at-btn {
        transition: none;
    }
}

@media print {
    .tn-article-tools,
    .tn-article-share-sticky,
    .tn-article-share-end,
    .tn-at-feedback {
        display: none !important;
    }
}
