* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: white;
  color: black;
  min-height: 100vh;

  font-family:
    "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP",
    sans-serif;
  overflow-wrap: anywhere; /* 収まらない場合に折り返す */
  word-break: auto-phrase;
  line-break: strict; /* 禁則処理を厳格に適用 */
}


.app {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px;
  text-align: center;

  @media (width <= 768px) {
    padding: 16px;
  }
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;

  .controls-inner {
    position: relative;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;

    @media (width <= 768px) {
      gap: 8px;
      flex-wrap: nowrap;
    }
  }

  button {
    position: relative;
    z-index: 1;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    background: transparent;
    color: rgb(85 85 85);
    border: none;
    cursor: pointer;
    transition: translate 0.2s;
    -webkit-tap-highlight-color: transparent;

    @media (width <= 768px) {
      padding: 8px 16px;
    }

    &:hover {
      color: rgb(17 17 17);
      translate: 0 -2px;
    }

    &:active {
      translate: 0 0;
    }

    &.active {
      color: rgb(17 17 17);
    }
  }

  .indicator {
    position: absolute;
    top: 0;
    border-radius: 999px;
    background: rgb(229 231 235);
    pointer-events: none;
    position-anchor: --button1;
    transition: all 0.3s;
    left: anchor(left);
    width: anchor-size(width);
    height: anchor-size(height);

    &[data-active="1"] {
      position-anchor: --button1;
    }

    &[data-active="2"] {
      position-anchor: --button2;
    }

    &[data-active="3"] {
      position-anchor: --button3;
    }
  }
}

.layout-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 32px 32px 32px;
  border-radius: 16px;

  @media (width <= 768px) {
    gap: 8px;
    padding: 0;
  }

  &[data-grid="1"] {
    grid-template-rows: repeat(4, 1fr);

    @media (width <= 768px) {
      grid-template-columns: repeat(3, 1fr);
      grid-template-rows: repeat(6, minmax(240px, 1fr));
    }

    .item-title {
      margin-bottom: 4px;
    }

    .item {
      &:nth-child(1) {
        grid-area: 1 / 1 / 3 / 2;
      }

      &:nth-child(2) {
        grid-area: 1 / 2 / 2 / 3;
      }

      &:nth-child(3) {
        grid-area: 1 / 3 / 2 / 4;
      }

      &:nth-child(4) {
        grid-area: 2 / 2 / 4 / 4;
      }

      &:nth-child(5) {
        grid-area: 3 / 1 / 4 / 2;
      }

      &:nth-child(6) {
        grid-area: 4 / 1 / 5 / 2;
      }

      &:nth-child(7) {
        grid-area: 4 / 2 / 5 / 3;
      }

      &:nth-child(8) {
        grid-area: 4 / 3 / 5 / 4;
      }
    }

    .item-description {
      @media (width <= 768px) {
        display: none;
      }
    }
  }

    &[data-grid="2"] {
      display: flex;
      align-items: center;
      flex-direction: column;
      gap: 16px;
      padding: 0 32px 32px 32px;

      @media (width <= 768px) {
        padding: 0;
      }

    .item {
      display: flex;
      flex-direction: row;
      height: 96px;
      background: rgb(238 238 238);
      max-width: 400px;
    }

    .item-image {
      width: 96px;
      height: 96px;
      flex-shrink: 0;
    }

    .item-content {
      position: static;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      padding: 8px 16px;
      background: rgb(238 238 238);
      color: black;
    }

    .item-title {
      color: black;
    }

    .item-description {
      color: rgb(100 100 100);
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      line-height: 1.5;
      margin-top: 4px;
      font-size: 0.8rem;
      max-height: 3em;
    }
  }

  &[data-grid="3"] {
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 200px;

    @media (width <= 768px) {
      grid-template-columns: repeat(2, 1fr);
    }

    .item {
      height: 100%;

      .item-description {
        display: none;
      }
    }
  }
}

.item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: white;

  .item-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .item-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: rgb(0 0 0 / 0.3);
    color: white;
    text-align: left;
    backdrop-filter: blur(2px);
  }

  .item-title {
    font-size: 1rem;
    font-weight: bold;
    margin: 0;
  }

  .item-description {
    font-size: 0.8rem;
    line-height: 1.5;
  }
}
