/* ============================================================
   ★ 技術解説: CSS Subgrid（フォームの label / input 列を揃える）
   ------------------------------------------------------------
   親 main で 2 列（max-content / 1fr）の Grid を定義し、
   各 .item に grid-template-columns: subgrid を継承させて
   ラベル列の幅を全行で揃える。狭い画面では 1 列にフォールバック。
   ============================================================ */

main {
  display: grid;
  grid-template-columns: max-content 1fr;

  @media (width < 600px) {
    grid-template-columns: 1fr;
  }
}

main .item {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: span 2;

  @media (width < 600px) {
    grid-column: span 1;
    gap: 8px;
  }
}

/* ============================================================
   以下、装飾スタイル
   （リセット / 配色 / フォーム部品の質感など、subgrid とは
   　直接関係のない見た目の調整）
   ============================================================ */

* {
  box-sizing: border-box;
}

html,
body {
  background-color: #f1f2f3;
}

body {
  font-family:
    "游ゴシック Medium", YuGothic, YuGothicM, "Hiragino Kaku Gothic ProN", Meiryo,
    sans-serif;
  line-height: 1.6;
  color: #000000;
}

.app {
  display: grid;
  padding-block: 40px;
  grid-template-columns:
    [app-start] minmax(16px, 1fr) [content-start] minmax(auto, 960px)
    [content-end] minmax(16px, 1fr) [app-end];
}

.wrapper {
  display: grid;
  border-radius: 16px;
  background: #fff;
  grid-column: content;
  row-gap: 64px;
  grid-template-columns:
    [app-start] minmax(16px, 1fr) [form-start] minmax(auto, 720px)
    [form-end] minmax(16px, 1fr) [app-end];
  padding-block: 100px;
}

.wrapper > * {
  grid-column: form;
}

header {
  text-align: center;
  color: #2d2d2d;
}

header h1 {
  font-size: 36px;
  font-weight: bold;
}

main {
  justify-content: center;
  gap: 40px;

  @media (width < 600px) {
    gap: 16px;
  }
}

.item {
  padding: 16px;

  @media (width < 600px) {
    gap: 8px;
  }
}

input {
  font-size: 20px;
  width: 100%;
  height: 56px;
  padding: 8px;
  border: none;
  border-radius: 4px;
  background-color: #f3f3f3;
}

label {
  position: relative;
  display: flex;
  align-self: center;
  gap: 8px;
}

label::before {
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  text-align: center;
  letter-spacing: 0.7px;
  border-radius: 4px;
}

label.optional::before {
  content: "任意";
  color: #fff;
  background-color: #6c6c6c;
}

label.required::before {
  content: "必須";
  color: #fff;
  background-color: #ff7e46;
}

.input-wrapper {
  position: relative;
}

.error-message {
  font-size: 14px;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  justify-content: center;
  padding: 6px;
  text-align: center;
  color: #fff;
  border-radius: 6px;
  background-color: #e02e2f;
  filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.25));

  @media (width < 600px) {
    top: calc(100% + 8px);
    bottom: auto;
    left: 8px;
  }
}

.error-message::after {
  position: absolute;
  bottom: -6px;
  left: 8px;
  width: 14px;
  height: 14px;
  content: "";
  background-color: #e02e2f;
  clip-path: polygon(50% 100%, 0 0, 100% 0);

  @media (width < 600px) {
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  }
}

@media (width < 600px) {
  .error-message::after {
    top: -6px;
    bottom: auto;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  }
}

button {
  font-weight: bold;
  align-items: center;
  justify-content: center;
  padding: 16px 60px;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  color: #fff;
  border: none;
  border-radius: 30px;
  background-color: #ff7e46;
  grid-column: span 2;
  justify-self: center;

  @media (width < 600px) {
    grid-column: span 1;
  }
}

.error-message {
  display: none;
}

input:user-invalid:not(:focus) + .error-message {
  display: block;
}

.item:has(input:user-invalid:not(:focus)) {
  background: #ffe5e5;
}
