html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: #2b2a26;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ブランド透かし: 「Yuga」を主役に、その下へ小さくタグライン。箱は持たず、
   地図ラベルと同じ白ハローで地図に馴染ませる */
#app-brand {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  color: #252a36;
  text-shadow:
    -1px -1px 2px #fff,
    1px -1px 2px #fff,
    -1px 1px 2px #fff,
    1px 1px 2px #fff;
  pointer-events: none;
}

#app-brand-name {
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.1;
}

#app-brand-tagline {
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  color: #6b675c;
}

#map {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

#lang-toggle {
  position: absolute;
  top: 56px;
  left: 8px;
  z-index: 5;
  display: flex;
  gap: 4px;
}

#error-banner {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: #c0392b;
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  z-index: 100;
}

#bottom-panel {
  flex: 0 0 auto;
  background: #f7f4ec;
  border-top: 1px solid #dedbd0;
  padding: 8px 16px 12px;
}

#timeline-presets {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 8px;
  border-bottom: 1px solid #dedbd0;
}

#timeline-presets button {
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 13px;
  padding: 2px 1px 7px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: #8a8578;
  cursor: pointer;
  position: relative;
  top: 1px;
}

#timeline-presets button:hover {
  color: #2b2a26;
}

#timeline-presets button.active {
  color: #252a36;
  font-weight: 700;
  border-bottom-color: #a84545;
}

#region-restore-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

/* 折りたたみトグルはプリセット行の常に一番右。地域復元チップの出現/非表示に関わらず
   最右翼に置きたいので、DOM 挿入順ではなく order で位置を確定させる */
#timeline-collapse {
  order: 9;
  align-self: center;
  margin-left: 8px;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid #dedbd0;
  border-radius: 3px;
  background: #e9e6dc;
  color: #6f6b5e;
  cursor: pointer;
}

#timeline-collapse:hover {
  background: #dedbd0;
}

.region-restore-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid #dedbd0;
  border-radius: 3px;
  background: #e9e6dc;
  color: #6f6b5e;
  cursor: pointer;
}

.region-restore-chip:hover {
  background: #dedbd0;
}

.region-restore-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.region-restore-showall {
  font-weight: bold;
  background: #f7f4ec;
}

#timeline {
  position: relative;
  width: 100%;
  height: 224px;
  background: #fcfbf6;
  border: 1px solid #dedbd0;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}

#timeline-axis {
  position: relative;
  width: 100%;
  height: 18px;
}

.timeline-axis-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 5px;
  background: #8a8578;
}

.timeline-axis-label {
  position: absolute;
  top: 6px;
  transform: translateX(-50%);
  font-size: 10px;
  color: #8a8578;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.timeline-gridline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #eae7dc;
  z-index: 1;
  pointer-events: none;
}

.timeline-lane {
  position: absolute;
  left: 0;
  width: 100%;
  height: 28px;
  border-bottom: 1px solid #dedbd0;
  box-sizing: border-box;
}

.timeline-lane-label {
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 11px;
  font-weight: bold;
  padding: 1px 6px;
  border-radius: 3px;
  color: #fff;
  z-index: 2;
  pointer-events: auto;
  cursor: pointer;
}

/* 出来事バンド(中部)のドット位置がデフォルト。国・王朝バンドは下で個別に上書きする */
.timeline-dot {
  position: absolute;
  top: 14px;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.35;
  z-index: 3;
  transition:
    opacity 0.1s,
    width 0.1s,
    height 0.1s,
    top 0.1s;
}

.timeline-dot.in-window {
  opacity: 1;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  top: 13px;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

/* 国・王朝バンド(上部)に属する点データ(期間の無い政体記録)はバンド上部に位置させる */
.timeline-dot.timeline-kind-polity {
  top: 3px;
}

.timeline-dot.timeline-kind-polity.in-window {
  top: 1px;
}

.timeline-bar {
  position: absolute;
  height: 5px;
  border-radius: 2.5px;
  cursor: pointer;
  opacity: 0.35;
  z-index: 3;
  transition:
    opacity 0.1s,
    box-shadow 0.1s;
}

.timeline-bar.in-window {
  opacity: 1;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

/* コンパクト表示: レーンを薄い概観行にする。COMPACT_LANE_HEIGHT (app.js) と高さを揃える。
   種類ごとのバンド分けはやめ、バー/ドットとも 1 行に重ねて表示する */
#timeline.timeline-compact .timeline-lane {
  height: 10px;
}

/* コンパクト時はラベル文字を隠し、地域色のチップだけにする(クリックの当たり判定は維持) */
#timeline.timeline-compact .timeline-lane-label {
  top: 2px;
  width: 14px;
  height: 6px;
  padding: 0;
  font-size: 0;
  border-radius: 2px;
}

#timeline.timeline-compact .timeline-dot {
  top: 3px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
}

#timeline.timeline-compact .timeline-dot.in-window {
  top: 3px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  box-shadow: none;
}

#timeline.timeline-compact .timeline-bar {
  height: 3px;
  border-radius: 1.5px;
}

#timeline.timeline-compact .timeline-bar.in-window {
  box-shadow: none;
}

.timeline-window-band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(37, 42, 54, 0.08);
  border-left: 1px solid rgba(37, 42, 54, 0.15);
  border-right: 1px solid rgba(37, 42, 54, 0.15);
  z-index: 1;
  cursor: grab;
  pointer-events: auto;
}

.timeline-window-band.dragging {
  cursor: grabbing;
}

/* 幅が数年まで絞られても掴めるように、見た目より広い透明の当たり判定を持たせる */
.timeline-window-band::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -5px;
  right: -5px;
}

