:root {
  --moss: #4f7a4a;
  --moss-dark: #2f4a32;
  --leaf: #8fbf6a;
  --soil: #6b4a33;
  --cream: #f6f1e3;
  --ink: #233024;
  --glass: rgba(255, 255, 255, 0.16);
  --glass-border: rgba(255, 255, 255, 0.35);
  --gold: #f3c34b;
  --r-blue: #5aa3e0;
  --danger: #c4553f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 30% 20%, #3b5a3c, #1a2a1c 70%);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--cream);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#phone {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #3f6343 0%, #2b4530 55%, #1f3324 100%);
}

@media (min-width: 600px) {
  body { display: flex; align-items: center; justify-content: center; }
  #phone {
    width: min(420px, calc((100vh - 40px) * 9 / 16));
    height: min(calc(100vh - 40px), 820px);
    aspect-ratio: 9 / 16;
    border-radius: 38px;
    border: 10px solid #111;
    box-shadow: 0 30px 80px rgba(0,0,0,.55), inset 0 0 0 2px #333;
  }
}

/* ---------- 狀態列 ---------- */
#statusbar {
  display: flex;
  gap: 6px;
  padding: calc(10px + var(--safe-top)) 10px 8px;
  justify-content: space-between;
  z-index: 3;
}
.stat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  padding: 7px 4px 9px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 600;
  color: var(--cream);
  white-space: nowrap;
}
.stat .ico { font-size: 14px; }
.stat-btn { cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.stat-btn:active { transform: scale(.95); }
.meter {
  position: absolute;
  left: 10px; right: 10px; bottom: 3px;
  height: 3px;
  border-radius: 3px;
  background: rgba(255,255,255,.2);
  overflow: hidden;
}
#st-hum-bar { height: 100%; width: 60%; background: #7fd3f0; transition: width .4s; }

.chip {
  align-self: center;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(0,0,0,.25);
  color: #d8e8c8;
  letter-spacing: .5px;
  z-index: 3;
}
.chip.ai { background: rgba(243,195,75,.25); color: #ffe7a6; }

/* ---------- 主舞台 ---------- */
#stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: pointer;
}

.banner {
  position: absolute;
  left: 14px; right: 14px; top: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 248, 225, .92);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  border-left: 6px solid var(--gold);
  animation: bannerIn .45s cubic-bezier(.2,1.4,.4,1);
  z-index: 4;
}
.banner-title { font-weight: 800; font-size: 15px; margin-bottom: 3px; }
.banner-text { font-size: 13px; line-height: 1.5; }
@keyframes bannerIn { from { transform: translateY(-30px) scale(.9); opacity: 0; } }

.toast {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translateX(-50%);
  max-width: 86%;
  padding: 9px 16px;
  border-radius: 20px;
  background: rgba(20, 30, 20, .85);
  color: var(--cream);
  font-size: 13px;
  text-align: center;
  z-index: 4;
  animation: fadeUp .3s ease-out;
}
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 10px); } }

.hidden { display: none !important; }

