:root {
    --bg: #ffffff;
    --gap: 2px;
    --cols: 3;
    --row-h: 120px;
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  }

  .grid-wrap {
    max-width: 935px;
    margin: 0 auto;
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-auto-rows: var(--row-h);
    gap: var(--gap);
  }

  /* 全タイル縦長: 1列 x 2行 */
  .tile {
    position: relative;
    overflow: hidden;
    background: #eee;
    cursor: pointer;
    grid-row: span 2;
  }

  .tile img,
  .tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  /* 下部を読みやすくするグラデーション(常時表示) */
  .tile .shade,
  .detail-slide .shade {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 45%;
    background: linear-gradient(to top, rgba(0,0,0,0.55), rgba(0,0,0,0));
    pointer-events: none;
  }

  /* 左下に常時表示するいいね/コメント数 */
  .tile .stats,
  .detail-slide .stats {
    position: absolute;
    left: 8px;
    bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    z-index: 4;
  }

  .detail-slide .stats {
    left: 16px;
    bottom: 34px;
    font-size: 16px;
    gap: 6px;
  }

  .stats span {
    display: flex;
    align-items: center;
    gap: 5px;
  }

  .stats svg {
    width: 14px;
    height: 14px;
    fill: #fff;
    flex-shrink: 0;
  }

  .detail-slide .stats svg {
    width: 18px;
    height: 18px;
  }

  .detail-uname {
    font-size: 16px;
    font-weight: 700;
  }

  .detail-caption {
    font-size: 14px;
    font-weight: 400;
    opacity: 0.95;
  }

  /* アカウント名の上に置くCTAボタン(動画/画像で文言が変わる) */
  .detail-cta-btn {
    display: inline-block;
    margin-bottom: 8px;
    padding: 9px 18px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.6);
    border-radius: 20px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    backdrop-filter: blur(2px);
    cursor: pointer;
    position: relative;
    z-index: 5;
  }

  .detail-uname {
    cursor: pointer;
  }

  /* エンゲージメント促進モーダル */
  .engage-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  .engage-modal.open {
    display: flex;
  }

  .engage-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
  }

  .engage-modal-card {
    position: relative;
    z-index: 1;
  }

  /* ============ iOS風(Apple端末) ============ */
  .platform-ios .engage-modal-card {
    width: min(270px, 84vw);
    background: rgba(40,40,42,0.9);
    backdrop-filter: blur(20px);
    border-radius: 14px;
    overflow: hidden;
    font-family: -apple-system, "SF Pro Text", "Hiragino Sans", sans-serif;
    text-align: center;
  }

  .platform-ios .engage-modal-body {
    padding: 20px 16px 16px;
  }

  .platform-ios .engage-modal-title {
    margin: 0 0 4px;
    color: #fff;
    font-size: 17px;
    font-weight: 600;
  }

  .platform-ios .engage-modal-text {
    margin: 0;
    color: rgba(235,235,245,0.6);
    font-size: 13px;
    line-height: 1.4;
  }

  .platform-ios .engage-modal-actions {
    display: flex;
    border-top: 1px solid rgba(255,255,255,0.15);
  }

  .platform-ios .engage-modal-actions button {
    flex: 1;
    padding: 11px 0;
    border: none;
    background: transparent;
    color: #0A84FF;
    font-size: 17px;
    cursor: pointer;
  }

  .platform-ios .engage-modal-actions button + button {
    border-left: 1px solid rgba(255,255,255,0.15);
  }

  .platform-ios .engage-modal-cta {
    font-weight: 600;
  }

  .platform-ios .engage-modal-close {
    color: rgba(235,235,245,0.6);
    font-weight: 400;
  }

  /* ============ Android風(Material Design) ============ */
  .platform-android .engage-modal-card {
    width: min(320px, 88vw);
    background: #2b2930;
    border-radius: 28px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    font-family: Roboto, "Noto Sans JP", "Hiragino Sans", sans-serif;
    text-align: left;
  }

  .platform-android .engage-modal-body {
    padding: 24px 24px 8px;
  }

  .platform-android .engage-modal-title {
    margin: 0 0 8px;
    color: #E6E0E9;
    font-size: 20px;
    font-weight: 500;
  }

  .platform-android .engage-modal-text {
    margin: 0;
    color: #CAC4D0;
    font-size: 14px;
    line-height: 1.5;
  }

  .platform-android .engage-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 16px 16px 16px;
  }

  .platform-android .engage-modal-actions button {
    padding: 10px 12px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: #D0BCFF;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
  }

  .platform-android .engage-modal-cta {
    background: #D0BCFF;
    color: #381E72;
  }

  /* 右上アイコン: 複数枚(カルーセル) / 動画 */
  .badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 18px;
    height: 18px;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.6));
    z-index: 2;
  }

  .badge svg {
    width: 100%;
    height: 100%;
    fill: #fff;
  }

  /* LIVE表記(動画コンテンツ用) */
  .live-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #ff3040;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7), 0 0 4px rgba(0,0,0,0.5),
                 0 0 8px rgba(255,48,64,0.8), 0 0 14px rgba(255,48,64,0.5);
  }

  .live-badge .live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ff3040;
    box-shadow: 0 0 3px rgba(0,0,0,0.6), 0 0 6px rgba(255,48,64,0.9);
    animation: livePulse 1.2s ease-in-out infinite;
  }

  /* 詳細画面(全画面)ではやや大きく */
  .detail-slide .live-badge {
    top: 26px;
    right: 16px;
    font-size: 17px;
    z-index: 6;
  }

  .detail-slide .live-badge .live-dot {
    width: 7px;
    height: 7px;
  }

  @keyframes livePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
  }

  /* ログイン中表記(画像コンテンツ用・黄緑系) */
  .online-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 4px;
    color: #00B900;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7), 0 0 4px rgba(0,0,0,0.5),
                 0 0 8px rgba(0,185,0,0.8), 0 0 14px rgba(0,185,0,0.5);
  }

  .online-badge .online-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #00B900;
    box-shadow: 0 0 3px rgba(0,0,0,0.6), 0 0 6px rgba(0,185,0,0.9);
    animation: livePulse 1.2s ease-in-out infinite;
  }

  .detail-slide .online-badge {
    top: 26px;
    right: 16px;
    font-size: 17px;
    z-index: 6;
  }

  .detail-slide .online-badge .online-dot {
    width: 7px;
    height: 7px;
  }

  .sentinel {
    grid-column: 1 / -1;
    height: 1px;
  }

  /* JSで内容だけ差し替える詳細オーバーレイ */
  .detail-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 100;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }

  .detail-overlay.open {
    transform: translateX(0);
  }

  .detail-overlay .detail-close {
    position: fixed;
    top: 22px;
    left: 12px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 17px;
    background: rgba(0,0,0,0.5);
    border-radius: 24px;
    cursor: pointer;
    font-size: 17px;
    font-weight: 600;
    color: #fff;
  }

  .detail-overlay .detail-feed {
    height: 100vh;
    height: 100dvh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
  }

  .detail-overlay .detail-slide {
    height: 100vh;
    height: 100dvh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
  }

  .detail-overlay .detail-slide img,
  .detail-overlay .detail-slide video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* 投げ銭/ハートが飛び交うエフェクト(動画スライドのみ) */
  .effect-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 5;
  }

  .effect-icon {
    position: absolute;
    bottom: 60px;
    font-size: 26px;
    line-height: 1;
    animation-name: floatUp;
    animation-timing-function: ease-in;
    animation-fill-mode: forwards;
    will-change: transform, opacity;
  }

  @keyframes floatUp {
    0% {
      transform: translate(0, 0) scale(0.7) rotate(0deg);
      opacity: 0;
    }
    15% {
      opacity: 1;
    }
    100% {
      transform: translate(var(--drift, 0px), -70vh) scale(1.2) rotate(var(--rot, 0deg));
      opacity: 0;
    }
  }

  /* ライブ配信風のコメントが流れる演出(動画スライドのみ) */
  .comment-flow {
    position: absolute;
    right: 12px;
    left: 90px;
    bottom: 110px;
    height: 55vh;
    overflow: hidden;
    pointer-events: none;
    z-index: 5;
  }

  .comment-bubble {
    position: absolute;
    right: 0;
    bottom: 0;
    display: inline-block;
    max-width: 100%;
    background: rgba(0,0,0,0.4);
    color: #fff;
    font-size: 13px;
    line-height: 1.4;
    padding: 5px 11px;
    border-radius: 14px;
    animation-name: commentFloat;
    animation-timing-function: ease-in-out;
    animation-fill-mode: forwards;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    will-change: transform, opacity;
  }

  @keyframes commentFloat {
    0% {
      transform: translateY(0) scale(0.94);
      opacity: 0;
    }
    12% {
      opacity: 1;
      transform: translateY(-20px) scale(1);
    }
    80% {
      opacity: 1;
    }
    100% {
      transform: translateY(-230px) scale(1);
      opacity: 0;
    }
  }

  @media (min-width: 600px) {
    :root { --cols: 4; }
  }

  @media (min-width: 900px) {
    :root { --cols: 5; }
  }

  /* ユーザーのOS/ブラウザ設定がダークモードの場合に自動追従 */
  @media (prefers-color-scheme: dark) {
    :root { --bg: #000000; }

    .tile {
      background: #222;
    }
  }