/* 家族共有リンクの閲覧ページ。年配の方も読むので、文字とボタンは大きめにする。 */
:root {
  --ink: #2b2a27;
  --ink-soft: #6b675f;
  --paper: #fffdf8;
  --panel: #ffffff;
  --line: #e5dfd3;
  --accent: #25648a;
  --danger: #b3261e;
  --bar-height: 52px;
  --footer-height: 44px;
  /* タイムマシンの操作欄の高さ。表示中だけ（body.tm）場所を取る */
  --timeline-height: 0px;
}
body.tm { --timeline-height: 60px; }

* { box-sizing: border-box; }

/* hidden 属性は、下で display を指定している要素でも必ず効かせる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  /* ページ全体の拡大（2本指・ダブルタップ）は止める。家系図の拡大は #stage の中で処理する。
     見出しや下端で指が広がったときに、ページごと拡大されて操作できなくなるのを防ぐ。 */
  touch-action: pan-x pan-y;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }

#bar {
  position: fixed; inset: 0 0 auto 0;
  height: calc(var(--bar-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 3;
}
#title {
  margin: 0; font-size: 18px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#stage {
  position: fixed;
  inset: calc(var(--bar-height) + env(safe-area-inset-top)) 0 calc(var(--footer-height) + var(--timeline-height) + env(safe-area-inset-bottom)) 0;
  overflow: hidden;
  background: #f4f0e6;
  touch-action: none;      /* 移動と拡大はこのページで処理する */
  cursor: grab;
  user-select: none; -webkit-user-select: none;
}
#stage.dragging { cursor: grabbing; }
#canvas {
  position: absolute; left: 0; top: 0;
  background: #ffffff;
  overflow: hidden;
  transform-origin: 0 0;
  /* 拡大・縮小は、区画を1枚ずつ表示の大きさで置いて行う（viewer.js の placeTile）。
     scale を掛けるのは操作中だけ（viewer.js の drawFrame）。掛けたままにしたり
     will-change を付けたりすると、文字がぼやけるブラウザがある。 */
}
#canvas img {
  position: absolute;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}

#controls {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(var(--footer-height) + var(--timeline-height) + 16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 2px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  z-index: 2;
}
#controls button {
  color: inherit;
  width: 48px; height: 48px;
  border: 0; border-radius: 50%;
  background: transparent;
  font-size: 26px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
#controls button:hover, #controls button:focus-visible { background: #eef3f7; }

/* タイムマシンを始めるボタン。何のボタンか分かるよう、文字も出す */
#time-machine {
  position: fixed;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(var(--footer-height) + 16px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 18px 0 14px;
  border: 0; border-radius: 24px;
  background: var(--accent); color: #fff;
  font: inherit; font-size: 16px; font-weight: 700;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 2;
}
#time-machine:hover, #time-machine:focus-visible { filter: brightness(1.1); }

/* タイムマシンの操作欄。家系図の場所を取らないよう、1段に収める: 再生・年・年のつまみ・戻る */
#timeline {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--footer-height) + env(safe-area-inset-bottom));
  height: var(--timeline-height);
  padding: 0 calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  z-index: 3;
}
#tm-play {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
#tm-year {
  flex: none;
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
#tm-slider {
  flex: 1; min-width: 60px;
  height: 44px; margin: 0;
  accent-color: var(--accent);
  touch-action: pan-y; /* 横に動かすのは、つまみの操作 */
}
#tm-exit {
  flex: none;
  height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 18px;
  background: transparent; color: var(--accent);
  font: inherit; font-size: 14px; white-space: nowrap; cursor: pointer;
}
#tm-exit:hover, #tm-exit:focus-visible { background: #eef3f7; }

#hint {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--bar-height) + 12px + env(safe-area-inset-top));
  margin: 0; padding: 6px 16px;
  max-width: calc(100% - 32px);
  background: rgba(43, 42, 39, 0.85); color: #fff;
  border-radius: 20px; font-size: 14px; text-align: center;
  z-index: 2;
  pointer-events: none;
}

