:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #8a8a8a;
  --line: #222222;
  --overlay: rgba(255, 255, 255, 0.97);
  --gutter: clamp(16px, 7.5vw, 64px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* スマホで2回タップしたときの自動拡大を止める（誤操作防止） */
html { touch-action: manipulation; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "DM Sans", "Zen Kaku Gothic New", system-ui, sans-serif;
  letter-spacing: .025em;
  font-weight: 400;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
ul { list-style: none; }

/* ---------- 3D ステージ ---------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  cursor: grab;
}
#stage:active { cursor: grabbing; }
/* 描画は画面全体に固定（拡大した写真が途中で切れないように）。操作は #stage が受け取る */
#stage canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

#loading {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  color: var(--muted);
  z-index: 1;
  pointer-events: none;
  transition: opacity .4s;
}
#loading.done { opacity: 0; }

/* UI を 3D の上に乗せる（クリックは UI 部分だけ拾う） */
.site-header, .tagline-en, .item-panel, .main-nav, .sub-nav, .site-footer {
  position: fixed;
  z-index: 2;
}

/* ---------- ヘッダー ---------- */
.site-header {
  top: 60px;
  left: var(--gutter);
}
.logo { display: block; font-family: "Zen Kurenaido", sans-serif; line-height: 1; }
.logo-en { display: block; font-size: 15px; letter-spacing: .06em; margin-bottom: 6px; }
.logo-ja { display: block; font-size: 44px; letter-spacing: .08em; }
.tagline { margin-top: 14px; font-size: 11px; line-height: 1.75; letter-spacing: .08em; }

.tagline-en {
  top: 62px;
  right: var(--gutter);
  font-size: 9px;
  line-height: 1.75;
  letter-spacing: .06em;
  width: 7.5em;
}

/* ---------- 写真パネル ---------- */
.item-panel {
  top: 50%;
  right: var(--gutter);
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 32px;
}
.item-title {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  line-height: 1.1;
  margin-bottom: 18px;
}
.item-title .chev { font-size: 18px; line-height: 1; transition: transform .2s; }
.item-title:hover .chev { transform: translateX(3px); }

/* 情報欄：英語の小さなラベル（グレー）と値だけ。シンプルに */
.item-meta { font-size: 5px; line-height: 2; letter-spacing: .06em; }
.item-meta div { display: flex; gap: 1.4em; }
.item-meta div[hidden] { display: none; }   /* 撮影情報がない項目は出さない */
.item-meta dt { font-weight: 400; color: var(--muted); width: 4.6em; flex: none; }
.item-meta dd { font-weight: 400; white-space: nowrap; }

.arrows { display: flex; gap: 6px; }
.arrow {
  width: 32px; height: 32px;
  border: 1px solid #555;
  border-radius: 50%;
  font-size: 14px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.6);
  transition: background .2s, color .2s;
}
.arrow:hover { background: var(--fg); color: var(--bg); border-color: var(--fg); }
/* ♪（写真のビート。jukebox.html だけ）：鳴っているあいだは黒く塗る */
.beat-btn { margin-left: 6px; }
.beat-btn.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
/* 波紋の円：右下、ナビの左。円の中心が下から約 85px、右のナビから少し離れた位置 */
.beat-rings {
  position: fixed;
  width: 230px;
  height: 230px;
  right: calc(var(--gutter) + 95px);
  bottom: -30px;
  pointer-events: none;
  z-index: 1;
}
@media (max-width: 720px), (orientation: landscape) and (max-height: 500px) {
  .beat-rings { display: none; }   /* スマホでは円盤があるので出さない */
}

/* ---------- ナビ ---------- */
.navs { display: contents; }   /* PC では包みを無視して、中の2つをそれぞれ固定配置 */
.main-nav {
  left: var(--gutter);
  bottom: 54px;
  font-size: 13px;
}
.main-nav li + li { margin-top: 10px; }
.main-nav a { display: inline-flex; align-items: center; gap: 6px; }
.main-nav a.muted { color: var(--muted); }
.main-nav a:hover { text-decoration: underline; text-underline-offset: 4px; }
.main-nav .ico { font-size: 11px; }

