:root {
  --bg: #2b1d16;
  --wall: #f6e3c4;
  --wood: #a86b3c;
  --wood-dark: #6e4224;
  --paper: #fffaf0;
  --ink: #3b2a20;
  --muted: #8a6a55;
  --green: #3f8f5a;
  --red: #c4553c;
  --gold: #f2c14e;
  --px: 4px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

/* 像素風外框 */
.pixel-box, #dialog, #panel, #askButtons button, #askForm input, #askForm button, #hud button {
  border: none;
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(-1 * var(--px)) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink);
}

#app {
  max-width: 720px;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--wall);
}

#hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--wood-dark);
  color: var(--paper);
  font-size: 15px;
  flex-wrap: wrap;
}
#hearts { display: flex; gap: 4px; }
#hearts img { width: 27px; height: 24px; image-rendering: pixelated; }
#aiStatus { margin-left: auto; font-size: 13px; opacity: 0.85; }
#hud button { background: var(--paper); color: var(--ink); padding: 2px 10px; font-size: 14px; }
#hud button.off { background: #c9b8a3; color: #6e5a4a; }

#stage {
  position: relative;
  padding: 0 16px 8px;
  background: var(--wall);
}
/* 窗外背景 157×65 像素，整個訪客區照這個比例；訪客的大小、位置都用寬度的百分比 */
#booth {
  position: relative;
  margin: 0 -16px;
  aspect-ratio: 157 / 65;
  background: url(assets/props/bg.png) center / 100% 100% no-repeat;
  image-rendering: pixelated;
}
#visitor {
  position: absolute;
  left: 36.75%;
  bottom: 22%;
  width: 26.5%;
  height: auto;
  image-rendering: pixelated;
  transition: transform 0.4s, opacity 0.4s;
}
#visitor.out { opacity: 0; transform: translateX(80px); }
#visitor.in { opacity: 0; transform: translateX(-80px); }
/* 訪客反應：開心跳一下、難過往下沉，頭上冒出符號 */
#reaction {
  position: absolute;
  top: 6%;
  left: 60%;
  font-size: 34px;
  animation: pop 0.5s ease-out;
}
#reaction[hidden] { display: none; }
@keyframes pop { from { transform: translateY(16px) scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
#booth.happy #visitor { animation: hop 0.5s ease-out 2; }
@keyframes hop { 40% { transform: translateY(-14px); } }
#booth.sad #visitor { transform: translateY(10px); transition: transform 0.6s ease-in; }
#returnTag {
  position: absolute;
  top: 8%;
  left: 64%;
  background: var(--gold);
  padding: 2px 8px;
  font-size: 13px;
  font-weight: bold;
}

#dialog {
  position: relative;
  min-height: 92px;
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--paper);
  cursor: pointer;
  user-select: none;
}
#speaker { font-weight: bold; color: var(--wood-dark); font-size: 14px; margin-bottom: 4px; }
#line { font-size: 17px; line-height: 1.6; min-height: 1.6em; }
#more { position: absolute; right: 12px; bottom: 6px; animation: bob 0.8s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

#desk {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  padding: 18px 16px;
  background: var(--wood) url(assets/ui/desk.png) 0 0 / 192px 96px repeat;
  image-rendering: pixelated;
  border-top: var(--px) solid var(--wood-dark);
}

#paper {
  position: relative;
  border: 24px solid transparent;
  border-image: url(assets/ui/paper9.png) 8 fill / 24px;
  image-rendering: pixelated;
  margin: -10px -6px;
  padding: 10px 14px;
  min-height: 150px;
  transition: outline 0.15s;
}
#paper.droppable { outline: 3px dashed rgba(242, 193, 78, 0.6); outline-offset: 4px; }
#paper.target { outline: 4px solid var(--gold); outline-offset: 4px; }
#paper h2 { font-size: 15px; margin: 0 0 6px; text-align: center; letter-spacing: 4px; }
#paper dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 14px; }
#paper dt { color: var(--muted); }
#paper dd { margin: 0; }
#stampMark {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 6px 12px;
  font-size: 22px;
  font-weight: bold;
  border: 4px solid currentColor;
  transform: rotate(-12deg);
  opacity: 0.85;
}
#stampMark.welcome { color: var(--green); }
#stampMark.wait { color: var(--red); }

