/* Note: no flex `gap`, no `inset` — keeps older iPad Safari working. */
:root {
  --ink: #1a1a1a;
  --sub: #444;
  --line: #d6d0c4;
  --panel: #f7f5f0;
  --accent: #b5452b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
/* ホーム画面のアプリでは、ページが時計・電池の帯の下まで広がり、iPadOS 26.1 からは画面の上の端がぼかされる。
   上の端に「動かない・透けない・横いっぱい」の板（#top-band）を置くとぼかしが入らない。26.1 は帯の高さを 0 と
   返すことがあるので、ホーム画面のアプリでは少なくとも12pxにする。アプリ全体はその板のすぐ下から始める */
:root { --sat: env(safe-area-inset-top, 0px); }
@media (display-mode: standalone) { :root { --sat: max(env(safe-area-inset-top, 0px), 12px); } }
body { padding-top: var(--sat); }
#top-band { position: fixed; top: 0; left: 0; right: 0; height: 0; height: var(--sat); background: #fff; z-index: 5000; pointer-events: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-size: 17px; color: var(--ink); background: #eee;
  -webkit-text-size-adjust: 100%;
}
button {
  font: inherit; color: inherit; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 12px; font-weight: 700; touch-action: manipulation;
}
button:disabled { opacity: .3; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: #b00020; border-color: #e3b3b9; }
.hidden { display: none !important; }

#app { display: flex; height: 100%; width: 100%; }
#mapWrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
#map { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #e6e6e6; }
#map.white { background: #fff; }
#map.mode-pin .leaflet-grab, #map.mode-text .leaflet-grab, #map.mode-draw .leaflet-grab, #map.mode-erase .leaflet-grab, #map.mode-arrow .leaflet-grab { cursor: crosshair; }
#map.mode-draw, #map.mode-erase { touch-action: none; }
.leaflet-container { font: inherit; }

/* ---- top bar ---- */
#topbar {
  position: absolute; z-index: 1000;
  top: 10px;
  left: 10px; right: 100px;
  display: flex; flex-wrap: wrap; align-items: flex-start;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; margin: 0 8px 8px 0; }
.box { display: flex; align-items: center; background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.22); overflow: hidden; }
#searchForm { display: flex; background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.22); width: 360px; max-width: 100%; }
#q { flex: 1; min-width: 0; border: 0; font: inherit; font-size: 18px; padding: 10px 12px; border-radius: 12px 0 0 12px; background: transparent; -webkit-appearance: none; outline: none; }
#searchForm button { border: 0; border-left: 1px solid var(--line); border-radius: 0 12px 12px 0; }
#results {
  position: absolute; top: 52px; left: 0; width: 400px; max-width: calc(100% - 8px);
  max-height: 60vh; overflow: auto; -webkit-overflow-scrolling: touch;
  background: #fff; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.28); z-index: 5;
}
#results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #eee; border-radius: 0; padding: 10px 14px; }
#results .r-name { font-size: 18px; font-weight: 800; }
#results .r-detail { font-size: 14px; font-weight: 400; color: var(--sub); }
#results .msg { padding: 12px 14px; color: var(--sub); }
#modes button, #bases button, #drawOpts > button { border: 0; border-radius: 0; border-right: 1px solid var(--line); padding: 10px 12px; }
#modes button:last-child, #bases button:last-child, #drawOpts > button:last-child { border-right: 0; }
#modes button.on { background: var(--ink); color: #fff; }
#colorSw { display: flex; padding: 0 6px; }
.swc { width: 30px; height: 30px; border-radius: 50%; padding: 0; margin: 0 3px; border: 3px solid #fff; box-shadow: 0 0 0 1px #999; }
.swc.on { box-shadow: 0 0 0 3px var(--ink); }
#hint { background: rgba(20,20,20,.85); color: #fff; font-weight: 700; padding: 8px 12px; border-radius: 10px; font-size: 15px; }

#bases { position: absolute; z-index: 1000; left: 10px; bottom: 90px; bottom: calc(90px + env(safe-area-inset-bottom)); }

/* year strip along the bottom of the map */
#yearbar {
  position: absolute; z-index: 1000; left: 10px; right: 54px;
  bottom: 26px; bottom: calc(26px + env(safe-area-inset-bottom));
}
#yearbar > button { flex: none; border: 0; border-radius: 0; border-left: 1px solid var(--line); padding: 12px 12px; white-space: nowrap; }
#yearbar > button:first-child { border-left: 0; }
#yPrev, #yNext { font-size: 24px; line-height: 1; padding: 8px 14px !important; }
#yRef.on { background: #fff3cd; }
#years { flex: 1; min-width: 0; display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; border-left: 1px solid var(--line); }
#years button { flex: none; border: 0; border-radius: 0; border-right: 1px solid #eee; padding: 10px 16px; font-size: 19px; font-weight: 800; white-space: nowrap; }
#years button.on { background: var(--ink); color: #fff; }
#yearTitle { padding: 10px 12px 4px; font-size: 24px; font-weight: 800; border-bottom: 1px solid var(--line); }
.note { margin: 0 0 6px; color: var(--sub); line-height: 1.5; font-size: 15px; }
#bases button.on { background: var(--accent); color: #fff; }
#panelToggle {
  position: absolute; z-index: 1000; right: 10px;
  top: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.22); border: 0; padding: 10px 12px;
}

