:root {
  --cream: #fff6ea;
  --mint: #bfeadf;
  --mint-deep: #6bbfa8;
  --peach: #ffd2c2;
  --peach-deep: #f4a48a;
  --lilac: #e4d7ff;
  --ink: #3d3a45;
  --muted: #7a7486;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.86);
  --shadow: 0 14px 40px rgba(70, 50, 80, 0.16);
  --radius: 24px;
  --radius-lg: 32px;
  --font: "PingFang SC", "Noto Sans SC", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #1c2a24;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.glass {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(255,255,255,0.75);
  box-shadow: var(--shadow);
}

/* ===== Views ===== */
.view {
  position: fixed; inset: 0;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
  z-index: 1;
}
.view.active { opacity: 1; pointer-events: auto; }

/* ===== Map / scene ===== */
.view-map { z-index: 2; }
.scene-bg {
  position: absolute; inset: 0;
  background:
    url("./assets/scenes/town-overview.jpg") center / cover no-repeat;
  transform: scale(1.02);
}
.scene-bg.night {
  background-image: url("./assets/scenes/town-night.jpg");
}
.scene-bg.late {
  background-image: url("./assets/scenes/town-night-dark.jpg");
}
.view-map.night .scene-vignette {
  background:
    radial-gradient(ellipse at 50% 45%, transparent 46%, rgba(8, 12, 28, 0.38) 100%),
    linear-gradient(180deg, rgba(8, 14, 32, 0.08), transparent 26%, transparent 68%, rgba(6, 10, 22, 0.42));
}
.scene-vignette {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 45%, transparent 40%, rgba(28, 30, 40, 0.28) 100%),
    linear-gradient(180deg, rgba(255,246,234,0.18), transparent 22%, transparent 70%, rgba(20,30,28,0.35));
  pointer-events: none;
}