#stamps { display: flex; flex-direction: column; gap: 14px; justify-content: center; }
.slot {
  position: relative;
  width: 96px;
  height: 96px;
  background: radial-gradient(ellipse at 50% 92%, rgba(0, 0, 0, 0.28) 0 34%, transparent 36%);
}
.stamp {
  position: absolute;
  inset: 0;
  padding: 0;
  background: none;
  border: none;
  touch-action: none;
  transition: transform 0.15s, opacity 0.15s;
}
.stamp img { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.stamp .label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  font-size: 15px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
  pointer-events: none;
}
.stamp:not(:disabled):hover { transform: translateY(-4px); }
.stamp.selected { transform: translateY(-8px); }
.stamp.selected img { filter: drop-shadow(0 0 4px var(--gold)) drop-shadow(0 0 2px var(--gold)); }
.stamp.lifted { opacity: 0; }

/* 拿起來的印章：放大、浮在空中、影子變遠 */
.stamp.ghost {
  position: fixed;
  left: 0;
  top: 0;
  right: auto;
  bottom: auto;
  width: 96px;
  height: 96px;
  z-index: 20;
  pointer-events: none;
  transition: none;
  filter: drop-shadow(6px 22px 6px rgba(0, 0, 0, 0.3));
}

#stampMark { animation: ink 0.35s ease-out; }
@keyframes ink {
  from { transform: scale(1.5) rotate(-12deg); opacity: 0; }
  60% { opacity: 0.95; }
  to { transform: scale(1) rotate(-12deg); opacity: 0.85; }
}
#desk.thump { animation: thump 0.18s; }
@keyframes thump { 30% { transform: translateY(3px); } 60% { transform: translateY(-1px); } }

.pulse { animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { outline: 4px solid var(--gold); outline-offset: 4px; } }

#guide { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
#guide[hidden] { display: none; }
#guideSvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#guidePath { animation: dash 0.8s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -18; } }
#guideHand { position: absolute; left: 0; top: 0; font-size: 34px; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4)); }

#askBox { padding: 14px 16px 18px; display: grid; gap: 10px; }
#askButtons { display: grid; gap: 8px; }
#askButtons button {
  text-align: left;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 12px;
  font-size: 15px;
}
#askButtons button.core::before { content: "🎯 "; }
#askForm { display: flex; gap: 10px; }
#askForm input { flex: 1; min-width: 0; padding: 8px 10px; font-size: 16px; background: #fff; color: var(--ink); }
#askForm button { padding: 0 16px; background: var(--gold); color: var(--ink); font-weight: bold; }
#askLeft { font-size: 13px; color: var(--muted); }

#hint {
  margin: 0;
  padding: 10px 14px;
  background: var(--gold);
  font-size: 15px;
  font-weight: bold;
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
#overlay[hidden] { display: none; }
#panel {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  max-height: 85dvh; /* 手機瀏覽器的網址列會吃掉高度，用 dvh 才不會超出畫面 */
  overflow-y: auto;
  background: var(--paper);
  padding: 20px 20px 0;
}
#panel h1 { margin: 0 0 8px; font-size: 26px; text-align: center; }
#panel h2 { margin: 0 0 10px; font-size: 20px; }
#panel p { line-height: 1.7; margin: 8px 0; }
/* 按鈕列固定在面板底部，內容再長也按得到 */
#panel .actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 16px -20px 0;
  padding: 12px 20px 16px;
  background: var(--paper);
  border-top: 2px solid #e7dccb;
}
#panel details.items { margin: 8px 0; }
#panel details.items summary { cursor: pointer; font-weight: bold; color: var(--wood-dark); }
#panel .actions button {
  padding: 10px 22px;
  background: var(--gold);
  color: var(--ink);
  font-weight: bold;
  border: none;
  box-shadow: 0 4px 0 var(--wood-dark);
}
#panel .actions button.secondary { background: #e7dccb; }
#panel textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px;
  font: inherit;
  font-size: 16px;
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  resize: vertical;
}
#panel .result-good { color: var(--green); }
#panel .result-bad { color: var(--red); }
#panel .tags span { display: inline-block; background: var(--gold); padding: 2px 8px; margin: 2px 4px 2px 0; font-size: 14px; }
#panel .verdict { background: #f3e7d3; padding: 10px 12px; }
#panel .rules li { margin: 4px 0; }
#panel .album { display: grid; gap: 6px; padding: 0; list-style: none; font-size: 14px; }
#panel canvas.card { width: 100%; height: auto; display: block; margin: 12px 0; }
#panel .muted { color: var(--muted); font-size: 14px; }

@media (max-width: 480px) {
  #desk { gap: 14px; }
  .slot { width: 72px; height: 72px; }
  .stamp .label { font-size: 13px; }
  #line { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #visitor, #more, #guidePath, .pulse, #stampMark, #reaction { transition: none; animation: none; }
}
