:root {
  --bg: #0e0c0b;
  --panel: #191513;
  --panel2: #221c19;
  --line: #3a2f29;
  --text: #d9cfc3;
  --muted: #8a7d71;
  --ember: #c4572f;
  --ember2: #e0884f;
  --good: #8fae6a;
  --warn: #d0a447;
  --bad: #c0463e;
  --flash: #9fc3e6;
  --hp: #8e2b2b;
  --exp: #6b5a8e;
  --job: #a0743a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  font-size: 14px;
  line-height: 1.5;
}
header {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(#1c1512, var(--bg));
}
h1 { margin: 0; font-size: 22px; letter-spacing: .2em; color: var(--ember2); }
h2 { margin: 0 0 8px; font-size: 14px; color: var(--muted); letter-spacing: .15em; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
h3 { margin: 10px 0 6px; font-size: 13px; color: var(--ember2); }
#res { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
#res .r b { color: var(--warn); font-size: 16px; }
main {
  display: grid; grid-template-columns: 300px 1fr 380px; gap: 10px; padding: 10px 16px;
}
@media (max-width: 1050px) { main { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 10px; min-width: 0; }
#logpanel { margin: 0 16px 16px; }
#log { max-height: 180px; overflow-y: auto; font-size: 13px; }
#roster { max-height: 460px; overflow-y: auto; margin: 8px 0 14px; }

button {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 3px; padding: 4px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--ember); color: #fff; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: #3a1c12; border-color: var(--ember); }
button.on { background: #3a1c12; border-color: var(--ember2); color: #fff; }
button.small { padding: 1px 6px; font-size: 12px; }
button.danger { border-color: #6a2a26; }

.card {
  border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; margin-bottom: 5px;
  background: var(--panel2); cursor: pointer;
}
.card.sel { border-color: var(--ember2); }
.card.away { opacity: .6; }
.card .top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.card .name { font-weight: bold; }
.muted { color: var(--muted); }
.tag { font-size: 11px; padding: 0 5px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); }
.tag.wolf { color: var(--bad); border-color: var(--bad); }

.bar { height: 6px; background: #0a0807; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: var(--hp); }
.bar.exp > i { background: var(--exp); }
.bar.job > i { background: var(--job); }
.bar.enemy > i { background: #5b6b3a; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 12px; margin: 6px 0; }
.stats div { display: flex; justify-content: space-between; }
.stats b { color: #fff; }
.skill { padding: 3px 0; border-bottom: 1px dashed var(--line); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.skill .desc { color: var(--muted); font-size: 12px; }
.jobs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.jobs button { text-align: left; padding: 6px 8px; }
.jobs button small { display: block; color: var(--muted); font-size: 11px; }

.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.ex { border: 1px solid var(--line); border-radius: 3px; padding: 8px; margin-top: 10px; background: var(--panel2); }
.ex .exlog { font-size: 12px; margin-top: 6px; min-height: 90px; }
.member { display: grid; grid-template-columns: 90px 1fr 60px; gap: 6px; align-items: center; font-size: 12px; }

.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.flash { color: var(--flash); }
.story { color: var(--ember2); font-style: italic; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* ===== 影絵・戦闘シーン・墓地 ===== */
.tabs { display: flex; gap: 6px; margin-bottom: 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.who { display: inline-flex; align-items: flex-end; gap: 6px; }
.who .sil { margin: -6px 0 -4px; }
.portrait { float: right; margin: -4px 0 4px 8px; background: radial-gradient(circle at 50% 65%, #2c221d, transparent 70%); }
.sil { overflow: visible; }
.sil .glow { filter: drop-shadow(0 0 2px rgba(255, 170, 90, .9)); }
.sil .eye { filter: drop-shadow(0 0 1px rgba(255, 230, 180, .8)); }
.sil.dead { filter: grayscale(1) invert(.42) sepia(.15); opacity: .7; }

.stage {
  position: relative; display: flex; justify-content: space-between; align-items: flex-end;
  height: 162px; margin-top: 8px; padding: 0 10px 6px; border-radius: 3px; overflow: hidden;
  background: linear-gradient(#17110f, #241a16 72%, #120d0b 72%, #0d0a09);
}
.stage.st-village { background: linear-gradient(#24140f, #2e1b14 72%, #150d0a 72%, #0d0908); }
.stage.st-crypt   { background: linear-gradient(#0e1013, #1b1d22 72%, #0c0d10 72%, #08090a); }
.stage.st-mine    { background: linear-gradient(#120f0a, #241d12 72%, #100c08 72%, #0a0806); }
.stage::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(160, 150, 140, .5), transparent),
    radial-gradient(1px 1px at 65% 12%, rgba(160, 150, 140, .4), transparent),
    radial-gradient(1.5px 1.5px at 82% 55%, rgba(160, 150, 140, .35), transparent),
    radial-gradient(1px 1px at 42% 72%, rgba(160, 150, 140, .45), transparent);
  background-size: 110px 110px;
  animation: ash 12s linear infinite; animation-delay: var(--ash, 0s);
}
@keyframes ash { from { background-position: 0 0; } to { background-position: -55px 110px; } }
.stage .side { display: flex; gap: 2px; align-items: flex-end; z-index: 1; }

.unit { position: relative; display: flex; flex-direction: column; align-items: center; width: 56px; }
.unit.foe { width: auto; min-width: 76px; }
.unit .uname { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.unit.foe .uname { max-width: 110px; }
.unit .bar { width: 100%; height: 4px; margin-top: 1px; }
.unit .sil { transform-origin: 50% 100%; }
.unit.act .sil { animation: lunge .35s ease-out; }
.unit.foe.act .sil { animation: lungeL .35s ease-out; }
.unit.hit .sil, .unit.foe.hit .sil { animation: hit .4s; }
.unit.dead .sil { transform: rotate(-80deg) translate(-6px, 14px); filter: grayscale(1); opacity: .35; }
.unit.boss .uname { color: var(--bad); }
.unit.reveal .sil { animation: reveal 1s; }
.unit.scarred::before {
  content: '死線'; position: absolute; top: -2px; color: var(--bad); font-size: 11px; font-weight: bold; letter-spacing: .1em; text-shadow: 0 0 4px #000;
  animation: pop 1s forwards; z-index: 2;
}
@keyframes lunge  { 40% { transform: translateX(9px); } }
@keyframes lungeL { 40% { transform: translateX(-9px); } }
@keyframes hit {
  0%, 100% { transform: none; filter: none; }
  20% { transform: translateX(-3px); filter: brightness(2.2) drop-shadow(0 0 4px #c0463e); }
  50% { transform: translateX(2px); }
}
@keyframes reveal { 0% { filter: brightness(3) drop-shadow(0 0 8px #f2c23a); } 100% { filter: none; } }
@keyframes pop { 0% { opacity: 0; transform: scale(.4); } 30% { opacity: 1; transform: scale(1.4); } 100% { opacity: 0; transform: translateY(-10px); } }

.float {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: bold; color: #f0e2d2; text-shadow: 0 0 3px #000, 0 0 2px #000;
  pointer-events: none; opacity: 0; white-space: nowrap; z-index: 3;
  animation: float .9s ease-out forwards;
}
.float.heal { color: var(--good); }
.float.miss { color: var(--muted); font-size: 10px; }
.float.crit { color: var(--ember2); font-size: 15px; }
@keyframes float {
  0% { opacity: 0; transform: translate(-50%, 6px); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -24px); }
}

.grave { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.grave .stone {
  flex: none; width: 44px; height: 52px; display: flex; align-items: flex-end; justify-content: center;
  background: linear-gradient(#2c2622, #191412); border: 1px solid var(--line);
  border-radius: 22px 22px 2px 2px; overflow: hidden;
}
.grave .ep { font-style: italic; color: #b9ab99; font-size: 13px; }

/* 遠征の文字表示 */
.textview { margin-top: 6px; }
.exlog.long { min-height: 200px; border-top: 1px dashed var(--line); padding-top: 4px; }
.exlog .minor { color: var(--muted); }

/* 天賦 */
.tag.gift { color: #e6d296; border-color: #8a7a50; }
.sil.gifted { filter: drop-shadow(0 0 3px rgba(230, 210, 150, .55)); }
.sil.gifted.dead { filter: grayscale(1) invert(.42) sepia(.4) drop-shadow(0 0 2px rgba(230, 210, 150, .5)); }
.giftline { color: #e6d296; font-size: 13px; margin: 4px 0; }
.card .top > span:first-child { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card .top > span:last-child { flex: none; white-space: nowrap; display: inline-flex; gap: 3px; align-items: center; }

/* 今わの際 */
.exlog .lastword, #log .lastword { color: #d9b8a8; font-style: italic; }
.grave .lastword { color: #a8988a; font-size: 12px; }
.bubble {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-30%); z-index: 4;
  width: max-content; max-width: 170px; padding: 3px 7px; font-size: 11px; line-height: 1.4;
  color: #e8dccf; background: rgba(20, 14, 12, .92); border: 1px solid #5a3a32; border-radius: 4px;
  animation: bubble 5s forwards; pointer-events: none;
}
@keyframes bubble { 0% { opacity: 0; } 8% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* 常備隊 */
.order { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); }

/* 神の寝返り（灰が舞う） */
.absurd { color: #f0d070; font-weight: bold; }
.stage.absurd::before {
  content: ''; position: absolute; inset: 0; z-index: 5; pointer-events: none;
  background: #fff; animation: absurdflash .9s ease-out forwards;
}
@keyframes absurdflash { 0% { opacity: .85; } 100% { opacity: 0; } }
.fast { color: #8fb8a8; font-size: 12px; }

/* 世界の墓地 */
.worldstats { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; margin: 6px 0; }
.worldstats b { color: var(--text); }
.tag.absurd { color: #f0d070; border-color: #8a7840; }
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(5, 4, 3, .75); padding: 16px; }
.modalbox { max-width: 460px; background: var(--panel); border: 1px solid var(--ember); border-radius: 4px; padding: 16px 18px; }
.modalbox h3 { margin-top: 0; font-size: 16px; }
