/* ===== みつけて、となりびと ===== */
:root {
  --night: #0b1230;
  --night-2: #141d45;
  --night-3: #1e2a5c;
  --amber: #ffcf7a;
  --amber-2: #ffb347;
  --warm: #ff9f5a;
  --text: #f6efe2;
  --muted: #b9b4c9;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #05081a;
  color: var(--text);
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, var(--night-3), var(--night) 60%, #070b20);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  opacity: 1;
}
.screen.active { display: flex; }

@keyframes fadeIn { from { opacity: .85; } to { opacity: 1; } }

/* ----- ボタン ----- */
.btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform .15s ease, filter .2s ease;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  color: #3a2208;
  background: linear-gradient(180deg, #ffe2a8, var(--amber-2));
  box-shadow: 0 0 24px rgba(255, 190, 100, .45), inset 0 -3px 0 rgba(150, 80, 0, .25);
}
.btn-ghost {
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .18);
}
.btn:disabled { opacity: .35; }

.icon-btn {
  font-size: 1.2rem;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .15);
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  cursor: pointer;
}
.chip {
  font-size: .8rem;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(255, 207, 122, .15);
  color: var(--amber);
  border: 1px solid rgba(255, 207, 122, .3);
  white-space: nowrap;
}

/* ----- 上部バー ----- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  min-height: 60px;
  background: linear-gradient(180deg, rgba(5, 8, 26, .85), rgba(5, 8, 26, 0));
  z-index: 5;
}
.topbar-title {
  font-family: 'Shippori Mincho', serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .08em;
  text-align: center;
  flex: 1;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ----- タイトル ----- */
.title-bg {
  position: absolute; inset: 0;
  background: url('assets/img/title.jpg') center top / cover no-repeat;
}
.title-bg::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(5, 8, 26, 0) 50%, rgba(5, 8, 26, .9) 85%);
}
.title-bottom {
  position: relative;
  margin-top: auto;
  padding: 0 24px 40px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.title-sub { margin: 0; color: var(--muted); font-size: .85rem; letter-spacing: .2em; }
.title-main {
  margin: 0 0 14px;
  font-family: 'Shippori Mincho', serif;
  font-size: 1.9rem;
  letter-spacing: .12em;
  text-shadow: 0 0 18px rgba(255, 200, 120, .6);
}
.title-note { margin: 4px 0 0; color: var(--muted); font-size: .75rem; }

/* ----- マップ ----- */
#screen-map .topbar { position: absolute; top: var(--safe-top); left: 0; right: 0; }
.map-scroll {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.map-scroll::-webkit-scrollbar { display: none; }
.map { position: relative; width: 100%; overflow: hidden; }
.map-img { display: block; width: 100%; height: auto; filter: brightness(.8) saturate(.9); }

.spot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  border: none; padding: 0; background: none;
  cursor: pointer;
}
.spot .spot-dot {
  position: absolute; inset: 12px;
  border-radius: 50%;
  background: rgba(160, 170, 210, .35);
  border: 1px dashed rgba(220, 225, 255, .55);
}
.spot.playable .spot-dot {
  background: rgba(255, 207, 122, .25);
  border: 2px solid var(--amber);
  animation: beckon 1.8s ease-in-out infinite;
}
.spot.lit .spot-dot {
  inset: 8px;
  border: none;
  background: radial-gradient(circle, #fff6d8 0%, var(--amber) 35%, rgba(255, 160, 60, 0) 72%);
  animation: flicker 3s ease-in-out infinite;
}
.spot.lit::before {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 150px; height: 150px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 190, 100, .35), rgba(255, 190, 100, 0) 65%);
  pointer-events: none;
}
.spot-label {
  position: absolute; top: 40px; left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(5, 8, 26, .75);
  color: var(--text);
}
.spot:not(.playable):not(.lit) .spot-label { display: none; }

@keyframes beckon {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 207, 122, .6); }
  50% { transform: scale(1.15); box-shadow: 0 0 0 10px rgba(255, 207, 122, 0); }
}
@keyframes flicker {
  0%, 100% { opacity: 1; } 45% { opacity: .85; } 50% { opacity: .95; } 70% { opacity: .8; }
}