.sub-nav {
  right: var(--gutter);
  bottom: 54px;
  font-size: 12px;
}
.sub-nav li + li { margin-top: 10px; }
.menu-btn { display: none; }   /* スマホだけ表示 */
.sub-nav a:hover { text-decoration: underline; text-underline-offset: 4px; }

.site-footer {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8px;
  letter-spacing: .04em;
  white-space: nowrap;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--overlay);
  overflow-y: auto;
  animation: fade .25s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.overlay-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 60px var(--gutter) 80px;
}
.overlay-inner.narrow { max-width: 640px; }
.overlay-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}
.overlay-head h2 { font-size: 18px; letter-spacing: .06em; }
.close { font-size: 28px; line-height: 1; width: 40px; height: 40px; }

.grid-day + .grid-day { margin-top: 40px; }
.grid-day h3 {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 12px;
}
.grid {
  /* 写真の縦横比のまま、行の高さをそろえて敷き詰める（--ar = 幅 / 高さ） */
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.grid::after { content: ""; flex-grow: 999; }   /* 最後の行が引き伸ばされないように */
.grid li { flex: var(--ar, 1.5) 1 calc(var(--ar, 1.5) * 150px); }
.grid button { width: 100%; text-align: left; }
.grid img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--ar, 1.5);
  object-fit: cover;
  background: #f4f2ee;
  transition: transform .2s;
}
.grid button:hover img { transform: scale(1.03); }
.grid .g-name { display: block; margin-top: 8px; font-size: 12px; font-weight: 500; }
.grid .g-size { display: block; font-size: 10px; color: var(--muted); font-weight: 400; }

