:root {
	--ink: #2b1d10;
	--parch: #f3e3bd;
	--parch-dark: #d8be86;
	--night: #1b1430;
	--night-2: #2a2147;
	--gold: #e8b23a;
	--ember: #b8321f;
	color-scheme: dark;
	font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--night); color: #f4ecdb; }
body { overflow: hidden; }

button, select, input {
	font: inherit;
	font-size: 0.95rem;
	border-radius: 8px;
	border: 1px solid #6b5230;
	padding: 0.45rem 0.8rem;
	background: #fff6df;
	color: var(--ink);
}
button { cursor: pointer; min-height: 40px; }
button:hover:not(:disabled) { filter: brightness(1.07); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: linear-gradient(#c8432a, #932313); border-color: #5c150b; color: #fff4dc; font-weight: bold; }
button.on { background: var(--gold); border-color: #7a5710; font-weight: bold; }
:focus-visible { outline: 3px solid #5fd0ff; outline-offset: 2px; }

.parchment {
	background: radial-gradient(circle at 30% 20%, #fbf0d3, var(--parch) 55%, var(--parch-dark));
	color: var(--ink);
}

/* ---------- title screen ---------- */
#title {
	height: 100dvh;
	overflow: auto;
	background: url("../assets/title.jpg") center / cover no-repeat;
	display: flex;
	justify-content: flex-end;
	align-items: flex-start;
	padding: 3vh 4vw;
}
.title-card {
	width: min(430px, 100%);
	margin: auto 0;
	padding: 1.2rem 1.4rem;
	border-radius: 14px;
	box-shadow: 0 12px 40px #0009;
}
.title-card h1 { margin: 0; font-size: 2.2rem; color: var(--ember); text-align: center; }
.tagline { text-align: center; margin: 0.3rem 0 1rem; }
.row { display: flex; gap: 0.6rem; align-items: center; }
.seat { display: grid; grid-template-columns: 14px 1fr 1.1fr; gap: 0.5rem; align-items: center; margin-top: 0.45rem; }
.seat input, .seat select { width: 100%; min-width: 0; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #0006; flex: none; }
.check { display: flex; gap: 0.5rem; align-items: center; margin: 0.8rem 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.error { color: var(--ember); font-weight: bold; }

dialog { border: 0; padding: 0; border-radius: 14px; width: min(620px, 94vw); max-height: 88dvh; }
dialog::backdrop { background: #000a; }
dialog > div { padding: 1rem 1.4rem; line-height: 1.45; }

/* ---------- picture guide: the buttons stay put, the middle scrolls ---------- */
#guide { width: min(640px, 94vw); max-height: 94dvh; overflow: hidden; }
#guide > div { display: flex; flex-direction: column; max-height: 94dvh; padding: 0.8rem 1rem; }
#guide header { display: flex; justify-content: space-between; align-items: baseline; gap: 0.8rem; }
#guide h2 { margin: 0 0 0.5rem; color: var(--ember); }
#guide-body { overflow: auto; min-height: 0; }
#guide-art { display: block; width: 100%; max-height: 46dvh; aspect-ratio: 480 / 270; margin: 0 auto; border-radius: 10px; background: var(--night); overflow: hidden; }
#guide-art .g-text { font-family: system-ui, sans-serif; font-weight: bold; text-anchor: middle; paint-order: stroke; stroke: #000a; stroke-width: 3px; stroke-linejoin: round; }
#guide-art .g-arrow { filter: drop-shadow(0 0 3px #000); }
#guide-lines { margin: 0.7rem 0 0.3rem; padding-left: 1.1rem; line-height: 1.4; }
#guide-lines li { margin-bottom: 0.25rem; }
#guide footer { display: flex; gap: 0.5rem; justify-content: flex-end; padding-top: 0.6rem; }
#guide-skip { margin-right: auto; }
@media (max-height: 520px) {
	#guide-art { max-height: 38dvh; width: auto; height: 38dvh; max-width: 100%; }
}

/* ---------- game screen ---------- */
#game { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: 100%; }
#viewport { position: relative; overflow: hidden; touch-action: none; background: #25395f; user-select: none; }
#stage { position: absolute; left: 0; top: 0; width: 1024px; height: 928px; transform-origin: 0 0; }
#stage > img:first-child { display: block; width: 1024px; height: 928px; }
#arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#arrow { stroke: #fff; stroke-width: 7; stroke-linecap: round; stroke-dasharray: 12 10; filter: drop-shadow(0 0 4px #000); animation: march 0.8s linear infinite; }
@keyframes march { to { stroke-dashoffset: -22; } }

.space {
	position: absolute;
	width: 40px;
	height: 40px;
	min-height: 0;
	margin: 8px 0 0 -20px; /* sit just under the printed name */
	padding: 0;
	border-radius: 50%;
	border: 3px solid #fff;
	background: var(--c, #333);
	color: #fff;
	font: bold 18px/1 system-ui, sans-serif;
	text-shadow: 0 1px 2px #000, 0 0 3px #000;
	box-shadow: 0 2px 6px #000a;
	transition: transform 0.15s;
}
/* the orc face fills the token; the number sits in the corner */
.space.orc { background: #fff url("../assets/orc.png") center / 175%; border-color: #111; border-radius: 8px; }
.space.orc .n { position: absolute; right: -9px; bottom: -8px; min-width: 20px; height: 20px; border-radius: 10px; background: #5d8f2c; border: 2px solid #fff; font-size: 13px; line-height: 16px; }
.space.empty { background: #0005; border: 2px dashed #fffa; }
.space .badges { position: absolute; top: -11px; left: 50%; transform: translateX(-50%); display: flex; gap: 2px; }
.space .badge { font: bold 11px/15px system-ui, sans-serif; width: 15px; border-radius: 4px; background: #fff6df; color: #111; text-shadow: none; }
.space .pips { position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); display: flex; gap: 2px; }
.space .pip { width: 20px; height: 11px; border-radius: 2px; background: #8fbf8a; border: 3px solid var(--t); box-shadow: 0 0 3px #000; }
.space .odds { position: absolute; left: 34px; top: 8px; font: bold 13px/1 system-ui, sans-serif; background: #111d; padding: 3px 5px; border-radius: 6px; white-space: nowrap; }
.space.shield { outline: 4px solid #6fe8ff; outline-offset: 1px; }
/* the ring shows even when the system asks for no animation */
.space.legal { animation: pulse 1.1s ease-in-out infinite; border-color: #fff36b; box-shadow: 0 0 0 5px #fff36b, 0 0 12px 8px #000c; z-index: 3; }
.space.from { box-shadow: 0 0 0 6px #fff36b, 0 0 18px 8px #fff36b; z-index: 4; }
.space.to { box-shadow: 0 0 0 6px #ff4d37, 0 0 18px 8px #ff4d37; z-index: 4; }
.space.hit { animation: hit 0.45s; }
@keyframes pulse { 50% { transform: scale(1.22); box-shadow: 0 0 0 5px #fff36bcc, 0 0 16px 8px #fff36b88; } }
@keyframes hit { 25% { transform: translateX(-6px) scale(1.2); } 55% { transform: translateX(6px) scale(1.2); } }

.beast { position: absolute; width: 38px; height: 36px; border-radius: 5px; border: 2px solid #111; box-shadow: 0 3px 8px #000c; pointer-events: none; transition: left 0.35s, top 0.35s; z-index: 5; }

#zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; }
#zoom button { width: 44px; height: 44px; font-size: 1.3rem; padding: 0; }
#toast { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); max-width: 92%; background: #1b1430ee; border: 1px solid var(--gold); border-radius: 10px; padding: 0.5rem 0.9rem; text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.25s; z-index: 10; }
#toast.show { opacity: 1; }

#panel { display: flex; flex-direction: column; min-height: 0; background: var(--night); border-left: 2px solid #000; }
#panel header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.5rem 0.6rem; background: var(--night-2); }
#phase { font-weight: bold; color: var(--gold); }
.tools { display: flex; gap: 0.3rem; }
.tools button, .tools select { min-height: 34px; padding: 0.2rem 0.55rem; }
#scroll { overflow: auto; padding: 0.6rem; display: flex; flex-direction: column; gap: 0.6rem; min-height: 0; }
.card { border-radius: 10px; padding: 0.7rem 0.8rem; background: var(--night-2); margin: 0; flex: none; }
#prompt.parchment { background: var(--parch); }
#prompt h2 { margin: 0 0 0.25rem; font-size: 1.15rem; }
#prompt p { margin: 0.2rem 0; line-height: 1.35; }
#prompt .buttons { margin-top: 0.6rem; }
#prompt .buttons.stack { flex-direction: column; align-items: stretch; }
#prompt .buttons.stack button { text-align: left; }
.stepper { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.stepper input[type="range"] { flex: 1; padding: 0; }

#battle { text-align: center; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.die { font-size: 3.4rem; line-height: 1; display: block; }
.die.hit { color: var(--gold); }
.die.miss { color: #8d86a8; }
.sides small { display: block; opacity: 0.85; }

#info h3 { margin: 0 0 0.2rem; font-size: 1rem; color: var(--gold); }
#info p { margin: 0.15rem 0; }

#players { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }
#players li { display: grid; grid-template-columns: 14px 1fr auto; gap: 0.15rem 0.5rem; align-items: center; padding: 0.25rem 0.3rem; border-radius: 6px; }
#players li.active { background: #ffffff1c; box-shadow: inset 3px 0 var(--gold); }
#players li.out { opacity: 0.4; text-decoration: line-through; }
#players .stats { grid-column: 2 / -1; font: 0.8rem system-ui, sans-serif; opacity: 0.85; }
#players .stars { color: var(--gold); letter-spacing: 2px; }

#log { padding-left: 0.8rem; list-style: none; font-size: 0.85rem; line-height: 1.35; }
#log li { padding: 0.2rem 0 0.2rem 0.55rem; border-left: 3px solid var(--c, transparent); margin-bottom: 2px; }
#log li:first-child { font-weight: bold; }

/* ---------- phones and narrow windows ---------- */
@media (max-width: 820px) {
	#title { background-position: left center; justify-content: center; padding: 12px; }
	.title-card { background: #f3e3bdf2; }
	#game { grid-template-columns: 100%; grid-template-rows: minmax(0, 52%) minmax(0, 48%); }
	#panel { border-left: 0; border-top: 2px solid #000; padding-bottom: env(safe-area-inset-bottom); }
	#zoom { flex-direction: row; bottom: 4px; right: 4px; }
	#zoom button { width: 38px; height: 38px; min-height: 0; }
}
@media (max-height: 520px) and (min-width: 600px) {
	#game { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: 100%; }
	#panel { border-top: 0; border-left: 2px solid #000; }
}
@media (prefers-reduced-motion: reduce) {
	.space, #arrow, .beast { animation: none !important; transition: none; }
}
