@font-face { font-family: 'Fell'; src: url('../fonts/fell.woff2') format('woff2'); font-style: normal; font-display: swap; }
@font-face { font-family: 'Fell'; src: url('../fonts/fell-italic.woff2') format('woff2'); font-style: italic; font-display: swap; }
@font-face { font-family: 'Fell SC'; src: url('../fonts/fell-sc.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Pirata'; src: url('../fonts/pirata.woff2') format('woff2'); font-display: swap; }

:root {
  --ink: #0b0907;
  --ink-2: #14100c;
  --ink-3: #1d1812;
  --line: #3b3024;
  --line-2: #5a4a36;
  --bone: #e7dabd;
  --dim: #9c8d71;
  --faint: #6b5f4c;
  --rubric: #c7391f;
  --rubric-2: #8e2413;
  --gold: #cda653;
  --verd: #74ab98;
  --blood: #a3261a;
  --body: 'Fell', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --caps: 'Fell SC', 'Fell', Georgia, serif;
  --display: 'Pirata', 'Fell SC', 'Old English Text MT', serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--ink); color: var(--bone); overflow: hidden; }
body {
  font-family: var(--body); font-size: 17px; line-height: 1.35;
  background:
    radial-gradient(1200px 700px at 30% 20%, #1a140e 0%, transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,240,200,.012) 0 1px, transparent 1px 3px),
    var(--ink);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
::selection { background: var(--rubric); color: var(--bone); }

#app {
  position: relative; height: 100vh; padding: 12px; gap: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: minmax(0, 1fr) 118px auto;
  grid-template-areas: "view side" "log side" "roster roster";
}

/* ---------- framed panels ---------- */
#view, #mapbox, #cmd, #log, #roster {
  position: relative; background: var(--ink-2);
  border: 1px solid var(--line-2);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 4px var(--line), inset 0 0 40px rgba(0,0,0,.6);
}
#view { grid-area: view; overflow: hidden; background: #000; }
#side { grid-area: side; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
#log { grid-area: log; }
#roster { grid-area: roster; }

#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
#vignette { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, transparent 45%, rgba(0,0,0,.62) 100%);
  mix-blend-mode: multiply; }
#flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: #fff; }
#flash.on { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }
#view.shake { animation: shake .5s linear; }
@keyframes shake {
  0%,100% { transform: translate(0,0); } 15% { transform: translate(-7px,3px); } 30% { transform: translate(6px,-4px); }
  45% { transform: translate(-5px,-2px); } 60% { transform: translate(4px,3px); } 80% { transform: translate(-2px,1px); }
}
#view.toll::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 2px solid var(--gold); animation: toll 2.4s ease-out forwards; }
@keyframes toll { 0% { inset: 46%; opacity: .9; } 100% { inset: -12%; opacity: 0; } }

#banner {
  position: absolute; left: 0; right: 0; top: 18%; text-align: center; pointer-events: none;
  font-family: var(--display); font-size: clamp(34px, 5vw, 64px); letter-spacing: .03em;
  color: var(--bone); text-shadow: 0 2px 0 #000, 0 0 30px rgba(199,57,31,.7); opacity: 0;
}
#banner small { display: block; font-family: var(--caps); font-size: .3em; letter-spacing: .4em; color: var(--rubric); margin-bottom: .2em; }
#banner.show { animation: banner 3.6s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: translateY(12px); letter-spacing: .2em; } 18% { opacity: 1; transform: none; letter-spacing: .03em; } 75% { opacity: 1; } 100% { opacity: 0; } }

#foes { position: absolute; left: 0; right: 0; top: 10px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.foe { font-family: var(--caps); font-size: 15px; letter-spacing: .06em; padding: 3px 12px 4px;
  background: rgba(11,9,7,.78); border: 1px solid var(--line-2); color: var(--bone); }
.foe b { color: var(--rubric); font-weight: normal; margin-right: .35em; font-family: var(--display); font-size: 18px; }
.foe.hot { border-color: var(--gold); color: var(--gold); }
.foe i { color: var(--dim); font-family: var(--body); margin-left: .4em; }