/* ---------- 工具列 ---------- */
#toolbar {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 8px calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,0,.35));
  z-index: 3;
}
.tool {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px;
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--cream);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: transform .12s;
}
.tool:active { transform: scale(.9); }
.tool-ico { font-size: 22px; line-height: 1; }
.tool-main {
  flex: 1.3;
  transform: translateY(-6px);
  padding: 12px 2px;
  background: radial-gradient(circle at 40% 30%, #a6d97f, var(--moss));
  border-color: #d4f0b8;
  box-shadow: 0 6px 18px rgba(143,191,106,.45);
  font-weight: 700;
}
.tool-main .tool-ico { font-size: 28px; }
.tool-main:active { transform: translateY(-6px) scale(.92); }

/* ---------- Modal ---------- */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 10, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%;
  max-height: 86%;
  overflow-y: auto;
  padding: 18px 18px calc(20px + var(--safe-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--cream);
  color: var(--ink);
  animation: slideUp .3s cubic-bezier(.2,.9,.3,1.1);
}
.sheet-center {
  align-self: center;
  width: 88%;
  border-radius: 26px;
  text-align: center;
  padding-bottom: 20px;
}
@keyframes slideUp { from { transform: translateY(60px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.close {
  border: none; background: rgba(0,0,0,.07); width: 32px; height: 32px;
  border-radius: 50%; font-size: 15px; cursor: pointer; color: var(--ink);
}
.sub { margin: 4px 0 12px; font-size: 12px; color: #6a7a62; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.btn {
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid #cfc6ac;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--moss); border-color: var(--moss); color: #fff; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
hr { border: none; border-top: 1px dashed #d4caa9; margin: 18px 0 4px; }

/* 辨識動畫 */
.scan-anim {
  position: relative;
  width: 180px; height: 180px;
  margin: 8px auto 12px;
  border-radius: 50%;
  overflow: hidden;
  background: #dfe9d2;
}
.scan-anim img { width: 100%; height: 100%; object-fit: cover; opacity: .85; }
.scan-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 5px solid transparent;
  border-top-color: var(--moss);
  border-right-color: var(--leaf);
  animation: spin 1s linear infinite;
  z-index: 2;
}
.scan-line {
  position: absolute; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, transparent, #b8ff8a, transparent);
  box-shadow: 0 0 12px #b8ff8a;
  animation: scanY 1.2s ease-in-out infinite alternate;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scanY { from { top: 6%; } to { top: 92%; } }
.scan-text { font-weight: 700; margin: 0; }

/* 物種卡 */
.card {
  border-radius: 18px;
  padding: 14px;
  background: linear-gradient(160deg, #fffdf5, #efe7cf);
  border: 2px solid #d9cfae;
  text-align: left;
}
.card.rar-R { border-color: var(--r-blue); }
.card.rar-SR {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(243,195,75,.3), 0 0 24px rgba(243,195,75,.5);
}
.card-top { display: flex; align-items: center; gap: 12px; }
.card-top canvas { width: 84px; height: 84px; border-radius: 16px; background: #e4ecd8; flex: none; }
.card-name { font-size: 19px; font-weight: 800; }
.card-sci { font-size: 12px; font-style: italic; color: #6a7a62; }
.rar {
  display: inline-block;
  font-size: 11px; font-weight: 800;
  padding: 1px 8px; border-radius: 8px;
  color: #fff; background: #8d958a;
  margin-right: 4px;
}
.rar.R { background: var(--r-blue); }
.rar.SR { background: linear-gradient(90deg, #f0a93b, #f6d36b); }
.tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11px; padding: 3px 8px; border-radius: 10px;
  background: #e2ead4; color: #3f5a3a;
}
.card p { font-size: 13px; line-height: 1.55; margin: 8px 0 0; }
.card .label { font-weight: 800; color: var(--moss-dark); }
.new-badge {
  display: inline-block; margin-bottom: 8px; font-weight: 800; color: var(--moss);
  animation: pop .6s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

/* 圖鑑 */
.dex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dex-item {
  position: relative;
  border-radius: 14px;
  padding: 8px 4px 6px;
  background: #fff;
  border: 2px solid #e4dbc0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.dex-item canvas { width: 64px; height: 64px; display: block; margin: 0 auto 4px; }
.dex-item.rar-R { border-color: var(--r-blue); }
.dex-item.rar-SR { border-color: var(--gold); }
.dex-item.locked { opacity: .45; filter: grayscale(1); cursor: default; }
.dex-item .heart { font-size: 10px; color: #c4553f; font-weight: 600; }
.dex-detail .back {
  border: none; background: none; color: var(--moss); font: inherit; font-weight: 700;
  padding: 0 0 10px; cursor: pointer;
}
.knowledge {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: #fff6d8; font-size: 12px; line-height: 1.5;
}

/* 測驗 */
.quiz-head { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; }
.quiz-head canvas { width: 48px; height: 48px; }
.quiz-q { font-size: 16px; font-weight: 700; line-height: 1.5; margin: 12px 0; }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; }
.quiz-opts .btn { text-align: left; }
.quiz-opts .btn.correct { background: #dff2cf; border-color: var(--moss); }
.quiz-opts .btn.wrong { background: #f8dcd4; border-color: var(--danger); }
.quiz-result { margin: 12px 0 0; font-size: 13px; line-height: 1.55; text-align: left; }
#quiz-done { margin-top: 12px; width: 100%; }

/* 設定 */
.field { display: block; margin-top: 14px; font-size: 13px; font-weight: 700; }
.field input, .field select {
  display: block; width: 100%; margin-top: 6px;
  padding: 11px 12px; border-radius: 12px;
  border: 1px solid #cfc6ac; background: #fff;
  font: inherit; font-size: 14px; color: var(--ink);
  user-select: text; -webkit-user-select: text;
}
.hint { font-size: 12px; color: #6a7a62; line-height: 1.5; margin-top: 10px; }
.hint a { color: var(--moss); font-weight: 700; }

/* ---------- v1.0 完整版介面 ---------- */
.ico-img { width: 1.35em; height: 1.35em; object-fit: contain; vertical-align: middle; }
.tool-ico .ico-img { width: 30px; height: 30px; }
.tool-main .tool-ico .ico-img { width: 38px; height: 38px; }
.stat .ico .ico-img { width: 18px; height: 18px; }
.tool { position: relative; }
.dot { position: absolute; top: 6px; right: 14px; width: 9px; height: 9px; border-radius: 50%; background: #ff5a4f; box-shadow: 0 0 0 2px rgba(0,0,0,.2); }
.big-btn .dot { top: 8px; right: 10px; }

#globe-nav { display: flex; align-items: center; justify-content: center; gap: 8px; z-index: 3; }
.globe-chip {
  border: 1px solid var(--glass-border); background: rgba(0,0,0,.25); color: #f0f7e6;
  font: inherit; font-size: 13px; font-weight: 700; padding: 5px 14px; border-radius: 20px; cursor: pointer;
}
.nav-arrow {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--glass-border);
  background: var(--glass); color: var(--cream); font-size: 20px; line-height: 1; cursor: pointer;
}
.globe-lock {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 25, 15, .45); z-index: 2;
}
.lock-card {
  width: 80%; padding: 18px; border-radius: 22px; background: rgba(246,241,227,.96); color: var(--ink); text-align: center;
}
.lock-title { font-size: 18px; font-weight: 800; }
.lock-card p { font-size: 13px; line-height: 1.6; }
.lock-note { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: #fff1d6; color: #7a4a12; font-size: 13px; line-height: 1.55; }
.ok-note { padding: 10px 12px; border-radius: 12px; background: #e3f1d6; color: #2f4a32; font-size: 13px; line-height: 1.55; }

.sheet-tall { max-height: 92%; }
.sheet-scroll { max-height: 88vh; overflow-y: auto; }
.sheet h3 { font-size: 15px; margin: 18px 0 8px; color: var(--moss-dark); }
.center { text-align: center; }
.row.wrap { flex-wrap: wrap; }
.btn.small { flex: none; padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.col-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.big-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.big-btn {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 8px; border-radius: 18px; border: 1px solid #d9cfae; background: #fff;
  font: inherit; font-size: 14px; font-weight: 700; color: var(--ink); cursor: pointer;
}
.big-btn > span { font-size: 30px; line-height: 1; }
.big-btn > span .ico-img { width: 40px; height: 40px; }
.big-btn:active { transform: scale(.96); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0; padding-bottom: 2px; }
.tab {
  flex: none; border: 1px solid #d9cfae; background: #fff; border-radius: 16px; padding: 6px 12px;
  font: inherit; font-size: 13px; color: var(--ink); cursor: pointer;
}
.tab.on { background: var(--moss); border-color: var(--moss); color: #fff; font-weight: 700; }

.pick-top { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.pick-top img { width: 92px; height: 92px; object-fit: cover; border-radius: 14px; flex: none; }
.pick-top .sub { margin: 0; }
#pick-search {
  width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid #cfc6ac;
  font: inherit; font-size: 14px; user-select: text; -webkit-user-select: text;
}
.pick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pick-item {
  position: relative; border-radius: 14px; border: 2px solid #e4dbc0; background: #fff; padding: 6px 2px;
  font: inherit; font-size: 12px; font-weight: 700; color: var(--ink); cursor: pointer;
}
.pick-item canvas { width: 60px; height: 60px; display: block; margin: 0 auto 2px; }
.pick-item.rar-R { border-color: var(--r-blue); }
.pick-item.rar-SR { border-color: var(--gold); }
.got { position: absolute; top: 4px; right: 4px; font-style: normal; font-size: 9px; background: var(--moss); color: #fff; border-radius: 6px; padding: 1px 4px; }

.knowledge.locked { background: #eee8d8; color: #8a8a7a; }
.knowledge + .knowledge { margin-top: 8px; }

.journal-list { display: flex; flex-direction: column; gap: 8px; }
.journal-item {
  display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 14px;
  border: 1px solid #e4dbc0; background: #fff; font: inherit; color: var(--ink); text-align: left; cursor: pointer;
}
.jthumb { width: 56px; height: 56px; border-radius: 12px; background: #e4ecd8 center/cover no-repeat; flex: none; overflow: hidden; }
.jthumb canvas { width: 56px; height: 56px; }
.jtext { flex: 1; display: flex; flex-direction: column; font-size: 14px; }
.jtext span { font-size: 12px; color: #6a7a62; }
.jarrow { font-size: 22px; color: #a9a089; }
.jphoto { width: 100%; border-radius: 16px; margin-bottom: 10px; }
.share-img { width: 100%; border-radius: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

.mission-list { display: flex; flex-direction: column; gap: 8px; }
.mission { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: #fff; border: 1px solid #e4dbc0; }
.mission > div { flex: 1; font-size: 14px; }
.mission.claimed { opacity: .6; }
.bar { height: 6px; border-radius: 4px; background: #eee6cf; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--leaf); }
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 14px; background: #fff; border: 1px solid #e4dbc0; text-align: center; font-size: 12px; }
.badge span { font-size: 10px; color: #6a7a62; line-height: 1.35; }
.badge .prog { font-weight: 700; color: var(--moss); }
.badge-img { width: 56px; height: 56px; object-fit: contain; }
.badge-emoji { font-size: 40px; }
.dim { filter: grayscale(1); opacity: .35; }

.upgrade { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: #fff; border: 1px solid #e4dbc0; }
.upgrade > div { flex: 1; display: flex; flex-direction: column; }
.upgrade .sub { margin: 2px 0 0; }
.decor-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.decor-item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 14px; background: #fff; border: 1px solid #e4dbc0; font-size: 12px; text-align: center; }
.decor-item .btn.small { padding: 5px 6px; font-size: 11px; }
.decor-img { width: 52px; height: 52px; object-fit: contain; }
.decor-emoji { font-size: 34px; }

.acct-box p { font-size: 13px; line-height: 1.6; margin: 6px 0; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.5; margin-top: 8px; }
.pair-code { font-size: 40px; font-weight: 900; letter-spacing: 8px; color: var(--moss-dark); margin: 16px 0; }
.dex-item canvas { width: 64px; height: 64px; }
.card-top canvas { width: 96px; height: 96px; }

/* ---------- v1.0 美術圖示 ---------- */
.ei { width: 1.15em; height: 1.15em; vertical-align: -0.22em; margin: 0 1px; }
.hab-ico { width: 1.5em; height: 1.5em; border-radius: 50%; object-fit: cover; vertical-align: -0.38em; margin-right: 6px; border: 2px solid rgba(255,255,255,0.7); box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.globe-chip .gn-sub { margin-left: 10px; opacity: 0.85; font-weight: 600; }
.h-ico { display: inline-block; width: 1.35em; height: 1.35em; vertical-align: -0.3em; margin-right: 6px; }
.h-ico img, .decor-ico img { width: 100%; height: 100%; object-fit: contain; }
.decor-ico { display: inline-block; width: 40px; height: 40px; }
.big-btn [data-icon] { display: inline-block; width: 40px; height: 40px; }
.big-btn [data-icon] img { width: 100%; height: 100%; object-fit: contain; }
.heart .hab-ico { width: 1.6em; height: 1.6em; margin: 0; opacity: 0.75; }
