/* =====================================================================
 * Stage Detail — /stage/:id
 *
 * A focused reading/viewing surface. The iframe preview is the anchor;
 * everything else (title, byline, conversation) sits around it with
 * restrained typography and generous whitespace.
 * ===================================================================== */

/* Paperlogy is loaded globally via common.css → vendor/paperlogy.css
   (self-hosted on static.s.show). No per-page @font-face declarations
   needed here — keeping it page-local would re-fetch on stylesheet
   reload and bloat the surface. */

#wrapper-contents { padding: 0; background-color: var(--global-body-background); }

.stage-detail-page {
    position: relative;
    width: 100%;
    /* border-box 필수: <section> 은 common.css 의 div 한정 box-sizing 리셋을
       못 받아, width:100% + 좌우 padding 이 뷰포트 밖으로 밀려 모바일에서
       콘텐츠가 가장자리에 붙는다 (.stage / #downloads-page 루트와 동일 패턴). */
    box-sizing: border-box;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    /* 좌우 최소 24px — 형제 페이지 .stage(24px)와 동일선상. 사이트 전반의
       모바일 콘텐츠 거터가 20~31px 대역이라 16px 은 유일한 아웃라이어였다. */
    padding: clamp(64px, 9vh, 110px) clamp(24px, 4vw, 48px) clamp(60px, 10vh, 120px);
    isolation: isolate;
    overflow: clip;
    font-family: inherit;
}
.stage-detail-aura {
    position: absolute;
    inset: -30% -10% auto -10%;
    height: 60%;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(40% 50% at 22% 28%, rgba(var(--brand-iris-rgb),     0.18), transparent 72%),
        radial-gradient(36% 44% at 80% 20%, rgba(var(--brand-mulberry-rgb), 0.14), transparent 72%),
        radial-gradient(30% 38% at 88% 78%, rgba(var(--brand-lichen-rgb),   0.14), transparent 72%),
        radial-gradient(28% 36% at 14% 86%, rgba(var(--brand-brass-rgb),    0.12), transparent 72%);
    filter: blur(90px) saturate(120%);
    opacity: 0.8;
}

/* ---------- Back link ---------- */
.stage-detail-back {
    max-width: 1080px;
    margin: 0 auto clamp(20px, 3vh, 30px);
}
.stage-detail-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--global-text-muted);
    text-decoration: none;
    font-size: 14px;
    padding: 8px 14px;
    border-radius: 999px;
    transition: background 0.2s ease, color 0.2s ease;
}
.stage-detail-back-link:hover {
    background: var(--global-hover-color);
    color: var(--global-text-color);
}

/* ---------- Shell ---------- */
.stage-detail-shell {
    max-width: 1080px;
    margin: 0 auto;
}

/* ---------- Header ---------- */
.stage-detail-header { margin-bottom: clamp(20px, 3vh, 32px); }
.stage-detail-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
    min-height: 28px;
}
.stage-detail-category {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.stage-detail-category:empty { display: none; }

/* Inner pills — category + themes + optional template badge — share the
   same shape so they read as a single meta cluster. Category and theme
   pills are clickable links back into the Stage filter; the badge is a
   non-interactive label. */
.stage-detail-category-pill,
.stage-detail-theme-pill,
.stage-detail-template-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.04em;
    background: var(--global-card-background);
    border: 1px solid var(--global-border-color);
    color: var(--global-text-color);
}
.stage-detail-category-pill,
.stage-detail-theme-pill {
    text-decoration: none;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.stage-detail-category-pill:hover,
.stage-detail-theme-pill:hover {
    background: var(--state-hover-bg);
}
.stage-detail-category-pill:focus-visible,
.stage-detail-theme-pill:focus-visible {
    outline: 2px solid var(--focus-outline-color);
    outline-offset: 2px;
}
.stage-detail-template-badge {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 500;
    background: var(--global-text-color);
    color: var(--global-background-color);
    border-color: transparent;
}

.stage-detail-title {
    margin: 0 0 20px;
    font-family: inherit;
    font-weight: 900;
    font-size: clamp(28px, 4vw, 48px);
    letter-spacing: -0.025em;
    line-height: 1.15;
    color: var(--global-text-color);
}

.stage-detail-byline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}
.stage-detail-author {
    display: flex;
    align-items: center;
    gap: 12px;
}
.stage-detail-author-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--global-hover-color);
    flex-shrink: 0;
}
.stage-detail-author-avatar img { width: 100%; height: 100%; object-fit: cover; }
.stage-detail-author-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stage-detail-author-name {
    font-size: 15px;
    font-weight: 400;
    color: var(--global-text-color);
    text-decoration: none;
}
/* When the author is linked to /u/:username, show an underline only on
   hover so the resting state stays as quiet as the existing typography. */
