* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  background: linear-gradient(180deg,
    var(--sky-top, #141126) 0%,
    var(--sky-mid, #1c1733) 45%,
    var(--sky-bottom, #251536) 100%);
  color: #cfc7e8;
  user-select: none;
  -webkit-user-select: none;
}
#app { height: 100%; max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
button {
  font-family: inherit; color: inherit; font-size: 15px;
  background: #241d40; border: 1px solid #4a3f6a; border-radius: 10px; padding: 12px 16px;
}
button:disabled { opacity: 0.4; }

/* タイトル */
#screen-title {
  justify-content: center; align-items: center; gap: 14px; text-align: center; padding: 24px;
  background: linear-gradient(180deg, #14112699 0%, #141126cc 55%, #141126f5 100%),
    url('../assets/title-bg.webp') center / cover no-repeat;
}
#screen-title h1 { font-size: 34px; letter-spacing: 10px; text-shadow: 0 0 18px #8a6cc9aa; }
.tagline { color: #8a7db0; font-size: 13px; letter-spacing: 3px; margin-bottom: 20px; }
.title-buttons { display: flex; flex-direction: column; gap: 10px; width: 70%; }
#title-virtue { color: #b3a5dd; font-size: 13px; }

/* ラン画面 */
#screen-run { position: relative; }
#ambience { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.fog {
  position: absolute; left: -50%; width: 200%; height: 45%;
  background: radial-gradient(ellipse 60% 50% at 50% 50%, #8a7db01c, transparent 70%);
  animation: fogdrift 70s ease-in-out infinite alternate;
}
.fog-a { top: 10%; }
.fog-b { top: 50%; animation-duration: 95s; animation-delay: -40s; }
@keyframes fogdrift { from { transform: translateX(-8%); } to { transform: translateX(8%); } }
.firefly {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #ffe9a8; box-shadow: 0 0 7px 2px #ffe9a855;
  opacity: 0; animation: fly 16s ease-in-out infinite;
}
.firefly:nth-of-type(1) { left: 12%; top: 68%; animation-delay: 0s; }
.firefly:nth-of-type(2) { left: 78%; top: 30%; animation-delay: 3s; }
.firefly:nth-of-type(3) { left: 30%; top: 45%; animation-delay: 6s; }
.firefly:nth-of-type(4) { left: 62%; top: 76%; animation-delay: 9s; }
.firefly:nth-of-type(5) { left: 46%; top: 20%; animation-delay: 12s; }
.firefly:nth-of-type(6) { left: 86%; top: 58%; animation-delay: 14s; }
@keyframes fly {
  0%, 100% { opacity: 0; transform: translate(0, 0); }
  12% { opacity: 0.9; }
  50% { opacity: 0.35; transform: translate(16px, -44px); }
  85% { opacity: 0.8; }
}
@media (prefers-reduced-motion: reduce) {
  .fog, .firefly { animation: none; opacity: 0; }
  .enemy-token { transition: none; }
}
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 8px;
  background: #12101fcc; border-bottom: 1px solid #3a2f5266; font-size: 13px;
}
#topbar small { color: #8a7db0; }
#lane { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; }
.gate {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 6px; border-radius: 8px; font-size: 13px; letter-spacing: 4px;
}
.art-gate { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; }
.gate.living { border: 1px solid #6e5a9e55; background: radial-gradient(ellipse at top, #4a3d7a44, transparent); }
.gate.nether { border: 1px solid #9e2a4a66; background: radial-gradient(ellipse at bottom, #7a1d3a55, transparent); }
.gate em { color: #d9788a; font-size: 11px; font-style: normal; letter-spacing: 1px; }
.slot { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: #241d40; }
.slot.empty {
  justify-content: center; background: #1d1836; border: 1px dashed #4a3f6a;
  color: #6b5f92; font-size: 12px; padding: 13px;
}
.slot .icon { font-size: 20px; filter: drop-shadow(0 0 8px #e8a44866); }
.slot .body { flex: 1; display: flex; flex-direction: column; font-size: 13px; }
.slot .body small { color: #8a7db0; font-size: 11px; }
.slot .cap { font-size: 11px; color: #8a7db0; }
.slot.b-work { box-shadow: 0 0 12px #e8a44822 inset; }
.slot.b-defense { box-shadow: 0 0 12px #7ec8e322 inset; }
.slot.b-send { box-shadow: 0 0 12px #d97ba822 inset; }
.slot.b-boost, .slot.b-support { box-shadow: 0 0 12px #8a6cc922 inset; }
.keep {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 8px;
  background: #2d2450; border: 1px solid #8a6cc966; font-size: 14px; letter-spacing: 3px;
}
.art-keep { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; box-shadow: 0 0 12px #8a6cc955; }
.keep-body { flex: 1; text-align: center; }
.keep .hp { height: 6px; border-radius: 3px; background: #1a1530; margin: 6px 18% 2px; overflow: hidden; }
.keep .hp i { display: block; height: 100%; background: linear-gradient(90deg, #8a6cc9, #d97ba8); }
.keep small { color: #b3a5dd; font-size: 11px; letter-spacing: 1px; }
.report {
  padding: 8px 12px; border-radius: 8px; background: #1d1836;
  border: 1px solid #4a3f6a88; font-size: 12px; color: #b3a5dd;
  display: flex; flex-direction: column; gap: 3px;
}
#actionbar {
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 14px);
  background: #12101fdd; border-top: 1px solid #3a2f5266; display: flex;
}
#btn-endnight {
  flex: 1; padding: 14px; font-size: 15px; letter-spacing: 3px;
  background: linear-gradient(135deg, #5a3d8a, #8a4d6e); border: none; border-radius: 12px;
  box-shadow: 0 0 16px #8a4d6e66;
}

/* ボトムシート */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto;
  background: #1c1733; border: 1px solid #4a3f6a; border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  z-index: 20; display: flex; flex-direction: column; gap: 8px;
  max-height: 70%; overflow-y: auto;
}
#sheet h3 { font-size: 15px; letter-spacing: 2px; }
#sheet h4 { font-size: 12px; color: #8a7db0; margin-top: 6px; }
.row { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; font-size: 13px; }
.row small { color: #8a7db0; flex: 1; }
.row span { color: #e8a448; font-size: 12px; white-space: nowrap; }
#btn-sheet-close { background: transparent; border: none; color: #8a7db0; }

/* 戦闘演出(レーン上) */
#lane { position: relative; }
.enemy-token {
  position: absolute; right: 22px; font-size: 22px; z-index: 6;
  opacity: 0; transition: top 0.45s ease, opacity 0.3s;
  filter: drop-shadow(0 0 8px #d9788a); pointer-events: none;
}
.token-die { animation: dissolve 0.5s forwards; }
@keyframes dissolve { to { opacity: 0; transform: scale(1.7); filter: blur(4px); } }
.gate-flash { box-shadow: 0 0 20px #d9788a88; }
.slot-flash { box-shadow: 0 0 20px #7ec8e3cc inset; }
.slot-shake { animation: shake 0.4s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.dmg-pop {
  position: absolute; right: 56px; font-size: 14px; color: #7ec8e3;
  z-index: 7; animation: popup 0.9s forwards; pointer-events: none;
}
.dmg-pop.loss { color: #d9788a; }
@keyframes popup { to { opacity: 0; transform: translateY(-26px); } }
.quake { animation: quake 0.4s; }
@keyframes quake {
  25% { transform: translate(3px, -3px); }
  50% { transform: translate(-3px, 2px); }
  75% { transform: translate(2px, 3px); }
}
.blackout { filter: brightness(0.35); transition: filter 1.2s; }
#battle-overlay {
  position: fixed; inset: 0; z-index: 30; pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 90px);
  background: linear-gradient(180deg, #0c0a18cc, transparent 25%, transparent 75%, #0c0a18cc);
}
#battle-banner {
  text-align: center; font-size: 14px; color: #d9c9f0;
  letter-spacing: 2px; text-shadow: 0 1px 6px #000;
}
#btn-skip { pointer-events: auto; align-self: flex-end; }

#fatal-toast {
  position: fixed; left: 8px; right: 8px;
  bottom: calc(env(safe-area-inset-bottom) + 8px); z-index: 99;
  background: #7a1d3aee; color: #ffdce5; font-size: 11px;
  padding: 8px 10px; border-radius: 8px; word-break: break-all;
}

/* 画像アセット(NBP素材) */
.art-icon { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; vertical-align: middle; }
.art-soul { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.art-token { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }

/* 遊び方 */
#help-body {
  flex: 1; overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 20px) 20px 12px;
}
#help-body h1 { font-size: 22px; letter-spacing: 6px; text-align: center; text-shadow: 0 0 14px #8a6cc9aa; margin-bottom: 18px; }
.help-sec { margin-bottom: 18px; padding: 12px 14px; border-radius: 10px; background: #1d183699; border: 1px solid #4a3f6a66; }
.help-sec h2 { font-size: 14px; letter-spacing: 2px; color: #d9c9f0; margin-bottom: 8px; }
.help-sec p { font-size: 13px; line-height: 1.9; color: #b3a5dd; }
.help-sec p + p { margin-top: 8px; }
.help-sec b { color: #e8d9a4; font-weight: 600; }
.help-note { font-size: 12px; color: #8a7db0; border-left: 2px solid #4a3f6a; padding-left: 8px; }
#help-foot { padding: 10px 20px calc(env(safe-area-inset-bottom) + 14px); display: flex; }
#btn-help-back { flex: 1; }

/* リザルト */
#screen-result { justify-content: center; align-items: center; gap: 12px; text-align: center; padding: 24px; }
#screen-result h1 { font-size: 22px; letter-spacing: 4px; text-shadow: 0 0 14px #8a6cc9aa; }
#result-body { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #b3a5dd; }
.unlock { color: #e8a448; }
