/* ===========================================================
   碎片商店 — 樣式
   色票：夜藍 ink / 木頭 wood / 燈光 lamp / 舊紙 paper / 霧紫 mist
   字體：拉丁與數字用像素字，中文用明體，兩種質地的對比就是這個店的性格
   =========================================================== */

:root {
  --ink:      #14121B;
  --ink-soft: #221D2C;
  --wood:     #4A3527;
  --wood-lit: #6E4E36;
  --lamp:     #F2C879;
  --lamp-dim: #C9A164;
  --paper:    #EDE0C8;
  --mist:     #A99BB5;
  --rose:     #D9737A;

  --px:   4px;              /* 像素邊框的基本單位 */
  --ease: cubic-bezier(.22,.61,.36,1);

  --font-pixel: "Press Start 2P", "Zpix", ui-monospace, monospace;
  --font-body:  "Noto Serif TC", "Songti TC", "PMingLiU", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

img { user-select: none; -webkit-user-drag: none; }

/* ---------------------------------------------------------- 場景 */

.stage {
  position: fixed; inset: 0;
  overflow: hidden;
  background: var(--ink);
  cursor: grab;
  touch-action: none;
}
.stage.is-dragging { cursor: grabbing; }

.world {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.scene-img {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.scene-img--next {
  position: absolute; inset: 0;
  opacity: 0;
  transition: opacity 1.2s var(--ease);
}
.scene-img--next.is-in { opacity: 1; }

.hotspots { position: absolute; inset: 0; }

/* 光線濾鏡：一張背景靠它變出 24 個時段 */
.tint {
  position: absolute; inset: 0; pointer-events: none;
  mix-blend-mode: multiply;
  transition: background 1.4s var(--ease), opacity 1.4s var(--ease);
}

/* 熱區＝物品本身。平常幾乎看不見，只有一點點呼吸感 */
.hot {
  position: absolute;
  padding: 0; border: 0; background: transparent;
  cursor: pointer;
}
.hot img {
  position: relative; z-index: 1;
  display: block; width: 100%; height: 100%;
  /* 維持原本的長寬比，底部貼齊格位下緣（也就是層板面） */
  object-fit: contain; object-position: bottom center;
  image-rendering: pixelated;
  transition: transform .3s var(--ease), filter .5s var(--ease);
}
/* 牆上的畫作：維持原比例、置中，不要拉伸也不要貼底 */
.hot--wall img { object-fit: contain; object-position: center; margin-bottom: 0 !important; }
/* 滑鼠移過去不做放大位移，只留鍵盤焦點的提示（無障礙需要） */
.hot--found img { filter: saturate(.82) brightness(.94); }

.hot::after {
  content: "";
  position: absolute; inset: -14%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(242,200,121,.34) 0%, rgba(242,200,121,0) 68%);
  opacity: 0;
  transition: opacity .5s var(--ease);
}
/* 沒撿過的物品不再自己發光，位置完全靠自己找 */
/* 熱區不給任何提示：滑鼠移過去沒反應，Tab 也不會選到 */

/* 左右還有東西沒看到的提示 */
.edge-hint {
  position: fixed; top: 50%; z-index: 4;
  transform: translateY(-50%);
  font-family: var(--font-body); font-size: 40px; line-height: 1;
  color: rgba(242,200,121,.55);
  text-shadow: 0 0 18px rgba(0,0,0,.9);
  pointer-events: none;
  opacity: 0;
  transition: opacity .8s var(--ease);
}
.edge-hint--l { left: 10px; }
.edge-hint--r { right: 10px; }
.edge-hint.is-on { animation: nudge 2.6s ease-in-out infinite; opacity: 1; }
.edge-hint--l.is-on { animation-name: nudge-l; }
@keyframes nudge   { 0%,100% { opacity:.25; transform:translate(0,-50%); } 50% { opacity:.8; transform:translate(6px,-50%); } }
@keyframes nudge-l { 0%,100% { opacity:.25; transform:translate(0,-50%); } 50% { opacity:.8; transform:translate(-6px,-50%); } }

.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 42%, rgba(10,8,16,.62) 100%);
  mix-blend-mode: multiply;
}

.dust { position: absolute; inset: 0; pointer-events: none; opacity: .5; }