a.stage-detail-author-name.stage-detail-author-link:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--global-text-muted);
}
.stage-detail-author-date {
    font-size: 13px;
    color: var(--global-text-muted);
}

/* Actions */
.stage-detail-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.stage-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 999px;
    border: 1px solid var(--global-border-color);
    background: var(--global-card-background);
    color: var(--global-text-color);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.stage-action[hidden] { display: none; }
.stage-action:hover:not(:disabled) {
    border-color: var(--global-text-color);
    transform: translateY(-1px);
}
.stage-action:disabled { opacity: 0.5; cursor: default; }

.stage-action-like.is-liked {
    background: var(--state-active-bg);
    border-color: transparent;
    color: var(--global-text-color);
}
.stage-action-like.is-liked svg {
    fill: var(--brand-mulberry);
    stroke: var(--brand-mulberry);
}

.stage-action-use {
    background: var(--global-text-color);
    color: var(--global-background-color);
    border-color: transparent;
}
.stage-action-use:hover:not(:disabled) {
    border-color: transparent;
    opacity: 0.9;
}

/* ---------- Stage frame ---------- */
.stage-detail-stage { margin-bottom: clamp(32px, 5vh, 48px); }
.stage-detail-frame-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    border-radius: 22px;
    overflow: hidden;
    background: #000;
    box-shadow:
        0 30px 80px rgba(var(--global-text-color-rgb), 0.14),
        0 0 0 1px var(--global-border-color);
}
.stage-detail-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
.stage-detail-frame-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    transition: opacity 0.3s ease;
}
.stage-detail-frame-loading.is-hidden {
    opacity: 0;
    pointer-events: none;
}
.stage-detail-frame-spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    animation: stage-spin 0.9s linear infinite;
}
@keyframes stage-spin { to { transform: rotate(360deg); } }

.stage-detail-metrics {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding: 0 6px;
    color: var(--global-text-muted);
    font-size: 13px;
}
.stage-detail-metrics-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ---------- Body ----------
   One alignment axis for the whole page: the body/CTA/comments used to sit
   on a CENTERED 760px column while the header/preview sat on the 1080px
   shell — the two axes read as a broken layout. Everything now shares the
   shell's left edge; long-form text keeps a readable measure via max-width
   on the text itself, not on a second centered container. */
.stage-detail-body {
    margin: 0 0 clamp(40px, 6vh, 64px);
}
/* When the item has no description/note/tags, quietly remove the empty
 * slab rather than leaving a blank gap between the iframe and comments. */
.stage-detail-body.is-empty { margin-bottom: clamp(20px, 3vh, 32px); }
.stage-detail-description {
    max-width: 72ch;
    font-size: clamp(15px, 1.2vw, 17px);
    line-height: 1.7;
    color: var(--global-text-color);
    white-space: pre-wrap;
    word-break: break-word;
}
.stage-detail-description:empty { display: none; }

.stage-detail-note {
    margin-top: 28px;
    padding: 20px 22px;
    border-radius: 16px;
    border: 1px solid var(--global-border-color);
    background: linear-gradient(
        135deg,
        rgba(var(--global-text-color-rgb), 0.04),
        rgba(var(--global-text-color-rgb), 0.02)
    );
}
.stage-detail-note-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--global-text-muted);
    margin-bottom: 10px;
}
.stage-detail-note-text {
    margin: 0;
    font-size: 15px;
    line-height: 1.65;
    color: var(--global-text-color);
    white-space: pre-wrap;
}