.detail-img { width: 100%; max-width: 360px; display: block; margin: 0 auto 24px; background: #f4f2ee; }
.detail-text { font-size: 16px; line-height: 2; font-weight: 400; letter-spacing: .065em; font-feature-settings: "palt"; }
.detail-text code { font-size: 12px; background: #f1f1f1; padding: 1px 5px; border-radius: 3px; }

/* ---------- スマホ ---------- */
/* ============================================================
 * スマホ・タブレット（幅 720px 以下）
 * 画面に貼り付けた配置をやめ、上から順に流れるレイアウトにする。
 * ページ全体がスクロールできるので、引っ張って更新も効く。
 * ============================================================ */
@media (max-width: 720px) {
  html, body { height: auto; }
  body {
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .site-header, .tagline-en, .item-panel, .main-nav, .sub-nav, .site-footer {
    position: static;
    transform: none;
  }
  /* 文字やボタンは写真より手前に（PC と同じく、拡大した写真の上に文字が乗る） */
  .site-header, .item-panel, .navs, .site-footer { position: relative; inset: auto; z-index: 1; }

  /* ヘッダー：ロゴと英字を横並び */
  .site-header {
    order: 1;
    padding: calc(20px + env(safe-area-inset-top)) var(--gutter) 0;
  }
  .logo-en { font-size: 13px; }
  .logo-ja { font-size: min(34px, 8vw); }   /* 幅の狭いスマホでも右上のメニューボタンに重ならない */
  .tagline { font-size: 12px; margin-top: 10px; }
  .tagline-en { display: none; }

  /* 3D：画面の幅いっぱい、高さは画面の 55% 程度 */
  #stage {
    order: 2;
    position: relative;
    inset: auto;
    width: 100%;
    height: clamp(300px, 56svh, 560px);
    margin-top: 8px;
    touch-action: none;          /* 写真の上では指で回す。ページのスクロールは写真の外で */
  }
  #loading { position: absolute; top: calc(env(safe-area-inset-top) + 50svh); }

  /* 写真の情報と ← → */
  .item-panel {
    order: 3;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 4px var(--gutter) 0;
  }
  .item-title { font-size: 16px; margin-bottom: 10px; }
  .item-meta { font-size: 6px; line-height: 1.9; }
  .arrows { gap: 10px; }
  .arrow { width: 48px; height: 48px; font-size: 18px; }

  .site-footer { margin-top: auto; }

  .site-footer {
    order: 5;
    text-align: center;
    font-size: 10px;
    padding: 16px var(--gutter) 20px;
  }

  /* 全写真一覧（下の文字が透けないよう不透明に） */
  .overlay { background: var(--bg); }
  .overlay-inner { padding: calc(24px + env(safe-area-inset-top)) var(--gutter) 60px; }
  .close { width: 48px; height: 48px; }
  .grid { gap: 6px; }
  .grid li { flex-basis: calc(var(--ar, 1.5) * 85px); }
  .grid-day h3 { font-size: 13px; }
  /* .detail-text は PC と同じ */
}

/* ============================================================
 * スマホを横にしたとき（高さ 500px 以下の横長画面）
 * PC と同じく 3D を画面いっぱいに出し、文字はごく小さく四隅に寄せる。
 * ナビは縦向きのスマホと同じく、右上の丸いボタンから開く。
 * ============================================================ */
@media (orientation: landscape) and (max-height: 500px) {
  .site-header { top: calc(14px + env(safe-area-inset-top)); }
  .logo-en { font-size: 9px; margin-bottom: 3px; }
  .logo-ja { font-size: 22px; }
  .tagline, .tagline-en { display: none; }

  .item-panel {
    top: auto;
    bottom: calc(14px + env(safe-area-inset-bottom));
    transform: none;
    gap: 20px;
  }
  .item-title { font-size: 13px; margin-bottom: 6px; }
  .item-meta { font-size: 5px; line-height: 1.8; }
  .arrows { gap: 8px; }
  .arrow { width: 40px; height: 40px; font-size: 16px; }

  .site-footer { bottom: 8px; font-size: 8px; }
}

/* 丸いメニューボタンとパネル：縦向きのスマホ・横向きのスマホ共通 */
@media (max-width: 720px), (orientation: landscape) and (max-height: 500px) {
  .main-nav, .sub-nav { position: static; transform: none; }
  /* メニューボタン：右上の丸い3本線（下層ページと同じ形） */
  .menu-btn {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top));
    right: var(--gutter);
    z-index: 4;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
  }
  .menu-ico { position: relative; width: 20px; height: 14px; }
  .menu-ico i {
    position: absolute;
    left: 0;
    width: 100%;
    height: 1px;
    background: currentColor;
    transition: transform .25s, opacity .2s, top .25s;
  }
  .menu-ico i:nth-child(1) { top: 0; }
  .menu-ico i:nth-child(2) { top: 6.25px; }
  .menu-ico i:nth-child(3) { top: 12.5px; }
  .menu-open .menu-ico i:nth-child(1) { top: 6.25px; transform: rotate(45deg); }
  .menu-open .menu-ico i:nth-child(2) { opacity: 0; }
  .menu-open .menu-ico i:nth-child(3) { top: 6.25px; transform: rotate(-45deg); }

  /* ナビ：ボタンの下の小さなパネルに縦積み。ページ名が上、3D表示についてなどはごく小さく下に */
  .navs {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top) + 54px);
    right: calc(var(--gutter) - 12px);
    z-index: 4;
    display: flex;
    flex-direction: column;
    padding: 18px 40px 20px 28px;
    background: var(--bg);
    box-shadow: 0 6px 24px rgba(0, 0, 0, .07);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity .18s, transform .18s, visibility 0s .18s;
  }
  .menu-open .navs { visibility: visible; opacity: 1; transform: none; transition: opacity .18s, transform .18s; }
  .sub-nav { order: 1; font-size: 16px; font-weight: 400; letter-spacing: .04em; }
  .sub-nav a { display: flex; align-items: center; min-height: 40px; white-space: nowrap; }
  .main-nav { order: 2; margin-top: 14px; padding-top: 10px; border-top: 1px solid #e5e5e5; font-size: 10px; font-weight: 400; }
  .main-nav li + li, .sub-nav li + li { margin-top: 0; }
  .main-nav a { display: flex; align-items: center; gap: 4px; min-height: 28px; white-space: nowrap; }
  .main-nav .ico { font-size: 8px; }
}

