:root {
  --paper: #efe6d2;
  --paper2: #e4d7bb;
  --card: #fbf5e8;
  --ink: #3b2c22;
  --ink2: #6b5646;
  --line: #cdbb98;
  --accent: #c2603a;
  --accent-d: #8f4126;
  --gold: #e0b04a;
  --ok: #5f7f45;
  --shadow: 0 6px 24px rgba(50, 30, 15, .25);
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #c9cbb0; color: var(--ink);
  font-family: 'LXGW WenKai TC', 'Klee One', 'Gowun Dodum', serif; user-select: none; -webkit-user-select: none; touch-action: none; }
html[lang="ja"] body { font-family: 'Klee One', 'LXGW WenKai TC', serif; }
html[lang="ko"] body { font-family: 'Gowun Dodum', 'LXGW WenKai TC', sans-serif; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; user-select: none; }
.hidden { display: none !important; }

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); font-size: 28px; z-index: 50; transition: opacity .6s; }
#loading.gone { opacity: 0; pointer-events: none; }

/* ── 共用按鈕 ── */
.big { display: inline-flex; align-items: center; justify-content: center; gap: 10px; font-size: 21px; padding: 11px 28px; border: 0; background: var(--accent); color: #fff6e6;
  border-radius: 8px 20px 10px 22px; box-shadow: 0 5px 0 var(--accent-d); }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-d); }
.big img { width: 30px; height: 30px; margin: -6px 0; }
.mid { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 17px; padding: 8px 20px; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 18px 8px 16px 10px; box-shadow: 0 3px 0 var(--line); }
.mid img { width: 26px; height: 26px; margin: -4px 0; }
.ghost { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); background: transparent; border-radius: 22px; padding: 5px 14px; font-size: 14px; color: var(--ink2); }
.ghost img { width: 20px; height: 20px; }
.close { border: 0; background: transparent; font-size: 22px; color: var(--ink2); width: 40px; height: 40px; }

