:root {
  color-scheme: light;
  --bg: #f4ece2;
  --bg-deep: #ebe0d2;
  --paper: #fffaf3;
  --ink: #6a5a70;
  --ink-soft: #9a8b9c;
  --line: #e3d6c6;
  --coral: #f2a7a0;
  --coral-deep: #e48d85;
  --mint: #8fc1b5;
  --lav: #c9b9ec;
  --butter: #f1d27a;
  --px: 3px;
  --font: 'Huninn', 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(var(--bg-deep) 1px, transparent 1px);
  background-size: 12px 12px;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  min-height: 100dvh; height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding-block: 12px 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  gap: 10px;
}

/* ───── 像素邊框 ───── */
.px {
  background: var(--paper);
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(var(--px) * -1) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink),
    0 calc(var(--px) * 2) 0 0 rgba(106, 90, 112, .18);
}

.btn {
  border: 0; cursor: pointer;
  padding: 10px 18px; min-height: 44px;
  background: var(--paper); color: var(--ink);
  box-shadow:
    0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset 0 -4px 0 0 rgba(106, 90, 112, .12);
  transition: transform .08s;
  font-size: 16px; letter-spacing: .05em;
}
.btn:active { transform: translateY(2px); box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink); }
.btn.primary { background: var(--coral); }
.btn.mint { background: var(--mint); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px dashed var(--coral-deep); outline-offset: 5px; }

.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 40px; height: 40px; display: grid; place-items: center; color: var(--ink);
}