/* 横向き：ボタンを少し小さく、パネルは画面の高さに収めて中をスクロール */
@media (orientation: landscape) and (max-height: 500px) {
  .menu-btn { top: calc(12px + env(safe-area-inset-top)); width: 40px; height: 40px; }
  .navs {
    top: calc(12px + env(safe-area-inset-top) + 46px);
    max-height: calc(100vh - 70px);
    overflow-y: auto;
    padding: 10px 36px 12px 24px;
  }
  .sub-nav a { min-height: 34px; font-size: 15px; }
  .main-nav { margin-top: 8px; padding-top: 6px; }
  .main-nav a { min-height: 24px; }
}

/* ============================================================
 * イントロ（<body data-intro> のページだけ）
 * 写真が着地するまで文字を隠し、着地したら上から順にフェードインする
 * ============================================================ */
body.intro:not(.intro-done) :is(.site-header, .tagline-en, .item-panel, .main-nav, .sub-nav, .site-footer, .menu-btn) {
  opacity: 0;
  filter: blur(6px);
  pointer-events: none;
}
body.intro :is(.site-header, .tagline-en, .item-panel, .main-nav, .sub-nav, .site-footer, .menu-btn) {
  transition: opacity 1.4s ease, filter 1.4s ease;
}
/* 出てくる順番：ロゴ → 右上の英字 → 写真の情報 → メニュー → フッター */
body.intro .tagline-en { transition-delay: .15s; }
body.intro .item-panel { transition-delay: .35s; }
body.intro :is(.main-nav, .sub-nav, .menu-btn) { transition-delay: .6s; }
body.intro .site-footer { transition-delay: .8s; }

/* ============================================================
 * ジュークボックス（<body data-jukebox> のページだけ）
 * 左の円盤が開いている間は、左側の小さな文字とメニューを薄くして写真を見やすくする
 * ============================================================ */
body[data-jukebox] :is(.tagline, .main-nav) { transition: opacity .4s ease; }
body.juke-open :is(.tagline, .main-nav) { opacity: .15; }

/* 縦向きのスマホ：
 * - 著作権表示は白い帯にして、後ろの円盤の写真が重ならないようにする（上の縁はぼかす）
 * - 見出しを小さく。円盤に一度触れたら、見出しの下の「日々の写真／デジタルアーカイブ」を消す */
@media (max-width: 720px) {
  body.juke-touch .site-footer { background: var(--bg); }
  body.juke-touch .site-footer::before {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 100%;
    height: 28px;
    background: linear-gradient(to bottom, transparent, var(--bg));
    pointer-events: none;
  }
  body[data-jukebox] .logo-en { font-size: 11px; }
  body[data-jukebox] .logo-ja { font-size: min(26px, 6.4vw); }
  body.juke-touch .tagline { transition: opacity .5s ease; }
  body.juke-touched .tagline { opacity: 0; }
}
/* 縦向きのスマホ：円盤が広がっているあいだは、写真の情報を少し上へずらして円盤と重ならないようにする
 * （ずらす量は jukebox.js の infoLift と同じ値に） */
@media (max-width: 720px) {
  body.juke-touch .item-panel { transition: transform .4s ease; }
  body.juke-active .item-panel { transform: translateY(-48px); }
}