.map-hint {
  position: absolute; bottom: calc(14px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: .8rem;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(5, 8, 26, .78);
  white-space: nowrap;
  pointer-events: none;
}

/* ----- イントロ ----- */
.intro-inner {
  margin: auto;
  padding: 24px 28px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.intro-night { margin: 0; color: var(--amber); letter-spacing: .4em; font-size: .9rem; }
.intro-title {
  margin: 0;
  font-family: 'Shippori Mincho', serif;
  font-size: 1.6rem;
  letter-spacing: .1em;
}
.intro-text {
  margin: 10px 0 18px;
  font-family: 'Shippori Mincho', serif;
  line-height: 2;
  white-space: pre-line;
  color: #e8e1d3;
}

/* ----- さがす ----- */
.play-lead {
  margin: 0 16px 10px;
  min-height: 2.8em;
  font-size: .88rem;
  line-height: 1.5;
  text-align: center;
  color: var(--muted);
  white-space: pre-line;
}
.stage {
  position: relative;
  width: min(100%, calc(100dvh - 240px - var(--safe-top) - var(--safe-bottom)));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 6px;
  touch-action: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.stage-bg, #dark {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
.stage-bg { object-fit: cover; }
#dark { z-index: 3; }

.target {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
}
.target.neighbor img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 0 6px rgba(255, 220, 160, .5));
}
.target.kakera {
  width: 5.5%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #fffbe8 0%, #ffd27a 35%, rgba(255, 150, 60, .0) 72%);
  animation: pulse 1.6s ease-in-out infinite;
}
.target.near { animation: wiggle .5s ease-in-out infinite; }
.target.found { animation: none; }
.target.found::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 140%; height: 140%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(255, 230, 170, .9);
  animation: ring .8s ease-out forwards;
}
@keyframes pulse { 0%, 100% { transform: translate(-50%, -50%) scale(.85); } 50% { transform: translate(-50%, -50%) scale(1.15); } }
@keyframes wiggle { 0%, 100% { transform: translate(-50%, -50%) rotate(-4deg); } 50% { transform: translate(-50%, -50%) rotate(4deg); } }
@keyframes ring { from { opacity: 1; width: 60%; height: 60%; } to { opacity: 0; width: 220%; height: 220%; } }

.toast {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translate(-50%, 20px);
  z-index: 6;
  max-width: 88%;
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(255, 246, 225, .95);
  color: #3a2a18;
  font-size: .9rem;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spark {
  position: absolute;
  z-index: 5;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #fff3c4;
  box-shadow: 0 0 8px #ffd27a;
  pointer-events: none;
  animation: sparkFly .9s ease-out forwards;
}
@keyframes sparkFly {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.3); }
}

/* ----- トレイ ----- */
.tray {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 16px;
  background: linear-gradient(180deg, rgba(120, 70, 30, .0), rgba(120, 70, 30, .35));
}
.tray-slots { flex: 1; display: flex; gap: 10px; justify-content: center; }
.slot {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: rgba(30, 20, 15, .55);
  border: 1px solid rgba(255, 207, 122, .2);
  display: grid; place-items: center;
  position: relative;
  overflow: hidden;
}
.slot img { width: 86%; height: 86%; object-fit: contain; filter: brightness(0) opacity(.45); transition: filter .6s ease; }
.slot .slot-orb {
  width: 34%; aspect-ratio: 1; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  transition: background .6s ease, box-shadow .6s ease;
}
.slot.got {
  border-color: var(--amber);
  box-shadow: 0 0 16px rgba(255, 207, 122, .45);
  background: rgba(255, 207, 122, .15);
}
.slot.got img { filter: none; }
.slot.got .slot-orb { background: radial-gradient(circle, #fffbe8, #ffc35a); box-shadow: 0 0 14px #ffc35a; }

.hint-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 64px; height: 64px;
  border-radius: 16px;
  border: 1px solid rgba(255, 207, 122, .4);
  background: rgba(255, 207, 122, .12);
  color: var(--amber);
  font-family: inherit;
  cursor: pointer;
}
.hint-btn:disabled { opacity: .35; }
.hint-lantern { font-size: 1.5rem; line-height: 1; }
.hint-label { font-size: .7rem; }

/* ----- 発見 ----- */
#screen-reveal { overflow-y: auto; }
.reveal-inner {
  position: relative;
  margin: auto;
  padding: 16px 24px 28px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.reveal-glow {
  position: absolute; top: -10px; left: 50%;
  width: 300px; height: 300px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 200, 120, .45), rgba(255, 200, 120, 0) 65%);
  animation: flicker 3s infinite;
  pointer-events: none;
}
.reveal-sprite { position: relative; width: min(200px, 28dvh); height: min(200px, 28dvh); object-fit: contain; animation: popIn .8s cubic-bezier(.2, 1.4, .4, 1); }
.reveal-label { position: relative; margin: 4px 0 0; color: var(--amber); letter-spacing: .4em; }
.reveal-name { position: relative; margin: 0; font-family: 'Shippori Mincho', serif; font-size: 1.9rem; letter-spacing: .15em; }
.reveal-title { position: relative; margin: 0; color: var(--muted); font-size: .9rem; }
.reveal-text {
  position: relative;
  margin: 12px 0 18px;
  font-family: 'Shippori Mincho', serif;
  line-height: 1.85;
  white-space: pre-line;
}
@keyframes popIn { from { opacity: 0; transform: scale(.4) translateY(30px); } to { opacity: 1; transform: none; } }