/* ---------- movement pad ---------- */
#pad { position: absolute; right: 12px; bottom: 12px; display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; opacity: .5; transition: opacity .2s; }
#pad[hidden], #page:not([hidden]) ~ #pad { display: none; }
#pad:hover { opacity: 1; }
#pad button { height: 36px; border: 1px solid var(--line-2); background: rgba(11,9,7,.75); color: var(--bone); font-size: 17px; }
#pad button:hover { border-color: var(--gold); color: var(--gold); }
#pad button:active { background: var(--rubric-2); }

/* ---------- page overlay (town, prose, sheets) ---------- */
#page {
  position: absolute; inset: 0; overflow: auto; padding: clamp(18px, 3.2vw, 44px) clamp(20px, 4.5vw, 64px);
  background:
    radial-gradient(900px 500px at 85% 0%, rgba(199,57,31,.10), transparent 60%),
    radial-gradient(700px 500px at 0% 100%, rgba(116,171,152,.06), transparent 60%),
    linear-gradient(180deg, #17120d, #0d0a08);
  animation: pagein .35s ease;
}
#page[hidden] { display: none; }
#page.veil { background: linear-gradient(180deg, rgba(11,9,7,.72), rgba(11,9,7,.93) 55%); }
@keyframes pagein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
#page .kicker { font-family: var(--caps); letter-spacing: .34em; font-size: 13px; color: var(--rubric); text-transform: lowercase; }
#page h2 { font-family: var(--display); font-weight: normal; font-size: clamp(36px, 4.6vw, 62px); line-height: 1; margin: .1em 0 .35em; color: var(--bone); }
#page h2::after { content: ''; display: block; width: 120px; height: 5px; margin-top: 14px;
  border-top: 1px solid var(--rubric); border-bottom: 1px solid var(--line-2); }
#page .prose { max-width: 62ch; font-size: 19px; line-height: 1.5; }
#page .prose p { margin: 0 0 .85em; }
#page .prose p:first-child::first-letter { font-family: var(--display); font-size: 3.1em; float: left; line-height: .82; padding: .06em .1em 0 0; color: var(--rubric); }
#page .prose.plain p:first-child::first-letter { all: unset; }
#page .prose em { color: var(--gold); }
#page .prose .carved { font-family: var(--caps); letter-spacing: .12em; color: var(--verd); display: block; margin: .5em 0 .5em 1.2em; padding-left: .9em; border-left: 2px solid var(--line-2); }
#page .prose .said { color: #f3e9cf; }
#page .fin { font-family: var(--display); font-size: 54px; color: var(--rubric); margin-top: .4em; }
#page .names { font-family: var(--caps); letter-spacing: .1em; color: var(--dim); columns: 2; max-width: 46ch; margin: .6em 0 1em; }
#page .names.fade span { animation: namefade 6s ease forwards; display: block; }
@keyframes namefade { to { opacity: 0; filter: blur(4px); letter-spacing: .5em; } }

