/*
 * Post page layout test (PC: image left / text right, phone: full screen with
 * a bottom bar). Every rule is scoped to html[data-post-layout="new"], so the
 * current layout is untouched. script.js checks --pl-css before switching its
 * own behaviour, so a failed load of this file keeps the current behaviour.
 *
 * html.pl-ready          script.js built the new controls
 * .pl-has-post           a post is shown (not loading / error / not found)
 */
:root[data-post-layout="new"] {
    --pl-css: 1;
    --pl-bar-height: 64px;
    --pl-line: #e6e6ea;
}

/* ---------- Frame: one scroll for the whole post ---------- */
:root[data-post-layout="new"] #detail-modal .detail-modal-content {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    align-items: flex-start;
    grid-template-rows: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
:root[data-post-layout="new"] #detail-modal .detail-info-container {
    overflow: visible;
    min-height: auto;
    box-sizing: border-box;
}
:root[data-post-layout="new"] #detail-modal .detail-media-container {
    box-sizing: border-box;
}
:root[data-post-layout="new"] #detail-modal .pl-no-media .detail-media-container {
    display: none;
}
/* Image and text share one row (built by script.js), so the following image
   on PC stops where the text ends and never covers the similar examples. */
:root[data-post-layout="new"] #detail-modal .pl-row {
    flex: 0 0 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    min-width: 0;
}

/* Until script.js is ready, keep the current controls; afterwards they move
   into the new action row, bottom bar and "…" menu. */
:root.pl-ready[data-post-layout="new"] #detail-modal #copy-prompt-btn,
:root.pl-ready[data-post-layout="new"] #detail-modal .detail-cta-row {
    display: none !important;
}
:root.pl-ready[data-post-layout="new"] #detail-modal .detail-modal-content:not(.pl-has-post) :is(.pl-actions, .pl-bar, .pl-related, .pl-more-top) {
    display: none !important;
}
:root[data-post-layout="new"] #detail-modal [data-pl-hidden] {
    display: none !important;
}

/* ---------- Close and "…" stay on screen while scrolling ---------- */
:root[data-post-layout="new"] #detail-modal .pl-top {
    order: -1;
    flex: 0 0 100%;
    position: sticky;
    top: 0;
    z-index: 30;
    height: 0;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 8px;
    padding: 0 12px;
    box-sizing: border-box;
    pointer-events: none;
}
:root[data-post-layout="new"] #detail-modal .pl-top > * {
    pointer-events: auto;
    margin-top: 12px;
}
:root[data-post-layout="new"] #detail-modal .pl-top #close-detail-modal-btn,
:root[data-post-layout="new"] #detail-modal .pl-top .pl-more-top {
    position: static;
    width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    color: #1a1a1a;
    font-size: 16px;
    line-height: 1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    cursor: pointer;
}
:root[data-post-layout="new"] #detail-modal .pl-top #close-detail-modal-btn:hover,
:root[data-post-layout="new"] #detail-modal .pl-top .pl-more-top:hover {
    background: #fff;
    color: #000;
}

/* ---------- Buttons ---------- */
:root[data-post-layout="new"] #detail-modal .pl-pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid #dcdce0;
    border-radius: 999px;
    background: #fff;
    color: var(--text-color);
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .05s ease;
}
:root[data-post-layout="new"] #detail-modal .pl-pill:hover { background: #f5f5f7; }
:root[data-post-layout="new"] #detail-modal .pl-pill:active { transform: scale(0.96); }
:root[data-post-layout="new"] #detail-modal .pl-pill:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }
:root[data-post-layout="new"] #detail-modal .pl-pill.pl-icon-only { width: 40px; padding: 0; }
:root[data-post-layout="new"] #detail-modal .pl-pill[aria-expanded="true"] { border-color: #1a1a1a; background: #f2f2f4; }
:root[data-post-layout="new"] #detail-modal .pl-pill .count:empty { display: none; }
:root[data-post-layout="new"] #detail-modal .pl-pill .count { min-width: 1ch; font-variant-numeric: tabular-nums; }
:root[data-post-layout="new"] #detail-modal .pl-pill .count.count-pop {
    animation: reaction-count-pop 340ms cubic-bezier(0.2, 0.85, 0.3, 1) both;
}
/* Same colours as the feed cards: grey until pressed, so black never reads as "already liked". */
:root[data-post-layout="new"] #detail-modal .pl-pill:is(.favorite-btn, .bookmark-btn) { color: var(--secondary-text-color); }
:root[data-post-layout="new"] #detail-modal .pl-pill:is(.favorite-btn, .bookmark-btn):hover { color: var(--text-color); }
:root[data-post-layout="new"] #detail-modal .pl-pill.favorite-btn.active { color: #ff4757; border-color: #ffc6cd; }
:root[data-post-layout="new"] #detail-modal .pl-pill.favorite-btn.is-liked-burst { color: #ff2f5f; }
:root[data-post-layout="new"] #detail-modal .pl-pill.bookmark-btn.active { color: #00b894; border-color: #a9e2d3; }
:root[data-post-layout="new"] #detail-modal .pl-primary {
    border-color: #1a1a1a;
    background: #1a1a1a;
    color: #fff;
    padding: 0 18px;
}
:root[data-post-layout="new"] #detail-modal .pl-primary:hover { background: #000; }
:root[data-post-layout="new"] #detail-modal .pl-primary.copied { border-color: #1f8a4c; background: #1f8a4c; }
:root[data-post-layout="new"] #detail-modal .pl-primary.error { border-color: #b3261e; background: #b3261e; }
:root[data-post-layout="new"] #detail-modal .pl-pill:disabled { opacity: .5; cursor: not-allowed; transform: none; }