/* ── HUD ── */
#hud { position: fixed; top: calc(12px + var(--sa-t)); left: calc(16px + var(--sa-l)); right: calc(16px + var(--sa-r)); display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; z-index: 10; gap: 10px; }
.area-box { background: rgba(239, 230, 210, .92); padding: 7px 14px 8px; border-radius: 4px 12px 6px 14px; box-shadow: var(--shadow); min-width: 0; }
#areaName { font-size: 21px; font-weight: 700; letter-spacing: .05em; white-space: nowrap; }
#count { font-size: 13.5px; color: var(--ink2); white-space: nowrap; display: flex; align-items: center; gap: 4px; }
#count img { width: 15px; height: 15px; }
.btns { display: flex; gap: 8px; pointer-events: auto; flex-shrink: 0; }
.ib { width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--line); background: rgba(239, 230, 210, .94); box-shadow: var(--shadow); display: grid; place-items: center; padding: 0; position: relative; }
.ib img { width: 32px; height: 32px; }
.ib.lang span { position: absolute; right: -4px; bottom: -4px; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 700; border-radius: 8px; padding: 1px 5px; line-height: 1.3; }
#bJournal.flash { animation: flash 1.4s ease 2; }
@keyframes flash { 50% { background: #f6c27e; transform: scale(1.12); } }
#langMenu { position: fixed; top: calc(66px + var(--sa-t)); right: calc(16px + var(--sa-r)); z-index: 26; background: var(--paper); border: 1.5px solid var(--line); border-radius: 10px 4px 12px 6px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; min-width: 140px; }
#langMenu button { border: 0; background: transparent; text-align: left; padding: 9px 12px; font-size: 16px; border-radius: 8px; }
#langMenu button.on { background: var(--paper2); font-weight: 700; }

#hint, #frameMsg { position: fixed; bottom: calc(18px + var(--sa-b)); left: 50%; transform: translateX(-50%); padding: 7px 16px; border-radius: 14px 6px 12px 8px; font-size: 15px;
  z-index: 9; max-width: calc(100% - 32px); text-align: center; pointer-events: none; }
#hint { background: rgba(239, 230, 210, .9); color: var(--ink2); box-shadow: var(--shadow); }
#frameMsg { background: rgba(50, 34, 24, .8); color: var(--paper); }

#tag { position: fixed; left: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; background: rgba(239, 230, 210, .94); border-radius: 20px; font-size: 15px; transform: translate(-50%, -100%); white-space: nowrap; z-index: 8; box-shadow: 0 3px 10px rgba(50, 30, 15, .2); pointer-events: none; }
#tag svg { width: 30px; height: 30px; transform: rotate(-90deg); }
#tag .bg { fill: #fff8ea; stroke: #d8c8a8; stroke-width: 3; }
#tag .fg { fill: none; stroke: var(--accent); stroke-width: 3.4; stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; }
#tag.got { opacity: .85; }
#tag small { color: #d08a1a; font-size: 13px; margin-left: 4px; letter-spacing: 1px; }
#tag.rare { background: #fbe9b8; box-shadow: 0 0 0 2px var(--gold), 0 3px 10px rgba(50, 30, 15, .2); }

#exitTags > div { position: fixed; left: 0; top: 0; transform: translate(-50%, -100%); background: rgba(58, 44, 34, .82); color: var(--paper); padding: 4px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap; pointer-events: none; z-index: 7; }
#exitTags > div.lock { background: rgba(110, 90, 80, .75); }

#toast { white-space: pre-line; position: fixed; top: calc(84px + var(--sa-t)); left: 50%; transform: translate(-50%, -10px); opacity: 0; transition: .35s; background: var(--ink); color: var(--paper); padding: 9px 18px; border-radius: 10px 4px 12px 6px; font-size: 16px; z-index: 20; pointer-events: none; text-align: center; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

#areaCard { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; z-index: 15; opacity: 0; transition: opacity .6s; padding: 16px; }
#areaCard.on { opacity: 1; }
#areaCard .t { font-size: clamp(32px, 7vw, 64px); font-weight: 700; letter-spacing: .12em; text-shadow: 0 2px 12px rgba(239, 230, 210, .8); }
#areaCard .s { font-size: 18px; color: var(--ink2); margin-top: 6px; }

/* ── 警戒符號 ── */
#alerts .al { position: fixed; left: 0; top: 0; z-index: 7; pointer-events: none; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px 12px 12px 3px;
  display: grid; place-items: center; font-weight: 700; font-size: 16px; line-height: 1; background: rgba(239, 230, 210, .92); color: var(--ink2); box-shadow: 0 2px 6px rgba(50, 30, 15, .2); }
#alerts .al[data-l="1"] { background: #f6c27e; color: #6b3c10; }
#alerts .al[data-l="2"] { background: #d4553a; color: #fff6e6; }

/* ── 取景框 ── */
#frame { position: fixed; left: 0; top: 0; z-index: 9; pointer-events: none; --col: #fff6e6; }
#frame .c { position: absolute; width: 22%; height: 22%; border: 3px solid var(--col); filter: drop-shadow(0 1px 2px rgba(40, 25, 10, .5)); transition: border-color .15s; }
#frame .tl { left: 0; top: 0; border-right: 0; border-bottom: 0; border-radius: 6px 0 0 0; }
#frame .tr { right: 0; top: 0; border-left: 0; border-bottom: 0; border-radius: 0 6px 0 0; }
#frame .bl { left: 0; bottom: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 6px; }
#frame .br { right: 0; bottom: 0; border-left: 0; border-top: 0; border-radius: 0 0 6px 0; }
#frame.out { --col: #e0603a; }
#frame.hold { --col: #f6c27e; }
#frame.peak { --col: #ffe27a; }
#frame.peak .c { filter: drop-shadow(0 0 6px #ffd24a); }
#frame .bars { position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%); width: max(120px, 80%); }
#frame .bar, #frame .meter { height: 8px; border-radius: 4px; background: rgba(40, 28, 20, .45); overflow: hidden; position: relative; }
#frame .bar b { display: block; height: 100%; width: 0; background: var(--paper); }
#frame .meter { display: none; height: 12px; }
#frame.hold .bar { display: none; }
#frame.hold .meter { display: block; }
#frame .meter .zone { position: absolute; left: 80%; right: 0; top: 0; bottom: 0; background: rgba(255, 226, 122, .45); }
#frame .meter b { position: relative; display: block; height: 100%; width: 0; background: #f6c27e; }
#frame.peak .meter b { background: #ffe27a; }