/* ---- side panel ---- */
#panel {
  width: 380px; flex: none; height: 100%;
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
}
#app.nopanel #panel { display: none; }
.ph { display: flex; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); }
#storySel { flex: 1; min-width: 0; font: inherit; font-size: 19px; font-weight: 800; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.ph button { margin-left: 5px; padding: 8px 10px; }
.pbar { display: flex; flex-wrap: wrap; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.pbar > * { margin: 3px 8px 3px 0; }
.pbar label { font-weight: 700; display: flex; align-items: center; }
.pbar input[type=checkbox] { width: 22px; height: 22px; margin: 0 5px 0 0; }
#list { list-style: none; margin: 0; padding: 8px 0; flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
#list li { position: relative; display: flex; align-items: flex-start; padding: 10px; margin: 0 8px 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
#list li:not(:last-child)::after { content: ""; position: absolute; left: 26px; bottom: -11px; width: 3px; height: 10px; background: #888; }
#list li.sel { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
#list li.empty { display: block; color: var(--sub); cursor: default; line-height: 1.7; font-weight: 600; }
#list .no { flex: none; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; margin-right: 10px; font-size: 16px; }
#list .ev { flex: 1; min-width: 0; }
#list .date { font-weight: 800; color: var(--accent); font-size: 16px; }
#list .title { font-weight: 800; font-size: 19px; line-height: 1.3; word-break: break-word; }
#list .place { font-size: 14px; color: var(--sub); margin-top: 2px; }
#list .memo { margin-top: 6px; white-space: pre-wrap; line-height: 1.5; font-size: 16px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
#list li.sel .memo { display: block; }
#list .ops { flex: none; display: flex; flex-direction: column; margin-left: 6px; }
#list .ops button { padding: 4px 10px; margin-bottom: 4px; font-size: 14px; }
.pf { display: flex; padding: 10px 10px 6px; border-top: 1px solid var(--line); }
.pf button { flex: 1; margin-right: 6px; }
.pf button:last-of-type { margin-right: 0; }

@media (max-width: 820px) {
  #app { flex-direction: column; }
  #panel { width: 100%; height: 45%; border-left: 0; border-top: 1px solid var(--line); padding-top: 0; }
  #searchForm, #results { width: 100%; }
  #topbar { right: 90px; }
}

/* ---- map items ---- */
.num-pin span {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: 16px;
  border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.num-pin.sel span { -webkit-transform: scale(1.25); transform: scale(1.25); box-shadow: 0 0 0 3px #111, 0 2px 6px rgba(0,0,0,.5); }
.txt-label.moving span { outline: 3px dashed #e53935; }
.num-pin.moving span { -webkit-animation: pulse .9s infinite alternate; animation: pulse .9s infinite alternate; }
@-webkit-keyframes pulse { to { -webkit-transform: scale(1.4); } }
@keyframes pulse { to { transform: scale(1.4); } }
.ev-tip { font-weight: 800; font-size: 15px; color: #111; background: rgba(255,255,255,.93); border: 1px solid #aaa; border-radius: 8px; padding: 2px 7px; box-shadow: none; }
.ev-tip::before { display: none; }
.arrow i { display: block; width: 0; height: 0; margin: 3px 0 0 4px; border-left: 13px solid #444; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.txt-label span {
  position: absolute; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);
  white-space: nowrap; font-weight: 800; font-size: 20px; line-height: 1.2; text-align: center;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
}
.txt-label.l span { font-size: 30px; }
.txt-label.ghost span { opacity: .35; }
.num-pin.ghost span { background: #fff; color: #888; border: 3px dashed #aaa; box-shadow: none; opacity: .8; }
.ev-tip.ghost { color: #888; background: rgba(255,255,255,.7); border-style: dashed; }
/* arrowhead whose tip sits exactly on the pointed spot (icon centre), rotating around the tip */
.lb-head i { display: block; width: 0; height: 0; margin: 12px 0 0 2px; border-left: 18px solid #222; border-top: 8px solid transparent; border-bottom: 8px solid transparent; -webkit-transform-origin: 100% 50%; transform-origin: 100% 50%; }
.search-pin span {
  position: absolute; left: 0; top: 0; width: 30px; height: 30px;
  background: #e53935; border: 3px solid #fff; border-radius: 50% 50% 50% 0;
  -webkit-transform: rotate(-45deg); transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
}
.search-pin span::after { content: ""; position: absolute; left: 8px; top: 8px; width: 8px; height: 8px; border-radius: 50%; background: #fff; }

.pop { font-size: 16px; min-width: 200px; }
.pop-date { color: var(--accent); font-weight: 800; }
.pop-title { font-size: 19px; font-weight: 800; line-height: 1.3; }
.pop-place { color: var(--sub); font-size: 14px; margin-top: 2px; }
.pop-memo { white-space: pre-wrap; margin-top: 6px; max-height: 220px; overflow: auto; line-height: 1.5; }
.pop-btns { margin-top: 10px; display: flex; flex-wrap: wrap; }
.pop-btns button { margin: 0 6px 4px 0; padding: 7px 10px; font-size: 15px; }

/* ---- modal / toast ---- */
#modal { position: fixed; top: 0; top: var(--sat); left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.4); z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet { background: #fff; border-radius: 16px; width: 520px; max-width: 100%; max-height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; padding: 18px 18px 14px; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.sheet h2 { margin: 0 0 8px; font-size: 21px; }
.fl { display: block; font-weight: 700; margin: 12px 0 4px; font-size: 15px; color: var(--sub); }
.fi { width: 100%; font: inherit; font-size: 18px; padding: 10px; border: 1px solid #aaa; border-radius: 10px; -webkit-appearance: none; background: #fff; color: var(--ink); }
textarea.fi { min-height: 130px; resize: vertical; line-height: 1.5; }
.row { display: flex; flex-wrap: wrap; align-items: center; }
.row > button { margin: 0 6px 6px 0; }
.row > button.on { background: var(--ink); color: #fff; }
#mBtns { display: flex; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }
#mBtns button { margin: 4px 0 0 8px; padding: 10px 16px; }
#mBtns button.danger { margin: 4px auto 0 0; }
#toast { position: fixed; left: 50%; bottom: 40px; -webkit-transform: translateX(-50%); transform: translateX(-50%); background: rgba(20,20,20,.9); color: #fff; font-weight: 700; padding: 10px 16px; border-radius: 10px; z-index: 4000; opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90%; }
#toast.show { opacity: 1; }

/* ---- year cards in a row, scrolled sideways ---- */
#stack {
  position: fixed; top: 0; top: var(--sat); left: 0; right: 0; bottom: 0; z-index: 2500; overflow: hidden;
  background: #0d1424; background: radial-gradient(ellipse at 50% 40%, #34476e 0%, #141d33 60%, #070b16 100%);
}
#stackScene {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; touch-action: none;
  -webkit-perspective: 1600px; perspective: 1600px;
  -webkit-perspective-origin: 50% 45%; perspective-origin: 50% 45%;
}
#stack .card {
  position: absolute; left: 21%; right: 21%; top: 11%; bottom: 25%;
  background: #fff; border-radius: 14px; overflow: hidden; cursor: pointer;
  box-shadow: 0 20px 60px rgba(0,0,0,.55);
  -webkit-user-select: none; user-select: none;
  transition: transform .45s ease, opacity .45s ease; -webkit-transition: -webkit-transform .45s ease, opacity .45s ease;
}
#stack .card.front { box-shadow: 0 0 0 4px #fff, 0 24px 70px rgba(0,0,0,.6); }
#stack .card-h { position: absolute; top: 0; left: 0; right: 0; height: 52px; z-index: 2; padding: 8px 16px; font-size: 26px; font-weight: 800; background: rgba(255,255,255,.94); border-bottom: 1px solid #ddd; }
#stack .card-map { position: absolute; top: 52px; left: 0; right: 0; bottom: 0; background: #e6e6e6; pointer-events: none; }
#stack .card-map.white { background: #fff; }
#stackTop { position: absolute; z-index: 300; top: 14px; left: 16px; right: 16px; display: flex; align-items: center; justify-content: space-between; color: #fff; }
#stackTitle { font-size: 30px; font-weight: 800; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
#stackSide {
  position: absolute; z-index: 300; left: 16px; right: 16px;
  bottom: 86px; bottom: calc(86px + env(safe-area-inset-bottom));
  display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
#stackSide button { flex: none; margin: 0 4px; background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.3); font-size: 18px; white-space: nowrap; }
/* centred when they fit, still scrollable to both ends when they don't */
#stackSide button:first-child { margin-left: auto; }
#stackSide button:last-child { margin-right: auto; }
#stackSide button.on { background: #fff; color: var(--ink); }
#stackBar { position: absolute; z-index: 300; left: 0; right: 0; bottom: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); display: flex; justify-content: center; flex-wrap: wrap; }
#stackBar button { margin: 0 6px 6px; padding: 12px 18px; font-size: 18px; }
#sClose { color: var(--ink); }
#yRef { max-width: 34%; overflow: hidden; text-overflow: ellipsis; }
#years { min-width: 160px; }
/* 重ねる popup: light backdrop and placed to the side, so the map changes stay visible */
#modal.see-through { background: rgba(0,0,0,.08); justify-content: flex-end; align-items: flex-start; padding-top: 70px; }
#modal.see-through .sheet { width: 440px; }

/* ---- version label and the "new version" bar ---- */
#panel .ver { font-size: 13px; color: var(--sub); text-align: right; padding: 0 12px 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
#upd-bar {
  position: fixed; z-index: 4500; left: 50%; top: 10px; top: calc(10px + var(--sat));
  -webkit-transform: translateX(-50%); transform: translateX(-50%);
  display: flex; align-items: center; background: var(--ink); color: #fff;
  padding: 8px 8px 8px 16px; border-radius: 12px; font-size: 17px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); white-space: nowrap;
}
#upd-bar button { margin-left: 10px; }
#upd-bar button.x { background: transparent; border-color: transparent; color: #fff; }