:root[data-post-layout="new"] #detail-modal .pl-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: -8px 0 24px;
}
/* Keep the row still when the label switches to "コピーしました". */
:root[data-post-layout="new"] #detail-modal .pl-actions .pl-primary { min-width: 184px; }
:root[data-post-layout="new"] #detail-modal .pl-actions[hidden] {
    /* Reserve the row before script.js fills it, so the prompt does not jump. */
    display: block;
    height: 40px;
    visibility: hidden;
}

/* ---------- Long prompts fold at about 11 lines (script.js decides) ---------- */
:root[data-post-layout="new"] #detail-modal #detail-prompt {
    /* A fixed line height keeps the 11-line fold and the line count exact. */
    line-height: 1.6;
}
:root[data-post-layout="new"] #detail-modal #detail-prompt.pl-folded {
    max-height: calc(1.6em * 11);
    overflow: hidden;
    -webkit-mask-image: linear-gradient(#000 72%, transparent);
    mask-image: linear-gradient(#000 72%, transparent);
}
:root[data-post-layout="new"] #detail-modal .pl-fold {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}
:root[data-post-layout="new"] #detail-modal .pl-fold button {
    min-height: 36px;
    padding: 0 16px;
    border: 1px solid #dcdce0;
    border-radius: 999px;
    background: #fff;
    color: var(--text-color);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
:root[data-post-layout="new"] #detail-modal .pl-fold button:hover { background: #f5f5f7; }
:root[data-post-layout="new"] #detail-modal .pl-fold button:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }

/* ---------- Similar examples and neighbours ---------- */
:root[data-post-layout="new"] #detail-modal .pl-related {
    flex: 0 0 100%;
    box-sizing: border-box;
    padding: 4px 32px 32px;
    border-top: 1px solid var(--pl-line);
    background: #fff;
}
:root[data-post-layout="new"] #detail-modal .pl-related-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 22px 0 14px;
}
:root[data-post-layout="new"] #detail-modal .pl-related-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}
:root[data-post-layout="new"] #detail-modal .pl-related-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px 16px;
}
:root[data-post-layout="new"] #detail-modal .pl-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}
:root[data-post-layout="new"] #detail-modal .pl-card:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 3px; border-radius: 10px; }
:root[data-post-layout="new"] #detail-modal .pl-card-thumb {
    position: relative;
    aspect-ratio: 4 / 3;
    border-radius: 10px;
    overflow: hidden;
    background: #f0f0f2;
}
:root[data-post-layout="new"] #detail-modal .pl-card-thumb img,
:root[data-post-layout="new"] #detail-modal .pl-card-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .25s ease;
}
:root[data-post-layout="new"] #detail-modal .pl-card:hover .pl-card-thumb img,
:root[data-post-layout="new"] #detail-modal .pl-card:hover .pl-card-thumb video { transform: scale(1.03); }
:root[data-post-layout="new"] #detail-modal .pl-card-badge {
    position: absolute;
    left: 8px;
    bottom: 8px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 11px;
}
:root[data-post-layout="new"] #detail-modal .pl-card-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.45;
}
:root[data-post-layout="new"] #detail-modal .pl-card-services {
    font-size: 12px;
    color: var(--secondary-text-color);
}
:root[data-post-layout="new"] #detail-modal .pl-card.is-skeleton .pl-card-thumb,
:root[data-post-layout="new"] #detail-modal .pl-card.is-skeleton .pl-card-title {
    background: linear-gradient(90deg, #f0f0f2 25%, #f7f7f9 50%, #f0f0f2 75%);
    background-size: 200% 100%;
    animation: pl-shimmer 1.2s ease-in-out infinite;
    border-radius: 10px;
}
:root[data-post-layout="new"] #detail-modal .pl-card.is-skeleton .pl-card-title { height: 18px; width: 80%; border-radius: 6px; }
@keyframes pl-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
:root[data-post-layout="new"] #detail-modal .pl-neighbours {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 26px;
}
:root[data-post-layout="new"] #detail-modal .pl-neighbour {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--pl-line);
    border-radius: 10px;
    color: inherit;
    text-decoration: none;
}
:root[data-post-layout="new"] #detail-modal .pl-neighbour:hover { background: #f7f7f9; }
:root[data-post-layout="new"] #detail-modal .pl-neighbour.is-older { grid-column: 2; text-align: right; }
:root[data-post-layout="new"] #detail-modal .pl-neighbour-label { font-size: 12px; color: var(--secondary-text-color); }
:root[data-post-layout="new"] #detail-modal .pl-neighbour-title {
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* ---------- Menus, sheets and the copied panel (outside the scroll) ---------- */
:root[data-post-layout="new"] #detail-modal .pl-layer {
    position: absolute;
    inset: 0;
    z-index: 40;
    pointer-events: none;
}
:root[data-post-layout="new"] #detail-modal .pl-layer > * { pointer-events: auto; }
:root[data-post-layout="new"] #detail-modal .pl-popover {
    position: absolute;
    min-width: 230px;
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
    padding: 6px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #dcdce0;
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16);
}
:root[data-post-layout="new"] #detail-modal .pl-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-color);
    font: inherit;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