.stage-detail-tags {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.stage-detail-tag {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--global-text-muted);
    background: var(--global-hover-color);
    text-decoration: none;
    transition: color 0.18s ease, background-color 0.18s ease;
}
.stage-detail-tag:hover {
    color: var(--global-text-color);
    background: var(--state-hover-bg);
}
.stage-detail-tag:focus-visible {
    outline: 2px solid var(--focus-outline-color);
    outline-offset: 2px;
}

/* ---------- Body CTA ---------- */
/* Sits between the body text and the comments rail. Uses the brand
   iridescent gradient as an ambient bloom (per DI: brand color =
   ambient surface, not solo button stop) so the panel reads as the
   page's emotional climax — “make this yours.” */
.stage-detail-cta {
    margin: clamp(24px, 4vh, 36px) 0 0;
    padding: 22px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border: 1px solid var(--global-border-color);
    border-radius: 16px;
    background:
        radial-gradient(120% 200% at 0% 0%, rgba(var(--brand-iris-rgb),     0.10), transparent 60%),
        radial-gradient(120% 200% at 100% 100%, rgba(var(--brand-mulberry-rgb), 0.08), transparent 60%),
        var(--global-card-background);
    flex-wrap: wrap;
}
.stage-detail-cta[hidden] { display: none; }
.stage-detail-cta-text { flex: 1; min-width: 0; }
.stage-detail-cta-title {
    margin: 0 0 4px;
    font-size: 17px;
    font-weight: 700;
    color: var(--global-text-color);
    letter-spacing: -0.01em;
}
.stage-detail-cta-sub {
    margin: 0;
    font-size: 13.5px;
    color: var(--global-text-muted);
    line-height: 1.5;
}

/* ---------- Comments ---------- */
.stage-detail-comments {
    max-width: 760px;
    margin: 0;
    padding-top: clamp(32px, 5vh, 48px);
    border-top: 1px solid var(--global-border-color);
}
.stage-detail-comments-title {
    margin: 0 0 24px;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: -0.01em;
    color: var(--global-text-color);
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.stage-detail-comments-count {
    font-size: 13px;
    font-weight: 400;
    color: var(--global-text-muted);
}

.stage-comment-form {
    display: flex;
    gap: 12px;
    margin-bottom: 28px;
    align-items: flex-start;
}
.stage-comment-form-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}
.stage-comment-form-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.stage-comment-form-field textarea {
    width: 100%;
    padding: 10px 0;
    border: 0;
    border-bottom: 1px solid rgba(var(--global-text-color-rgb), 0.18);
    border-radius: 0;
    resize: vertical;
    min-height: 56px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.55;
    color: var(--global-text-color);
    background: transparent;
    transition: border-color 0.2s ease;
}
.stage-comment-form-field textarea:hover {
    border-bottom-color: rgba(var(--global-text-color-rgb), 0.32);
}
.stage-comment-form-field textarea:focus {
    outline: none;
    border-bottom-color: var(--global-text-color);
}
.stage-comment-form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stage-comment-form-hint {
    font-size: 12px;
    color: var(--global-text-muted);
}
.stage-comment-submit {
    padding: 8px 18px;
    border-radius: 999px;
    border: none;
    background: var(--global-button-background-color);
    color: var(--global-button-text-color);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: transform 0.18s ease, opacity 0.18s ease;
}
.stage-comment-submit:hover { transform: translateY(-1px); }
.stage-comment-submit:disabled { opacity: 0.5; cursor: default; }

.stage-comment-gate {
    text-align: center;
    padding: 24px;
    border-radius: 14px;
    background: var(--global-card-background);
    border: 1px dashed var(--global-border-color);
    margin-bottom: 28px;
}
.stage-comment-gate-link {
    color: var(--global-primary-color);
    text-decoration: none;
    font-size: 14px;
}
.stage-comment-gate-link:hover { text-decoration: underline; }

