:root {
	--bg: #0b0c0f;
	--panel: rgba(18, 16, 20, 0.86);
	--panel-solid: #16141a;
	--line: rgba(255, 200, 140, 0.16);
	--text: #eadfcf;
	--muted: #a39887;
	--candle: #ffb050;
	--marsh: #8fd16a;
	--blood: #b0182c;
	--blood-bright: #e0334a;
	--moon: #c9d6ef;
	--display: 'Creepster', cursive;
	--serif: 'IM Fell English', Georgia, serif;
	--caps: 'IM Fell English SC', Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 17px/1.4 var(--serif);
	overflow: hidden;
}

button, input { font: inherit; color: inherit; }

.screen { position: fixed; inset: 0; }
.muted { color: var(--muted); }

.btn {
	background: linear-gradient(#2a2229, #1a1519);
	border: 1px solid var(--line);
	border-radius: 6px;
	padding: 8px 16px;
	cursor: pointer;
	font-family: var(--caps);
	letter-spacing: 0.03em;
	transition: border-color 0.15s, transform 0.1s, filter 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--candle); filter: brightness(1.2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: linear-gradient(#a3172c, #6d0e1d); border-color: #e0334a88; color: #fff3e6; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 14px; }
.btn.on { border-color: var(--marsh); color: var(--marsh); }
.link { background: none; border: 0; cursor: pointer; padding: 0; font-family: var(--caps); font-size: 19px; color: var(--candle); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 50%; width: 32px; height: 32px; cursor: pointer; }
.icon-btn.off { opacity: 0.4; text-decoration: line-through; }

input {
	background: #0e0d11;
	border: 1px solid var(--line);
	border-radius: 6px;
	padding: 8px 12px;
	outline: none;
}
input:focus { border-color: var(--candle); }

h1, h2 { font-weight: normal; margin: 0 0 12px; }
h2 { font-family: var(--caps); color: var(--candle); font-size: 22px; letter-spacing: 0.04em; }

/* ---------- title ---------- */
#title {
	display: grid;
	place-items: center;
	background: linear-gradient(rgba(5, 6, 10, 0.35), rgba(5, 6, 10, 0.85)), url(assets/images/keyart.webp) center / cover;
}
.title-card { text-align: center; padding: 24px; max-width: 520px; }
.title-card .logo { width: 150px; filter: drop-shadow(0 0 30px #8fd16a55); }
.title-card h1 {
	font-family: var(--display);
	font-size: clamp(48px, 9vw, 92px);
	color: var(--marsh);
	text-shadow: 0 0 24px #8fd16a66, 0 4px 0 #1a3010;
	margin: 0;
	line-height: 1;
}
.subtitle { font-style: italic; font-size: 20px; margin: 6px 0 24px; }
#title-form { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
#title-form input { width: 220px; }

/* ---------- hub ---------- */
#hub {
	display: flex;
	flex-direction: column;
	background: linear-gradient(rgba(8, 8, 12, 0.82), rgba(8, 8, 12, 0.95)), url(assets/images/keyart.webp) center / cover fixed;
}
.hub-bar {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 8px 20px;
	border-bottom: 1px solid var(--line);
	background: rgba(0, 0, 0, 0.4);
}
.hub-logo { width: 46px; }
.hub-title { font-family: var(--display); font-size: 32px; color: var(--marsh); flex: 1; white-space: nowrap; }
.hub-player { display: flex; align-items: center; gap: 18px; }
.level { display: flex; align-items: center; gap: 8px; font-family: var(--caps); }
.xpbar { width: 120px; height: 8px; background: #000a; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
#hub-xp { height: 100%; background: linear-gradient(90deg, #5c9a3a, var(--marsh)); width: 0; transition: width 0.6s; }
.coins { display: flex; align-items: center; gap: 6px; font-family: var(--caps); font-size: 20px; color: #e8d9b0; }
.coins img { width: 26px; }

.tabs { display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
	background: none;
	border: 1px solid transparent;
	border-bottom: 0;
	padding: 8px 16px;
	border-radius: 8px 8px 0 0;
	cursor: pointer;
	font-family: var(--caps);
	font-size: 17px;
	color: var(--muted);
	white-space: nowrap;
}
.tabs button.active { color: var(--candle); border-color: var(--line); background: var(--panel); }

.hub-body { flex: 1; display: flex; min-height: 0; }
.hub-body main { flex: 1; overflow-y: auto; padding: 20px; }
#party {
	width: 340px;
	border-left: 1px solid var(--line);
	background: var(--panel);
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	overflow-y: auto;
}

.missions { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 28px; }
.act-heading { grid-column: 1 / -1; margin: 12px 0 -4px; font-family: var(--caps); color: var(--candle); letter-spacing: 0.08em; }
.mission {
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 10px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	transition: transform 0.15s, border-color 0.15s;
}
.mission:not(.locked):hover { transform: translateY(-2px); border-color: var(--candle); }
.mission .art { position: relative; aspect-ratio: 3 / 2; background: #000 center / cover; }
.mission .art .num {
	position: absolute; top: 8px; left: 10px;
	font-family: var(--display); font-size: 30px; color: var(--marsh); text-shadow: 0 2px 6px #000;
}
.mission.boss .art .num { color: var(--blood-bright); }
.mission.locked .art { filter: grayscale(1) brightness(0.35); }
.mission .art .lock { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--caps); font-size: 18px; text-shadow: 0 2px 6px #000; }
.mission .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.mission h3 { margin: 0; font-family: var(--caps); font-weight: normal; font-size: 21px; color: var(--candle); }
.mission p { margin: 0; color: var(--muted); font-size: 15px; flex: 1; }
.mission .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.mission .meta .cleared { color: var(--marsh); }

.party-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.party-row {
	display: flex; align-items: center; gap: 12px;
	background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
}
.party-row .code { font-family: var(--caps); color: var(--candle); width: 54px; }
.party-row .who { flex: 1; color: var(--muted); font-size: 15px; }
.join-form { display: flex; gap: 8px; }
.join-form input { width: 100px; text-transform: uppercase; letter-spacing: 0.2em; }

.party-head { display: flex; justify-content: space-between; align-items: center; }
.party-head h2 { margin: 0; }
.party-mission { border-radius: 8px; overflow: hidden; position: relative; aspect-ratio: 3 / 1.4; background: center / cover; }
.party-mission span { position: absolute; bottom: 0; left: 0; right: 0; padding: 6px 10px; background: linear-gradient(transparent, #000c); font-family: var(--caps); }
.party-mission select { position: absolute; top: 6px; right: 6px; background: #000c; color: var(--text); border: 1px solid var(--line); border-radius: 4px; font: 14px var(--serif); }
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.members li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: #0006; border-radius: 6px; }
.members img { width: 36px; height: 44px; object-fit: contain; }
.members .name { flex: 1; }
.members .name small { display: block; color: var(--muted); font-size: 13px; }
.members .state { font-size: 13px; font-family: var(--caps); }
.members .state.ready { color: var(--marsh); }
.members .state.host { color: var(--candle); }
.party-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chat { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 120px; }
.chat-log { flex: 1; overflow-y: auto; font-size: 15px; background: #0006; border-radius: 6px; padding: 6px 8px; max-height: 260px; }
.chat-log p { margin: 2px 0; }
.chat-log b { color: var(--candle); font-weight: normal; }
.chat input { width: 100%; }

.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.class {
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px;
	display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
	cursor: pointer; transition: border-color 0.15s, transform 0.15s;
}
.class:hover { transform: translateY(-2px); }
.class.selected { border-color: var(--marsh); box-shadow: 0 0 24px #8fd16a33 inset; }
.class img { height: 240px; object-fit: contain; filter: drop-shadow(0 6px 12px #000); }
.class h3 { margin: 0; font-family: var(--caps); font-weight: normal; font-size: 24px; color: var(--candle); }
.class .role { color: var(--marsh); font-style: italic; }
.class p { margin: 0; color: var(--muted); font-size: 15px; }
.class dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; text-align: left; font-size: 14px; margin: 6px 0 0; }
.class dt { color: var(--candle); font-family: var(--caps); }
.class dd { margin: 0; }

.shop-intro { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; }
.shop-intro img { height: 160px; }
.shop-intro blockquote { margin: 0; font-style: italic; font-size: 18px; max-width: 560px; }
.shop-intro cite { display: block; color: var(--muted); font-size: 14px; margin-top: 6px; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.item {
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
	display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
}
.item.equipped { border-color: var(--marsh); }
.item img { width: 96px; height: 96px; filter: drop-shadow(0 4px 10px #000); }
.item h3 { margin: 0; font-family: var(--caps); font-weight: normal; font-size: 18px; color: var(--candle); }
.item .slot { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.item p { margin: 0; font-size: 15px; flex: 1; }
.item .price { display: flex; align-items: center; gap: 4px; font-family: var(--caps); }
.item .price img { width: 20px; height: 20px; }
.item .btn { margin-top: 6px; width: 100%; }

.help { max-width: 760px; }
.keys { display: grid; grid-template-columns: 180px 1fr; gap: 6px 16px; margin: 0 0 24px; }
.keys dt { font-family: var(--caps); color: var(--candle); }
.keys dd { margin: 0; }
.help li { margin-bottom: 6px; }

/* ---------- game ---------- */
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label {
	position: absolute; transform: translate(-50%, -100%); white-space: nowrap; text-align: center;
	font-family: var(--caps); font-size: 14px; text-shadow: 0 1px 3px #000, 0 0 2px #000;
}
.label .hpbar { width: 54px; height: 5px; background: #000b; margin: 2px auto 0; border-radius: 2px; overflow: hidden; }
.label .hpbar div { height: 100%; background: var(--blood-bright); }
.label.player .hpbar div { background: var(--marsh); }
.label.enemy { font-size: 12px; }
.label.shielded .hpbar { box-shadow: 0 0 0 1px #9fd0ff; }
.dmg {
	position: absolute; transform: translate(-50%, -50%); pointer-events: none;
	font-family: var(--display); font-size: 22px; color: #ffe08a; text-shadow: 0 2px 3px #000;
	animation: float-up 0.9s ease-out forwards;
}
.dmg.hurt { color: #ff5a5a; }
.dmg.heal { color: var(--marsh); }
@keyframes float-up { to { transform: translate(-50%, -160%); opacity: 0; } }

#song-tint { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.6s; background: radial-gradient(transparent 30%, rgba(110, 40, 160, 0.55)); }
#song-tint.on { opacity: 1; }
#hurt-flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(transparent 45%, rgba(200, 0, 20, 0.6)); transition: opacity 0.4s; }
#hurt-flash.on { opacity: 1; transition: none; }

.hud { position: absolute; inset: 0; pointer-events: none; }
.hud .bar { height: 10px; background: #000a; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; position: relative; }
.hud .bar > div { height: 100%; transition: width 0.15s; }

.objective {
	position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
	text-align: center; min-width: 320px; max-width: 70vw;
	background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 18px;
}
#objective-text { font-family: var(--caps); font-size: 19px; color: var(--candle); }
#objective-bar { margin-top: 6px; }
#objective-fill { background: linear-gradient(90deg, #c47a20, var(--candle)); }
#npc-bar { margin-top: 6px; height: 14px; }
#npc-bar span { position: absolute; left: 6px; top: -2px; font-size: 12px; z-index: 1; }
#npc-fill { background: linear-gradient(90deg, #5c9a3a, var(--marsh)); }

.boss-hud { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); width: min(640px, 80vw); text-align: center; }
#boss-name { font-family: var(--display); font-size: 30px; color: #d6e2ff; text-shadow: 0 0 16px #6a7fff; }
.boss-hud .bar { height: 16px; }
#boss-fill { background: linear-gradient(90deg, #6d0e1d, var(--blood-bright)); }
.boss-hud.shielded #boss-fill { background: linear-gradient(90deg, #4a6a9a, #a8d0ff); }

.party-frames { position: absolute; top: 14px; left: 14px; display: flex; flex-direction: column; gap: 6px; }
.frame { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px 4px 4px; width: 210px; }
.frame img { width: 34px; height: 40px; object-fit: contain; }
.frame .info { flex: 1; font-size: 14px; }
.frame .bar { height: 7px; }
.frame .bar div { background: var(--marsh); }
.frame.down { opacity: 0.6; }
.frame.down .bar div { background: var(--blood); }

.me {
	position: absolute; bottom: 16px; left: 16px; display: flex; gap: 10px; align-items: flex-end;
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px 10px 8px;
}
.me img { width: 80px; height: 100px; object-fit: contain; }
.me-body { width: 260px; display: flex; flex-direction: column; gap: 6px; }
#me-name { font-family: var(--caps); font-size: 18px; color: var(--candle); }
.bar.hp { height: 18px; }
#me-hp { background: linear-gradient(90deg, #3d7a2a, var(--marsh)); }
#me-hp-text { position: absolute; inset: 0; text-align: center; font-size: 13px; line-height: 16px; text-shadow: 0 1px 2px #000; }
.skills { display: flex; gap: 8px; }
.skill { position: relative; flex: 1; background: #000a; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 13px; overflow: hidden; }
.skill b { font-weight: normal; }
.skill .cd { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.7); transform-origin: left; transform: scaleX(0); }
.key { display: inline-block; font-family: var(--caps); font-size: 12px; border: 1px solid var(--muted); border-radius: 3px; padding: 0 4px; margin-right: 4px; color: var(--muted); }

.interact { position: absolute; left: 50%; top: 62%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; font-family: var(--caps); text-align: center; }
.interact .bar { margin-top: 4px; height: 6px; }
#interact-fill { background: var(--candle); }
.downed { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); font-family: var(--display); font-size: 34px; color: var(--blood-bright); text-shadow: 0 2px 8px #000; text-align: center; }

.toasts { position: absolute; top: 180px; right: 16px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.toast { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; font-size: 15px; animation: toast 4.5s forwards; }
.toast.big { font-family: var(--caps); font-size: 20px; color: var(--candle); }
@keyframes toast { 0% { opacity: 0; transform: translateX(20px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.game-chat { position: absolute; bottom: 150px; left: 16px; width: 360px; font-size: 15px; text-shadow: 0 1px 2px #000; }
.game-chat p { margin: 2px 0; animation: toast 9s forwards; }
.game-chat b { color: var(--candle); font-weight: normal; }
.game-chat-form { position: absolute; bottom: 140px; left: 16px; pointer-events: auto; }
.game-chat-form input { width: 360px; }

.lore {
	position: absolute; left: 50%; top: 30%; transform: translateX(-50%); width: min(720px, 86vw);
	text-align: center; font-style: italic; font-size: 26px; color: #f2e6cc; text-shadow: 0 2px 10px #000, 0 0 30px #000;
	animation: lore 7s forwards;
}
@keyframes lore { 0% { opacity: 0; } 10%, 85% { opacity: 1; } 100% { opacity: 0; } }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 5, 8, 0.72); z-index: 5; padding: 16px; }
.briefing-card { display: flex; max-width: 920px; width: 100%; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.briefing-card > img { width: 48%; object-fit: cover; }
.briefing-body { padding: 24px; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.briefing-body h2 { font-family: var(--display); font-size: 36px; color: var(--marsh); margin: 0; }
.host-line { display: flex; gap: 12px; align-items: flex-start; }
.host-line img { width: 72px; border-radius: 50%; border: 2px solid var(--blood); }
.host-line p { margin: 0; font-style: italic; font-size: 18px; }
.menu-card, .results-card, .loading-card { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; padding: 24px 28px; text-align: center; min-width: 320px; max-width: 640px; }
.menu-card { display: flex; flex-direction: column; gap: 10px; }
#results-title { font-family: var(--display); font-size: 48px; }
#results-title.win { color: var(--marsh); }
#results-title.lose { color: var(--blood-bright); }
.reward { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin: 14px 0; font-family: var(--caps); font-size: 20px; }
.reward .pill { display: flex; align-items: center; gap: 6px; background: #0008; border: 1px solid var(--line); border-radius: 20px; padding: 4px 14px; }
.reward .pill img { width: 26px; }
.reward .levelup { color: var(--marsh); }
.board { width: 100%; border-collapse: collapse; margin: 10px 0 18px; font-size: 15px; }
.board th, .board td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.board th { font-family: var(--caps); color: var(--muted); font-weight: normal; }
.spinner { width: 40px; height: 40px; margin: 0 auto 12px; border: 3px solid var(--line); border-top-color: var(--marsh); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #3a0d14; border: 1px solid var(--blood-bright); border-radius: 8px; padding: 8px 16px; z-index: 10; }

@media (max-width: 860px) {
	.hub-body { flex-direction: column; overflow-y: auto; }
	.hub-body main { overflow: visible; }
	#party { width: auto; border-left: 0; border-top: 1px solid var(--line); }
	.hub-title { display: none; }
	.briefing-card { flex-direction: column; }
	.briefing-card > img { width: 100%; max-height: 220px; }
	.party-frames, .game-chat { display: none; }
}