/* ───── HUD ───── */
.hud {
  width: var(--screen-w); max-width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 2px 0 2px 4px;
}
.hud-here { display: flex; align-items: baseline; gap: 8px; font-size: 17px; white-space: nowrap; }
.hud-dot { width: 10px; height: 10px; background: var(--tw-color, #f6e08f); box-shadow: 0 0 0 2px var(--ink); align-self: center; }
.hud-dot.de { background: var(--de-color, #9dbfe3); }
.hud-clock { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.hud-there { flex: 1; min-width: 0; text-align: right; font-size: 12px; color: var(--ink-soft); line-height: 1.45; }
.hud-there b { color: var(--ink); font-weight: normal; }

/* ───── 直式遊戲畫面 ─────
   畫面比例 160:272，手機上撐滿寬度，電腦上像一支直立的手機 */
:root { --screen-w: min(100%, calc((100dvh - 110px) * 160 / 272), 440px); }
.stage { width: 100%; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.screen {
  position: relative; width: var(--screen-w); max-width: 100%; aspect-ratio: 160 / 272;
  box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), 0 10px 0 0 rgba(106,90,112,.15);
  background: var(--paper);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
.pixel { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; cursor: pointer; }
.layer { position: absolute; inset: 0; pointer-events: none; }
.hint { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); text-align: center; }

/* ───── 門口 ───── */
.door-screen { transition: opacity .4s; }
.door-screen.leaving { opacity: 0; }
.door-sign {
  position: absolute; left: 50%; top: calc(79 / 272 * 100%); transform: translate(-50%, -50%);
  width: calc(18 / 160 * 100%); line-height: 0;
}
.door-sign svg { width: 100%; height: auto; display: block; }
.pin-pad {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 18px 20px; background: #3f3b4b; color: #f3eefb;
  box-shadow: 0 -4px 0 0 var(--ink);
  animation: slideup .25s cubic-bezier(.2, 1.2, .4, 1);
}
@keyframes slideup { from { transform: translateY(100%); } }
.pin-dots { display: flex; justify-content: center; gap: 16px; }
.pin-dots span { width: 14px; height: 14px; background: #5c5670; box-shadow: inset 0 0 0 2px #7a7390; }
.pin-dots span.on { background: #c9b9ec; box-shadow: none; }
.pin-dots[data-state="ok"] span { background: #8fd6a0; box-shadow: none; }
.pin-dots[data-state="bad"] span { background: #f2a7a0; box-shadow: none; }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.pin-msg { margin: 10px 0 14px; text-align: center; font-size: 14px; color: #c8c1d8; min-height: 1.3em; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  border: 0; cursor: pointer; height: clamp(40px, 7.5vh, 52px);
  background: #524c63; color: #fffaf3; font-size: 22px; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18);
}
.pin-key:active { transform: translateY(2px); box-shadow: none; background: #625b76; }
.pin-key.fn { font-size: 15px; color: #c8c1d8; background: #47425a; }
.pin-key:focus-visible { outline: 3px dashed #c9b9ec; outline-offset: 2px; }

.bubble {
  position: absolute; transform: translate(-50%, -100%);
  pointer-events: auto; border: 0; cursor: pointer;
  background: var(--paper); color: var(--ink);
  padding: 6px 12px; font-size: clamp(13px, 3.6vw, 15px); white-space: nowrap; min-height: 32px;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
  animation: bob 1.2s ease-in-out infinite;
}
.bubble::after {
  content: ''; position: absolute; left: calc(50% + var(--arrow, 0px)); bottom: -8px; margin-left: -4px;
  width: 8px; height: 6px; background: var(--ink);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.bubble.mail { background: var(--butter); }
.bubble.say { pointer-events: none; animation: none; background: #eaf4fb; }
.bubble .key { display: inline-block; margin-left: 6px; padding: 0 4px; font-size: .8em; background: var(--bg-deep); }
@keyframes bob { 50% { transform: translate(-50%, calc(-100% - 3px)); } }

.nametag {
  position: absolute; transform: translate(-50%, -100%);
  font-size: clamp(11px, 3vw, 13px); white-space: nowrap;
  padding: 2px 8px; background: rgba(255, 250, 243, .82); color: var(--ink-soft);
}
.nametag.online { color: var(--ink); background: var(--paper); }
.nametag.online::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 6px; background: #7cc08a; vertical-align: 1px; }

/* ───── 彈出視窗 ───── */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(244, 236, 226, .82);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  animation: fadein .18s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.panel {
  width: 100%; max-width: 520px; max-height: calc(100dvh - 48px);
  overflow: auto; padding: 22px 22px 24px; position: relative;
  animation: pop .22s cubic-bezier(.2, 1.4, .4, 1);
}
.panel.wide { max-width: 680px; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.panel h2 { margin: 0 0 4px; font-size: 22px; font-weight: normal; letter-spacing: .06em; }
.panel .sub { margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; }
.close {
  position: absolute; top: 10px; right: 10px;
  width: 40px; height: 40px; border: 0; background: transparent; cursor: pointer; font-size: 22px; color: var(--ink-soft);
}
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.actions { display: flex; gap: 14px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.label { display: block; font-size: 14px; color: var(--ink-soft); margin: 18px 0 8px; }

.field {
  width: 100%; border: 0; padding: 10px 12px; background: #fff;
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
  font-size: 16px;
}
.field:focus { outline: none; box-shadow: 0 -2px 0 0 var(--coral), 0 2px 0 0 var(--coral), -2px 0 0 0 var(--coral), 2px 0 0 0 var(--coral); }
textarea.field { resize: vertical; min-height: 72px; line-height: 1.6; }

/* 上傳照片 */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 120px; padding: 16px; cursor: pointer; text-align: center;
  background: repeating-linear-gradient(45deg, #fff, #fff 8px, #fbf5ec 8px, #fbf5ec 16px);
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
  color: var(--ink-soft); font-size: 15px;
}
.drop:hover { color: var(--ink); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 3 / 4; background: #fff; padding: 4px; box-shadow: 0 0 0 2px var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border: 0; cursor: pointer;
  background: var(--ink); color: #fff; font-size: 14px; line-height: 24px; padding: 0;
}

/* 選信封、郵票 */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 44px; height: 44px; border: 0; cursor: pointer; padding: 0;
  box-shadow: 0 0 0 2px var(--line);
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--paper), 0 0 0 8px var(--coral); }
.swatch.stamp-pick { background: #fff; display: grid; place-items: center; }

/* ───── 信封 ───── */
.env {
  --env: #fbf1df; --env-dark: #ecdcc0;
  position: relative; width: 100%; aspect-ratio: 16 / 10;
  background: var(--env);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 0 8px 0 0 rgba(106,90,112,.15);
}
.env[data-c="sage"] { --env: #dcebd9; --env-dark: #c3d9bf; }
.env[data-c="sky"] { --env: #dce9f5; --env-dark: #c2d6ea; }
.env[data-c="blush"] { --env: #f8dfdb; --env-dark: #eec6c0; }
.env[data-c="lav"] { --env: #e7def5; --env-dark: #d3c6ec; }
.env::before {
  content: ''; position: absolute; inset: 0;
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), var(--env-dark) calc(50% - 1px), var(--env-dark) calc(50% + 1px), transparent calc(50% + 1px)) left bottom / 50% 60% no-repeat,
    linear-gradient(to top left, transparent calc(50% - 1px), var(--env-dark) calc(50% - 1px), var(--env-dark) calc(50% + 1px), transparent calc(50% + 1px)) right bottom / 50% 60% no-repeat;
}
.env .flap {
  position: absolute; left: 0; right: 0; top: 0; height: 58%;
  background: var(--env-dark);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top; transition: transform .5s cubic-bezier(.5, 0, .3, 1);
  z-index: 3;
}
.env .flap::after {
  content: ''; position: absolute; inset: 0 3px 3px;
  background: var(--env); clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.env .seal {
  position: absolute; left: 50%; top: 58%; width: 13%; aspect-ratio: 1; transform: translate(-50%, -50%);
  background: var(--coral-deep); z-index: 4; display: grid; place-items: center;
  clip-path: polygon(30% 0, 70% 0, 70% 10%, 90% 10%, 90% 30%, 100% 30%, 100% 70%, 90% 70%, 90% 90%, 70% 90%, 70% 100%, 30% 100%, 30% 90%, 10% 90%, 10% 70%, 0 70%, 0 30%, 10% 30%, 10% 10%, 30% 10%);
  transition: opacity .25s, transform .3s;
}
.env .seal::after { content: ''; width: 40%; height: 40%; background: #f6c1ba; }
.env .stamp {
  position: absolute; right: 5%; top: 7%; width: 17%; aspect-ratio: 4 / 5; z-index: 5;
  background: #fff; padding: 4%;
  -webkit-mask: radial-gradient(circle at 3px 3px, transparent 1.6px, #000 2px) -3px -3px / 6px 6px;
  mask: radial-gradient(circle at 3px 3px, transparent 1.6px, #000 2px) -3px -3px / 6px 6px;
}
.env .stamp svg { width: 100%; height: 100%; display: block; }
.env .addr {
  position: absolute; left: 8%; bottom: 10%; z-index: 2; font-size: clamp(12px, 3vw, 16px); line-height: 1.5;
}
.env .addr small { display: block; color: var(--ink-soft); font-size: .8em; }
.env .paper {
  position: absolute; left: 8%; right: 8%; top: 10%; bottom: 8%;
  background: #fffdf8; z-index: 1;
  background-image: repeating-linear-gradient(transparent 0 14px, #eadfd2 14px 15px);
  box-shadow: 0 0 0 2px var(--env-dark);
  opacity: 0; transform: translateY(10%);
  transition: transform .7s cubic-bezier(.3, 1.2, .4, 1) .35s, opacity .3s .3s;
}
.env.open .flap { transform: rotateX(180deg); z-index: 0; }
.env.open .seal { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
.env.open .paper { opacity: 1; transform: translateY(-62%); z-index: 6; }
.env.fly { animation: fly 1.1s cubic-bezier(.5, -0.3, .7, 1) forwards; }
@keyframes fly {
  30% { transform: translateY(8px) rotate(-2deg); }
  100% { transform: translate(60vw, -80vh) rotate(18deg) scale(.4); opacity: 0; }
}
.env.wiggle { animation: wiggle 1.6s ease-in-out infinite; cursor: pointer; }
@keyframes wiggle { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-2deg); } 82% { transform: rotate(2deg); } 88% { transform: rotate(-1deg); } }

.opening { width: min(420px, 86vw); display: flex; flex-direction: column; align-items: center; gap: 22px; }
.opening p { margin: 0; color: var(--ink-soft); }

/* 小信封（收藏冊、信箱） */
.mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 22px 18px; padding: 6px; }
.mini { border: 0; background: transparent; padding: 0; cursor: pointer; text-align: left; }
.mini .env { box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink), 0 5px 0 0 rgba(106,90,112,.12); transition: transform .15s; }
.mini:hover .env { transform: translateY(-3px) rotate(-1deg); }
.mini .env .addr { font-size: 12px; }
.mini .meta { margin-top: 10px; font-size: 13px; color: var(--ink-soft); line-height: 1.4; }
.mini .meta b { color: var(--ink); font-weight: normal; }
.tag { display: inline-block; padding: 0 6px; font-size: 12px; margin-left: 4px; background: var(--butter); color: var(--ink); }
.tag.way { background: var(--lav); }

.tabs { display: flex; gap: 8px; margin: 4px 0 18px; }
.tab { border: 0; background: transparent; cursor: pointer; padding: 6px 14px; font-size: 15px; color: var(--ink-soft); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--bg-deep); }

.empty { text-align: center; color: var(--ink-soft); padding: 26px 8px; line-height: 1.8; }
.transit { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: #f3eefb; margin-bottom: 18px; font-size: 14px; }

/* ───── 讀信 ───── */
.letter-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.letter-head .from { font-size: 20px; }
.letter-head .when { font-size: 13px; color: var(--ink-soft); }
.photos { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.photo { background: #fff; padding: 10px 10px 14px; box-shadow: 0 0 0 2px var(--line), 0 6px 0 rgba(106,90,112,.08); cursor: zoom-in; max-width: 100%; border: 0; }
.photo:nth-child(odd) { transform: rotate(-.8deg); }
.photo:nth-child(even) { transform: rotate(.8deg); }
.photo img { display: block; max-width: 100%; max-height: 70dvh; }
.note-card {
  margin: 22px auto 0; max-width: 420px; padding: 14px 18px; font-size: 17px; line-height: 1.8;
  background: #fffdf8; background-image: repeating-linear-gradient(transparent 0 29px, #eadfd2 29px 30px);
  box-shadow: 0 0 0 2px var(--line);
}
.zoom { position: fixed; inset: 0; z-index: 40; background: rgba(40, 32, 44, .92); display: grid; place-items: center; overflow: auto; cursor: zoom-out; }
.zoom img { max-width: 100vw; max-height: 100dvh; }
.zoom.big img { max-width: none; max-height: none; width: 200vw; }

/* ───── 開始畫面 ───── */
.start { width: 100%; max-width: 520px; margin: auto 0; padding: 30px 26px; text-align: center; }
.start h1 { font-size: 30px; font-weight: normal; margin: 6px 0 6px; letter-spacing: .12em; }
.start .sub { color: var(--ink-soft); margin: 0 0 24px; line-height: 1.7; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.who button { border: 0; cursor: pointer; padding: 18px 10px 14px; background: #fff; box-shadow: 0 0 0 2px var(--line); display: flex; flex-direction: column; align-items: center; gap: 10px; font-size: 16px; transition: transform .12s; }
.who button:hover { transform: translateY(-3px); box-shadow: 0 0 0 3px var(--ink); }
.who canvas { width: 72px; height: 96px; image-rendering: pixelated; }
.who small { color: var(--ink-soft); font-size: 13px; }
.start form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.err { color: #c66d64; font-size: 14px; min-height: 1.2em; margin: 0; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--bg-deep); padding: 8px; text-align: left; }

/* ───── 提示訊息 ───── */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100vw - 32px); padding: 12px 18px; text-align: center; line-height: 1.6;
  background: var(--ink); color: #fffaf3; font-size: 15px;
  animation: up .25s ease-out;
}
@keyframes up { from { transform: translate(-50%, 12px); opacity: 0; } }

.settings-list { display: flex; flex-direction: column; gap: 14px; }
.settings-list .btn { width: 100%; text-align: left; }
.small { font-size: 13px; color: var(--ink-soft); line-height: 1.6; }

@media (max-width: 560px) {
  .hud { padding: 4px 0 4px 6px; gap: 8px; }
  .hud-here { font-size: 16px; }
  .hud-there { font-size: 12px; }
  .panel { padding: 20px 16px 22px; }
  .mini-grid { grid-template-columns: repeat(2, 1fr); gap: 18px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ───── 冰箱畫面 ───── */
.fridge-view { position: absolute; inset: 0; z-index: 5; animation: fadein .2s ease-out; transition: opacity .25s; }
.fridge-view.leaving { opacity: 0; }
.fridge-bar {
  position: absolute; left: 0; right: 0; bottom: 4%;
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; padding: 0 12px;
}
.fridge-bar .btn { background: var(--paper); }

/* ───── 要一起打遊戲嗎？ ───── */
.ask { max-width: 360px; text-align: center; }
.ask h2 { margin-bottom: 4px; }
.ask-arena { position: relative; height: 190px; margin-top: 8px; }
.ask-yes, .ask-no { position: absolute; top: 70px; min-width: 96px; }
.ask-yes { left: 14%; }
.ask-no { right: 14%; transition: left .18s ease-out, top .18s ease-out; touch-action: none; }
.ask-hint { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--ink-soft); }

/* ───── 穿越任意門 ───── */
.travel-text {
  position: absolute; left: 0; right: 0; top: 72%;
  text-align: center; color: #fbf6ff; opacity: 0; transition: opacity .35s;
  text-shadow: 0 1px 0 rgba(40, 32, 60, .45);
  padding: 0 16px;
}
.travel-text.show { opacity: 1; }
.travel-line { margin: 0 0 10px; font-size: clamp(16px, 4.6vw, 20px); letter-spacing: .12em; }
.travel-time { margin: 0; font-size: clamp(12px, 3.4vw, 14px); letter-spacing: .08em; color: #e3dcff; font-variant-numeric: tabular-nums; white-space: pre; }

/* ───── 通知 ───── */
.notice { max-width: 340px; text-align: center; }
.notice p { margin: 8px 0 0; line-height: 1.7; }

/* ───── 寫信：選送達時間 ───── */
.seg { display: flex; gap: 10px; flex-wrap: wrap; }
.seg button {
  border: 0; cursor: pointer; padding: 8px 14px; min-height: 40px; font-size: 15px;
  background: #fff; color: var(--ink-soft); box-shadow: 0 0 0 2px var(--line);
}
.seg button[aria-pressed="true"] { color: var(--ink); background: var(--bg-deep); box-shadow: 0 0 0 2px var(--ink); }
.seg button:focus-visible { outline: 3px dashed var(--coral-deep); outline-offset: 3px; }
.pick-row { display: flex; gap: 10px; margin-top: 12px; }
.pick-row .field { flex: 1; min-width: 0; }
.when-info { margin: 10px 0 0; white-space: pre-line; }   /* 保留文字裡的換行 \n */

/* ───── 手機：避開 Safari 上方那層模糊 ─────
   iPhone 的 Safari 會在最上面蓋一層霧霧的模糊，整個畫面往下挪一點，房間也跟著縮一點免得被切到 */
@media (pointer: coarse) {
  #app { padding-top: 40px; }
  :root { --screen-w: min(100%, calc((100dvh - 140px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 160 / 272), 440px); }
}

/* ───── 小紙條 ───── */
.note-paper {
  background: #fffdf6;
  background-image: repeating-linear-gradient(transparent 0 27px, #eadfd2 27px 28px);
  box-shadow: 0 0 0 2px var(--line), 0 6px 0 rgba(106, 90, 112, .08);
  padding: 14px 16px; line-height: 28px;
}
.note-input { background: transparent; box-shadow: none !important; padding: 0; min-height: 112px; line-height: 28px; font-size: 17px; }
.note-found { width: min(340px, 86vw); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.note-title { margin: 0; color: var(--ink-soft); letter-spacing: .1em; }
.note-found .note-paper { width: 100%; transform: rotate(-1.5deg); animation: unfold .5s cubic-bezier(.3, 1.3, .5, 1); }
@keyframes unfold { from { transform: rotate(-1.5deg) scaleY(.1); opacity: 0; } }
.note-text { margin: 0; font-size: 19px; white-space: pre-line; }
.note-from { margin: 6px 0 0; text-align: right; color: var(--ink-soft); font-size: 15px; }
.desk-menu { max-width: 340px; }
.desk-choices { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.desk-choices .btn { width: 100%; }

/* ───── 想一起去的地方（地圖） ───── */
.map-panel { padding-bottom: 20px; }
.map-panel .sub { margin-bottom: 12px; }
.map-wrap { position: relative; aspect-ratio: 4 / 3; max-height: 46dvh; width: 100%; box-shadow: 0 0 0 3px var(--ink); background: #d3e5ef; }
.map-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; image-rendering: pixelated; }
.map-canvas:active { cursor: grabbing; }
.map-zooms { position: absolute; right: 6px; bottom: 6px; display: flex; flex-direction: column; gap: 6px; }
.map-zoom {
  width: 32px; height: 32px; border: 0; cursor: pointer; font-size: 17px; line-height: 1; padding: 0;
  background: rgba(255, 250, 243, .92); color: var(--ink); box-shadow: 0 0 0 2px var(--ink);
}
.map-zoom.small { font-size: 14px; }
.map-zoom:active { transform: translateY(1px); }
.map-pick-hint {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); white-space: nowrap; pointer-events: none;
  padding: 4px 10px; font-size: 14px; background: var(--ink); color: #fffaf3; animation: fadein .2s;
}
.map-body { margin-top: 14px; }
.map-body .actions { margin-top: 16px; }
.map-list { display: flex; flex-direction: column; gap: 8px; }
.map-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  border: 0; padding: 10px 12px; background: #fff; box-shadow: 0 0 0 2px var(--line);
}
.map-item:active { background: var(--bg-deep); }
.map-dot { flex: none; width: 10px; height: 10px; background: #e48d85; box-shadow: 0 0 0 2px var(--ink); }
.map-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.map-item-text b { font-weight: normal; font-size: 16px; }
.map-item-text small { color: var(--ink-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-check { flex: none; font-size: 12px; color: #5f9c8e; }
.map-detail h3 { margin: 0; font-size: 19px; font-weight: normal; line-height: 28px; }
.map-note { margin: 0; white-space: pre-line; }
.map-detail .small { margin: 0; }
.map-detail-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.map-detail-actions .btn { padding-inline: 4px; }
.map-detail-actions .btn:last-child { grid-column: 1 / -1; order: -1; }
.map-search { display: flex; gap: 10px; }
.map-search .field { flex: 1; min-width: 0; }
.map-search-go { flex: none; }

/* ───── 現在在幹嘛 ───── */
.status-menu { max-width: 380px; }
.status-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.status-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px 10px;
  border: 0; cursor: pointer; background: #fff; box-shadow: 0 0 0 2px var(--line); font-size: 14px; color: var(--ink);
}
.status-opt canvas { width: 28px; height: 28px; image-rendering: pixelated; }
.status-opt.on { background: var(--bg-deep); box-shadow: 0 0 0 2px var(--ink); }
.status-opt:active { transform: translateY(1px); }

/* ───── 手搖飲 ───── */
.drink-panel { max-width: 420px; }
.drink-panel .seg button { padding: 7px 12px; min-height: 38px; font-size: 14px; }
.drink-today { margin-top: 18px; }
.drink-today ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.drink-today li { display: flex; gap: 10px; padding: 8px 10px; background: #fff; box-shadow: 0 0 0 2px var(--line); font-size: 15px; text-align: left; }
.drink-time { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ───── v2：偷吃的回覆 ───── */
.notice p { white-space: pre-line; }
.notice-quote { font-size: 20px; margin: 12px 0 4px !important; }
.notice-choices { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.notice-choices .btn { width: 100%; }

/* ───── 手上的 Skyr ───── */
.hold-bar {
  position: absolute; left: 50%; bottom: 3%; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; white-space: nowrap;
  background: rgba(255, 250, 243, .94); box-shadow: 0 0 0 2px var(--ink); font-size: 14px;
  pointer-events: auto;
}
.hold-bar span { color: var(--ink-soft); }
.hold-bar button {
  border: 0; cursor: pointer; padding: 6px 12px; min-height: 34px; font-size: 14px;
  background: #fff; color: var(--ink); box-shadow: 0 0 0 2px var(--ink);
}
.hold-bar button:first-of-type { background: var(--coral); }
.hold-bar button:active { transform: translateY(1px); }

/* ───── Skyr 的你來我往 ───── */
.skyr-notice { max-width: 360px; }
.skyr-speech { display: flex; align-items: center; gap: 14px; margin-top: 12px; text-align: left; }
.skyr-speech p { margin: 0 !important; }
.skyr-face { width: 48px; height: 60px; flex: none; image-rendering: pixelated; }
.skyr-bubble { flex: 1; padding: 10px 12px; background: #fff; box-shadow: 0 0 0 2px var(--ink); font-size: 18px; line-height: 1.5; }
.skyr-bubble small { display: block; font-size: 12px; color: var(--ink-soft); }
.skyr-replies { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.skyr-replies > .btn { width: 100%; }
.skyr-own { display: flex; gap: 8px; }
.skyr-own .field { flex: 1; min-width: 0; }

/* 右上角：對方在線 / 離線 */
.hud-online { margin-left: 6px; color: var(--ink-soft); }
.hud-online.on::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 5px; background: #7cc08a; vertical-align: 1px; }

/* ───── 收藏櫃 ───── */
.cabinet-tag { animation: none; font-size: clamp(12px, 3.3vw, 14px); padding: 4px 10px; min-height: 28px; }
.note-list { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; max-height: 60vh; overflow-y: auto; padding: 4px 4px 8px; }
.note-list .note-text { font-size: 17px; }

/* ───── 戴上耳機：遊戲畫面下面的迷你播放器（參考 Apple Music／Spotify） ───── */
body.music-on { --screen-w: min(100%, calc((100dvh - 214px) * 160 / 272), 440px); }
@media (pointer: coarse) {
  body.music-on { --screen-w: min(100%, calc((100dvh - 244px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 160 / 272), 440px); }
}
.mp {
  --mp-accent: #9dbfe3;
  position: relative; isolation: isolate;
  width: var(--screen-w); max-width: 100%; margin-top: 6px;
  padding: 10px 12px 8px; border-radius: 14px;
  color: #fff; background: #1c1b20;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  box-shadow: 0 8px 24px rgba(40, 30, 50, .28);
  animation: mp-in .3s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes mp-in { from { transform: translateY(14px); opacity: 0; } }
/* 背景：目前這首的封面模糊放大，蓋一層暗色 */
.mp-bg { position: absolute; inset: 0; z-index: -1; border-radius: inherit; overflow: hidden; background-size: cover; background-position: center; }
.mp-bg::before { content: ''; position: absolute; inset: -30px; background: inherit; filter: blur(26px) saturate(1.4); transform: scale(1.2); }
.mp-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20, 18, 24, .55), rgba(20, 18, 24, .82)); }
.mp-row { display: flex; align-items: center; gap: 10px; }
.mp-art { position: relative; flex: none; width: 76px; aspect-ratio: 16 / 9; border-radius: 6px; overflow: hidden; background: #2b2930; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
.mp-thumb, .mp-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mp-thumb:not([src]) { display: none; }
.mp-video { opacity: 0; overflow: hidden; transition: opacity .25s; }
/* 播的時候才露出影片；暫停時蓋回封面，擋掉 YouTube 自己的暫停圖示 */
.mp.has-video.playing .mp-video { opacity: 1; }
/* 影片放大一點再裁掉邊邊：YouTube 疊在左上角的頻道頭像、標題列就不會露出來 */
.mp-video iframe { position: absolute; width: 170%; height: 170%; left: -35%; top: -35%; border: 0; pointer-events: none; display: block; }
.mp-text { flex: 1; min-width: 0; cursor: pointer; }
.mp-title { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-artist { margin: 2px 0 0; font-size: 12px; color: rgba(255, 255, 255, .62); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-ctls { display: flex; align-items: center; gap: 2px; flex: none; }
.mp-btn { border: 0; background: none; color: #fff; padding: 0; width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer; border-radius: 50%; -webkit-tap-highlight-color: transparent; transition: transform .12s, opacity .12s; }
.mp-btn:active { transform: scale(.88); opacity: .7; }
.mp-icon { display: grid; place-items: center; width: 20px; height: 20px; }
.mp-icon svg { width: 100%; height: 100%; fill: currentColor; }
.mp-play { width: 36px; height: 36px; background: #fff; color: #1c1b20; }
.mp-play .mp-icon { width: 18px; height: 18px; }
.mp-small { width: 26px; height: 26px; color: rgba(255, 255, 255, .7); }
.mp-small .mp-icon { width: 17px; height: 17px; }
.mp-small .mp-icon svg { fill: none; }
.mp-small.on { color: var(--mp-accent); }
.mp-progress { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 10px; color: rgba(255, 255, 255, .55); font-variant-numeric: tabular-nums; }
.mp-track { flex: 1; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .22); cursor: pointer; position: relative; }
.mp-track::before { content: ''; position: absolute; inset: -8px 0; }
.mp-fill { height: 100%; width: 0; border-radius: inherit; background: #fff; transition: width .5s linear; }
.mp-foot { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.mp-device { display: flex; align-items: center; gap: 5px; flex: 1; min-width: 0; font-size: 11px; font-weight: 600; color: var(--mp-accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-device .mp-icon { width: 13px; height: 13px; flex: none; }
.mp-device .mp-icon svg { fill: none; }
.mp-device .mp-icon svg rect { fill: currentColor; }
.mp-disconnect { border: 0; background: rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .85); font: inherit; font-size: 11px; padding: 4px 10px; border-radius: 999px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.mp-disconnect:active { background: rgba(255, 255, 255, .22); }
/* 歌單：從播放器往上展開 */
.mp-queue {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 6;
  max-height: 48vh; overflow-y: auto; padding: 6px;
  background: rgba(28, 27, 32, .94); border-radius: 14px;
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  box-shadow: 0 10px 30px rgba(40, 30, 50, .35);
  animation: mp-in .22s ease-out;
}
.mp-queue[hidden] { display: none; }
.mp-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; color: #fff; font: inherit; text-align: left; padding: 6px; border-radius: 8px; cursor: pointer; }
.mp-item:active { background: rgba(255, 255, 255, .08); }
.mp-item img { width: 48px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; background: #2b2930; flex: none; }
.mp-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mp-item-text b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-item-text small { font-size: 11px; color: rgba(255, 255, 255, .55); }
.mp-item.on b { color: var(--mp-accent); }
/* 正在播的那首：跳動的小長條 */
.mp-eq { display: none; align-items: flex-end; gap: 2px; height: 12px; flex: none; margin-right: 4px; }
.mp-item.on .mp-eq { display: flex; }
.mp-eq i { width: 3px; height: 4px; background: var(--mp-accent); border-radius: 1px; }
.mp.playing .mp-item.on .mp-eq i { animation: mp-eq .9s ease-in-out infinite; }
.mp-eq i:nth-child(2) { animation-delay: -.3s; }
.mp-eq i:nth-child(3) { animation-delay: -.6s; }
@keyframes mp-eq { 0%, 100% { height: 3px; } 50% { height: 12px; } }
