/* 分身の旅日記 ビューア。参照実装の意匠を踏襲しつつ、レスポンシブ + アーカイブUIを追加。 */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --ink: #2c3a47;
  --ink2: #3d5265;
  --paper: #f4f2f0;
  --card: #fff;
  --pass: #ece9e4;
  --accent: #e8657c;
  --muted: #6b6459;
}
html, body { height: 100%; }
body {
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}
#app { display: flex; height: 100vh; }
#map { flex: 1; min-width: 0; background: #dfe6ea; }

#panel {
  width: 400px;
  max-width: 42vw;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  border-left: 1px solid #ddd;
}
header { padding: 14px 20px 12px; background: var(--ink); color: #fff; }
.titlerow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
header h1 { font-size: 16px; line-height: 1.4; }
header .sub { font-size: 12px; opacity: .88; margin-top: 5px; line-height: 1.6; }

#controls {
  display: flex; gap: 8px; padding: 10px 20px;
  background: #fff; border-bottom: 1px solid #e5e0d8;
}
button {
  padding: 9px 12px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--ink); color: #fff; font-size: 13px; font-weight: bold;
  font-family: inherit; flex: 1;
}
button:hover { background: var(--ink2); }
button.secondary { background: #c9c2b6; color: #443f38; }
button.secondary:hover { background: #bdb5a6; }
button.icon { flex: 0 0 auto; background: transparent; font-size: 16px; padding: 4px 8px; }
header button.icon { color: #fff; }
#controls button.icon { background: #efe9df; }

#diary { flex: 1; overflow-y: auto; padding: 14px 20px 30px; -webkit-overflow-scrolling: touch; }
.card {
  background: var(--card); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08); cursor: pointer;
  opacity: 0; transform: translateY(8px); transition: opacity .5s, transform .5s;
}
.card.shown { opacity: 1; transform: none; }
.card.pass { background: var(--pass); padding: 8px 14px; font-size: 12px; color: var(--muted); }
.card .meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.card .time { font-size: 11px; color: #999; }
.card .st { font-weight: bold; font-size: 15px; color: var(--ink); }
.card .st a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--ink); }
.card .st a:hover { background: #e9edf1; }
.card .tag { font-size: 10px; background: var(--accent); color: #fff; border-radius: 3px; padding: 1px 5px; }
.card.pass .tag { background: #a5a095; }
.card p { font-size: 13px; line-height: 1.85; color: #3a362f; }
.card p a { color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--ink); }
.card p a:hover { background: #e9edf1; }
.card.active { outline: 2px solid var(--accent); }

#fin { text-align: center; font-size: 12px; color: #999; padding: 6px 0 16px; display: none; }
footer#credit { font-size: 10px; color: #a49; opacity: .55; color: #9a948b; padding: 8px 20px 12px; line-height: 1.5; }

/* 分身マーカー */
.avatar-icon div { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }

/* タイル切替コントロール (Leaflet 上に載せる) */
.tile-toggle {
  background: #fff; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.3);
  display: flex; overflow: hidden; font-size: 12px;
}
.tile-toggle button {
  flex: 0 0 auto; background: #fff; color: var(--ink); border-radius: 0;
  padding: 6px 10px; font-weight: normal;
}
.tile-toggle button.on { background: var(--ink); color: #fff; }

/* シート共通 (路線ピッカー / 共有) */
.sheet-inner {
  background: var(--paper); border-radius: 12px; width: min(420px, 90vw);
  max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; background: var(--ink); color: #fff; font-weight: bold;
}
.sheet-head button.icon { color: #fff; }

.hidden { display: none !important; }
.headbtns { display: flex; gap: 2px; flex: 0 0 auto; align-items: center; }
a.icon { text-decoration: none; display: inline-flex; align-items: center; }

/* トリップビューア(左右)の戻りリンク */
header .backlink {
  display: inline-flex; align-items: center; gap: 4px;
  color: #c9d3dc; text-decoration: none; font-size: 12.5px; font-weight: bold;
  margin-bottom: 9px; padding: 3px 9px 3px 7px; border-radius: 20px;
  background: rgba(255,255,255,.1);
}
header .backlink:hover { background: rgba(255,255,255,.22); color: #fff; }

/* ===== トップ: 縦スクロールのランディング ===== */
#homeView { display: block; height: 100vh; overflow-y: auto; background: var(--paper); }

.site-header {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--ink); color: #fff;
}
.site-header .brand { color: #fff; text-decoration: none; font-size: 17px; font-weight: bold; display: inline-flex; align-items: center; gap: 9px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; display: block; }
.site-header .hdr-btns { display: flex; gap: 8px; }
.hdr-btn {
  flex: 0 0 auto; background: rgba(255,255,255,.14); color: #fff;
  border-radius: 20px; padding: 7px 14px; font-size: 13px; font-weight: bold;
}
.hdr-btn:hover { background: rgba(255,255,255,.26); }

.hero { max-width: 760px; margin: 0 auto; padding: 28px 20px 6px; }
.hero-lead { font-size: 15px; line-height: 2.05; color: #3a362f; }
.hero-lead b { color: var(--ink); font-weight: bold; }

#homeTeaser {
  display: block; margin: 16px 0 0; padding: 13px 16px 14px;
  background: #fff; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0;
  font-size: 13px; line-height: 1.9; color: #6b6459; text-decoration: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
#homeTeaser:hover { background: #fbf7f4; }
#homeTeaser .tq { color: var(--accent); font-weight: bold; }
#homeTeaser .tmore { display: block; margin-top: 8px; color: var(--accent); font-weight: bold; font-size: 12.5px; }

a.cta {
  display: block; margin: 18px auto 0; max-width: 340px; padding: 13px; text-align: center;
  background: var(--accent); color: #fff; border-radius: 10px; text-decoration: none;
  font-weight: bold; font-size: 15px;
}
a.cta:hover { background: #d9536b; }

.coverage { max-width: 940px; margin: 0 auto; padding: 24px 20px 6px; }
#homeStats {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #e5e0d8; border-radius: 12px; padding: 16px 18px;
}
#homeStats .stat { flex: 1; text-align: center; min-width: 72px; }
#homeStats .num { font-size: 26px; font-weight: bold; color: var(--ink); line-height: 1.1; }
#homeStats .num small { font-size: 13px; font-weight: bold; margin-left: 2px; color: var(--muted); }
#homeStats .lbl { font-size: 11px; color: var(--muted); margin-top: 3px; }
#homeStats .cov { flex-basis: 100%; text-align: center; font-size: 11px; color: #a49f95; margin-top: 6px; }
#homeMap {
  height: 56vh; min-height: 340px; margin-top: 14px;
  border-radius: 12px; overflow: hidden; border: 1px solid #ddd; background: #dfe6ea;
}
.coverage-cap { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; }

.serial { max-width: 760px; margin: 0 auto; padding: 22px 20px 6px; }
.sec-h {
  font-size: 13px; font-weight: bold; color: var(--muted); letter-spacing: .04em;
  margin-bottom: 4px; padding-bottom: 8px; border-bottom: 1px solid #e5e0d8;
}
#homeList { list-style: none; }
#homeList a {
  display: flex; gap: 12px; align-items: baseline; text-decoration: none; color: var(--ink);
  padding: 12px; border-radius: 8px; border-bottom: 1px solid #efe9df;
}
#homeList a:hover { background: #efe9e1; }
#homeList .h-date { font-size: 11px; color: #999; flex: 0 0 auto; width: 84px; }
#homeList .h-emoji { flex: 0 0 auto; font-size: 16px; }
#homeList .h-line { font-weight: bold; font-size: 14px; }
#homeList .h-co { font-size: 11px; color: var(--muted); }
.home-line-tip b { color: var(--ink); }

.site-footer {
  margin-top: 28px; background: var(--ink); color: #c9c2b6;
  padding: 30px 20px max(30px, env(safe-area-inset-bottom));
}
.site-footer > div { max-width: 760px; margin-left: auto; margin-right: auto; }
.foot-about { font-size: 13px; line-height: 1.95; color: #e7e2d8; }
.foot-credit { margin-top: 16px; font-size: 11px; opacity: .72; line-height: 1.8; }
.foot-credit a { color: inherit; text-decoration: underline; }
.foot-copy { margin-top: 14px; font-size: 11px; opacity: .5; }

@media (max-width: 720px) {
  #homeMap { height: 48vh; min-height: 300px; }
  .hero { padding-top: 22px; }
}

/* 路線ピッカー (アーカイブシートと同じ土台) */
#pickSheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
#pickSheet.hidden { display: none; }
.pick-search { padding: 12px 14px 6px; }
.pick-search input {
  width: 100%; padding: 10px 12px; border: 1px solid #cfc7ba; border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
#pickList { list-style: none; overflow-y: auto; padding: 6px 8px 8px; flex: 1; }
#pickList li button {
  width: 100%; text-align: left; display: flex; align-items: baseline; gap: 10px;
  background: transparent; color: var(--ink); border-radius: 8px; padding: 10px 12px;
  font-weight: normal; flex: 1;
}
#pickList li button:hover { background: #e9e4dc; }
#pickList .p-line { font-weight: bold; font-size: 14px; }
#pickList .p-co { font-size: 11px; color: var(--muted); }
#pickList .p-n { font-size: 11px; color: #aaa; margin-left: auto; flex: 0 0 auto; }
.pick-note { font-size: 11px; color: var(--muted); padding: 8px 16px 14px; border-top: 1px solid #e5e0d8; }
#pickList .pick-msg { padding: 12px; color: #999; font-size: 12px; list-style: none; }

/* 生成中オーバーレイ */
#genOverlay {
  position: fixed; inset: 0; background: rgba(20,26,32,.72);
  display: flex; align-items: center; justify-content: center; z-index: 2500;
}
#genOverlay.hidden { display: none; }
.gen-box {
  background: var(--paper); border-radius: 14px; padding: 28px 30px 22px;
  width: min(360px, 88vw); text-align: center;
}
.gen-emoji { font-size: 44px; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.gen-line { font-weight: bold; margin-top: 8px; color: var(--ink); }
.gen-msg { margin-top: 10px; color: var(--ink2); font-size: 14px; min-height: 20px; }
.gen-steps { margin-top: 12px; text-align: left; font-size: 12px; color: var(--muted); line-height: 1.9; max-height: 180px; overflow-y: auto; }
.gen-steps .err { color: #c0392b; }
.gen-box button { margin-top: 16px; }

/* 共有シート */
#shareSheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
#shareSheet.hidden { display: none; }
.share-grid { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px 20px; }
.share-btn { padding: 13px; border-radius: 10px; font-size: 15px; font-weight: bold; color: #fff; }
.share-btn.x { background: #000; }
.share-btn.x:hover { background: #222; }
.share-btn.line { background: #06c755; }
.share-btn.line:hover { background: #05b34c; }
.share-btn.fb { background: #1877f2; }
.share-btn.fb:hover { background: #1467d8; }
.share-btn.copy { background: #c9c2b6; color: #443f38; }
.share-btn.copy:hover { background: #bdb5a6; }

/* トースト */
#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 24px;
  font-size: 13px; z-index: 4000; box-shadow: 0 4px 16px rgba(0,0,0,.3);
  transition: opacity .3s; opacity: 1;
}
#toast.hidden { opacity: 0; pointer-events: none; }

#loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--paper); color: var(--muted); font-size: 14px; z-index: 3000;
}
#loading.hidden { display: none; }

/* モバイル: 縦積み (地図上 / 日記下) */
@media (max-width: 720px) {
  #app { flex-direction: column; }
  #map { flex: 0 0 42vh; }
  #panel { width: 100%; max-width: none; flex: 1; border-left: none; border-top: 1px solid #ddd; }
  header { padding-top: max(14px, env(safe-area-inset-top)); }
}
