/* 2 画面の機種（Surface Duo など）。Tailwind を通すとこの media が落ちるので素の CSS で置く。 */

/* 左右に開いたとき: .seam の子を左の画面と右の画面に 1 つずつ置く。継ぎ目には何も置かない */
@media (horizontal-viewport-segments: 2) {
  .wrap {
    max-width: none;
    padding-inline: 0;
  }
  .seam {
    display: grid !important;
    grid-template-columns: env(viewport-segment-width 0 0) env(viewport-segment-width 1 0);
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
    align-items: start;
  }
  .seam > * {
    min-width: 0;
    padding-inline: 16px;
    grid-column: auto !important;
    width: auto !important;
    max-width: none !important;
  }
  .seam-one > * {
    grid-column: 1 !important;
  }
  .duo-hide {
    display: none !important;
  }
  .duo-show {
    display: block !important;
  }
  .duo-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
  .sheet {
    inset: 0 auto 0 0;
    width: env(viewport-segment-width 0 0);
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
  }
}

/* 上下に開いたとき: 窓は下の画面の中だけに出す */
@media (vertical-viewport-segments: 2) {
  .sheet {
    inset: auto 0 0 0;
    max-height: env(viewport-segment-height 0 1);
    border-radius: 0;
  }
}

/* 一覧を 2 画面に流す。継ぎ目の列には何も置かない */
@media (horizontal-viewport-segments: 2) {
  .duo-pad {
    padding-inline: 16px;
  }
  /* 1 列ずつ左右の画面へ */
  .duo-flow-2 {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0) + 32px) !important;
  }
  /* カードを左に 3 列・右に 3 列 */
  .duo-flow-6 {
    display: grid !important;
    column-gap: 16px !important;
    grid-template-columns:
      repeat(3, minmax(0, 1fr))
      calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0))
      repeat(3, minmax(0, 1fr)) !important;
  }
  .duo-flow-6 > :nth-child(6n + 1) { grid-column: 1; }
  .duo-flow-6 > :nth-child(6n + 2) { grid-column: 2; }
  .duo-flow-6 > :nth-child(6n + 3) { grid-column: 3; }
  .duo-flow-6 > :nth-child(6n + 4) { grid-column: 5; }
  .duo-flow-6 > :nth-child(6n + 5) { grid-column: 6; }
  .duo-flow-6 > :nth-child(6n + 6) { grid-column: 7; }
}

/* 入力の多いフォームは、項目を左右の画面に 1 列ずつ並べる */
@media (horizontal-viewport-segments: 2) {
  .seam:has(.seam-form) {
    display: block !important;
  }
  .seam:has(.seam-form) > * {
    max-width: none !important;
    padding-inline: 16px;
  }
  .seam-form {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0) + 32px);
    align-items: end;
  }
}

/* トップの棚: 2 画面のときは右の画面の幅で 3 列 */
@media (horizontal-viewport-segments: 2) {
  .duo-shelf {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    overflow: visible !important;
    margin-inline: 0 !important;
    padding-inline: 0 !important;
  }
  .duo-shelf > li {
    width: auto !important;
    display: block !important;
  }
  .duo-shelf > li:nth-child(n + 4) {
    display: none !important;
  }
}

/* 項目ごとに左右の画面を決めるフォーム（.duo-l は左、.duo-r は右）。.duo-contents は箱を外して中身を並べる */
@media (horizontal-viewport-segments: 2) {
  .seam-form .duo-contents {
    display: contents !important;
  }
  .seam-form:has(.duo-l) {
    grid-auto-flow: row dense;
    align-items: start;
  }
  .seam-form .duo-l {
    grid-column: 1 !important;
  }
  .seam-form .duo-r {
    grid-column: 2 !important;
  }
}
