/**
 * @file portfolio.css
 * @description ポートフォリオ一覧・作品詳細ページのスタイル定義
 * @summary
 *   - ポートフォリオ一覧（フィルター、カード）
 *   - 作品詳細モーダル
 *   - Markdown 本文
 *   - レスポンシブデザイン
 * @recent_changes
 *   - ファイル先頭に説明コメントを追加
 */

/* ==========================================================================
   1. ポートフォリオ一覧（フィルター）
   ========================================================================== */
.portfolio-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem 1.2rem;
    align-items: center;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.portfolio-filter {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.portfolio-filter__label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.2rem;
}

.portfolio-filter__control {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-smooth);
}

.portfolio-filter__control::placeholder {
    color: var(--color-text-muted);
    opacity: 0.7;
}

.portfolio-filter__control:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(
        --shadow-glow
    ); /* グローエフェクト適用 */
}

.portfolio-filter:first-child {
    min-width: 10rem;
}
.portfolio-filter:last-child {
    flex: 1;
    min-width: 16rem;
}

/* ==========================================================================
   2. ポートフォリオ一覧（カード本体）
   ========================================================================== */
.portfolio-card {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 1.5rem;
    align-items: stretch;
    background: var(--color-panel);
    border-radius: var(--radius-lg);
    padding: 1.8rem;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    transition: var(--transition-smooth);
    overflow: hidden;
    cursor: pointer; /* カード全体をクリック可能に */
}

.portfolio-card::before {
    content: "";
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    border: 1px solid transparent;
    background: linear-gradient(
            to right,
            var(--color-accent),
            var(--color-accent-dark)
        )
        border-box;
    mask:
        linear-gradient(#fff 0 0) padding-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: destination-out;
    mask-composite: exclude;
    opacity: 0;
    transition: var(--transition-smooth);
}

.portfolio-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    background: var(--color-surface);
}

.portfolio-card:hover::before {
    opacity: 1;
}

/* サムネイル枠 */
.portfolio-card .card__thumb {
    flex-shrink: 0;
    width: 16rem;
    height: 9rem;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
}

.portfolio-card .card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: var(--transition-smooth);
}
.portfolio-card:hover .card__thumb img {
    transform: scale(1.05);
}

/* 本文側 */
.portfolio-card .card__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.portfolio-card .card__meta {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 0.4rem;
}

.portfolio-card .card__title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-heading);
    line-height: 1.3;
    margin-bottom: 0.4rem;
}

.portfolio-card .card__description {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    margin-bottom: 0.8rem;
    flex-grow: 1;
}

.portfolio-card .card__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: auto;
}

.tag {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    background: var(--color-accent-soft);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    white-space: nowrap;
    transition: var(--transition-smooth);
    text-decoration: none;
}
.tag:hover {
    background: var(--color-accent);
    color: #fff;
    box-shadow: var(--shadow-glow);
}

/* ==========================================================================
   3. 作品詳細モーダル
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
    padding: 2rem;
}

.modal-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* Make the modal container act as a framing box only.
   Parent should not be the scroll container to avoid double scrollbars.
   The inner .modal-content will be the single scrollable area. */
.modal-container {
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    background: var(--color-panel);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-xl);
    position: relative;
    overflow: hidden; /* CHANGED: prevent parent scrolling, delegate to .modal-content */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition:
        opacity 0.3s ease,
        transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.is-open .modal-container {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* The actual scrollable area inside the modal.
   This keeps a single scrollbar inside .modal-content. */
.modal-content {
    overflow: auto;
    overflow-y: auto;
    max-height: calc(90vh - 48px);
    padding: 1rem;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
    min-height: 0; /* ensure flex children don't force parent to grow */
}

/* 閉じるボタン */
.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: rgba(22, 27, 34, 0.6);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
    z-index: 10;
    font-size: 1.5rem;
    line-height: 1;
    padding-bottom: 2px; /* 位置微調整 */
}

.modal-close:hover {
    background: var(--color-accent);
    color: #fff;
    border-color: transparent;
    transform: rotate(90deg);
}

/* ==========================================================================
   4. 作品詳細コンテンツ (モーダル内)
   ========================================================================== */
.work-detail {
    padding: 3rem;
    /* work-detail 自体は枠線を持たず、モーダルコンテナが枠を持つ */
}

.work-detail__header {
    text-align: center;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid var(--color-border-soft);
}