/* ── 標題畫面 ── */
#title { position: fixed; inset: 0; display: grid; place-items: center; z-index: 30; padding: calc(16px + var(--sa-t)) calc(16px + var(--sa-r)) calc(16px + var(--sa-b)) calc(16px + var(--sa-l));
  background: radial-gradient(ellipse at center, rgba(239, 230, 210, .1), rgba(60, 40, 25, .3)); overflow-y: auto; }
#title .sheet { background: rgba(239, 230, 210, .95); padding: 30px 34px 22px; width: min(820px, 100%); display: grid; grid-template-columns: 300px 1fr; gap: 30px; align-items: center;
  border-radius: 6px 18px 8px 22px / 18px 6px 22px 8px; box-shadow: var(--shadow); border: 1.5px solid var(--line); }
#title .hero img { width: 100%; aspect-ratio: 1; display: block; border-radius: 18px 6px 22px 8px; box-shadow: 0 6px 18px rgba(60, 40, 20, .25); transform: rotate(-1.5deg); }
#title .tcol { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
#title h1 { margin: 0; font-size: clamp(30px, 5vw, 48px); letter-spacing: .08em; line-height: 1.15; }
#title p { margin: 0; color: var(--ink2); font-size: 17px; }
#title .prog { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1.5px dashed var(--line); padding: 4px 14px; border-radius: 14px; font-size: 15px; color: var(--ink2); }
#title .prog img { width: 20px; height: 20px; }
#title .big { margin-top: 4px; min-width: 240px; }
#title .mid { min-width: 200px; }
.langs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.langs button { border: 1.5px solid var(--line); background: transparent; border-radius: 16px; padding: 4px 12px; font-size: 14px; color: var(--ink2); }
.langs button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
#title .row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#title .credit { font-size: 12px; color: #9a8672; }

/* ── 遊戲說明 ── */
#guide { position: fixed; inset: 0; z-index: 32; background: rgba(40, 28, 20, .5); display: grid; place-items: center; padding: calc(16px + var(--sa-t)) calc(16px + var(--sa-r)) calc(16px + var(--sa-b)) calc(16px + var(--sa-l)); overflow-y: auto; }
.gsheet { position: relative; background: var(--paper); width: min(860px, 100%); display: grid; grid-template-columns: 340px 1fr; gap: 28px; padding: 28px; align-items: center;
  border-radius: 6px 18px 8px 22px / 18px 6px 22px 8px; border: 1.5px solid var(--line); box-shadow: var(--shadow); }
.gsheet .close { position: absolute; top: 6px; right: 6px; }
.gart img { width: 100%; aspect-ratio: 1; display: block; border-radius: 16px; box-shadow: 0 4px 14px rgba(60, 40, 20, .2); transform: rotate(-1deg); }
.gnum { font-size: 14px; color: var(--accent); letter-spacing: .1em; }
.gtext h2 { margin: 4px 0 10px; font-size: 28px; }
.gtext p { margin: 0 0 22px; font-size: 17.5px; line-height: 1.75; color: var(--ink2); min-height: 6.5em; }
.gnav { display: flex; align-items: center; gap: 12px; }
.gnav .big { margin-left: auto; font-size: 18px; padding: 9px 22px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); width: 20px; border-radius: 4px; }

