/* 小島日記：手機直向為主。畫面上的面板都是不透明底色（不用 backdrop-filter，3D 畫布才不用每幀重新合成模糊） */
:root {
  --ink: #3b3326; --muted: #8a7f6c; --paper: #fffaf0; --card: #ffffff; --line: #efe4cf;
  --coral: #ff8a5b; --coralD: #e76a3a; --teal: #2fa7a0; --gold: #f2c14e; --pink: #ff7b8f; --good: #4caf7a;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --bar: calc(64px + var(--safe-b));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe8f2; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; font-size: 15px;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; outline: none; }
[hidden] { display: none !important; }
.ic { width: 18px; height: 18px; vertical-align: -4px; flex: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; padding: calc(8px + var(--safe-t)) 10px 0; pointer-events: none; z-index: 5; }
.stats { display: flex; gap: 6px; }
.pill { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 4px; background: rgba(255, 250, 240, .94);
  border-radius: 999px; padding: 6px 6px; box-shadow: 0 2px 8px rgba(40, 60, 80, .14); font-size: 14px; white-space: nowrap; }
.pill b { font-weight: 800; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.goal { pointer-events: auto; margin-top: 7px; width: 100%; border: 0; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 5px;
  column-gap: 8px; row-gap: 5px; align-items: center; text-align: left; background: rgba(255, 250, 240, .94); border-radius: 14px; padding: 7px 12px 8px;
  box-shadow: 0 2px 8px rgba(40, 60, 80, .14); }
.goal-ch { font-size: 12px; font-weight: 800; color: #fff; background: var(--teal); border-radius: 6px; padding: 2px 6px; }
.goal-t { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal-bar { grid-column: 1 / 3; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.goal-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--coral)); border-radius: 3px; transition: width .4s; }

/* ---------- 底部按鈕 ---------- */
#bar { position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar); padding: 6px 8px var(--safe-b); display: flex; gap: 4px; z-index: 8;
  background: var(--paper); border-radius: 20px 20px 0 0; box-shadow: 0 -3px 14px rgba(40, 60, 80, .16); }
#bar button { position: relative; flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 14px; color: #6e604b; font-size: 12px; font-weight: 700; }
#bar button svg { width: 26px; height: 26px; }
#bar button:active { background: #f4ead6; }
#bar [data-act=build] { color: var(--coralD); }
.badge { position: absolute; top: 2px; right: calc(50% - 22px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--pink); color: #fff;
  font-size: 11px; font-style: normal; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0 4px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { transform: scale(1.15); } }

/* ---------- 面板 ---------- */
.sheet { position: fixed; left: 0; right: 0; bottom: var(--bar); max-height: min(62vh, 560px); overflow-y: auto; z-index: 7; background: var(--paper);
  border-radius: 20px 20px 0 0; padding: 6px 16px 14px; box-shadow: 0 -4px 18px rgba(40, 60, 80, .18); -webkit-user-select: text; user-select: text;
  transform: translateY(12px); opacity: 0; transition: transform .18s, opacity .18s; }
.sheet.on { transform: none; opacity: 1; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: #e2d6bf; margin: 2px auto 8px; }
.sheet h3 { margin: 4px 0 4px; font-size: 19px; }
.lv { font-size: 13px; color: #fff; background: var(--coral); border-radius: 6px; padding: 1px 6px; vertical-align: 2px; }
.muted { color: var(--muted); margin: 4px 0 8px; line-height: 1.5; }
.small { font-size: 12.5px; }
.center { text-align: center; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.row span:first-child { color: var(--muted); }
.cost { display: inline-flex; align-items: center; gap: 2px; font-weight: 800; font-variant-numeric: tabular-nums; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btns > * { flex: 1 1 auto; }
.primary, .ghost { border: 0; border-radius: 14px; padding: 11px 14px; font-weight: 800; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.primary { background: var(--coral); color: #fff; box-shadow: 0 3px 0 var(--coralD); }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--coralD); }
.primary:disabled { background: #d9cfbd; box-shadow: 0 3px 0 #c4b9a5; color: #fff; }
.primary .ic { filter: drop-shadow(0 0 1px rgba(0,0,0,.2)); }
.ghost { background: #f1e7d3; color: #6b5c45; }
.ghost:disabled { opacity: .55; }
.danger.ghost { color: #c0473a; }
.primary.danger { background: #e05a4c; box-shadow: 0 3px 0 #b8443a; }
.wide { width: 100%; margin-top: 10px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.tabs button { border: 0; background: #f1e7d3; border-radius: 999px; padding: 7px 14px; font-weight: 700; color: #7a6a52; white-space: nowrap; }
.tabs button.on { background: var(--teal); color: #fff; }

.bcards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bcard { border: 0; background: var(--card); border-radius: 14px; padding: 6px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: 0 2px 6px rgba(80, 60, 30, .1); }
.bcard img { width: 72px; height: 72px; border-radius: 10px; background: #e9f6ee; }
.bcard b { font-size: 14px; }
.bcard small { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.3; min-height: 14px; }
.bcard.poor .cost { color: #c0473a; }
.bcard.off { opacity: .45; }

#place { position: fixed; left: 8px; right: 8px; bottom: calc(var(--bar) + 8px); z-index: 7; background: var(--paper); border-radius: 18px; padding: 10px 12px;
  box-shadow: 0 4px 16px rgba(40, 60, 80, .2); }
.pl-t { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pl-t small { margin-left: auto; color: var(--muted); }
.pl-t small.bad { color: #c0473a; font-weight: 700; }
.pl-b { display: flex; gap: 8px; }
.pl-b .primary { flex: 2; }
.pl-b .ghost { flex: 1; }

.who, .prow, .mrow { width: 100%; border: 0; background: var(--card); border-radius: 14px; padding: 8px 10px; display: flex; align-items: center; gap: 10px; text-align: left;
  box-shadow: 0 2px 6px rgba(80, 60, 30, .08); margin: 6px 0; }
.who span, .prow span, .mrow span { display: flex; flex-direction: column; min-width: 0; }
.who small, .prow small, .mrow small { color: var(--muted); font-size: 12.5px; }
.pt { flex: none; border-radius: 50%; }
.mrow.ready { background: #fff4d6; box-shadow: 0 0 0 2px var(--gold) inset; }
.env { width: 40px; height: 30px; border-radius: 5px; flex: none; background: #f6efe0; position: relative; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.env::after { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, transparent 49%, rgba(0,0,0,.12) 50%, transparent 52%), linear-gradient(20deg, transparent 49%, rgba(0,0,0,.12) 50%, transparent 52%); }
.env-r { background: linear-gradient(135deg, #ffd6e7, #d9d2ff, #c9f2e6); }
.env-sr { background: #f3e2bd; }
.env-sr::before { content: ""; position: absolute; left: 14px; top: 9px; width: 12px; height: 12px; border-radius: 50%; background: #c0392b; z-index: 1; }
.env-sea { background: #a9e4f0; border-radius: 50% 50% 10px 10px; width: 18px; margin: 0 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 0; background: var(--card); border-radius: 999px; padding: 3px 10px 3px 3px; font-size: 13px; font-weight: 700;
  box-shadow: 0 1px 4px rgba(80, 60, 30, .1); }
.chip i { font-style: normal; color: var(--muted); font-weight: 400; font-size: 12px; }
.rar { font-size: 11px; font-weight: 800; border-radius: 6px; padding: 1px 5px; vertical-align: 2px; }
.rar-n { background: #dff2e8; color: #2f7a55; }
.rar-r { background: #e4dcff; color: #5a45b8; }
.rar-sr { background: linear-gradient(90deg, #ffe08a, #ffb86b); color: #7a4a00; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; text-align: left; }
.field span { font-size: 13px; color: var(--muted); }
.field input { font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--ink); -webkit-user-select: text; user-select: text; }

/* ---------- 對話框 ---------- */
#modal { position: fixed; inset: 0; z-index: 20; }
.ov { position: absolute; inset: 0; background: rgba(30, 40, 50, .45); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .18s; }
@keyframes fade { from { opacity: 0; } }
.card { width: 100%; max-width: 420px; max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--paper); border-radius: 22px; padding: 18px 18px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3); animation: pop .22s cubic-bezier(.2, 1.4, .4, 1); -webkit-user-select: text; user-select: text; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.card.narrow { max-width: 360px; }
.card h2 { margin: 0 0 6px; font-size: 21px; }
.card h4 { margin: 14px 0 4px; font-size: 15px; }
.ch-head { display: flex; gap: 12px; align-items: center; }
.ch-head h2 { margin: 0; }
.ch-head .muted { margin: 2px 0; }
.quote { margin: 4px 0 0; font-size: 14px; color: #6b5c45; }
.meter { flex: 1; max-width: 170px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--pink); }
.stories { padding-left: 20px; margin: 4px 0; line-height: 1.6; }
.stories li { margin: 6px 0; }
.stories .locked { color: #b8ab92; }
.goals { list-style: none; padding: 0; margin: 10px 0; }
.goals li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px dashed var(--line); }
.goals li span { flex: 1; display: flex; flex-direction: column; }
.goals li small { color: var(--coralD); font-size: 12.5px; margin-top: 2px; line-height: 1.4; }
.goals li em { font-style: normal; font-size: 12px; white-space: nowrap; display: flex; gap: 4px; align-items: center; color: var(--muted); }
.goals li.done b { color: var(--muted); text-decoration: line-through; }
.goals li.cur { background: #fff4d6; border-radius: 10px; }
.goals .num { width: 18px; height: 18px; border-radius: 50%; background: var(--line); font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex: none; }
.soon { text-align: center; font-weight: 800; color: var(--teal); font-size: 17px; }
.away { padding-left: 4px; list-style: none; line-height: 2; }
.help { padding-left: 18px; line-height: 1.6; }
.news { border-bottom: 1px dashed var(--line); padding: 8px 0; }
.news small { color: var(--muted); display: block; }
.news ul { padding-left: 18px; margin: 4px 0; line-height: 1.5; }
.gift { width: 72px; height: 72px; margin: 0 auto 6px; border-radius: 50%; background: #ffe3ea; display: flex; align-items: center; justify-content: center; }
.gift .ic { width: 44px; height: 44px; }

/* 信紙：普通便條／稀有彩色信紙／傳說封蠟信 */
.card.letter-card { background: transparent; box-shadow: none; padding: 0; overflow: visible; }
.paper { border-radius: 6px; padding: 18px 20px 16px; line-height: 1.75; box-shadow: 0 10px 30px rgba(0,0,0,.3); animation: slide .4s cubic-bezier(.2, 1.2, .4, 1); position: relative; }
@keyframes slide { from { transform: translateY(30px) rotate(-3deg); opacity: 0; } }
.paper p { margin: 6px 0; }
.paper-n { background: #fffef7 repeating-linear-gradient(transparent 0 27px, #cfe3f2 27px 28px); background-position: 0 6px; transform: rotate(-.6deg); }
.paper-n::before { content: ""; position: absolute; left: 36px; top: 0; bottom: 0; width: 1px; background: #f2b5b5; }
.paper-r { background: linear-gradient(135deg, #ffe1ee 0%, #e6deff 50%, #d6f5ea 100%); border: 2px solid #fff; transform: rotate(.5deg); }
.paper-r::after { content: ""; position: absolute; inset: 6px; border: 1.5px dashed rgba(150, 120, 220, .5); border-radius: 4px; pointer-events: none; }
.paper-sr { background: radial-gradient(circle at 30% 20%, #fff8e4, #f3e2bd 70%); border: 3px double #c9a24a; color: #4a3920; }
.paper-sr::after { content: ""; position: absolute; right: 14px; top: 14px; width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #e05a4c, #9b2d22); box-shadow: 0 2px 4px rgba(0,0,0,.3); }
.lhead { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.lhead small { display: block; color: var(--muted); font-size: 12.5px; }
.lto { font-weight: 700; }
.lsign { text-align: right; font-weight: 700; }
.lfoot { font-size: 13.5px; color: #6b5c45; background: rgba(255,255,255,.6); border-radius: 8px; padding: 6px 10px; }
.story { font-size: 14px; background: rgba(255,255,255,.7); border-radius: 8px; padding: 8px 10px; }
.envelope { display: block; width: 100%; height: 220px; border: 0; border-radius: 10px; position: relative; background: linear-gradient(#f3e2bd, #e8d19c); box-shadow: 0 10px 30px rgba(0,0,0,.3);
  animation: wiggle 1.4s infinite; }
.envelope::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 60%; background: #ead49e; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.envelope .seal { position: absolute; left: 50%; top: 60%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #e05a4c, #9b2d22); box-shadow: 0 3px 6px rgba(0,0,0,.35); }
.envelope small { position: absolute; bottom: 14px; left: 0; right: 0; color: #7a5a20; font-weight: 700; }
.envelope.opening { animation: open .65s forwards; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-2deg); } 90% { transform: rotate(2deg); } 95% { transform: rotate(-1deg); } }
@keyframes open { to { transform: scale(1.1) rotate(-4deg); opacity: 0; } }

/* 見面對話 */
.card.meet { background: transparent; box-shadow: none; padding: 0; text-align: center; }
.dlg .pt { margin: 0 auto -16px; position: relative; z-index: 1; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
.dlg-box { background: var(--paper); border-radius: 20px; padding: 24px 18px 14px; text-align: left; cursor: pointer; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.dlg-name { display: block; color: var(--coralD); }
.dlg-text { font-size: 17px; line-height: 1.6; margin: 6px 0; min-height: 54px; }
.dlg-more { display: block; text-align: right; color: var(--muted); font-size: 12px; }
.dlg-choice { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; background: var(--paper); border-radius: 18px; padding: 12px; }

/* 丟瓶子 */
.throw { text-align: center; }
.sea-anim { position: relative; height: 120px; overflow: hidden; border-radius: 14px; background: linear-gradient(#bfe8f2 55%, #4cc3d9 55%); margin-bottom: 10px; }
.btl { position: absolute; left: 20px; top: 70px; width: 16px; height: 34px; border-radius: 6px 6px 4px 4px; background: #9fe3d0; box-shadow: inset 0 0 0 3px #7fcfb9;
  animation: fly 1.6s cubic-bezier(.3, .6, .5, 1) forwards; }
.btl::before { content: ""; position: absolute; left: 4px; top: -8px; width: 8px; height: 9px; background: #b98552; border-radius: 2px; }
@keyframes fly { 0% { transform: translate(0, 0) rotate(0); } 50% { transform: translate(140px, -60px) rotate(300deg); } 100% { transform: translate(260px, 0) rotate(560deg); } }
.wave { position: absolute; left: -20%; right: -20%; height: 16px; border-radius: 50%; background: rgba(255,255,255,.45); top: 60%; animation: wave 2.5s infinite linear; }
.wave.w2 { top: 75%; animation-delay: -1.2s; opacity: .6; }
@keyframes wave { 50% { transform: translateX(8%); } }

/* 日記、相簿 */
.diary .dday h4 { margin: 10px 0 4px; color: var(--teal); }
.dent { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border-radius: 14px; padding: 8px 10px; margin: 6px 0; box-shadow: 0 1px 4px rgba(80, 60, 30, .08); }
.dent p { margin: 0; line-height: 1.6; font-size: 14.5px; }
.dent b { display: block; font-size: 13px; color: var(--coralD); }
.card.diarycard { background: #fffdf5; }
.album { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.album figure { margin: 0; background: #fff; padding: 6px 6px 8px; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.album figure:nth-child(odd) { transform: rotate(-1.2deg); }
.album figure:nth-child(even) { transform: rotate(1deg); }
.album img { width: 100%; aspect-ratio: 4 / 3; display: block; border-radius: 3px; background: #ddd; }
.album figcaption { font-size: 12.5px; margin-top: 4px; display: flex; flex-direction: column; }
.album small { color: var(--muted); }

.festcard { background: linear-gradient(#2b3c66, #5b4a8a); color: #fff; }
.festcard .muted { color: #d8d0ff; }
.fest p { line-height: 1.7; }
.festcard .soon { color: #ffe08a; }

/* 對話泡泡、浮字、通知 */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.bubble { position: absolute; left: 0; top: 0; max-width: 220px; background: #fff; border-radius: 14px; padding: 7px 11px 6px; font-size: 14px; line-height: 1.45;
  box-shadow: 0 4px 12px rgba(0,0,0,.18); animation: pop .2s; will-change: transform; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fff; }
.bubble b { display: block; font-size: 12px; color: var(--coralD); }
.bubble small { display: block; font-size: 10.5px; color: #b8ab92; }
.float { position: fixed; z-index: 15; transform: translate(-50%, 0); font-weight: 900; font-size: 20px; color: #fff; text-shadow: 0 2px 0 #c9952a, 0 0 6px rgba(0,0,0,.25);
  pointer-events: none; animation: rise 1.2s forwards; display: flex; align-items: center; gap: 3px; }
@keyframes rise { to { transform: translate(-50%, -60px); opacity: 0; } }
#toasts { position: fixed; left: 0; right: 0; top: calc(100px + var(--safe-t)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 18; pointer-events: none; }
.toast { background: rgba(50, 42, 30, .92); color: #fff; border-radius: 999px; padding: 8px 16px; font-size: 14px; font-weight: 700; max-width: calc(100vw - 32px);
  animation: pop .2s; transition: opacity .3s, transform .3s; text-align: center; }
.toast.good { background: rgba(47, 167, 160, .96); }
.toast.out { opacity: 0; transform: translateY(-8px); }

#debug { position: fixed; right: 6px; top: calc(104px + var(--safe-t)); z-index: 9; display: flex; flex-direction: column; gap: 3px; background: rgba(0,0,0,.55); color: #fff;
  padding: 6px; border-radius: 10px; font-size: 11px; }
#debug button { border: 0; border-radius: 6px; padding: 4px 6px; font-size: 11px; background: #fff; color: #333; }

@media (min-width: 700px) {
  .sheet, #place { left: 50%; right: auto; width: 460px; transform: translateX(-50%); }
  .sheet.on { transform: translateX(-50%); }
  #hud { max-width: 520px; margin: 0 auto; }
  #bar { left: 50%; right: auto; width: 460px; transform: translateX(-50%); }
}

#debug .dbg-in { display: flex; flex-direction: column; gap: 3px; }
#debug .dbg-in[hidden] { display: none; }

/* 參觀、雲端 */
#visit { position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); z-index: 8; background: var(--paper); border-radius: 18px; padding: 10px 12px;
  box-shadow: 0 4px 16px rgba(40, 60, 80, .25); }
.v-t { display: flex; flex-direction: column; }
.v-t small { color: var(--muted); font-size: 12.5px; }
#visit .btns { margin-top: 8px; }
.cloud { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 4px; }
.cloud h4 { margin: 8px 0 2px; }
.cloud-state { font-size: 13px; color: var(--muted); }
.cloud-state.ok { color: var(--good); }
.frow { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); border-radius: 12px; padding: 6px 8px 6px 12px; margin: 6px 0; }
.frow span { display: flex; flex-direction: column; }
.frow small { color: var(--muted); font-size: 12px; }
.frow .ghost { min-height: 36px; padding: 6px 12px; }
.linkbox { width: 100%; font: inherit; font-size: 14px; padding: 10px; border-radius: 10px; border: 2px solid var(--line); -webkit-user-select: all; user-select: all; }