#status {
  position: fixed;
  inset: calc(var(--bar-height) + env(safe-area-inset-top)) 0 calc(var(--footer-height) + env(safe-area-inset-bottom)) 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: var(--paper);
  z-index: 1;
}
#status-title { margin: 12px 0 4px; font-size: 21px; }
#status-hint { margin: 0; color: var(--ink-soft); max-width: 28em; }

#spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#retry, #passcode-submit {
  margin-top: 20px; padding: 12px 32px; min-height: 48px;
  border: 0; border-radius: 24px;
  background: var(--accent); color: #fff; font-weight: 700;
  cursor: pointer;
}
#retry:disabled, #passcode-submit:disabled { opacity: 0.6; cursor: default; }

#passcode-form {
  display: flex; flex-direction: column; align-items: stretch;
  width: min(100%, 320px); margin-top: 20px;
}
#passcode-label { text-align: left; font-size: 14px; color: var(--ink-soft); }
#passcode {
  margin-top: 4px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 12px;
  background: #fff;
  font-size: 22px; letter-spacing: 0.08em; text-align: center;
}
#passcode:focus { outline: none; border-color: var(--accent); }
#passcode-error { min-height: 1.6em; margin: 8px 0 0; color: var(--danger); font-size: 15px; }

#detail {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--footer-height) + var(--timeline-height) + env(safe-area-inset-bottom));
  max-height: 60%;
  overflow-y: auto;
  padding: 20px 20px 24px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  z-index: 4;
}
#detail-close {
  position: absolute; top: 8px; right: 8px;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: transparent;
  font-size: 26px; line-height: 1; cursor: pointer;
  color: inherit;
  display: flex; align-items: center; justify-content: center;
}
#detail-close:hover, #detail-close:focus-visible { background: #f1ede4; }
#detail-name { margin: 0 44px 0 0; font-size: 24px; }
#detail-furigana { margin: 0; color: var(--ink-soft); font-size: 15px; }
#detail-list { margin: 12px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
#detail-list dt { color: var(--ink-soft); font-size: 15px; }
#detail-list dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

#footer {
  position: fixed; inset: auto 0 0 0;
  height: calc(var(--footer-height) + env(safe-area-inset-bottom));
  padding: 0 12px env(safe-area-inset-bottom);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-soft);
  z-index: 3;
}
#footer p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#footer-encrypted-short { display: none; }
#footer a { color: var(--accent); white-space: nowrap; text-decoration: none; flex-shrink: 0; }
#footer a:hover { text-decoration: underline; }

/* 狭い画面（スマホの縦向き）では、家系図の場所を広く取る:
   見出しを低くし、下端は短い説明の1行にする。タイムマシンの表示中は、下端を出さない。 */
@media (max-width: 599px) {
  :root { --bar-height: 44px; --footer-height: 34px; }
  #title { font-size: 16px; }
  #footer-encrypted { display: none; }
  #footer-encrypted-short { display: block; }
  body.tm { --footer-height: 0px; }
  body.tm #footer { display: none; }
}

/* 高さの無い画面（スマホの横向き）では、見出しと下端を出さず、画面いっぱいに家系図を出す。
   家系図は横に長いことが多いので、横向きにすると大きく見られる。 */
@media (max-height: 480px) {
  :root { --bar-height: 0px; --footer-height: 0px; }
  body.tm { --timeline-height: 52px; }
  #bar, #footer { display: none; }
}

/* 広い画面（PC・タブレットの横向き）では、人物の詳細を右側に出す */
@media (min-width: 900px) {
  #detail {
    left: auto; right: 16px;
    top: calc(var(--bar-height) + 16px);
    bottom: auto;
    width: 360px; max-height: calc(100% - var(--bar-height) - var(--footer-height) - 32px);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
  }
  #controls { right: 16px; }
}
