:root {
	/* Backgrounds */
	--bg-0: #0b0e12;
	--bg-1: #1f2428;
	--surface-muted: #6f757a;

	/* Text */
	--text-primary: #ede6d8;
	--text-dark: #0b0e12;

	/* Accents */
	--accent-primary: #e1b54b;
	--accent-cta: #d96a34;
	--accent-danger: #b74d3a;
	--accent-nega: #7fb96a;

	/* Utility */
	--glass-01: rgba(255, 255, 255, 0.03);
	--glass-02: rgba(255, 255, 255, 0.06);
	--border: rgba(255, 255, 255, 0.06);
	--border-light: rgba(255, 255, 255, 0.2);

	/* Card sizing */
	--card-w: 84px;
	--card-h: 120px;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	background-color: var(--bg-0);
	width: 100%;
	min-height: 100dvh;
	overflow-x: hidden;

	display: flex;
	flex-direction: column;
	align-items: center;

	font-family: "IBM Plex Mono", monospace;
}

/* ── Header ── */

header {
	width: 100%;
	max-width: 640px;
	display: flex;
	flex-direction: column;
	row-gap: 6px;
	justify-content: center;
	align-items: center;
	padding: 12px 16px;

	border-bottom: 1px solid #333;
}

header .logo {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	text-align: center;
}

header .logo h1 {
	letter-spacing: 6px;
	font-family: "New Rocker", system-ui;
	color: var(--accent-primary);
}

header .logo h4 {
	color: var(--text-primary);
	text-decoration: underline;
	font-size: clamp(11px, 3vw, 14px);
}

header .nav {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 4px 8px;
	width: 100%;
}

header .nav a,
header .nav button {
	background-color: transparent;
	color: var(--accent-primary);
	outline: none;
	border: none;
	text-decoration: underline;
	font-size: clamp(13px, 3.5vw, 16px);
	font-family: "Times New Roman", Times, serif;
	cursor: pointer;
	padding: 2px 4px;
}

/* ── Main ── */

main {
	width: 100%;
	max-width: 640px;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 0 12px;
	margin-top: 16px;
	gap: 12px;
}

/* ── Dungeon section ── */

.dungeon-container {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: center;
	gap: 10px;
	width: 100%;
}

.dungeon-card-container {
	display: flex;
	flex-direction: column;
	row-gap: 6px;
	align-items: center;
}

.dungeon-card-container h3 {
	padding-bottom: 3px;
	color: var(--accent-primary);
	text-align: center;
	border-bottom: 1px solid var(--accent-cta);
	width: 100%;
}

.dungeon-stats-bar {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	gap: 6px 12px;
	justify-content: center;
	align-items: center;
	color: var(--text-primary);
	font-size: 14px;
	width: 100%;
	padding: 6px 0;
	border-bottom: 1px solid var(--border);
	margin-bottom: 4px;
}

.dungeon-stats-bar strong {
	color: var(--accent-primary);
}

.stat-divider {
	color: var(--surface-muted);
}

/* ── Room ── */

.room-container {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	padding: 0 4px;
	/* no min-width — let it be fluid */
}

/* ── Cards ── */

.card {
	width: var(--card-w);
	height: var(--card-h);
	border: 1px solid var(--border);
	border-radius: 6px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background-color: var(--bg-1);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
	cursor: pointer;
	user-select: none;
	color: var(--text-primary);
	font-size: 24px;
	flex-shrink: 0;
}

.card-top {
	font-size: 18px;
	font-weight: 600;
}

.card-sub {
	font-size: 12px;
	color: #555;
	margin-top: 8px;
}

.card.monster {
	border-color: var(--accent-nega);
}

.card.potion {
	border-color: var(--accent-danger);
}

.card.weapon {
	border-color: var(--accent-primary);
}

.card.disabled {
	opacity: 0.45;
	pointer-events: none;
}

/* ── Player section ── */

.player-container {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: center;
	gap: 16px;
	width: 100%;
}

.player-info-container {
	display: flex;
	flex-direction: column;
	row-gap: 6px;
	min-width: 0;
}

.player-info-container h3 {
	padding-bottom: 3px;
	color: var(--accent-primary);
	text-align: center;
	border-bottom: 1px solid var(--accent-cta);
}

.equipped-item-container {
	flex: 1 1 200px;
}

.equipped-item {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	flex-wrap: wrap;
}