.timeline-window-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  z-index: 2;
  cursor: ew-resize;
  pointer-events: auto;
}

.timeline-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #a84545;
  z-index: 4;
  pointer-events: none;
}

/* カーソル(選択年)の読み値。タイムライン本体の外側(上・地域レーンの上)の専用レールに置き、
   バー/ドットに重ならないようにする。選択年はライブなフィードバックなので、地図と操作(プリセット)
   に近い上端に置く。ラベルはカーソル位置に追従し、朱のステムで連結する */
#timeline-cursor-rail {
  position: relative;
  height: 26px;
}

#timeline-cursor-stem {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  height: 6px;
  background: #a84545;
  pointer-events: none;
}

.timeline-cursor-label {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 3px;
  padding: 0 4px;
  white-space: nowrap;
  pointer-events: none;
}

/* レール端でラベルが切れないよう、寄せ方向を反転する(ステムは常にカーソル位置) */
.timeline-cursor-label.at-left {
  transform: translateX(0);
}

.timeline-cursor-label.at-right {
  transform: translateX(-100%);
}

.timeline-cursor-year {
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.15;
  color: #252a36;
  font-variant-numeric: tabular-nums;
}

/* ±ウィンドウは既定では隠し、ウィンドウ幅を調整中(ハンドルのドラッグ)のみ表示する。
   平時は年だけを見せ、調整時にだけ±YY年 のフィードバックを出す */
.timeline-cursor-window {
  display: none;
  font-size: 9.5px;
  color: #8a8578;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timeline-cursor-label.adjusting .timeline-cursor-window {
  display: block;
}

.timeline-density-info {
  position: absolute;
  top: 3px;
  right: 6px;
  font-size: 10px;
  color: #8a8578;
  background: rgba(252, 251, 246, 0.85);
  padding: 1px 5px;
  border-radius: 3px;
  z-index: 4;
  pointer-events: none;
}

/* #kind-toggle のチップ hover 時、タイムライン上の他種類のバー/ドットを薄くする */
#timeline.timeline-dim-except-event .timeline-kind-polity {
  opacity: 0.15;
}

#timeline.timeline-dim-except-polity .timeline-kind-event {
  opacity: 0.15;
}

.timeline-tooltip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 6px));
  background: #fcfbf6;
  color: #252a36;
  border: 1px solid #dedbd0;
  box-shadow: 0 1px 3px rgba(37, 42, 54, 0.14);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

#kind-toggle {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
}

.border-caption {
  font-size: 11px;
  color: #8a8578;
  white-space: nowrap;
}

/* 地図上に浮くレイヤーフィルタ(各種類の独立 ON/OFF)。プリセットと同じ紙のパレットで、
   朱=アクティブ に揃える。既定は OFF 表示(退色)、有効時に墨字 + 朱枠 で「点いている」を示す */
.kind-toggle-btn {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #dedbd0;
  border-radius: 3px;
  background: rgba(252, 251, 246, 0.85);
  color: #8a8578;
  cursor: pointer;
}

.kind-toggle-btn:hover {
  color: #2b2a26;
}

.kind-toggle-btn.active {
  background: #fcfbf6;
  color: #252a36;
  border-color: #a84545;
}

/* display: flex が hidden 属性(UA の display:none)より優先されてしまうため明示的に打ち消す */
#person-panel[hidden] {
  display: none;
}

#person-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 26px;
  width: 240px;
  display: flex;
  flex-direction: column;
  /* 透明感(0.42 + blur)は残しつつ、内側フェードはやめて外枠ヘアラインで名簿としての輪郭を保つ */
  background: rgba(252, 251, 246, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-left: 1px solid #dedbd0;
  z-index: 5;
  overflow: hidden;
}

#person-panel-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  padding: 12px 14px 8px;
  border-bottom: 1px solid #dedbd0;
}

#person-panel-title {
  order: 2;
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  color: #252a36;
  font-variant-numeric: tabular-nums;
}

#person-panel-subtitle {
  order: 1;
  margin-bottom: 3px;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: #a84545;
}

#person-panel-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 12px;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 2px;
  border-bottom: 1px solid #eae7dc;
  cursor: pointer;
}

.person-row:last-child {
  border-bottom: none;
}

.person-row:hover {
  background: rgba(43, 42, 38, 0.05);
}

.person-row-image {
  width: 30px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 0;
  border: 1px solid #dedbd0;
  padding: 2px;
  background: #fff;
  object-fit: cover;
}

.person-row-name {
  flex: 1 1 auto;
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 12.5px;
  color: #252a36;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-row-age {
  flex: 0 0 auto;
  font-size: 11px;
  color: #8a8578;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.map-label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-size: 11px;
  font-weight: bold;
  color: #2b2a26;
  text-shadow:
    -1px -1px 2px #fff,
    1px -1px 2px #fff,
    -1px 1px 2px #fff,
    1px 1px 2px #fff;
  white-space: nowrap;
  cursor: pointer;
}

.map-label-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid #fff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
}

.maplibregl-popup-content {
  font-family: inherit;
  background: #fcfbf6;
  box-shadow: 0 2px 6px rgba(37, 42, 54, 0.15);
}

.popup-image {
  display: block;
  max-width: 96px;
  border-radius: 4px;
  border: 1px solid #dedbd0;
  margin-bottom: 6px;
}

.popup-title {
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", serif;
  font-weight: bold;
  margin-bottom: 4px;
}

.popup-meta {
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
}

.popup-desc {
  font-size: 13px;
  line-height: 1.4;
}
