/* =========================================================
   KAWABATA YUTA — Portfolio
   ========================================================= */
:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #777777;
  --line: #e5e5e5;
  --accent: #c94b3d;
  --header-h: 96px;
  --gutter: 80px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111;
    --fg: #f2f2f2;
    --muted: #999999;
    --line: #333333;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  /* M PLUS Rounded 1c(Google Fonts・index.html で読み込み)。通常 400 / 太字 500。
     読み込めない環境では後ろのフォントで表示 */
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
body.is-locked { overflow: hidden; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) calc(var(--gutter) + env(safe-area-inset-right, 0px)) 0 calc(var(--gutter) + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.logo {
  font-size: 30px;
  font-weight: 500;
  letter-spacing: .12em;
  text-decoration: none;
  white-space: nowrap;
}
.site-nav { display: flex; align-items: center; gap: 20px; }
.site-nav a {
  font-size: 13px;
  letter-spacing: .06em;
  text-decoration: none;
  color: var(--muted);
  transition: color .2s;
}
.site-nav a:hover,
.site-nav a.is-current { color: var(--fg); }
.site-nav .ig { display: flex; color: var(--fg); }

/* ---------- Pages ---------- */
.page { flex: 1; }
.page-text {
  width: 100%;
  /* 文章の幅は最大640px(左右の余白は別に確保) */
  max-width: calc(640px + var(--gutter) * 2);
  margin: 0 auto;
  padding: 64px var(--gutter);
}
.page-text h2 { margin: 0 0 24px; font-size: 18px; font-weight: 500; letter-spacing: .08em; }
.page-text h3 { margin: 40px 0 8px; font-size: 13px; letter-spacing: .08em; }
.page-text p { margin: 0 0 12px; line-height: 1.9; }
/* 名前とメールアドレスは本文より少し大きく */
.page-text .name,
.page-text .mail { font-size: 20px; line-height: 1.5; }
.page-text .name { margin-bottom: 40px; font-size: 18px; }
/* 名前のローマ字部分はロゴと同じく字間を広めに */
.name-en { letter-spacing: .12em; white-space: nowrap; }
/* メールアドレスの上の見出し(プロフィール文との間は広めに) */
.contact { width: fit-content; margin-top: calc(12px + 3.8em); text-align: center; }
.page-text .contact-lead { margin: 0 0 8px; letter-spacing: .08em; line-height: 1.25; }

/* メールアドレス(クリックでコピー) */
/* 「Copied」はアドレスの下に出す */
.mail-row { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mail {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.mail:hover { color: var(--accent); }
.mail-copied {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: .04em;
  opacity: 0;
  transition: opacity .2s;
}
.mail-copied.is-show { opacity: 1; }

/* ---------- TOP layout ---------- */
/* ソートはサムネイルの上に横並び。スクロールしてもヘッダーの下に固定 */
.sort {
  position: sticky;
  top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  z-index: 5;
  display: flex;
  gap: 28px;
  overflow-x: auto;
  padding: 24px var(--gutter) 20px;
  background: var(--bg);
}
.sort-item {
  flex: none;
  padding: 5px 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  letter-spacing: .04em;
  color: var(--muted);
  cursor: pointer;
  transition: color .2s;
}
.sort-item:hover,
.sort-item.is-active { color: var(--fg); }
.sort-item.is-active { font-weight: 500; }

.works { padding: 0 var(--gutter) 40px; }

/* ---------- Masonry grid(位置は script.js で計算) ---------- */
.grid { position: relative; }
.thumb {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  padding: 0;
  border: 0;
  overflow: hidden;
  cursor: pointer;
  opacity: 0;
  animation: thumb-in .5s ease forwards;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity .3s ease;
}
@keyframes thumb-in { to { opacity: 1; } }

/* カーソルを合わせると画像が少し透ける(タッチ端末では残らないようマウス操作時のみ) */
@media (hover: hover) {
  .thumb:hover img { opacity: .7; }
}
.thumb:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.sentinel { height: 1px; }

/* ---------- Detail(全画面表示) ---------- */
.detail {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg);
  animation: detail-in .25s ease;
}
@keyframes detail-in { from { opacity: 0; } to { opacity: 1; } }
/* 幅を画像に合わせる。左右の余白は閉じるボタンが画像の横に収まる幅を確保 */
.detail-inner {
  width: fit-content;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px max(var(--gutter), 72px) 80px;
}
/* タイトル(中央)と閉じるボタン(画像の右外側)。スクロールしても上部に残る */
.detail-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 0 8px;
  margin-bottom: 8px; /* ×ボタンと画像の間を 10px に */
  background: var(--bg);
}
.detail-head h2 { margin: 0; font-size: 16px; font-weight: 500; letter-spacing: .04em; line-height: 1.5; text-align: center; white-space: pre-line;
  text-wrap: balance; word-break: auto-phrase; /* 折り返す場合は行の長さをそろえ、文節で区切る */ }
.detail-images { display: flex; flex-direction: column; gap: 24px; }
/* 縦長の画像も1枚が画面内に収まるよう高さを制限 */
.detail-images img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  max-height: calc(100svh - 120px);
  margin: 0 auto;
}
.detail-close {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: calc(50% + 4px + env(safe-area-inset-top, 0px) / 2); /* タイトルと上下中央をそろえる */
  right: -50px; /* 画像の右端から 12px 外側 */
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .18);
  cursor: pointer;
  transition: transform .2s ease;
}
.detail-close { transform: translateY(-50%); }
.detail-close:hover { transform: translateY(-50%) scale(1.06); }

/* ---------- Footer ---------- */
.site-footer {
  padding: 24px var(--gutter) calc(24px + env(safe-area-inset-bottom, 0px));
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .06em;
}

/* スマホ専用の表示(titleSp など)。720px 以下でのみ表示 */
.sp-only { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 999px) {
  :root { --gutter: 40px; }
}
@media (max-width: 720px) {
  :root { --gutter: 16px; --header-h: 72px; }
  /* ABOUT などの文章ページは左右の余白を広めに */
  .page-text { padding-left: 40px; padding-right: 40px; }
  .page-text .mail { font-size: min(20px, 5.4vw); }
  .page-text .name { font-size: 17px; }
  .logo { font-size: 20px; }
  .sort { gap: 18px; padding: 12px var(--gutter); }
  .works { padding: 4px var(--gutter) 32px; }
  /* スマホは画像の横に余白がないため、×は画像の上(右寄せ)に置く */
  .detail-inner { padding: 8px var(--gutter) 80px; }
  .detail-head { padding-left: 46px; padding-right: 46px; }
  .detail-close { right: 0; }
  .detail-head { margin-bottom: 10px; }
  .detail-head h2 { font-size: 13px; }
  .pc-only { display: none; }
  .sp-only { display: inline; }
  .detail-images { gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .thumb, .detail { animation: none; opacity: 1; }
  .thumb img { transition: none; }
}