.hud-top {
  position: absolute; top: 16px; left: 16px; right: 16px;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  z-index: 5;
}
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 999px;
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.85);
  box-shadow: 0 8px 24px rgba(60,40,70,0.12);
  font-size: 0.92rem; font-weight: 600;
}
.hud-top .chip {
  padding: 0;
  border-radius: 0;
  background: none;
  backdrop-filter: none;
  border: none;
  box-shadow: none;
  text-shadow: 0 1px 2px rgba(255,255,255,0.85), 0 0 8px rgba(255,246,234,0.9);
}
.brand-chip { padding: 0; }
.brand-chip strong { display: block; line-height: 1.1; }
.coin-chip { margin-left: auto; background: none; }
button.music-chip {
  width: 28px; height: 28px; padding: 0;
  border: none; background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff6ea;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,0.9)) drop-shadow(0 2px 3px rgba(20,16,30,0.65));
}
button.music-chip svg { width: 22px; height: 22px; display: block; }
button.music-chip.on { color: #fff; }
button.tts-toggle {
  width: 36px; height: 36px; padding: 6px;
  border: 1px solid rgba(255,255,255,0.9); border-radius: 50%;
  background: rgba(255,255,255,0.7); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: #8a8494;
}
button.tts-toggle svg { width: 22px; height: 22px; display: block; }
button.tts-toggle.on { color: #2f6f5e; }
.user-chip { background: none; }

.bulletin {
  position: absolute; left: 8px; top: 48px; z-index: 4;
  width: min(300px, 42vw);
  pointer-events: none;
}
.bulletin img { width: 100%; height: auto; display: block; }
.bulletin-notes {
  position: absolute;
  left: 22%; right: 10%; top: 36%; bottom: 46%;
  overflow: hidden;
  color: #6a4b32;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}
.bulletin-notes p { margin: 0 0 4px; }
.bulletin-notes span { margin-right: 6px; color: #8a6244; font-weight: 650; }
.bulletin-empty { color: #8d735c; font-weight: 650; }

.map-hotspots, .npc-pins {
  position: absolute; inset: 0; z-index: 3;
}
.npc-pins { pointer-events: none; }
.hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 0; max-width: 140px;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  cursor: pointer; text-align: center;
  transition: transform .15s ease;
}
.hotspot:hover, .hotspot:focus-visible {
  transform: translate(-50%, -54%) scale(1.04);
  outline: none;
}
.hotspot .name {
  font-weight: 700; font-size: 0.82rem; white-space: nowrap;
  text-shadow:
    0 1px 0 rgba(255,255,255,0.95),
    0 0 8px rgba(255,246,234,0.95),
    0 2px 4px rgba(40,30,50,0.45);
}

.npc-pin {
  position: absolute; transform: translate(-50%, calc(-100% - 16px));
  display: flex; flex-direction: column; align-items: center;
  pointer-events: auto; z-index: 4;
  border: none; background: none; padding: 0;
  cursor: pointer;
}
.npc-pin:hover, .npc-pin:focus-visible {
  transform: translate(-50%, calc(-100% - 18px)) scale(1.08);
  outline: none;
  z-index: 6;
}
.npc-pin img {
  width: 25px; height: 25px; border-radius: 50%;
  object-fit: cover; border: 1.5px solid #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
  background: #f3ebe3;
  pointer-events: none;
}
.npc-pin .bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: none;
  margin: 0;
  padding: 4px 8px;
  border-radius: 10px;
  background: rgba(255, 246, 234, 0.96);
  color: var(--ink);
  font-size: 0.72rem;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(20, 16, 30, 0.18);
  opacity: 0;
  pointer-events: none;
}
.npc-pin .bubble strong { font-weight: 700; }
.npc-pin .bubble small { color: var(--muted); font-weight: 650; }
.npc-pin:hover .bubble,
.npc-pin:focus-visible .bubble { opacity: 1; }

/* First-visit greeting */
.greet-card {
  position: absolute; left: 16px; bottom: 60px;
  width: min(320px, calc(100% - 32px)); z-index: 6;
  border-radius: var(--radius-lg); padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.greet-who { display: flex; gap: 10px; align-items: center; }
.greet-who img {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
  border: 2px solid #fff; background: #f3ebe3;
}
.greet-who strong { display: block; line-height: 1.2; }
.greet-who small { color: var(--muted); }
.greet-card p { margin: 0; line-height: 1.45; font-size: 0.92rem; }
.greet-people { display: flex; flex-direction: column; gap: 8px; }
.greet-person {
  text-align: left; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.95);
  background: rgba(255,255,255,0.85);
  border-radius: 14px; padding: 8px 12px;
  font-weight: 650; font-size: 0.84rem;
}
.greet-person:hover { background: linear-gradient(135deg, var(--peach), var(--mint)); }
.greet-wander { align-self: flex-start; }

/* Resident rail */
.resident-rail {
  position: absolute; right: 16px; top: 88px; bottom: 16px;
  width: min(220px, 34vw); z-index: 5;
  border-radius: var(--radius-lg); padding: 12px;
  display: none; flex-direction: column; gap: 8px;
  overflow: hidden;
}
.resident-rail.open { display: flex; }
.rail-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 700; padding: 4px 4px 8px;
}
.rail-head small { color: var(--muted); font-weight: 500; }
.rail-list { overflow: auto; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.rail-item {
  display: flex; gap: 10px; align-items: center;
  padding: 8px; border-radius: 16px;
  background: rgba(255,255,255,0.55);
  cursor: pointer; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.rail-item:hover { background: rgba(255,255,255,0.9); border-color: rgba(191,234,223,0.9); }
.rail-item img {
  width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; border: 2px solid #fff; flex-shrink: 0;
  background: linear-gradient(135deg, var(--peach), var(--mint));
}
.rail-item .txt { min-width: 0; }
.rail-item strong { display: block; font-size: 0.88rem; }
.rail-item small {
  display: block; color: var(--muted); font-size: 0.72rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ===== Talk window ===== */
.view-talk {
  inset: auto 16px 16px auto;
  width: min(440px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 116px));
  z-index: 6;
  display: flex;
  background: none;
}
.talk-panel {
  margin: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 0; overflow: hidden;
  position: relative;
}
.talk-head {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.talk-face {
  width: 72px; height: 88px;
  object-fit: contain; object-position: bottom center;
  background: transparent;
  pointer-events: none; user-select: none;
}
.talk-who { min-width: 0; }
.talk-tools {
  display: flex; flex-direction: row; align-items: center; gap: 6px;
}
.talk-close {
  border: none; background: rgba(255,255,255,0.7);
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--muted);
}
.talk-who h2 { margin: 0; font-size: 1.15rem; }
.talk-who p { margin: 2px 0 0; font-size: 0.8rem; }
.rel-line {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px; min-width: 0;
  font-size: 0.75rem; color: var(--peach-deep);
}
.rel-heart { color: #e07a8a; line-height: 1; }
.rel-line strong { font-size: 0.75rem; }
.rel-line small { color: var(--muted); white-space: nowrap; }
.rel-bar {
  width: 56px; height: 4px; flex: 0 0 56px;
  border-radius: 999px; background: rgba(0,0,0,0.06);
  margin: 0; overflow: hidden;
}
.rel-bar i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #ffb3c1, #ff8fab);
  border-radius: inherit;
}
.talk-log {
  flex: 1; min-height: 0; overflow: auto;
  background: rgba(255,255,255,0.5);
  border-radius: 18px; padding: 12px;
}
.bubble {
  max-width: 88%; margin: 8px 0; padding: 10px 12px;
  border-radius: 16px; line-height: 1.45; font-size: 0.92rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.bubble.me {
  margin-left: auto;
  background: linear-gradient(135deg, #ffe0d2, #ffd0c0);
  border-bottom-right-radius: 6px;
}
.bubble.npc {
  background: #fff;
  border-bottom-left-radius: 6px;
}
.bubble .who { font-weight: 700; font-size: 0.78rem; margin-bottom: 2px; color: var(--mint-deep); }
.bubble.sys {
  margin: 8px auto; max-width: 80%; text-align: center;
  background: rgba(191,234,223,0.7); font-size: 0.78rem; color: var(--muted);
  border-radius: 999px; padding: 6px 12px;
}

.talk-input { display: flex; gap: 8px; align-items: center; }
.talk-input input, .mem-tools select, .mem-tools input {
  flex: 1; border-radius: 999px; border: 1px solid rgba(0,0,0,0.06);
  padding: 12px 16px; background: rgba(255,255,255,0.92);
  outline: none;
}
.talk-input input:focus { box-shadow: 0 0 0 3px rgba(107,191,168,0.35); }
.btn {
  border: none; border-radius: 999px; padding: 12px 18px;
  font-weight: 700; cursor: pointer;
  background: rgba(255,255,255,0.85);
}
.btn.primary {
  background: linear-gradient(135deg, #7fd4bd, #f4b39a);
  color: #2f2a35;
}
button.btn.send {
  width: 42px; height: 42px; padding: 0; flex: 0 0 42px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #25d366; color: #fff;
}
button.btn.send svg { width: 20px; height: 20px; display: block; fill: currentColor; margin-left: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Dock ===== */
.dock {
  position: fixed; left: 12px; bottom: 12px; transform: none;
  z-index: 40;
  display: flex; gap: 2px; padding: 0;
  width: auto;
  background: none; border: none; box-shadow: none;
  backdrop-filter: none;
}
.dock-item,
.dock-toggle {
  position: relative;
  flex: 0 0 auto; width: 32px; height: 32px;
  border: none; background: transparent;
  padding: 0; border-radius: 0;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  color: var(--ink);
}
.dock-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(255, 246, 234, 0.96);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(20, 16, 30, 0.18);
  opacity: 0;
  pointer-events: none;
}
.dock-item:hover .dock-tip,
.dock-item:focus-visible .dock-tip,
.dock-toggle:hover .dock-tip,
.dock-toggle:focus-visible .dock-tip { opacity: 1; }
.dock-item .ico,
.dock-toggle .ico {
  font-size: 1.35rem; line-height: 1;
  filter:
    drop-shadow(0 0 2px rgba(255,255,255,0.95))
    drop-shadow(0 1px 0 rgba(255,255,255,0.9))
    drop-shadow(0 2px 4px rgba(20, 16, 30, 0.75));
}
.dock-toggle svg { width: 22px; height: 22px; display: block; }
.dock-item img,
.dock-toggle img {
  width: 32px; height: 32px; display: block;
  filter: none;
}
.dock-item.active .ico {
  filter:
    drop-shadow(0 0 6px rgba(255, 246, 234, 0.95))
    drop-shadow(0 2px 5px rgba(20, 16, 30, 0.7));
}
.dock-tick:active { transform: scale(0.96); }

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(40, 35, 50, 0.38);
  backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
}
.modal-card {
  width: min(560px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  border-radius: var(--radius-lg);
  padding: 20px 20px 16px;
  position: relative;
  background: var(--glass-strong);
}
.building-card { width: min(620px, 100%); }
.settings-card { width: min(440px, 100%); }
.settings-card h2 { margin: 0 0 8px; }
.settings-hint { margin: 0 0 14px; font-size: 0.85rem; }
.settings-row { flex-wrap: wrap; }
.close {
  position: absolute; right: 14px; top: 10px;
  border: none; background: rgba(255,255,255,0.7);
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 1.3rem; cursor: pointer; color: var(--muted);
}
.b-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.eyebrow { margin: 0; font-size: 0.75rem; color: var(--muted); letter-spacing: 0.04em; }
.b-head h2 { margin: 4px 0; font-size: 1.45rem; }
.b-thumb {
  width: 92px; height: 72px; border-radius: 16px; flex-shrink: 0;
  background:
    url("./assets/scenes/town-overview.jpg") center / cover no-repeat;
  border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.modal-card h3 { margin: 14px 0 8px; font-size: 0.95rem; }
.present-row { display: flex; flex-wrap: wrap; gap: 10px; }
.present-card {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 16px;
  background: rgba(255,255,255,0.7); cursor: pointer;
  border: 1px solid rgba(255,255,255,0.9);
}
.present-card img {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  border: 2px solid #fff;
}
.present-card strong { display: block; font-size: 0.85rem; }
.present-card small { color: var(--muted); font-size: 0.72rem; }
.empty-present { color: var(--muted); font-size: 0.88rem; padding: 8px 0; }

.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.action-card {
  border: none; text-align: left; cursor: pointer;
  padding: 12px; border-radius: 18px;
  background: linear-gradient(160deg, rgba(255,255,255,0.95), rgba(191,234,223,0.55));
  box-shadow: 0 6px 16px rgba(60,40,70,0.08);
}
.action-card:nth-child(2) { background: linear-gradient(160deg, #fff, rgba(255,210,194,0.65)); }
.action-card:nth-child(3) { background: linear-gradient(160deg, #fff, rgba(228,215,255,0.65)); }
.action-card:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.2); }
.action-card strong { display: block; margin-bottom: 4px; }
.action-card small { color: var(--muted); line-height: 1.35; display: block; }
.tip {
  margin: 14px 0 0; padding: 10px 12px; border-radius: 14px;
  background: rgba(255, 246, 234, 0.9); font-size: 0.8rem; color: var(--muted);
}

.status-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.stat {
  padding: 12px; border-radius: 16px; background: rgba(255,255,255,0.7);
}
.stat small { color: var(--muted); display: block; }
.stat strong { font-size: 1.2rem; }
.mem-card .mem-tools { margin: 8px 0 12px; }
.mem-results { min-height: 220px; max-height: 420px; }

.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 80; padding: 10px 16px; border-radius: 999px;
  background: rgba(45, 40, 55, 0.9); color: #fff;
  font-size: 0.88rem; box-shadow: var(--shadow);
  max-width: min(520px, 90vw); text-align: center;
}

@media (max-width: 900px) {
  .bulletin { width: min(220px, 58vw); top: 42px; }
  .bulletin-notes { font-size: 0.68rem; }
  .resident-rail.open { left: 12px; right: 12px; width: auto; bottom: 56px; }
  .view-talk {
    left: 64px; right: 10px; bottom: 12px; width: auto;
    height: min(62vh, 640px);
  }
  .talk-face { width: 60px; height: 74px; }
  .talk-head { grid-template-columns: 60px minmax(0, 1fr) auto; }
  .hotspot { padding: 0; }
  .hotspot .name { font-size: 0.74rem; }
}