/* ── Weapon card ── */

.weapon-card {
	width: var(--card-w);
	height: var(--card-h);
	border: 1px solid var(--accent-primary);
	border-radius: 6px;
	background-color: var(--bg-1);
	color: var(--text-primary);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 24px;
	position: relative;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
	flex-shrink: 0;
}

.weapon-card .card-badge {
	position: absolute;
	top: 8px;
	font-size: 16px;
	padding: 4px 6px;
	border-radius: 6px;
	background: var(--surface-muted);
	color: var(--text-primary);
	font-weight: 700;
}

/* ── Weapon stack ── */

.weapon-stack {
	position: relative;
	width: var(--card-w);
	height: var(--card-h);
	margin-left: 12px;
	pointer-events: none;
	flex-shrink: 0;
}

.weapon-stack .chip {
	position: absolute;
	top: 6px;
	left: 0;
	width: var(--card-w);
	height: var(--card-h);
	border-radius: 6px;
	background: var(--bg-1);
	color: var(--text-primary);
	display: flex;
	align-items: flex-start;
	justify-content: flex-start;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
	border: 1px solid var(--accent-nega);
	transform-origin: left center;
	transition:
		transform 220ms cubic-bezier(0.2, 0.9, 0.25, 1),
		left 220ms;
	overflow: hidden;
}

.weapon-stack .chip .chip-rank {
	position: absolute;
	font-weight: 700;
	font-size: 14px;
	margin-left: 2px;
	color: var(--text-primary);
	pointer-events: none;
	line-height: 1;
}

.weapon-stack .chip .chip-rank--top {
	top: 6px;
	left: 6px;
}

.weapon-stack .chip .chip-rank--bottom {
	bottom: 6px;
	right: 6px;
	transform: rotate(180deg);
}

.weapon-stack .chip.just-added {
	animation: chipIn 260ms cubic-bezier(0.2, 0.9, 0.25, 1) forwards;
}

@keyframes chipIn {
	from {
		transform: translateY(8px) scale(0.98);
		opacity: 0;
	}
	to {
		transform: translateY(0) scale(1);
		opacity: 1;
	}
}

.weapon-empty {
	width: var(--card-w);
	height: var(--card-h);
	color: var(--text-primary);
	font-size: 14px;
	border-radius: 6px;
	background: none;
	border: 1px dashed var(--border-light);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
}

/* ── Player stats ── */

.player-stats {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	text-align: center;
}

.player-stats .health-row {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
}

#health {
	font-weight: 800;
	color: var(--accent-nega);
	font-size: 16px;
}

.player-stats span {
	color: var(--text-primary);
}

.player-health {
	display: flex;
	gap: 6px;
	align-items: center;
	flex-wrap: wrap;
	max-width: 180px;
	margin-top: 6px;
	justify-content: center;
}

.heart {
	width: 27px;
	height: 27px;
	background-size: contain;
	background-repeat: no-repeat;
	background-position: center;
	display: inline-block;
}

.moves-row {
	display: flex;
	gap: 8px;
	align-items: center;
	flex-wrap: wrap;
	justify-content: center;
	margin-top: 6px;
}

.move-token {
	width: 27px;
	height: 27px;
	background-size: contain;
	background-repeat: no-repeat;
	background-position: center;
	display: inline-block;
}

.moves-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 28px;
	height: 22px;
	padding: 0 6px;
	border-radius: 12px;
	background: linear-gradient(
		180deg,
		rgba(255, 255, 255, 0.03),
		rgba(255, 255, 255, 0.02)
	);
	border: 1px solid var(--border-light);
	color: var(--text-primary);
	font-weight: 700;
	font-size: 13px;
}

.player-stats .row {
	margin-top: 6px;
	color: var(--text-primary);
}

/* ── Controls ── */

.game-controls {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	column-gap: 6px;
	row-gap: 6px;
	justify-content: center;
	align-items: center;
	width: 100%;
}

.hints {
	font-size: 13px;
	color: var(--text-primary);
}

/* ── Popover ── */

#card-popover {
	position: fixed;
	z-index: 1200;
	background: var(--bg-1);
	border: 1px solid var(--border-light);
	border-radius: 8px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
	padding: 8px;
	display: flex;
	gap: 8px;
	color: var(--text-primary);
	/* prevent overflow on narrow screens */
	max-width: calc(100vw - 24px);
	flex-wrap: wrap;
}