/* ---------------------------------------------------------- 抬頭資訊 */

.hud {
  position: fixed; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 18px 16px;
  pointer-events: none;
  z-index: 5;
}
.hud--top { top: 0; background: linear-gradient(to bottom, rgba(12,10,18,.75), transparent); }
.hud--bottom {
  top: auto; bottom: 0; align-items: flex-end;
  padding: 20px 18px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(12,10,18,.78), transparent);
}
.hud button { pointer-events: auto; }
.hud .clock { pointer-events: auto; }

.clock { display: flex; flex-direction: column; gap: 7px; }
.clock-time {
  font-family: var(--font-pixel);
  font-size: 15px; letter-spacing: .06em;
  color: var(--lamp);
  text-shadow: 0 0 14px rgba(242,200,121,.35);
}

.hud-actions { display: flex; gap: 8px; }

.caption {
  margin: 0; max-width: 62ch;
  font-size: 14px; font-weight: 300; line-height: 1.85;
  letter-spacing: .12em;
  color: rgba(237,224,200,.72);
  text-shadow: 0 2px 12px rgba(0,0,0,.8);
  transition: opacity .8s var(--ease);
}
.tally {
  margin: 0; flex: none;
  font-family: var(--font-pixel); font-size: 10px;
  color: var(--mist); letter-spacing: .04em;
}

/* ---------------------------------------------------------- 按鈕 */

.btn {
  font-family: var(--font-body);
  font-size: 14px; letter-spacing: .2em;
  color: var(--paper);
  background: var(--ink-soft);
  border: var(--px) solid var(--wood-lit);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.35);
  padding: 12px 22px;
  cursor: pointer;
  transition: transform .12s var(--ease), background .2s var(--ease), color .2s var(--ease);
}
.btn:hover { background: var(--wood); }
.btn:active { transform: translateY(2px); }
.btn:focus-visible { outline: 2px solid var(--lamp); outline-offset: 3px; }