:root[data-post-layout="new"] #detail-modal .pl-menu-item:hover,
:root[data-post-layout="new"] #detail-modal .pl-menu-item:focus-visible { background: #f2f2f4; outline: none; }
:root[data-post-layout="new"] #detail-modal .pl-menu-item:disabled { opacity: .55; cursor: default; background: transparent; }
:root[data-post-layout="new"] #detail-modal .pl-menu-item.is-danger { color: #a3322c; }
:root[data-post-layout="new"] #detail-modal .pl-menu-item > i { width: 20px; text-align: center; color: inherit; }
:root[data-post-layout="new"] #detail-modal .pl-menu-sep { height: 1px; margin: 4px 6px; background: #ededf0; }

:root[data-post-layout="new"] #detail-modal .pl-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}
:root[data-post-layout="new"] #detail-modal .pl-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85%;
    overflow-y: auto;
    box-sizing: border-box;
    padding: 10px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #fff;
    border-radius: 18px 18px 0 0;
    animation: pl-sheet-in .22s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes pl-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
:root[data-post-layout="new"] #detail-modal .pl-sheet-grip { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: #d4d4d8; }
:root[data-post-layout="new"] #detail-modal .pl-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
:root[data-post-layout="new"] #detail-modal .pl-sheet-head strong { font-size: 17px; }
:root[data-post-layout="new"] #detail-modal .pl-round-close {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #f2f2f4;
    color: #1a1a1a;
    cursor: pointer;
}
:root[data-post-layout="new"] #detail-modal .pl-share-preview {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--pl-line);
    border-radius: 12px;
}
:root[data-post-layout="new"] #detail-modal .pl-share-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; background: #f0f0f2; }
:root[data-post-layout="new"] #detail-modal .pl-share-preview span { display: block; min-width: 0; overflow-wrap: anywhere; }
:root[data-post-layout="new"] #detail-modal .pl-share-preview .pl-share-url { font-size: 12px; color: var(--secondary-text-color); }
:root[data-post-layout="new"] #detail-modal .pl-share-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
:root[data-post-layout="new"] #detail-modal .pl-share-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-color);
    font: inherit;
    font-size: 12px;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
:root[data-post-layout="new"] #detail-modal .pl-share-option > span:last-child {
    font-size: 11px;
    white-space: nowrap;
    letter-spacing: -0.02em;
}
:root[data-post-layout="new"] #detail-modal .pl-share-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f2f2f4;
    font-size: 22px;
}
:root[data-post-layout="new"] #detail-modal .pl-wide-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    border: 1px solid #1a1a1a;
    border-radius: 12px;
    background: #fff;
    color: #1a1a1a;
    font: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

:root[data-post-layout="new"] #detail-modal .pl-copied-card {
    position: absolute;
    width: 360px;
    max-width: calc(100vw - 32px);
    box-sizing: border-box;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #fff;
    border: 1px solid var(--pl-line);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
    animation: pl-sheet-in .2s ease-out both;
}
:root[data-post-layout="new"] #detail-modal .pl-copied-head { display: flex; align-items: flex-start; gap: 10px; }
:root[data-post-layout="new"] #detail-modal .pl-copied-check {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e8f7ed;
    color: #1f8a4c;
}
:root[data-post-layout="new"] #detail-modal .pl-copied-text { flex: 1 1 auto; min-width: 0; }
:root[data-post-layout="new"] #detail-modal .pl-copied-text strong { display: block; font-size: 15px; }
:root[data-post-layout="new"] #detail-modal .pl-copied-text span { font-size: 13px; color: var(--secondary-text-color); }
:root[data-post-layout="new"] #detail-modal .pl-service-links { display: flex; flex-wrap: wrap; gap: 8px; }
:root[data-post-layout="new"] #detail-modal .pl-service-links:empty { display: none; }
:root[data-post-layout="new"] #detail-modal .pl-service-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    background: #1a1a1a;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}
:root[data-post-layout="new"] #detail-modal .pl-service-link:hover { background: #000; }
:root[data-post-layout="new"] #detail-modal .pl-copied-actions { display: flex; flex-direction: column; gap: 2px; }