#card-popover.hidden {
	display: none;
}

.popover-btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	cursor: pointer;
	user-select: none;
	appearance: none;
	padding: 8px 12px;
	font-weight: 700;
	font-size: 14px;
	line-height: 1;
	transition:
		transform 160ms cubic-bezier(0.2, 0.9, 0.25, 1),
		box-shadow 160ms cubic-bezier(0.2, 0.9, 0.25, 1),
		background-color 160ms;
	box-shadow: 0 6px 14px rgba(2, 6, 23, 0.06);
	color: var(--text-primary);
	background: linear-gradient(180deg, var(--bg-1), rgba(255, 255, 255, 0.02));
	border: 1px solid var(--accent-danger);
}

.popover-btn.primary {
	border-color: var(--accent-nega);
}

/* ── Modals ── */

.modal {
	position: fixed;
	inset: 0;
	display: grid;
	place-items: center;
	background: rgba(0, 0, 0, 0.55);
	z-index: 2000;
	padding: 16px;
}

.modal.hidden {
	display: none;
}

.modal .modal-content {
	background: var(--bg-1);
	border: 1px solid var(--border-light);
	padding: 18px;
	width: 100%;
	max-width: 420px;
	text-align: center;
	color: var(--text-primary);
	max-height: 90dvh;
	overflow-y: auto;
}

.modal-content h3 {
	font-size: clamp(18px, 5vw, 24px);
	font-family: "New Rocker", system-ui;
	text-decoration: underline;
	margin-bottom: 6px;
}

.modal .modal-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: center;
	margin-top: 12px;
}

/* ── Seed options ── */

.seed-options {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 6px;
}

.seed-options h4 {
	margin-bottom: 6px;
	text-decoration: underline;
}

.seed-options button {
	background-color: transparent;
	color: var(--accent-primary);
	outline: none;
	border: none;
	text-decoration: underline;
	font-size: 16px;
	font-family: "Times New Roman", Times, serif;
	cursor: pointer;
	padding-left: 6px;
}

.seed-options span {
	margin-top: 6px;
}

.seed-input {
	background-color: var(--bg-1);
	color: var(--text-primary);
	border: 1px solid var(--border);
	outline: none;
	padding: 4px 6px;
	font-size: 14px;
	max-width: 160px;
}

/* ── Buttons ── */

.default-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	cursor: pointer;
	user-select: none;
	appearance: none;
	border: 0;
	padding: 10px 16px;
	font-weight: 700;
	font-size: clamp(13px, 3.5vw, 14px);
	line-height: 1;
	transition:
		transform 160ms cubic-bezier(0.2, 0.9, 0.25, 1),
		box-shadow 160ms cubic-bezier(0.2, 0.9, 0.25, 1),
		background-color 160ms;
	box-shadow: 0 6px 14px rgba(2, 6, 23, 0.06);
	color: var(--text-primary);
	background: linear-gradient(180deg, var(--bg-1), rgba(255, 255, 255, 0.02));
	border: 1px solid var(--accent-primary);
}

.default-button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

/* ── History ── */

.history-list {
	text-align: left;
	max-height: 40dvh;
	overflow-y: auto;
	margin-top: 8px;
}

.history-ul {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.history-item {
	font-size: 13px;
	color: var(--text-primary);
	padding: 6px 8px;
	border: 1px solid var(--border);
	border-radius: 4px;
	cursor: pointer;
	line-height: 1.6;
	word-break: break-all;
}

.history-item:hover {
	border-color: var(--border-light);
}

.muted {
	color: var(--surface-muted);
	font-size: 12px;
}

/* ── Footer ── */

.footer {
	color: var(--text-primary);
	font-size: 13px;
	text-align: center;
	padding-bottom: 16px;
}

.footer a {
	color: var(--accent-primary);
}

/* ── Accessibility ── */

.visually-hidden,
.sr-only {
	position: absolute !important;
	left: -9999px;
	top: auto;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.info-label {
	font-size: 12px;
	color: #666;
	margin-left: 6px;
}

/* ── Responsive tweaks ── */

@media (max-width: 400px) {
	:root {
		--card-w: 72px;
		--card-h: 104px;
	}

	.card-top {
		font-size: 15px;
	}

	.weapon-card {
		font-size: 20px;
	}
}