.btn--primary { color: var(--ink); background: var(--lamp); border-color: var(--lamp-dim); }
.btn--primary:hover { background: #FFDA96; }

.btn--small { padding: 9px 18px; font-size: 13px; }

.btn--icon {
  width: 42px; height: 42px; padding: 0;
  font-size: 15px; line-height: 1;
  display: grid; place-items: center;
}
.btn--icon[aria-pressed="false"] { color: rgba(237,224,200,.38); }

.btn--ghost {
  background: transparent; border-width: 2px; border-color: rgba(169,155,181,.4);
  box-shadow: none; color: var(--mist); font-size: 12px; padding: 8px 14px;
}

/* ---------------------------------------------------------- 開場 */

.gate {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 60%, #251E30 0%, var(--ink) 70%);
  transition: opacity 1s var(--ease), visibility 1s;
}
.gate.is-out { opacity: 0; visibility: hidden; }

.gate-inner { text-align: center; padding: 32px 18px; max-width: 34rem; }

.gate-eyebrow {
  font-family: var(--font-pixel); font-size: 9px;
  color: var(--rose); letter-spacing: .3em;
  margin: 0 0 26px;
}
.gate-title {
  margin: 0 0 26px;
  font-size: clamp(34px, 9vw, 58px);
  font-weight: 500; letter-spacing: .42em; text-indent: .42em;
  color: var(--lamp);
  text-shadow: 0 0 40px rgba(242,200,121,.28);
}
.gate-line {
  margin: 0 0 10px;
  /* 兩句各自維持一行：字級隨螢幕寬度縮放，最大 14px */
  font-size: min(14px, calc((100vw - 56px) / 24));
  font-weight: 300; letter-spacing: .12em; line-height: 2;
  color: rgba(237,224,200,.8);
  white-space: nowrap;
}
.gate-line--dim { color: var(--mist); margin-bottom: 34px; }
.gate-note {
  margin: 22px 0 0; font-size: 11px; letter-spacing: .16em;
  color: rgba(169,155,181,.6);
}

/* ---------------------------------------------------------- 物品視窗（招牌畫面） */

.item-layer { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; }
.item-scrim {
  position: absolute; inset: 0;
  background: rgba(9,7,14,.8);
  opacity: 0; transition: opacity .5s var(--ease);
}
.item-layer.is-in .item-scrim { opacity: 1; }

.item-card {
  position: relative;
  width: min(90vw, 27rem);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  opacity: 0; transform: translateY(18px);
  transition: opacity .55s var(--ease), transform .55s var(--ease);
}
.item-layer.is-in .item-card { opacity: 1; transform: none; }

.item-card-frame {
  width: 100%;
  padding: 30px 26px 26px;
  background: linear-gradient(180deg, #251F2E 0%, #1A1622 100%);
  border: var(--px) solid var(--wood-lit);
  box-shadow:
    inset 0 0 0 2px rgba(0,0,0,.5),
    0 0 0 2px rgba(242,200,121,.12),
    0 24px 60px rgba(0,0,0,.6);
}

.item-kicker {
  margin: 0 0 14px;
  font-family: var(--font-pixel); font-size: 8px;
  letter-spacing: .24em; color: var(--rose);
}
.item-name {
  margin: 0 0 16px;
  /* 長名稱也維持一行：字距先收，仍裝不下就整體縮小 */
  font-size: clamp(15px, 4.6vw, 19px); font-weight: 500; letter-spacing: .12em;
  color: var(--lamp);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.item-text {
  margin: 0; min-height: 5.2em;
  font-size: 13.5px; font-weight: 300; line-height: 2.05; letter-spacing: .08em;
  color: rgba(237,224,200,.9);
}
.item-text .cursor { color: var(--lamp); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.item-stamp {
  margin: 22px 0 0; padding-top: 14px;
  border-top: 1px solid rgba(169,155,181,.2);
  font-family: var(--font-pixel); font-size: 8px;
  letter-spacing: .12em; color: rgba(169,155,181,.65);
}

/* ---------------------------------------------------------- 收藏冊 */

.book-layer {
  position: fixed; left: 0; right: 0; top: 0; z-index: 35;
  height: 100vh;
  height: var(--appvh, 100vh);
  display: grid; place-items: center;
  box-sizing: border-box;
  /* 留出瀏海與底部工具列的安全區域 */
  padding: max(14px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
}
.book-scrim { position: absolute; inset: 0; background: rgba(9,7,14,.86); }

.book {
  position: relative;
  width: min(94vw, 40rem);
  /* --appvh 由 app.js 依實際視窗高度寫入；iOS 的 vh 不可靠，只當備援 */
  max-height: min(86vh, 46rem);
  max-height: min(calc(var(--appvh, 100vh) - 28px), 46rem);
  display: flex; flex-direction: column; min-height: 0;
  background: linear-gradient(180deg, #221C2B, #171320);
  border: var(--px) solid var(--wood-lit);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.5), 0 30px 80px rgba(0,0,0,.7);
  animation: rise .45s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(22px); } }

.book-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 22px 0;
}
.book-title { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: .3em; color: var(--lamp); }
.book-sub {
  margin: 12px 22px 18px;
  font-family: var(--font-pixel); font-size: 9px; letter-spacing: .06em; color: var(--mist);
}
.book-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 22px 8px;
}

/* 空的收藏冊 */
.book-empty {
  margin: 30px 0 34px;
  font-size: 14px; font-weight: 300; line-height: 2.2; letter-spacing: .14em;
  color: rgba(169,155,181,.7); text-align: center;
}

.book-list { margin: 4px 0 0; padding: 0; list-style: none; display: grid; gap: 20px; }
.book-item { display: grid; grid-template-columns: 12px 1fr; gap: 12px; align-items: start; }
.book-dot { width: 8px; height: 8px; margin-top: 8px; background: var(--lamp); }
.book-item b { display: block; font-size: 15px; font-weight: 500; letter-spacing: .16em; color: var(--paper); }
.book-item small {
  display: block; margin-top: 7px;
  font-size: 13px; font-weight: 300; line-height: 2; letter-spacing: .08em;
  color: rgba(237,224,200,.62);
}
.book-item em {
  display: block; margin-top: 9px; font-style: normal;
  font-family: var(--font-pixel); font-size: 8px; letter-spacing: .08em;
  color: rgba(169,155,181,.5);
}

.book-note {
  margin: 20px 0 4px; text-align: center;
  font-size: 12px; line-height: 1.9; letter-spacing: .14em;
  color: rgba(169,155,181,.72);
}
.book-note--done { color: var(--lamp-dim); }

.book-foot {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 22px 18px;
  border-top: 1px solid rgba(169,155,181,.14);
}
.book-foot-note {
  display: inline-block; margin-top: 4px;
  font-size: .86em; color: rgba(169,155,181,.5);
}
.book-foot p { margin: 0 auto; font-size: 11px; line-height: 1.8; letter-spacing: .1em; color: rgba(169,155,181,.6); }
.book-foot button:not([hidden]) ~ p, .book-foot p:has(~ button:not([hidden])) { margin: 0; }

/* ---------------------------------------------------------- 預覽列 */

.devbar {
  position: fixed; z-index: 20; left: 50%; bottom: 84px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: rgba(20,18,27,.9);
  border: 2px solid rgba(169,155,181,.3);
}
.devbar span { font-family: var(--font-pixel); font-size: 9px; color: var(--mist); }

/* ---------------------------------------------------------- 響應式與無障礙 */

@media (max-width: 560px) {
  .clock-time { font-size: 12px; }
  .caption { font-size: 12.5px; letter-spacing: .08em; line-height: 1.9; }
  .hud--bottom { flex-direction: column; align-items: flex-start; gap: 10px; }
  .item-name { font-size: clamp(14px, 4.4vw, 17px); }
  .item-text { font-size: 13px; line-height: 1.95; }
  .book-foot { flex-direction: column; align-items: stretch; }
  .book-head, .book-sub, .book-body { padding-left: 16px; padding-right: 16px; }
  .book-sub { margin-left: 0; margin-right: 0; }
}

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

/* ---------------------------------------------------------- 物品視窗裡的物品圖 */
.item-figure {
  margin: 0 0 18px;
  display: flex; align-items: flex-end; justify-content: center;
  min-height: 140px;
}
.item-figure img {
  max-width: 68%; max-height: 180px;
  width: auto; height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,.45));
  animation: item-rise .5s var(--ease) both;
}
.item-figure[hidden] { display: none; }
@keyframes item-rise {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
@media (max-height: 700px) {
  .item-figure { min-height: 100px; margin-bottom: 12px; }
  .item-figure img { max-height: 130px; }
}

/* ---------------------------------------------------------- 背景物件的低語 */
.whisper {
  position: fixed; inset: 0;
  /* 低語出現時攔下整個畫面的點擊，避免跟物品視窗疊在一起 */
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; padding: 0 32px; z-index: 60;
  opacity: 0; transform: translateY(10px) scale(.98);
  transition: opacity .45s var(--ease), transform .45s var(--ease);
}
.whisper.is-in { opacity: 1; transform: none; }
.whisper-text {
  margin: 0; text-align: center; white-space: nowrap;
  /* 一律維持一行：字級隨螢幕寬度縮放，長句自動變小 */
  font-size: min(15px, calc((100vw - 64px) / var(--chars, 20)));
  line-height: 2.1; letter-spacing: .12em;
  color: rgba(237,224,200,.94);
  text-shadow: 0 2px 16px rgba(0,0,0,.9), 0 0 40px rgba(0,0,0,.75),
               0 0 80px rgba(0,0,0,.5);
}
/* 背景物件的熱區：完全隱形，沒有呼吸微光 */
.hot--ambient { background: none !important; }
.hot--ambient::before, .hot--ambient::after { display: none !important; }
/* 背景物件的熱區疊在物品之上，避免大件物品蓋住背景可點範圍 */
.hot--ambient { z-index: 3; }

/* ---------------------------------------------------------- 關於 */
.btn--about {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 45;
  padding: 6px 4px;
  background: none; border: 0; box-shadow: none;
  font-family: var(--font-pixel); font-size: 8px; letter-spacing: .2em;
  color: rgba(255,255,255,.72);
  text-shadow: 0 1px 6px rgba(0,0,0,.8);
  transition: color .3s var(--ease);
}
.btn--about:hover, .btn--about:focus-visible { color: #fff; background: none; }
.btn--about:active { transform: none; }
/* 收藏冊或物品面板打開時，關於按鈕要退到後面，不然會壓在面板上 */
body.panel-open .btn--about,
body:has(.book-layer:not([hidden])) .btn--about,
body:has(.item-layer:not([hidden])) .btn--about { opacity: 0; pointer-events: none; }
/* 藏在左上角時鐘裡的時光機。時鐘本體不做任何可點提示。 */
.timegate {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 0 28px;
  background: rgba(12,10,17,.86);
  opacity: 0; transition: opacity .4s var(--ease);
}
.timegate.is-in { opacity: 1; }
.timegate[hidden] { display: none; }
.timegate-inner { text-align: center; max-width: 340px; width: 100%; }
.timegate-title {
  margin: 0 0 18px;
  font-size: 12px; letter-spacing: .18em; line-height: 1.9;
  color: rgba(169,155,181,.85);
}
.timegate-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
  margin-bottom: 18px;
}
.timegate-hour {
  padding: 9px 0; border: 0; cursor: pointer;
  background: rgba(237,224,200,.06);
  color: rgba(237,224,200,.85);
  font: 11px/1 var(--font-pixel);
  letter-spacing: .06em;
  transition: background .25s var(--ease), color .25s var(--ease);
}
.timegate-hour:hover, .timegate-hour:focus-visible { background: rgba(242,200,121,.18); color: var(--lamp); }
.timegate-hour.is-current { color: var(--lamp); background: rgba(242,200,121,.1); }
.timegate-hour.is-closed {
  cursor: default; pointer-events: none;
  color: rgba(169,155,181,.22); background: rgba(237,224,200,.02);
}
.timegate-now {
  padding: 8px 22px; border: 0; cursor: pointer;
  background: transparent;
  color: rgba(169,155,181,.75);
  font-size: 12px; letter-spacing: .22em;
  transition: color .25s var(--ease);
}
.timegate-now:hover, .timegate-now:focus-visible { color: var(--paper); }

.about {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 0 32px;
  background: rgba(12,10,17,.82);
  opacity: 0; transition: opacity .4s var(--ease);
}
.about.is-in { opacity: 1; }
.about[hidden] { display: none; }
.about-inner { text-align: center; }
.about-line {
  margin: 0 0 10px;
  font-size: 13px; line-height: 2; letter-spacing: .1em;
  color: rgba(237,224,200,.9);
}
.about-line--dim { color: rgba(169,155,181,.75); font-size: 12px; margin: 0; }


/* ---------------------------------------------------------- 寬螢幕
   桌機或平板橫放:把整個介面收成一個手機比例的直欄置中,
   比例跟手機一致(場景 1024:1536 = 2:3),兩側留暗邊。
   用 max-width + margin auto 置中,不動 transform,免得跟動畫打架。 */
@media (min-aspect-ratio: 7/10) {
  /* 只把「店」收成手機比例的直欄:場景、抬頭資訊、預覽列。
     彈窗類(物品、收藏冊、關於、時光機)維持整個視窗置中,
     置中交給各自的 place-items / flex,最不容易歪。 */
  .stage,
  .hud,
  .devbar {
    max-width: calc(var(--appvh, 100vh) * 0.6667);
    margin-left: auto;
    margin-right: auto;
  }

  /* 物品卡一律縮到裝得進視窗:不捲動、不被切掉,一眼看完整張。
     卡片寬度和物品圖高度都跟著視窗高度縮,矮視窗自動變小。 */
  .item-layer {
    place-items: center;
    overflow: hidden;
    padding: 20px 0;
  }
  .item-card {
    width: min(86vw, 27rem, var(--appvh, 100vh) * 0.42);
    gap: 12px;
  }
  .item-card-frame { padding: 22px 20px 20px; }
  .item-figure { min-height: 0; margin-bottom: 12px; }
  .item-figure img { max-height: min(22vh, 180px); width: auto; max-width: 68%; }
  .item-name { margin-bottom: 12px; font-size: clamp(14px, 1.9vh, 18px); }
  .item-text { min-height: 4.2em; font-size: 13px; line-height: 1.9; }
  .item-stamp { margin-top: 16px; padding-top: 12px; }

  /* 底部資訊照手機的排法:低語在左下、拾起數在它下面 */
  .hud--bottom { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* 關於按鈕貼齊直欄的右下角,而不是整個螢幕的右下角 */
  .btn--about {
    right: calc((100vw - min(100vw, var(--appvh, 100vh) * 0.6667)) / 2 + 16px);
  }
}
