* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Hiragino Sans', 'Yu Gothic', 'Segoe UI', sans-serif;
  background: #10141f;
  color: #eef1f8;
  overflow-x: hidden;
}
.hidden { display: none !important; }
button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 10px;
  background: #2b3450; color: #eef1f8; padding: 8px 14px; font-size: 14px;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); background: #384166; }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: .4; cursor: not-allowed; }

#app { position: relative; min-height: 100vh; display: flex; flex-direction: column; }
#fx-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 500; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 18px;
  background: linear-gradient(135deg, #1b2138, #232a4a);
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
  position: sticky; top: 0; z-index: 50;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat {
  display: flex; flex-direction: column; align-items: center; min-width: 84px;
  background: rgba(255,255,255,.05); border-radius: 10px; padding: 4px 10px;
}
.stat-label { font-size: 10px; opacity: .65; }
.stat span:last-child { font-weight: 700; font-size: 14px; }
.rank-stat { background: linear-gradient(135deg, rgba(255,217,61,.18), rgba(255,159,67,.12)); }
#stat-rank-value { color: #ffd93d; }

/* ---------- Layout ---------- */
.layout { display: flex; flex: 1; gap: 14px; padding: 14px; }
@media (max-width: 900px) { .layout { flex-direction: column; } }

.scene-wrap { flex: 1.4; min-width: 0; }
.scene {
  position: relative; width: 100%; height: 62vh; min-height: 380px;
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,.45);
  background: #87ceeb;
}
.scene .sky {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, #6ec6ff 0%, #bdeaff 55%, #eafff3 100%);
  transition: background 1.5s ease;
}
.scene.night .sky {
  background: linear-gradient(to bottom, #0b1030 0%, #1a2050 55%, #2a2f5c 100%);
}
.sun-moon {
  position: absolute; top: 8%; font-size: 34px; transform: translateX(-50%);
  transition: left 3s linear; filter: drop-shadow(0 0 12px rgba(255,240,150,.8));
}
.scene.night .sun-moon { filter: drop-shadow(0 0 10px rgba(200,210,255,.8)); }
.clouds { position: absolute; inset: 0; overflow: hidden; }
.cloud {
  position: absolute; left: -10%; font-size: 30px; opacity: .8;
  animation-name: drift; animation-timing-function: linear; animation-iteration-count: infinite;
}
@keyframes drift { from { left: -10%; } to { left: 110%; } }

/* 季節演出: skyにフィルターをかけつつ、舞う粒子(花びら/落ち葉/雪/きらめき)を重ねる */
.scene.season-spring .sky { filter: saturate(1.1) hue-rotate(-6deg); }
.scene.season-autumn .sky { filter: sepia(.18) saturate(1.35) hue-rotate(-8deg); }
.scene.season-winter .sky { filter: saturate(.75) brightness(1.05); }
.scene.season-winter .ground { filter: brightness(1.12) saturate(.65); }
.season-particles { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 4; }
.season-particle { position: absolute; top: -8%; }
.season-particle.fall { animation-name: season-fall; animation-timing-function: linear; animation-iteration-count: infinite; }
.season-particle.rise { top: auto; bottom: -8%; animation-name: season-rise; animation-timing-function: ease-in-out; animation-iteration-count: infinite; }
@keyframes season-fall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: .9; }
  50% { transform: translate(14px, 55vh) rotate(180deg); }
  100% { transform: translate(-14px, 112vh) rotate(360deg); opacity: .6; }
}
@keyframes season-rise {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-80vh); opacity: 0; }
}

/* 地面(.ground)の範囲(下46%)にぴったり合わせる。空を歩いて見えるのを防ぐため */
.pedestrian-layer { position: absolute; left: 0; right: 0; top: 58%; bottom: 3%; overflow: hidden; z-index: 2; }
.pedestrian {
  position: absolute; font-size: 18px; transform: translate(-50%, -50%);
  transition-property: left, top; transition-timing-function: ease-in-out;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.3));
}

