/* main.css - Front-end styles */
body { margin: 0; font-family: sans-serif; background: #fafafa; }
.container { max-width: 100%; margin: 0 auto; padding: 20px; box-sizing: border-box; }

/* Header */
.site-header { background: #fff; padding: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-bottom: 20px; }
.site-title a { text-decoration: none; color: #333; font-size: 24px; font-weight: bold; }

/* Grid container */
.portal-front-grid {
    position: relative;
    width: 100%;
    margin-bottom: 30px;
}

/* Grid items */
/* Base unit size calculation (e.g. 1 unit = 100px) */
/* スマホの場合は最大横幅3カラムと指定されているため、画面幅に応じて単位サイズを可変にする */
/* CSS Variable を活用 */

:root {
    --grid-gap: 10px;
    --grid-unit-pc: 100px;  /* PC時 1単位の幅 */
}

.portal-grid-item {
    position: relative;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    overflow: hidden;
    cursor: move;
    /* transition: transform 0.2s; */
}

/* Hover effects */
.portal-grid-item:hover {
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 10;
}
.portal-grid-item.is-dragging {
    opacity: 0.8;
}

/* ドラッグハンドルは削除（front-page.phpからHTML要素を削除済み） */
/* ブロック全体がドラッグエリア・ Draggabilly staticClickでクリックは転送 */

/* Packery Sizer Elements */
.grid-sizer { width: var(--grid-unit-pc); }
.gutter-sizer { width: var(--grid-gap); }

/* Size classes via Packery dimensions */
/* Default PC */
.grid-size-1x1 { width: var(--grid-unit-pc); height: var(--grid-unit-pc); }
.grid-size-2x1 { width: calc(var(--grid-unit-pc) * 2 + var(--grid-gap)); height: var(--grid-unit-pc); }
.grid-size-3x1 { width: calc(var(--grid-unit-pc) * 3 + var(--grid-gap) * 2); height: var(--grid-unit-pc); }
.grid-size-1x2 { width: var(--grid-unit-pc); height: calc(var(--grid-unit-pc) * 2 + var(--grid-gap)); }
.grid-size-2x2 { width: calc(var(--grid-unit-pc) * 2 + var(--grid-gap)); height: calc(var(--grid-unit-pc) * 2 + var(--grid-gap)); }
.grid-size-3x2 { width: calc(var(--grid-unit-pc) * 3 + var(--grid-gap) * 2); height: calc(var(--grid-unit-pc) * 2 + var(--grid-gap)); }
.grid-size-1x3 { width: var(--grid-unit-pc); height: calc(var(--grid-unit-pc) * 3 + var(--grid-gap) * 2); }
.grid-size-2x3 { width: calc(var(--grid-unit-pc) * 2 + var(--grid-gap)); height: calc(var(--grid-unit-pc) * 3 + var(--grid-gap) * 2); }
.grid-size-3x3 { width: calc(var(--grid-unit-pc) * 3 + var(--grid-gap) * 2); height: calc(var(--grid-unit-pc) * 3 + var(--grid-gap) * 2); }

@media screen and (max-width: 768px) {
    /* スマホでも Packery を使わせる - flex上書きをすると Packeryの absolute配置が無効になるため制御しない */
    /* 大きさは JS ( front-grid.js ) がコンテナ幅から動的に計算してインラインでセットする */

    /* グリッドアイテムのカーソルスタイル */
    .portal-grid-item { cursor: grab !important; }
    .portal-grid-item.is-dragging { cursor: grabbing !important; opacity: 0.8; }

    /* フォールバックとしての CSS サイズクラス（JSがインラインで上書きする） */
    .grid-size-1x1 { width: 32%; height: 32vw; }
    .grid-size-2x1 { width: 66%; height: 32vw; }
    .grid-size-3x1 { width: 100%; height: 32vw; }
    .grid-size-1x2 { width: 32%; height: 66vw; }
    .grid-size-2x2 { width: 66%; height: 66vw; }
    .grid-size-3x2 { width: 100%; height: 66vw; }
    .grid-size-1x3 { width: 32%; height: 100vw; }
    .grid-size-2x3 { width: 66%; height: 100vw; }
    .grid-size-3x3 { width: 100%; height: 100vw; }
}

.portal-grid-item-content {
    width: 100%;
    height: 100%;
    position: relative;
}
.portal-grid-item-content img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.portal-grid-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: #eef;
    color: #666;
    font-size: 14px;
}

/* Controls */
.grid-controls { text-align: center; margin-top: 20px; }
.button {
    background: #0073aa; color: #fff; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; text-decoration: none; font-size: 16px;
}
.button:hover { background: #005177; }

/* カスタムロゴ: スマホでからでもはみ出さないよう制約 */
.custom-logo-link img,
.custom-logo {
    max-width: 100%;
    height: auto;
    display: block;
}
@media screen and (max-width: 768px) {
    /* ロゴ画像をスマホ画面横一杯に */
    .custom-logo-link { display: block; width: 100%; }
    .custom-logo-link img, .custom-logo { width: 100%; max-width: 100%; height: auto; }
    .site-title a { font-size: 18px; }

    /* Sortable.js ドラッグ中のクローン記述（forceFallback用） */
    .sortable-fallback {
        opacity: 0.85 !important;
        background: rgba(0,115,170,0.15) !important;
        border: 2px dashed #0073aa !important;
        box-shadow: 0 8px 20px rgba(0,0,0,0.25) !important;
        border-radius: 8px !important;
    }
}

/* Single Page Additions */
.portal-main-image img { max-width: 100%; height: auto; border-radius: 8px; }
.portal-sub-images { display: flex; gap: 10px; margin-top: 10px; }
.portal-sub-images .sub-img { flex: 1; }
.portal-sub-images img { width: 100%; height: auto; border-radius: 5px; }
.portal-details-table table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.portal-details-table th, .portal-details-table td { padding: 15px; border-bottom: 1px solid #ddd; text-align: left; }
.portal-details-table th { width: 150px; background: #f9f9f9; }
.portal-sns-links a { margin-right: 15px; color: #0073aa; text-decoration: none; font-weight: bold; }
.portal-gallery-flex { display: flex; flex-wrap: wrap; gap: 10px; }
.portal-gallery-flex .gallery-item { width: calc(20% - 8px); }
.portal-gallery-flex img { width: 100%; height: auto; border-radius: 5px; }

@media screen and (max-width: 768px) {
    .portal-gallery-flex .gallery-item { width: calc(33.33% - 6px); }
}

/* ============================================================
   レスポンシブ対応：画面幅からのはみ出し防止
   YouTube・iframe・画像・テーブル等すべてが画面内に収まる
   ============================================================ */

/* --- 全コンテンツ共通：最大幅を100%に制限 --- */
img,
video,
audio,
canvas,
svg,
embed,
object {
    max-width: 100%;
    height: auto;
}

pre,
code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

table {
    max-width: 100%;
    overflow-x: auto;
    display: block;
    border-collapse: collapse;
}

/* --- iframe（YouTube等）：アスペクト比 16:9 を維持してレスポンシブ化 --- */
/*
   WordPressの投稿内・ウィジェット内・テンプレート内のiframeを
   アスペクト比保持ラッパーで包むCSSを定義。
   既存の固定width/height指定を上書きして自動縮小させる。
*/
iframe {
    max-width: 100% !important;
    width: 100% !important;
}

/* iframeの高さを固定しない場合の安全策: 最大高さを制限しない */
/* ただし高さを固定していた場合は縦横比が崩れるため、
   .wp-block-embed や .video-container ラッパーで管理する */

/* --- WordPress標準の埋め込みブロック（ブロックエディタ） --- */
.wp-block-embed__wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
}
.wp-block-embed__wrapper iframe,
.wp-block-embed__wrapper embed,
.wp-block-embed__wrapper object {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* --- ウィジェット内の埋め込みコンテンツ --- */
.widget iframe,
.widget embed,
.widget object {
    max-width: 100% !important;
    width: 100% !important;
}

/* --- 投稿コンテンツ・固定ページ・ウィジェット内の共通ラッパー --- */
.entry-content,
.widget,
.portal-content,
.portal-widget-area,
.post-content,
.page-content,
.site-main,
.wp-block-group {
    max-width: 100%;
    overflow-x: hidden;
}

/* --- 小画面（スマホ）での追加対応 --- */
@media screen and (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    /* iframeを動的アスペクト比ラッパーで管理（YouTube等） */
    .video-wrap,
    .youtube-wrap {
        position: relative;
        width: 100%;
        padding-bottom: 56.25%; /* 16:9 */
        height: 0;
        overflow: hidden;
        margin-bottom: 1em;
    }
    .video-wrap iframe,
    .youtube-wrap iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
    }

    /* テーブルをスクロール可能に */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 幅指定付きの画像をすべて収める */
    img[width] {
        width: 100% !important;
        height: auto !important;
    }
}

/* ============================================================
   ナビゲーションメニュー（ヘッダー・フッターブロック風表示）
   ============================================================ */
.portal-nav-menu {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 15px;
}
.portal-nav-menu li {
    margin: 0;
    padding: 0;
}
.portal-nav-menu a {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    background: #0073aa;
    color: #ffffff;
    text-decoration: none;
    font-weight: bold;
    border-radius: 8px;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-width: 120px;
    text-align: center;
}
.portal-nav-menu a:hover {
    background: #005177;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

@media screen and (max-width: 768px) {
    .mobile-menu-toggle {
        display: inline-block !important;
    }
    .portal-nav-menu {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }
    .portal-nav-menu.is-active {
        display: flex !important;
    }
    .portal-nav-menu li {
        width: 100%;
    }
    .portal-nav-menu a {
        padding: 12px;
        font-size: 16px;
        width: 100%;
        box-sizing: border-box;
    }
}

/* ============================================================
   投稿ページ(body.single-post)と固定ページ(body.page)のみ 2カラム適用
   ※ 紹介ページのメインカラムと2カラムの表示サイズ（1200px / 比率2:1）に極密に合わせる
   ============================================================ */
body.single-post .site-main .container,
body.page .site-main .container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 0 20px;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    align-items: start;
}

body.single-post .site-main .main-content-area,
body.page .site-main .main-content-area {
    min-width: 0;
    background: #ffffff;
    padding: 20px; /* 余白を20pxに減らして文字領域を広げる（紹介ページと近付けるため） */
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    box-sizing: border-box;
}

/* スマホ等での左右余白を縮小（はみ出し・窮屈さ防止） */
@media screen and (max-width: 768px) {
    body.single-post .site-main .main-content-area,
    body.page .site-main .main-content-area {
        padding: 20px;
    }
}

/* サイドバー領域（1fr の役割として、メイン2:サイド1のサイズ比に追従） */
.sidebar-container {
    width: 100%;
    max-width: 100%;
}

/* ============================================================
   ウィジェット共通デザイン
   ============================================================ */
.widget {
    background: #ffffff;
    padding: 20px;
    margin-bottom: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.widget:last-child {
    margin-bottom: 0;
}

.widget-title {
    font-size: 18px;
    font-weight: bold;
    color: #333333;
    border-bottom: 3px solid #0073aa;
    padding-bottom: 10px;
    margin-top: 0;
    margin-bottom: 20px;
}

/* 追尾用ウィジェット */
.sidebar-scroll-area {
    position: sticky;
    top: 20px;
}

/* --- スマホ閲覧時の1カラム化対応 --- */
@media screen and (max-width: 992px) {
    body.single-post .site-main .container,
    body.page .site-main .container {
        display: flex;
        flex-direction: column;
    }
    .sidebar-container {
        width: 100%;
    }
}