/* sheets and tables inside page */
.sheet { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px 34px; max-width: 900px; }
.sheet h3, .tbl-h { font-family: var(--caps); font-weight: normal; font-size: 14px; letter-spacing: .26em; color: var(--rubric); margin: 0 0 .5em; text-transform: lowercase; border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 1px 14px; }
.kv span:nth-child(odd) { color: var(--dim); }
.kv span:nth-child(even) { text-align: right; }
.muster { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; max-width: 980px; }
.muster .card { border: 1px solid var(--line); padding: 10px 14px 12px; background: rgba(0,0,0,.25); }
.muster .card.sel { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.muster .card h4 { margin: 0; font-family: var(--display); font-weight: normal; font-size: 27px; line-height: 1.1; }
.muster .card .sub { font-family: var(--caps); color: var(--rubric); letter-spacing: .12em; font-size: 14px; }
.muster .card .st { color: var(--dim); font-size: 15px; margin-top: 4px; }
.muster .card .row { font-family: var(--caps); font-size: 12px; letter-spacing: .2em; color: var(--faint); }
.goods { width: 100%; max-width: 640px; border-collapse: collapse; }
.goods td { padding: 2px 10px 2px 0; border-bottom: 1px dotted var(--line); }
.goods td:last-child { text-align: right; color: var(--gold); }
.goods .no { color: var(--faint); }

/* ---------- side: map ---------- */
#mapbox { padding: 8px 8px 0; }
#map { width: 100%; aspect-ratio: 1; display: block; background: #090705; image-rendering: pixelated; }
#where { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 4px 7px; font-family: var(--caps); letter-spacing: .1em; font-size: 15px; }
#where-dir { color: var(--rubric); font-family: var(--display); font-size: 21px; line-height: 1; }

/* ---------- side: command panel ---------- */
#cmd { flex: 1; min-height: 0; overflow: auto; padding: 12px 14px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
#cmd .m-title { font-family: var(--display); font-size: 27px; line-height: 1.05; color: var(--bone); }
#cmd .m-title::after { content: ''; display: block; height: 3px; margin: 7px 0 8px; border-top: 1px solid var(--rubric); border-bottom: 1px solid var(--line); }
#cmd .m-text { color: var(--dim); font-size: 16px; margin-bottom: 8px; font-style: italic; }
#cmd .opt { display: flex; width: 100%; text-align: left; gap: 9px; padding: 3px 6px 4px; border: 1px solid transparent; align-items: baseline; }
#cmd .opt .k { font-family: var(--caps); color: var(--rubric); min-width: 1.1em; text-align: center; }
#cmd .opt .l { flex: 1; }
#cmd .opt .h { color: var(--dim); font-size: 14px; white-space: nowrap; }
#cmd .opt.cur { border-color: var(--line-2); background: linear-gradient(90deg, rgba(199,57,31,.22), transparent); }
#cmd .opt.cur .l::after { content: ' ❧'; color: var(--rubric); }
#cmd .opt:disabled { color: var(--faint); cursor: default; }
#cmd .opt:disabled .k { color: var(--faint); }
#cmd .m-foot { margin-top: 10px; font-size: 13px; color: var(--faint); font-family: var(--caps); letter-spacing: .12em; }
#cmd input { width: 100%; font: inherit; font-size: 20px; color: var(--bone); background: #000; border: 1px solid var(--line-2); padding: 6px 9px; outline: none; }
#cmd input:focus { border-color: var(--gold); }
#cmd .keys { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 15px; }
#cmd .keys kbd { font-family: var(--caps); color: var(--gold); letter-spacing: .08em; }
#cmd .keys span { color: var(--dim); }
#cmd .keys button { text-align: left; color: var(--dim); }
#cmd .keys button:hover { color: var(--bone); }

/* ---------- log ---------- */
#log { overflow: hidden; padding: 8px 16px; display: flex; flex-direction: column; justify-content: flex-end; font-size: 16.5px; }
#log p { margin: 0; animation: logline .25s ease; }
#log p:not(:last-child) { color: var(--dim); }
#log p:nth-last-child(n+4) { color: var(--faint); }
#log .bad { color: #e2674f !important; }
#log .good { color: var(--verd) !important; }
#log .gold { color: var(--gold) !important; }
#log .lore { font-style: italic; color: #d9c9a3 !important; }
@keyframes logline { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }

/* ---------- roster ---------- */
#roster { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.pc { padding: 7px 12px 9px; border-right: 1px solid var(--line); position: relative; min-width: 0; text-align: left; }
.pc:last-child { border-right: 0; }
.pc:nth-child(4) { box-shadow: inset 3px 0 0 -1px var(--line-2); }
.pc .nm { font-family: var(--display); font-size: 22px; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc .cl { font-family: var(--caps); font-size: 12.5px; letter-spacing: .1em; color: var(--dim); display: flex; justify-content: space-between; }
.pc .cl b { font-weight: normal; color: var(--rubric); }
.pc .bar { height: 5px; background: #000; border: 1px solid var(--line); margin: 5px 0 3px; }
.pc .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--rubric-2), var(--rubric)); transition: width .3s; }
.pc .hp { font-size: 14px; display: flex; justify-content: space-between; color: var(--dim); }
.pc .hp b { font-weight: normal; color: var(--bone); }
.pc .st { font-family: var(--caps); letter-spacing: .1em; font-size: 12.5px; }
.pc .st.ok { color: var(--faint); } .pc .st.ill { color: #b6c35a; } .pc .st.dead { color: var(--blood); }
.pc .pips { color: var(--verd); font-size: 12px; letter-spacing: .05em; }
.pc.dead .nm { color: var(--faint); text-decoration: line-through; text-decoration-color: var(--blood); }
.pc.act { background: linear-gradient(180deg, rgba(205,166,83,.16), transparent 70%); }
.pc.act::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--gold); }
.pc.hit { animation: pchit .4s; }
@keyframes pchit { 0% { background: rgba(199,57,31,.7); } 100% { background: transparent; } }
.pc.heal { animation: pcheal .5s; }
@keyframes pcheal { 0% { background: rgba(116,171,152,.5); } 100% { background: transparent; } }
.pc.empty { color: var(--faint); font-style: italic; display: grid; place-items: center; }