.work-detail__title {
    font-size: 2.2rem;
    color: var(--color-heading);
    margin-bottom: 0.8rem;
    line-height: 1.25;
}

.work-detail__meta {
    font-size: 0.95rem;
    color: var(--color-accent);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.work-detail__description {
    font-size: 1.1rem;
    color: var(--color-text-muted);
    margin-top: 1rem;
    line-height: 1.6;
}

.work-detail__tags {
    margin-top: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.work-detail__tags a.tag {
    text-decoration: none;
}

/* ==========================================================================
   5. Markdown 本文 (blog.css と同期)
   ========================================================================== */
.markdown-body {
    line-height: 1.8;
    font-size: 1.05rem;
    color: var(--color-text);
}

.markdown-body > *:first-child {
    margin-top: 0;
}
.markdown-body > *:last-child {
    margin-bottom: 0;
}

/* リンク */
.markdown-body a {
    color: var(--color-accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
    transition: var(--transition-smooth);
}
.markdown-body a:hover {
    color: var(--color-accent-dark);
    text-decoration-thickness: 2px;
}

/* 見出し */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    color: var(--color-heading);
    font-family: var(--font-heading);
    margin-top: 2.5rem;
    margin-bottom: 1.2rem;
    line-height: 1.4;
}

.markdown-body h2 {
    font-size: 1.7rem;
    padding: 0.4rem 0 0.4rem 1rem;
    border-left: 5px solid var(--color-accent);
    background: linear-gradient(
        to right,
        rgba(var(--color-accent-rgb), 0.1),
        transparent
    );
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-body h3 {
    font-size: 1.4rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--color-border-soft);
}

.markdown-body p {
    margin: 1.5rem 0;
}
.markdown-body ul,
.markdown-body ol {
    padding-left: 1.5rem;
    margin: 1.5rem 0;
}
.markdown-body ul {
    list-style: disc;
}
.markdown-body li {
    margin-bottom: 0.5rem;
}
.markdown-body li::marker {
    color: var(--color-accent);
}

/* 引用 */
.markdown-body blockquote {
    margin: 2rem 0;
    padding: 1rem 1.5rem;
    border-left: 4px solid var(--color-accent);
    background: var(--color-surface);
    color: var(--color-text-muted);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-style: italic;
}

/* コード */
.markdown-body code {
    font-family:
        "Fira Code", "Cascadia Code", "JetBrains Mono",
        Consolas, monospace;
    font-size: 0.9em;
    background: rgba(var(--color-accent-rgb), 0.15);
    color: var(--color-heading);
    padding: 0.2em 0.5em;
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
}

.markdown-body pre {
    position: relative;
    background: #0d1117;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 0.9em;
    line-height: 1.5;
    margin: 2rem 0;
    border: 1px solid var(--color-border);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}
.markdown-body pre code {
    background: transparent;
    padding: 0;
    color: #c9d1d9;
    border-radius: 0;
}

/* 画像 */
.markdown-body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2rem auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border-soft);
}

/* 水平線 */
.markdown-body hr {
    height: 0;
    border: 0;
    border-top: 2px dashed var(--color-border);
    margin: 3rem 0;
}

/* ==========================================================================
   6. レスポンシブデザイン
   ========================================================================== */
@media (max-width: 680px) {
    .portfolio-filters {
        flex-direction: column;
        align-items: stretch;
        gap: 0.8rem;
    }
    .portfolio-card {
        flex-direction: column;
        padding: 1.25rem;
        gap: 1rem;
    }
    .portfolio-card .card__thumb {
        width: 100%;
        height: auto;
    }

    /* モーダルレスポンシブ */
    .modal-overlay {
        padding: 0; /* スマホは全画面 */
        align-items: flex-end; /* 下から出す感じでも良いが、ここでは中央/全画面 */
    }
    .modal-container {
        width: 100%;
        height: 100dvh; /* フルハイト */
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        overflow: hidden; /* keep parent non-scrollable on mobile as well */
    }
    .modal-content {
        max-height: calc(
            100dvh - 48px
        ); /* adapt the content scroll area for full-height modal */
        overflow: auto;
    }
    .work-detail {
        padding: 1.5rem;
        padding-top: 3.5rem; /* 閉じるボタンのスペース確保 */
    }
    .modal-close {
        top: 1rem;
        right: 1rem;
    }
    .work-detail__title {
        font-size: 1.8rem;
    }
}