@media (prefers-reduced-motion: reduce) {
    :root[data-post-layout="new"] #detail-modal .pl-sheet,
    :root[data-post-layout="new"] #detail-modal .pl-copied-card,
    :root[data-post-layout="new"] #detail-modal .pl-card.is-skeleton .pl-card-thumb,
    :root[data-post-layout="new"] #detail-modal .pl-card.is-skeleton .pl-card-title { animation: none; }
    :root[data-post-layout="new"] #detail-modal .pl-card-thumb img,
    :root[data-post-layout="new"] #detail-modal .pl-card-thumb video { transition: none; }
}

/* ---------- PC (900px and wider): image left, text right ---------- */
@media (min-width: 900px) {
    :root[data-post-layout="new"] #detail-modal .detail-modal-content {
        width: min(94vw, 1200px);
        max-width: none;
        height: 92vh;
    }
    :root[data-post-layout="new"] #detail-modal .detail-media-container {
        flex: 0 0 56%;
        width: 56%;
        height: min(80vh, 760px);
        min-height: 360px;
    }
    :root[data-post-layout="new"] #detail-modal .detail-info-container {
        flex: 1 1 0;
        min-width: 0;
        padding: 28px 32px 28px;
    }
    :root[data-post-layout="new"] #detail-modal .pl-no-media .detail-info-container {
        flex: 1 1 100%;
        max-width: 860px;
        margin: 0 auto;
    }
    /* A long prompt scrolls while the image stays in view beside it. */
    :root[data-post-layout="new"] #detail-modal .pl-row > .detail-media-container {
        position: sticky;
        top: 0;
        z-index: 1;
    }
    :root[data-post-layout="new"] #detail-modal #detail-title { padding-right: 52px; }
    :root[data-post-layout="new"] #detail-modal :is(.pl-bar, .pl-more-top, .pl-title-sp) { display: none !important; }
}

/* ---------- Phone (below 900px): full screen, bottom bar ---------- */
@media (max-width: 899px) {
    :root[data-post-layout="new"] #detail-modal.modal-overlay {
        align-items: stretch;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    :root[data-post-layout="new"] #detail-modal .detail-modal-content {
        width: 100%;
        max-width: none;
        height: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    :root[data-post-layout="new"] #detail-modal .detail-media-container {
        flex: 0 0 100%;
        width: 100%;
        height: min(100vw, 70vh);
        min-height: 240px;
    }
    :root[data-post-layout="new"] #detail-modal .detail-before-after-view { padding-top: 60px; }
    :root[data-post-layout="new"] #detail-modal .detail-info-container {
        flex: 0 0 100%;
        width: 100%;
        padding: 20px 20px 12px;
    }
    :root[data-post-layout="new"] #detail-modal .pl-no-media .detail-info-container { padding-top: 64px; }
    :root[data-post-layout="new"] #detail-modal .pl-related {
        padding: 0 20px 24px;
        border-top: 0;
    }
    :root[data-post-layout="new"] #detail-modal .pl-related-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 16px 12px;
    }
    :root[data-post-layout="new"] #detail-modal .pl-related-grid > .pl-card:nth-child(n + 7) { display: none; }
    :root[data-post-layout="new"] #detail-modal .pl-bar {
        flex: 0 0 100%;
        position: sticky;
        bottom: 0;
        z-index: 25;
        display: flex;
        align-items: center;
        gap: 8px;
        min-height: var(--pl-bar-height);
        box-sizing: border-box;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, 0.97);
        border-top: 1px solid #ececf0;
        box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.06);
    }
    :root[data-post-layout="new"] #detail-modal .pl-bar .pl-pill { height: 44px; padding: 0 12px; }
    :root[data-post-layout="new"] #detail-modal .pl-bar .pl-primary { flex: 1 1 auto; min-width: 0; }
    :root[data-post-layout="new"] #detail-modal .pl-typing .pl-bar { display: none !important; }
    :root[data-post-layout="new"] #detail-modal :is(.pl-actions, .pl-title-pc) { display: none !important; }
    :root[data-post-layout="new"] body.pl-bar-visible #toast-container {
        bottom: calc(var(--pl-bar-height) + 16px + env(safe-area-inset-bottom, 0px));
    }
}
