/* 華城昆蟲圖鑑 — 野外筆記本風 */
:root {
  --paper: #EEF3E6;
  --paper-2: #E2EAD6;
  --ink: #1F2A1C;
  --ink-2: #5B6854;
  --line: #C9D4BA;
  --shutter: #D23F2E;
  --r1: #9AA39B;  /* 常見 */
  --r2: #5FAE63;  /* 少見 */
  --r3: #3F7FD6;  /* 稀有 */
  --r4: #E0A526;  /* 傳說 */
  --hand: "LXGW WenKai TC", "Noto Sans TC", sans-serif;
  --sans: "Noto Sans TC", system-ui, sans-serif;
  --tabs-h: 72px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); -webkit-tap-highlight-color: transparent; }
/* 不用 position:fixed（iOS Safari 捲動時會跑位），改成整頁 flex、只有 main 捲動 */
html, body { height: 100%; overflow: hidden; }
body { height: 100dvh; display: flex; flex-direction: column; }
.top { flex: none; }
.view { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3 { font-family: var(--hand); font-weight: 700; margin: 0; }

.top { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 16px 6px; }
.brand { font-size: 22px; letter-spacing: .04em; }
.who { width: 36px; height: 36px; border-radius: 50%; background: var(--paper-2); font-family: var(--hand); font-size: 17px; border: 1.5px solid var(--line); }

.view { padding: 8px 16px 32px; width: 100%; max-width: 720px; margin: 0 auto; box-sizing: border-box; }
.view h2 { font-size: 20px; margin: 18px 0 10px; }
.muted { color: var(--ink-2); font-size: 13px; }

/* 底部分頁 */
.tabs { flex: none; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: 1fr 1fr 88px 1fr 1fr; align-items: center; background: #fff; border-top: 1.5px solid var(--line); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--ink-2); font-family: var(--hand); }
.tabs a .ico { font-size: 20px; line-height: 1; }
.tabs a.on { color: var(--ink); }
.shutter { align-self: start; margin-top: -22px; }
.shutter span { display: block; width: 68px; height: 68px; border-radius: 50%; background: var(--shutter); border: 5px solid #fff; box-shadow: 0 0 0 1.5px var(--line), 0 4px 10px rgba(31,42,28,.18); position: relative; }
.shutter span::after { content: ""; position: absolute; inset: 14px; border-radius: 50%; border: 2.5px solid rgba(255,255,255,.85); }
.shutter span::before { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; background: #1F2A1C; left: 50%; top: 50%; transform: translate(-50%,-50%); }

/* 首頁 */
.progress { background: #fff; border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.progress .big { font-family: var(--hand); font-size: 34px; line-height: 1; }
.progress .big small { font-size: 16px; color: var(--ink-2); }
.bar { height: 10px; border-radius: 6px; background: var(--paper-2); overflow: hidden; margin: 10px 0 6px; }
.bar i { display: block; height: 100%; background: var(--r2); border-radius: 6px; transition: width .6s ease; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); }
.pill.rare { background: #E4ECF9; color: #2B5AA6; }
.pill.gold { background: #FBF0D1; color: #8A6410; }

.hscroll { display: flex; gap: 10px; overflow-x: auto; padding: 4px 0 8px; scroll-snap-type: x mandatory; }
.hscroll > * { scroll-snap-align: start; flex: 0 0 120px; }

.season { border-radius: 16px; padding: 14px 16px; background: linear-gradient(135deg, #DCE9C8, #EEF3E6); border: 1.5px solid var(--line); }
.season h3 { font-size: 17px; }

/* 卡牌 */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card { position: relative; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden; background: #fff; border: 1.5px solid var(--line); display: flex; flex-direction: column; }
.card.unknown { background: var(--paper-2); border-style: dashed; align-items: center; justify-content: center; }
.card.unknown .q { font-family: var(--hand); font-size: 48px; color: var(--ink-2); opacity: .55; line-height: 1; }
.card.unknown .cat { font-size: 11px; color: var(--ink-2); margin-top: 8px; }
.card img { width: 100%; flex: 1; object-fit: cover; min-height: 0; }
.card .name { font-family: var(--hand); font-size: 14px; padding: 6px 8px 7px; background: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { position: absolute; top: 7px; right: 7px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.08); }
.dot.r1 { background: var(--r1); } .dot.r2 { background: var(--r2); } .dot.r3 { background: var(--r3); } .dot.r4 { background: var(--r4); }
.card.new::before { content: "新"; position: absolute; top: 6px; left: 6px; z-index: 1; font-family: var(--hand); font-size: 12px; background: var(--shutter); color: #fff; border-radius: 6px; padding: 1px 6px; }

/* 翻牌動畫 */
.flip { perspective: 900px; }
.flip .inner { transition: transform .9s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.flip.go .inner { transform: rotateY(180deg); }
.flip .face { backface-visibility: hidden; }
.flip .back { position: absolute; inset: 0; transform: rotateY(180deg); aspect-ratio: auto; height: 100%; }

/* 篩選列 */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; }
.filters button { flex: 0 0 auto; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; }
.filters button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--ink-2); margin: 4px 0 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* 物種頁 */
.hero { border-radius: 18px; overflow: hidden; border: 1.5px solid var(--line); background: #fff; }
.hero img { width: 100%; display: block; aspect-ratio: 4 / 3; object-fit: cover; }
.hero .meta { padding: 12px 14px 14px; }
.hero .meta h2 { margin: 0 0 2px; font-size: 24px; }
.sci { font-style: italic; color: var(--ink-2); font-size: 13px; }
.fact { background: var(--paper-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; line-height: 1.5; }
.wall { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.wall img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.map { height: 50vh; border-radius: 16px; overflow: hidden; border: 1.5px solid var(--line); }
.map.small { height: 220px; }
.backlink { font-size: 14px; color: var(--ink-2); display: inline-block; margin: 6px 0; }

/* 相簿 */
.month { margin: 14px 0 6px; font-family: var(--hand); font-size: 16px; }

/* 拍照流程 sheet */
.sheet { position: fixed; inset: 0; background: rgba(31,42,28,.45); display: flex; align-items: flex-end; z-index: 20; }
.sheet .panel { width: 100%; max-height: 92vh; overflow: auto; background: var(--paper); border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet .preview { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 12px; background: #000; }
.cand { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; margin-top: 8px; width: 100%; text-align: left; }
.cand.on { border-color: var(--ink); background: #fff; box-shadow: inset 0 0 0 1px var(--ink); }
.cand .n { font-family: var(--hand); font-size: 17px; }
.cand .c { margin-left: auto; font-size: 12px; color: var(--ink-2); }
.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; font-size: 16px; font-family: var(--hand); background: var(--ink); color: #fff; margin-top: 12px; text-align: center; }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn[disabled] { opacity: .5; }
.field { margin-top: 10px; }
.field input, .field select { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font: inherit; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: sp .8s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30; }

.empty { text-align: center; color: var(--ink-2); padding: 40px 0; font-family: var(--hand); font-size: 16px; }

@media (prefers-reduced-motion: reduce) { .flip .inner, .bar i { transition: none; } }

/* 圖鑑分組與卡名 */
.rgroup { margin-bottom: 18px; }
.rhead { display: flex; align-items: center; gap: 6px; font-family: var(--hand); font-size: 17px; margin: 6px 0 8px; }
.rhead .dot { width: 12px; height: 12px; }
.cardwrap { display: flex; flex-direction: column; gap: 4px; }
.cname { font-family: var(--hand); font-size: 13px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.found .done { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(31,42,28,.62); color: #fff; font-size: 11px; text-align: center; padding: 3px 0; font-family: var(--hand); }
.card.found img { flex: 1; }