.stage-comment-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.stage-comment {
    display: flex;
    gap: 12px;
}
.stage-comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}
.stage-comment-body { flex: 1; min-width: 0; }
.stage-comment-head {
    display: flex;
    gap: 8px;
    align-items: baseline;
    margin-bottom: 4px;
}
.stage-comment-author {
    font-weight: 400;
    font-size: 14px;
    color: var(--global-text-color);
    text-decoration: none;
}
a.stage-comment-author:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--global-text-muted);
}
.stage-comment-date {
    font-size: 12px;
    color: var(--global-text-muted);
}
.stage-comment-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    color: var(--global-text-color);
    white-space: pre-wrap;
    word-break: break-word;
}
.stage-comment-delete {
    margin-top: 4px;
    padding: 0;
    background: none;
    border: none;
    font-size: 12px;
    color: var(--global-text-muted);
    cursor: pointer;
}
.stage-comment-delete:hover { color: var(--global-error-color); }

.stage-comment-more {
    margin: 24px auto 0;
    display: block;
    padding: 10px 22px;
    border-radius: 999px;
    border: 1px solid var(--global-border-color);
    background: var(--global-card-background);
    color: var(--global-text-color);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.stage-comment-more:hover { background: var(--global-hover-color); }
/* display:block 이 [hidden] 을 이기므로 짝 룰 필수 — 없으면 댓글 0개에도
   "Load earlier comments" 가 상시 노출된다. */
.stage-comment-more[hidden] { display: none; }

/* ---------- Skeleton lines ---------- */
.stage-skeleton-line {
    display: block;
    height: 16px;
    width: 120px;
    border-radius: 8px;
    background: linear-gradient(
        90deg,
        var(--global-hover-color) 0%,
        var(--global-card-background) 40%,
        var(--global-hover-color) 80%
    );
    background-size: 200% 100%;
    animation: stage-detail-shimmer 1.4s linear infinite;
}
.stage-skeleton-line-sm { height: 12px; width: 80px; }
.stage-skeleton-line-xl { height: 40px; width: 70%; }
.stage-detail-author-avatar.is-skeleton {
    animation: stage-detail-shimmer 1.4s linear infinite;
    background: linear-gradient(
        90deg,
        var(--global-hover-color) 0%,
        var(--global-card-background) 40%,
        var(--global-hover-color) 80%
    );
    background-size: 200% 100%;
}
@keyframes stage-detail-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
    .stage-detail-byline { flex-direction: column; align-items: flex-start; }
    .stage-detail-actions { width: 100%; overflow-x: auto; }
    .stage-action span:not(.stage-action-count) { display: none; }
}

/* ---------- Use-template modal ---------- */
/* Styles live in `/css/use-template-modal.css` (linked from this page
   and the /stage browse page so the partial renders identically). */

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .stage-detail-frame-spinner,
    .stage-skeleton-line,
    .stage-detail-author-avatar.is-skeleton {
        animation: none !important;
    }
    .stage-detail-back-link,
    .stage-action,
    .stage-detail-tag,
    .stage-detail-frame-loading,
    .stage-detail-category-pill,
    .stage-detail-theme-pill {
        transition: none !important;
    }
}

/* ---------- Toast ---------- */
/* Surfaces load failures (e.g. comments) — created on demand by stage-detail.js.
   Inverted pill so it reads on light and dark backgrounds. */
.stage-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translate(-50%, 12px);
    z-index: 1000;
    max-width: min(90vw, 440px);
    padding: 12px 18px;
    border-radius: 12px;
    background: var(--global-text-color);
    color: var(--global-card-background);
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: -0.005em;
    box-shadow: 0 14px 36px -14px rgba(var(--global-text-color-rgb), 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.stage-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
    .stage-toast { transition: opacity 0.2s ease; }
}