/* ----- 絵本 ----- */
.book {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto;
  padding: 0 18px;
}
.book-img {
  width: min(100%, 52dvh);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  animation: fadeIn .6s ease;
}
.book-text {
  margin: 18px 0;
  font-family: 'Shippori Mincho', serif;
  font-size: 1.05rem;
  line-height: 2;
  text-align: center;
  white-space: pre-line;
  animation: fadeIn .8s ease;
}
.book-nav { display: flex; gap: 12px; justify-content: center; padding: 12px 16px 18px; }
.book-nav .btn { min-width: 120px; }

/* ----- 図鑑 ----- */
.zukan-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 6px 16px 24px;
  align-content: start;
}
.zcard {
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}
.zcard .zno { font-size: .7rem; letter-spacing: .1em; }
.zcard .zimg { width: 72%; aspect-ratio: 1; display: grid; place-items: center; font-size: 2rem; opacity: .4; }
.zcard .zimg img { width: 100%; height: 100%; object-fit: contain; }
.zcard .zname { font-size: .85rem; }
.zcard.got {
  color: var(--text);
  border-color: rgba(255, 207, 122, .5);
  background: linear-gradient(180deg, rgba(255, 207, 122, .14), rgba(255, 207, 122, .04));
}
.zcard.got .zimg { opacity: 1; }

.zukan-footer {
  padding: 10px 16px 16px;
  display: flex;
  justify-content: center;
  background: linear-gradient(0deg, rgba(5, 8, 26, .9), rgba(5, 8, 26, 0));
}
.zukan-footer .btn { width: 100%; max-width: 320px; font-size: .92rem; padding: 12px 20px; }

/* ----- モーダル ----- */
.modal {
  position: absolute; inset: 0;
  z-index: 50;
  display: grid; place-items: center;
  background: rgba(3, 5, 18, .75);
  padding: 20px;
  animation: fadeIn .3s ease;
}
.modal.hidden { display: none; }
.modal-card {
  width: 100%;
  max-height: 90%;
  overflow-y: auto;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--night-3), var(--night-2));
  border: 1px solid rgba(255, 207, 122, .25);
  padding: 22px 20px 18px;
  text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-card h3 { margin: 0; font-family: 'Shippori Mincho', serif; font-size: 1.5rem; letter-spacing: .1em; }
.modal-card .m-sub { margin: 0; color: var(--muted); font-size: .85rem; }
.modal-card .m-quote { margin: 0; font-family: 'Shippori Mincho', serif; line-height: 1.8; }
.modal-card .m-img { width: 160px; height: 160px; object-fit: contain; margin: 0 auto; }
.m-table { font-size: .82rem; color: var(--muted); line-height: 1.8; }
.m-links { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.m-links a, .m-share-btn {
  font-family: inherit;
  font-size: .8rem;
  color: var(--amber);
  background: rgba(255, 207, 122, .08);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 207, 122, .4);
  cursor: pointer;
}
.m-share {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding-top: 4px;
}
.m-share-btn.primary-share {
  color: #3a2208;
  background: linear-gradient(180deg, #ffe2a8, var(--amber-2));
  border: none;
  font-weight: 700;
}