/* ---------- title ---------- */
#title { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; text-align: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(11,9,7,.55) 0%, rgba(11,9,7,.93) 62%, var(--ink) 100%); }
#title[hidden] { display: none; }
.title-inner > * { animation: rise .9s both; }
.title-inner > :nth-child(2) { animation-delay: .15s; } .title-inner > :nth-child(3) { animation-delay: .35s; }
.title-inner > :nth-child(4) { animation-delay: .55s; } .title-inner > :nth-child(5) { animation-delay: .8s; }
.title-inner > :nth-child(6) { animation-delay: 1.1s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.title-kicker { font-family: var(--caps); letter-spacing: .5em; color: var(--rubric); font-size: 14px; text-transform: lowercase; }
#title h1 { font-family: var(--display); font-weight: normal; font-size: clamp(84px, 15vw, 190px); line-height: .88; margin: .04em 0 0;
  color: var(--bone); text-shadow: 0 0 60px rgba(199,57,31,.55), 0 4px 0 #000; letter-spacing: .01em; }
#title h1::first-letter { color: var(--rubric); }
.title-sub { font-style: italic; font-size: clamp(19px, 2.2vw, 27px); color: var(--gold); margin-top: .1em; }
.bell { width: 74px; margin: 20px auto 8px; display: block; color: var(--gold); overflow: visible; }
.bell-swing { transform-origin: 60px 8px; animation: swing 4.5s ease-in-out infinite; }
.clapper { transform-origin: 60px 60px; animation: swing 4.5s ease-in-out infinite reverse; }
@keyframes swing { 0%,100% { transform: rotate(-9deg); } 50% { transform: rotate(9deg); } }
#title-menu { display: inline-flex; flex-direction: column; gap: 2px; min-width: 300px; margin-top: 6px; }
#title-menu button { font-family: var(--caps); font-size: 21px; letter-spacing: .2em; padding: 6px 20px 8px; border: 1px solid transparent; color: var(--dim); text-transform: lowercase; }
#title-menu button.cur, #title-menu button:hover { color: var(--bone); border-color: var(--line-2); background: linear-gradient(90deg, transparent, rgba(199,57,31,.25), transparent); }
#title-menu button:disabled { color: var(--faint); }
.title-foot { margin-top: 26px; font-family: var(--caps); font-size: 12.5px; letter-spacing: .22em; color: var(--faint); }

@media (max-width: 1100px) {
  #app { grid-template-columns: minmax(0, 1fr) 270px; }
  body { font-size: 15.5px; }
  .pc .nm { font-size: 18px; }
}
@media (max-height: 760px) {
  #app { grid-template-rows: minmax(0, 1fr) 92px auto; padding: 8px; gap: 8px; }
  #mapbox { padding: 6px 6px 0; } #map { width: 62%; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; } }