.rain-overlay {
  position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(115deg, rgba(180,210,255,.35) 0 2px, transparent 2px 22px);
  animation: rainfall .4s linear infinite;
}
@keyframes rainfall { from { background-position: 0 0; } to { background-position: -40px 60px; } }

.ground {
  position: absolute; left: 0; right: 0; bottom: 0; height: 46%;
  background: linear-gradient(to bottom, #7bc47f, #4f9d5b);
  border-top: 4px solid #3f7f49;
}

/* 町のテーマ(コスメティック): 空・地面の上にtint(色)を重ねるだけの層。昼夜サイクルや
   季節演出は.sky/.groundの背景・filterを直接変えているため、別レイヤーにすることで衝突しない。 */
.theme-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  opacity: 0; transition: opacity .6s ease, background-color .6s ease;
}
.theme-overlay.active { opacity: .38; }

.buildings-layer {
  position: absolute; left: 0; right: 0; top: 8%; bottom: 2%;
  overflow: hidden;
}
.building-icon {
  position: absolute; font-size: 22px; line-height: 1; transform: translate(-50%, -50%);
  user-select: none;
  animation: bob 2.2s ease-in-out infinite;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.building-icon:hover { animation-play-state: paused; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)) drop-shadow(0 0 6px rgba(255,255,255,.6)); }
@keyframes bob { 0%, 100% { transform: translate(-50%, -50%) translateY(0); } 50% { transform: translate(-50%, -50%) translateY(-4px); } }
.building-icon.constructing { animation: construct-shake .3s ease-in-out infinite; opacity: .9; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)) grayscale(.2); }
.building-icon.construction-complete { animation: construct-pop .5s ease; }
.building-icon.evolved { filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)) drop-shadow(0 0 7px rgba(255,217,61,.9)); }
@keyframes construct-shake { 0%, 100% { transform: translate(-50%, -50%) rotate(-4deg); } 50% { transform: translate(-50%, -50%) rotate(4deg); } }
@keyframes construct-pop { 0% { transform: translate(-50%, -50%) scale(0.3); } 60% { transform: translate(-50%, -50%) scale(1.3); } 100% { transform: translate(-50%, -50%) scale(1); } }
.building-more, #layout-overflow {
  position: absolute; top: 6px; right: 10px; font-size: 11px;
  background: rgba(0,0,0,.4); border-radius: 8px; padding: 3px 8px; color: #fff; z-index: 6;
}

.decorations-layer {
  position: absolute; left: 0; right: 0; top: 8%; bottom: 2%;
  overflow: hidden; z-index: 3;
}
.decoration-icon {
  position: absolute; font-size: 26px; line-height: 1; transform: translate(-50%, -50%);
  user-select: none; animation: deco-sparkle 3s ease-in-out infinite;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)) drop-shadow(0 0 8px rgba(255,230,150,.7));
}
@keyframes deco-sparkle {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.08); }
}

/* 町役場: ホバー演出は不具合報告が続いたため廃止。クリック時のバンプ演出のみ残す。
   共通の button:hover(transform: translateY(-1px))が中央寄せ用のtranslateX(-50%)を
   上書きして右にズレていたのが真因だったため、IDセレクタで確実に無効化する。 */