/* ── 圖鑑 ── */
#journal { position: fixed; inset: 0; z-index: 25; background: rgba(40, 28, 20, .45); display: grid; place-items: center; padding: calc(16px + var(--sa-t)) calc(16px + var(--sa-r)) calc(16px + var(--sa-b)) calc(16px + var(--sa-l)); }
.book { background: var(--paper); width: min(980px, 100%); max-height: 100%; height: 100%; overflow: hidden; display: flex; flex-direction: column; border-radius: 6px 14px 8px 16px; box-shadow: var(--shadow); border: 1.5px solid var(--line); }
.tabs { display: flex; gap: 6px; padding: 10px 12px 0; border-bottom: 1.5px dashed var(--line); align-items: flex-end; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; font-size: 18px; color: var(--ink2); border-radius: 10px 10px 0 0; display: inline-flex; align-items: center; gap: 6px; }
.tabs button img { width: 26px; height: 26px; }
.tabs button.on { background: var(--paper2); color: var(--ink); font-weight: 700; }
.tabs .close { margin-left: auto; align-self: center; }
.page { overflow-y: auto; padding: 14px 18px 22px; flex: 1; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.sp { margin-bottom: 18px; }
.sp h3 { margin: 4px 0 8px; font-size: 19px; display: flex; gap: 10px; align-items: baseline; }
.sp h3 small { font-size: 13px; color: var(--ink2); font-weight: 400; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--card); padding: 8px 8px 10px; border-radius: 3px; box-shadow: 0 2px 8px rgba(60, 40, 20, .15); transform: rotate(var(--r, 0deg)); }
.card .img { aspect-ratio: 1; background: #e9dfca; display: grid; place-items: center; overflow: hidden; border-radius: 2px; }
.card img.shot { width: 100%; height: 100%; object-fit: cover; filter: sepia(.18) contrast(1.05) saturate(1.05); }
.card .q { font-size: 40px; color: #c9b896; }
.card .n { font-weight: 700; margin-top: 6px; font-size: 16px; }
.card .d { font-size: 13px; color: var(--ink2); line-height: 1.5; margin-top: 2px; }
.card.miss .n { color: var(--ink2); }
.card.rare { background: #fdf3d6; box-shadow: 0 0 0 2px var(--gold), 0 2px 8px rgba(60, 40, 20, .15); }
.card .n em { font-style: normal; color: #b07a10; font-size: 13px; display: inline-flex; align-items: center; gap: 2px; }
.card .n em img { width: 16px; height: 16px; }
.card .st { float: right; color: #d08a1a; letter-spacing: 1px; font-size: 15px; }
.mapgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.mapc { padding: 16px; background: var(--card); border-radius: 6px; box-shadow: 0 2px 8px rgba(60, 40, 20, .15); text-align: center; }
.mapc .sw { height: 90px; border-radius: 6px 16px 8px 20px; margin-bottom: 10px; }
.mapc h4 { margin: 0 0 4px; font-size: 20px; }
.mapc p { margin: 0 0 10px; color: var(--ink2); font-size: 14px; }
.mapc button { border: 0; background: var(--accent); color: #fff6e6; padding: 8px 18px; border-radius: 10px; font-size: 15px; }
.mapc button:disabled { background: #b8a890; cursor: default; }
.fin { text-align: center; padding: 6px 0 14px; font-size: 18px; color: var(--accent); }

/* ── 觸控操作 ── */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 9; }
#stick { position: absolute; left: calc(20px + var(--sa-l)); bottom: calc(26px + var(--sa-b)); width: 132px; height: 132px; border-radius: 50%; background: rgba(239, 230, 210, .3); border: 2px solid rgba(239, 230, 210, .75); pointer-events: auto; touch-action: none; }
#knob { position: absolute; left: 41px; top: 41px; width: 50px; height: 50px; border-radius: 50%; background: rgba(239, 230, 210, .94); box-shadow: var(--shadow); }
/* 右下：大「速寫」鍵 + 弧形排列的種子、小燈 */
.tbtns { position: absolute; right: calc(16px + var(--sa-r)); bottom: calc(22px + var(--sa-b)); width: 176px; height: 168px; pointer-events: none; }
.tb { position: absolute; pointer-events: auto; touch-action: none; border: 2px solid var(--line); background: rgba(239, 230, 210, .94); border-radius: 50%; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; font-size: 12px; line-height: 1; color: var(--ink2); }
.tb img { width: 34px; height: 34px; }
.tb b { position: absolute; right: -2px; top: -2px; background: var(--ink); color: var(--paper); font-size: 12px; border-radius: 9px; padding: 2px 6px; }
#tSketch { right: 0; bottom: 0; width: 96px; height: 96px; background: var(--accent); border-color: var(--accent-d); color: #fff6e6; font-size: 15px; font-weight: 700; }
#tSketch img { width: 44px; height: 44px; margin-bottom: 2px; }
#tSketch.on { transform: scale(.94); background: #a94f2e; }
#tSeed { left: 0; bottom: 6px; width: 62px; height: 62px; }
#tLamp { right: 18px; top: 0; width: 62px; height: 62px; }
#tLamp.on { background: #f6c27e; box-shadow: 0 0 18px rgba(255, 210, 120, .8); }

/* 手機直式：底部留給拇指，提示浮在操作區上方 */
@media (orientation: portrait) {
  body.touch #hint, body.touch #frameMsg { bottom: calc(196px + var(--sa-b)); }
  body.touch #toast { top: calc(74px + var(--sa-t)); }
}
/* 手機橫式：畫面矮，提示移到上方中央，HUD 縮小 */
@media (orientation: landscape) and (max-height: 540px) {
  #hud { top: calc(8px + var(--sa-t)); }
  #areaName { font-size: 16px; }
  #count { font-size: 12px; }
  .ib { width: 40px; height: 40px; }
  .ib img { width: 27px; height: 27px; }
  #hint, #frameMsg { bottom: auto; top: calc(10px + var(--sa-t)); font-size: 14px; max-width: 46%; }
  #toast { top: calc(60px + var(--sa-t)); font-size: 15px; }
  #stick { width: 120px; height: 120px; bottom: calc(18px + var(--sa-b)); left: calc(24px + var(--sa-l)); }
  #knob { left: 35px; top: 35px; }
  .tbtns { transform: scale(.88); transform-origin: right bottom; bottom: calc(14px + var(--sa-b)); right: calc(22px + var(--sa-r)); }
  #areaCard .t { font-size: 34px; }

  #title .sheet { grid-template-columns: 46vh 1fr; gap: 20px; padding: 14px 20px; width: min(760px, 100%); }
  #title h1 { font-size: 26px; }
  #title p { font-size: 13px; }
  #title .tcol { gap: 6px; }
  #title .big { font-size: 17px; padding: 7px 18px; min-width: 200px; margin-top: 0; }
  #title .mid { font-size: 14px; padding: 4px 14px; }
  #title .credit { display: none; }
  .langs button { padding: 2px 10px; font-size: 13px; }
  #title .ghost { padding: 3px 10px; font-size: 13px; }

  .gsheet { grid-template-columns: 58vh 1fr; gap: 18px; padding: 14px 18px; }
  .gtext h2 { font-size: 21px; margin-bottom: 6px; }
  .gtext p { font-size: 14.5px; line-height: 1.6; min-height: 0; margin-bottom: 12px; }
  .gnav .big { font-size: 16px; padding: 7px 16px; }

  #journal { padding: calc(6px + var(--sa-t)) calc(10px + var(--sa-r)) calc(6px + var(--sa-b)) calc(10px + var(--sa-l)); }
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 6px 6px 8px; }
  .card .img { aspect-ratio: 16 / 10; }
  .card .n { font-size: 14px; margin-top: 4px; }
  .card .d { font-size: 11.5px; line-height: 1.4; }
  .tabs button { font-size: 16px; padding: 5px 12px; }
  .page { padding: 8px 14px 14px; }
}

/* 窄螢幕（手機直式）：標題、說明改成上下排 */
@media (max-width: 720px) and (orientation: portrait) {
  #areaName { font-size: 17px; }
  #count { font-size: 12px; }
  .btns { gap: 6px; }
  .ib { width: 40px; height: 40px; }
  .ib img { width: 27px; height: 27px; }
  #title .sheet { grid-template-columns: 1fr; gap: 14px; padding: 22px 18px 16px; }
  #title .hero { width: min(52vw, 220px); margin: 0 auto; }
  #title .big { min-width: 0; width: 100%; }
  #title .mid { min-width: 0; width: 100%; }
  .gsheet { grid-template-columns: 1fr; gap: 12px; padding: 18px 16px 16px; }
  .gart { width: min(70vw, 300px); margin: 0 auto; }
  .gtext h2 { font-size: 22px; text-align: center; }
  .gnum { text-align: center; }
  .gtext p { font-size: 15.5px; min-height: 7.5em; }
  #journal { padding: 0; }
  .book { border-radius: 0; border: 0; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mapgrid { grid-template-columns: 1fr; }
  .card .d { font-size: 12px; }
}
