/* レイアウト: 地図が全画面。上に成績のHUD、右下に撮影ボタン、下にタブ、タブの上に引き出しシート */
:root {
  --bg: #f3f4f1;          /* 紙 */
  --surface: #ffffffee;
  --surface-solid: #ffffff;
  --ink: #16191d;         /* 文字 */
  --muted: #5d646c;
  --line: #d9dcd6;
  --fill: #127a86;        /* 塗ったメッシュ（現像液の青緑） */
  --fill-ink: #ffffff;
  --target: #e8a700;      /* ガチャの的（フレームラインの黄色） */
  --ok: #2f8a4c;
  --danger: #c2412d;
  --grid: #16191d;
  --shadow: 0 2px 10px #0000001f;
  --f-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --tabs-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --surface: #1a1f25ee; --surface-solid: #1a1f25; --ink: #eceeea; --muted: #9aa2aa; --line: #2e353d;
    --fill: #2bb3bf; --fill-ink: #06272b; --target: #ffc531; --ok: #5cc27a; --danger: #ef7a63; --grid: #eceeea;
    --shadow: 0 2px 12px #00000066; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --surface: #1a1f25ee; --surface-solid: #1a1f25; --ink: #eceeea; --muted: #9aa2aa; --line: #2e353d;
  --fill: #2bb3bf; --fill-ink: #06272b; --target: #ffc531; --ok: #5cc27a; --danger: #ef7a63; --grid: #eceeea;
  --shadow: 0 2px 12px #00000066; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.6 var(--f-body); -webkit-tap-highlight-color: transparent; overflow: hidden; }
button, input, label { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--target); outline-offset: 2px; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

#map { position: fixed; inset: 0; background: var(--bg); }
.leaflet-container { font-family: var(--f-body); background: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .base-pale .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92); } }
:root[data-theme="dark"] .base-pale .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92); }
.leaflet-control-attribution { font-size: 10px; background: var(--surface) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-bottom { bottom: calc(var(--tabs-h) + var(--sab)); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-solid); color: var(--ink); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; min-width: 200px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

/* HUD */
.hud { position: fixed; z-index: 1000; top: calc(var(--sat) + 10px); left: max(12px, var(--sal)); right: max(12px, var(--sar)); display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.hud > * { pointer-events: auto; }
.stats { display: flex; gap: 2px; background: var(--surface); backdrop-filter: blur(8px); border-radius: 12px; box-shadow: var(--shadow); padding: 6px 4px; min-width: 0; }
.stat { display: flex; flex-direction: column; align-items: center; padding: 0 10px; line-height: 1.15; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat b { font-family: var(--f-mono); font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10.5px; color: var(--muted); letter-spacing: .04em; white-space: nowrap; }
.icon-btn { margin-left: auto; width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; }
.popover { position: absolute; right: 0; top: 52px; background: var(--surface-solid); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; display: grid; gap: 8px; width: 220px; }
.popover fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 4px; }
.popover legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.popover label { display: flex; gap: 8px; align-items: center; min-height: 30px; }
.popover .check { border-top: 1px solid var(--line); padding-top: 6px; }
.popover .check + .check { border-top: 0; padding-top: 0; }

/* ガチャのチップ（地図上） */
.gacha-chip { position: fixed; z-index: 999; top: calc(var(--sat) + 68px); left: max(12px, var(--sal)); max-width: calc(100% - 24px); display: flex; gap: 8px; align-items: baseline; background: var(--surface); backdrop-filter: blur(8px); border: 2px solid var(--target); border-radius: 10px; padding: 6px 12px; box-shadow: var(--shadow); cursor: pointer; }
.gacha-chip b { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip-label { font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.gacha-chip .mono { font-size: 12px; color: var(--muted); white-space: nowrap; }

.pick-banner { position: fixed; z-index: 1001; top: calc(var(--sat) + 10px); left: max(12px, var(--sal)); right: max(12px, var(--sar)); display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--target); color: #1b1600; border-radius: 12px; padding: 10px 14px; font-weight: 700; box-shadow: var(--shadow); }

/* 右下のボタン */
.fabs { position: fixed; z-index: 1000; right: max(12px, var(--sar)); bottom: calc(var(--tabs-h) + var(--sab) + 24px); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.fab { display: inline-flex; gap: 8px; align-items: center; height: 48px; padding: 0 18px; border-radius: 24px; border: 0; background: var(--surface-solid); color: var(--ink); box-shadow: var(--shadow); font-weight: 700; cursor: pointer; user-select: none; }
.fab.small { width: 48px; padding: 0; justify-content: center; }
.fab.primary { background: var(--fill); color: var(--fill-ink); height: 56px; padding: 0 22px; border-radius: 28px; font-size: 16px; }
.fab:active { transform: scale(.97); }
body.sheet-open .fabs { display: none; }

/* 下のタブ */
.tabs { position: fixed; z-index: 1002; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + var(--sab)); padding: 0 max(8px, var(--sar)) var(--sab) max(8px, var(--sal)); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-solid); border-top: 1px solid var(--line); }
.tab { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tab[aria-current="page"] { color: var(--ink); font-weight: 700; }
.tab[aria-current="page"] svg { color: var(--fill); }

/* 引き出しシート */
.sheet { position: fixed; z-index: 1001; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--sab)); max-height: min(64dvh, 640px); overflow-y: auto; overscroll-behavior: contain; background: var(--surface-solid); border-radius: 18px 18px 0 0; box-shadow: 0 -4px 20px #0000002a; padding-block: 18px 24px; padding-left: max(16px, var(--sal)); padding-right: max(16px, var(--sar)); }
.view { display: grid; gap: 16px; max-width: 640px; margin: 0 auto; }
.view h2 { font-size: 18px; margin: 0; text-wrap: balance; }
.view h3 { font-size: 12px; margin: 4px 0 0; color: var(--muted); letter-spacing: .1em; font-weight: 500; }
.lead { margin: 0; color: var(--muted); font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-solid); font-weight: 700; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--fill); border-color: var(--fill); color: var(--fill-ink); }
.btn.big { min-height: 54px; font-size: 17px; width: 100%; }
.btn.danger { color: var(--danger); }
.text-btn { border: 0; background: none; padding: 6px 4px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { flex: 1; text-align: center; padding: 8px 4px; font-size: 13px; cursor: pointer; border-left: 1px solid var(--line); line-height: 1.3; }
.seg label:first-child { border-left: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--ink); color: var(--bg); font-weight: 700; }
.seg small { display: block; font-size: 10.5px; opacity: .75; font-weight: 400; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }
.toggle { display: flex; gap: 10px; align-items: center; min-height: 36px; }

/* ガチャのカード */
.ticket { border: 2px solid var(--target); border-radius: 14px; padding: 16px; display: grid; gap: 10px; position: relative; }
.ticket .cat { font-size: 11px; letter-spacing: .1em; color: var(--muted); }
.ticket .prompt { font-size: 24px; font-weight: 700; line-height: 1.35; text-wrap: balance; }
.ticket .where { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; font-size: 13px; color: var(--muted); }
.ticket .where b { color: var(--ink); font-family: var(--f-mono); font-size: 16px; }
.ticket.done { border-color: var(--ok); }
.stamp { position: absolute; right: 12px; top: 10px; color: var(--ok); border: 2px solid var(--ok); border-radius: 6px; padding: 0 8px; font-weight: 700; transform: rotate(6deg); font-size: 13px; }
@keyframes spin-in { from { transform: translateY(8px) scale(.98); opacity: .2; } to { transform: none; opacity: 1; } }
.ticket.fresh { animation: spin-in .35s ease-out; }
@media (prefers-reduced-motion: reduce) { .ticket.fresh { animation: none; } }

.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.hist li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.hist li span:last-child { color: var(--muted); font-size: 12px; white-space: nowrap; }
.hist .ok { color: var(--ok); font-weight: 700; }

/* シリーズ */
.badges { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.badge { flex: none; width: 74px; display: grid; justify-items: center; gap: 4px; text-align: center; font-size: 11px; line-height: 1.25; color: var(--muted); }
.badge i { width: 54px; height: 54px; display: grid; place-items: center; font-style: normal; font-family: var(--f-mono); font-weight: 500; font-size: 15px; border-radius: 50%; border: 2px dashed var(--line); color: var(--muted); }
.badge.got { color: var(--ink); }
.badge.got i { border: 0; background: var(--fill); color: var(--fill-ink); }
.badge.got.gold i { background: var(--target); color: #1b1600; }
.series { border: 1px solid var(--line); border-radius: 12px; }
.series summary { list-style: none; padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: baseline; cursor: pointer; }
.series summary::-webkit-details-marker { display: none; }
.series .name { font-weight: 700; }
.series .count { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.series .count small { color: var(--muted); }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--fill); border-radius: 3px; }
.series.complete { border-color: var(--target); }
.series.complete .bar > span { background: var(--target); }
.series .desc { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.items { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 14px; }
.item { font-size: 12.5px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: none; }
.item.on { background: var(--fill); border-color: var(--fill); color: var(--fill-ink); font-weight: 700; }

/* 記録 */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
.thumbs button { padding: 0; border: 0; aspect-ratio: 1; max-width: 100%; background: var(--line); border-radius: 4px; overflow: hidden; position: relative; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .ci { display: grid; place-items: center; height: 100%; font-size: 11px; color: var(--muted); gap: 2px; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.summary b { display: block; font-family: var(--f-mono); font-size: 20px; }
.summary span { font-size: 11px; color: var(--muted); }

/* ポップアップ内 */
.pop h4 { margin: 0 0 2px; font-size: 14px; }
.pop .code { font-family: var(--f-mono); font-size: 11px; color: var(--muted); }
.pop-thumbs { display: grid; grid-template-columns: repeat(3, 64px); gap: 4px; margin-top: 8px; }
.pop-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; display: block; }
.pop ul { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12.5px; }
.pop li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-top: 1px solid var(--line); align-items: center; }
.pop li button { border: 0; background: none; color: var(--danger); font-size: 12px; padding: 4px; }

/* モーダル・トースト */
.modal { position: fixed; inset: 0; z-index: 1100; background: #0007; display: grid; place-items: end center; padding: 16px max(16px, var(--sar)) calc(16px + var(--sab)) max(16px, var(--sal)); }
.modal-card { background: var(--surface-solid); border-radius: 16px; padding: 18px; width: min(100%, 460px); display: grid; gap: 12px; max-height: 85dvh; overflow: auto; }
.modal-card h2 { margin: 0; font-size: 17px; }
.modal-card img { max-width: 100%; max-height: 40dvh; border-radius: 8px; display: block; margin: 0 auto; }
.modal-actions { display: grid; gap: 8px; }
.toast { position: fixed; z-index: 1200; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--sab) + 96px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 700; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }
.mesh-label { background: none; border: 0; box-shadow: none; color: var(--ink); font-weight: 700; }
body.sheet-open .toast { bottom: auto; top: calc(var(--sat) + 76px); }