.town-hall {
  position: absolute; left: 50%; bottom: 6%; z-index: 8;
  transform: translateX(-50%);
  font-size: 64px; line-height: 1; background: none; padding: 0; border: 0;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.4));
}
#town-hall:hover { transform: translateX(-50%); background: none; }
.town-hall-icon { display: inline-block; animation: idle-bob 3s ease-in-out infinite; }
.town-hall-icon.bump { animation: bump-anim .25s ease; }
@keyframes idle-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes bump-anim { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

.golden-building {
  position: absolute; font-size: 40px; background: none; padding: 0;
  animation: golden-pulse 1s ease-in-out infinite, golden-spin 4s linear infinite;
  filter: drop-shadow(0 0 14px gold);
  z-index: 10;
}
@keyframes golden-pulse { 0%, 100% { filter: drop-shadow(0 0 8px gold); } 50% { filter: drop-shadow(0 0 22px gold); } }
@keyframes golden-spin { 0%, 92%, 100% { transform: rotate(0deg); } 96% { transform: rotate(8deg); } }

.ufo {
  position: absolute; right: 5%; font-size: 34px; background: none; padding: 0;
  animation: ufo-fly 3s ease-in-out infinite;
  filter: drop-shadow(0 0 10px #8affc1);
}
@keyframes ufo-fly { 0%, 100% { transform: translateX(0) translateY(0); } 50% { transform: translateX(-30px) translateY(10px); } }

.combo-display {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  font-size: 22px; font-weight: 800; color: #ffd93d;
  text-shadow: 0 0 10px rgba(255,217,61,.8);
}
.combo-display.pop { animation: combo-pop .5s ease; }
@keyframes combo-pop { 0% { transform: translateX(-50%) scale(1.6); opacity: 0; } 60% { transform: translateX(-50%) scale(1); opacity: 1; } 100% { opacity: 1; } }

.petition-panel {
  position: absolute; top: 44px; left: 50%; transform: translateX(-50%);
  width: min(92%, 420px); background: rgba(20,24,40,.94); border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; padding: 12px 14px; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: petition-in .3s ease;
}
@keyframes petition-in { from { transform: translateX(-50%) translateY(-14px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
.petition-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.petition-icon { font-size: 26px; }
.petition-text { font-size: 13px; font-weight: 600; line-height: 1.4; }
.petition-actions { display: flex; gap: 8px; }
.petition-agree-btn { flex: 1; background: linear-gradient(135deg, #4caf6b, #7ed957); font-weight: 700; color: #0c1b0f; font-size: 12px; }
.petition-agree-btn:hover { background: linear-gradient(135deg, #5fc27e, #8ee968); }
.petition-ignore-btn { flex: 1; background: #3a3f55; font-size: 12px; }
.petition-timer { height: 4px; background: rgba(255,255,255,.12); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.petition-timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, #ffd93d, #ff9f43); }

.sickness-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 18px;
  background: linear-gradient(90deg, #5a1f1f, #7a2e1f); color: #ffe1cf;
  animation: sickness-pulse 1.6s ease-in-out infinite;
  font-size: 13px;
}
.sickness-icon { font-size: 20px; }
.sickness-text { flex: 1; }
#sickness-cure-btn { background: #ff8a3d; color: #2a1200; font-weight: 800; white-space: nowrap; }
#sickness-cure-btn:hover:not(:disabled) { background: #ffa25f; }
@keyframes sickness-pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.15); } }
.fire-banner { background: linear-gradient(90deg, #6b2f0a, #9a3f0a); color: #ffe0c2; }
.fire-banner #fire-cure-btn { background: #ff6a3d; color: #2a1200; font-weight: 800; white-space: nowrap; }
.fire-banner #fire-cure-btn:hover:not(:disabled) { background: #ff8a5f; }
.collapse-banner { background: linear-gradient(90deg, #2f0a6b, #5a1a9a); color: #e4d6ff; }
.collapse-banner #collapse-cure-btn { background: #a35dff; color: #1a0033; font-weight: 800; white-space: nowrap; }
.collapse-banner #collapse-cure-btn:hover:not(:disabled) { background: #b87cff; }

/* ---------- Panel ---------- */
.panel {
  flex: 1; min-width: 320px; display: flex; flex-direction: column;
  background: #171b2c; border-radius: 18px; padding: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.35);
  max-height: 82vh;
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tab-btn { flex: 1 1 30%; min-width: 88px; background: #232a45; font-size: 13px; padding: 8px 6px; border-radius: 10px; }
.tab-btn.active { background: linear-gradient(135deg, #5b6ef5, #7b5bf5); box-shadow: 0 0 10px rgba(123,91,245,.5); }

.buy-qty { display: flex; gap: 6px; margin-bottom: 8px; }
.qty-btn { flex: 1; background: #232a45; font-size: 12px; padding: 6px; }
.qty-btn.active { background: #4d5ee0; }
.buy-all-row { display: flex; gap: 6px; margin-bottom: 8px; }
.order-btn { flex: 1; background: #232a45; font-size: 12px; padding: 6px; }
.order-btn.active { background: #4d5ee0; }
.buy-all-btn { flex: 1.4; background: #2f9e63; font-size: 12px; font-weight: 700; padding: 6px; white-space: nowrap; }
.buy-all-btn:hover:not(:disabled) { background: #38b975; }

.tab-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 2px; }
.tab-content::-webkit-scrollbar { width: 6px; }
.tab-content::-webkit-scrollbar-thumb { background: #333c5e; border-radius: 4px; }

.card {
  display: flex; align-items: center; gap: 10px; background: #1f2740; border-radius: 12px; padding: 10px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:not(.disabled):not(.locked):hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.card.disabled { opacity: .55; }
.card.locked { opacity: .4; }
.card.pulse { animation: card-pulse .3s ease; }
@keyframes card-pulse { 0% { box-shadow: 0 0 0 rgba(123,220,120,0); } 40% { box-shadow: 0 0 20px rgba(123,220,120,.6); } 100% { box-shadow: 0 0 0 rgba(123,220,120,0); } }
.card-icon { font-size: 30px; width: 40px; text-align: center; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 14px; }
.card-count { color: #8fd3ff; font-weight: 600; }
.card-desc { font-size: 11px; opacity: .7; margin-top: 2px; }
.card-sub { font-size: 11px; color: #9fe8b0; margin-top: 2px; }
.district-badge { color: #ffb46b; font-weight: 700; }
.buy-btn { white-space: nowrap; background: #3a54c9; font-weight: 700; }
.buy-btn:hover:not(:disabled) { background: #4a66e6; }

.upgrade-card .card-title { color: #ffd93d; }
.evolution-card { background: linear-gradient(160deg, #1f2740, #2a2340); }
.evolution-card.owned { box-shadow: 0 0 12px rgba(255,217,61,.35); }
.card-count.evolved-badge { color: #ffd93d; margin-left: 4px; }

.streak-box { background: linear-gradient(135deg, #3a2a1f, #1f2740); border-radius: 12px; padding: 12px; }
.streak-num { font-weight: 800; font-size: 15px; color: #ff9f43; }
.daily-heading { font-size: 13px; opacity: .8; margin: 4px 0 2px; font-weight: 700; }
.quest-intro { margin-bottom: 10px; }
.quest-stage-heading { margin-top: 16px; font-size: 14px; }
.quest-locked-note { opacity: .6; margin: 4px 0 6px; padding: 10px 12px; background: rgba(255,255,255,.04); border-radius: 8px; }
.mission-bar { height: 6px; background: rgba(255,255,255,.1); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.mission-bar-fill { height: 100%; background: linear-gradient(90deg, #4caf6b, #7ed957); }
.mission-card.ready .mission-claim-btn { background: linear-gradient(135deg, #4caf6b, #7ed957); color: #0c1b0f; }
.mission-card.ready { box-shadow: 0 0 12px rgba(123,220,120,.3); }
.mission-card.claimed { opacity: .55; }

.bgm-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; margin: 10px 0; }
.bgm-row.ready { box-shadow: 0 0 10px rgba(123,220,120,.25); }
.bgm-preview-btn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; padding: 0;
  font-size: 14px; background: #2f3757; display: flex; align-items: center; justify-content: center;
}
.bgm-preview-btn:hover { background: #3c4670; }

.empty { text-align: center; opacity: .6; padding: 30px 10px; }

.ach-summary { font-size: 13px; opacity: .8; margin-bottom: 4px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.ach-badge {
  background: #1f2740; border-radius: 10px; padding: 8px; font-size: 11px; text-align: center;
  opacity: .45;
}
.ach-badge.unlocked { opacity: 1; background: linear-gradient(160deg, #2b3a2e, #1f2740); box-shadow: 0 0 10px rgba(123,220,120,.25); }
.ach-name { font-weight: 700; margin-bottom: 2px; }
.ach-desc { opacity: .7; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.stats-item { background: #1f2740; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; opacity: .85; }
.stats-item b { font-size: 15px; color: #8fd3ff; }
.stats-sub { font-size: 11px; color: #9fe8b0; font-weight: 400; }

.prestige-box { background: #1f2740; border-radius: 12px; padding: 16px; text-align: center; }
.prestige-box p { margin: 6px 0; }
.prestige-box.dimension-box { background: linear-gradient(160deg, #1f2740, #2a1d4a); box-shadow: 0 0 16px rgba(150,100,255,.15); }
.prestige-box.relic-box { background: linear-gradient(160deg, #1f2740, #4a3a1d); box-shadow: 0 0 16px rgba(255,200,100,.15); }
.danger-btn { background: linear-gradient(135deg, #f5525b, #f59f52); font-weight: 800; }
.danger-btn:hover:not(:disabled) { background: linear-gradient(135deg, #ff6b73, #ffb46b); }

.fame-shop-list { display: flex; flex-direction: column; gap: 8px; }
.fame-tier-header { font-size: 12px; font-weight: 700; opacity: .75; margin: 6px 2px 0; }
.card.owned { opacity: .7; }
.owned-badge { white-space: nowrap; font-size: 12px; font-weight: 700; color: #7ed957; }

/* ---------- Footer ---------- */
.footer {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 18px; background: #151827; font-size: 12px; opacity: .9;
}
.footer .ver { margin-right: auto; opacity: .6; }
.footer input[type="range"] { width: 80px; accent-color: #7b5bf5; }
.footer .credit { opacity: .55; font-size: 11px; }
.footer .credit a { color: #8fb8ff; text-decoration: none; }
.footer .credit a:hover { text-decoration: underline; }
#save-btn.save-flash { animation: save-flash-anim .8s ease; }
@keyframes save-flash-anim { 0% { box-shadow: 0 0 0 rgba(123,220,120,0); } 30% { box-shadow: 0 0 14px rgba(123,220,120,.8); background: #2e6b45; } 100% { box-shadow: 0 0 0 rgba(123,220,120,0); } }

/* ---------- Toast ---------- */
#toast-container { position: fixed; top: 18px; right: 18px; z-index: 800; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 8px; background: #1f2740; border-radius: 12px; padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); transform: translateX(120%); opacity: 0; transition: transform .35s ease, opacity .35s ease;
  max-width: 300px; font-size: 13px; border: 1px solid rgba(255,255,255,.08);
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-icon { font-size: 20px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,7,15,.65); display: flex; align-items: center; justify-content: center; z-index: 900; padding: 16px; }
.modal-box {
  background: #1c2138; border-radius: 16px; padding: 24px; max-width: 460px; width: 100%;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.55);
  animation: modal-in .25s ease;
}
@keyframes modal-in { from { transform: translateY(20px) scale(.96); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.modal-box h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.offline-earned { font-size: 30px; font-weight: 800; color: #ffd93d; text-align: center; text-shadow: 0 0 14px rgba(255,217,61,.6); }
.completion-modal { box-shadow: 0 0 40px rgba(255,217,61,.35), 0 20px 60px rgba(0,0,0,.55); border: 1px solid rgba(255,217,61,.4); }
.changelog-entry { margin-bottom: 14px; }
.changelog-entry h3 { margin-bottom: 4px; }
.changelog-entry small { opacity: .5; font-weight: 400; }
.changelog-entry ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; opacity: .85; }
.settings-list { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.settings-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; user-select: none; }
.settings-row input { accent-color: #7b5bf5; margin-top: 3px; }
.settings-row-text { display: flex; flex-direction: column; }
.settings-row-locked { opacity: .45; }
.settings-subhead { margin: 18px 0 4px; }
.settings-wide-btn { width: 100%; margin-top: 8px; }
.bv-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; max-height: 45vh; overflow-y: auto; }
.bv-row { gap: 6px; font-size: 13px; }
.bv-row input { margin-top: 1px; }
@media (max-width: 560px) { .bv-list { grid-template-columns: 1fr; } }
